Browse Source

fix(nc-gui): validation logic

pull/4519/head
Wing-Kam Wong 2 years ago
parent
commit
d2bcf4ace2
  1. 8
      packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts
  2. 16
      packages/nc-gui/utils/parsers/parserHelpers.ts

8
packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts

@ -132,15 +132,15 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
if (column.uidt === UITypes.SingleLineText) {
// check for long text
if (isMultiLineTextType(rows)) {
if (isMultiLineTextType(rows, col)) {
column.uidt = UITypes.LongText
}
if (isEmailType(rows)) {
if (isEmailType(rows, col)) {
column.uidt = UITypes.Email
}
if (isUrlType(rows)) {
if (isUrlType(rows, col)) {
column.uidt = UITypes.URL
} else {
const vals = rows
@ -148,7 +148,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
.map((r: any) => r[col])
.filter((v: any) => v !== null && v !== undefined && v.toString().trim() !== '')
const checkboxType = isCheckboxType(vals)
const checkboxType = isCheckboxType(vals, col)
if (checkboxType.length === 1) {
column.uidt = UITypes.Checkbox
} else {

16
packages/nc-gui/utils/parsers/parserHelpers.ts

@ -20,11 +20,11 @@ const booleanOptions = [
]
const aggBooleanOptions: any = booleanOptions.reduce((obj, o) => ({ ...obj, ...o }), {})
const getColVal = (row: any, col = null) => {
const getColVal = (row: any, col?: number) => {
return row && col ? row[col] : row
}
export const isCheckboxType: any = (values: [], col = null) => {
export const isCheckboxType: any = (values: [], col?: number) => {
let options = booleanOptions
for (let i = 0; i < values.length; i++) {
const val = getColVal(values[i], col)
@ -45,7 +45,7 @@ export const getCheckboxValue = (value: any) => {
return value && aggBooleanOptions[value]
}
export const isMultiLineTextType = (values: [], col = null) => {
export const isMultiLineTextType = (values: [], col?: number) => {
return values.some(
(r) => (getColVal(r, col) || '').toString().match(/[\r\n]/) || (getColVal(r, col) || '').toString().length > 255,
)
@ -107,13 +107,15 @@ export const isDecimalType = (colData: []) =>
return v && parseInt(v) !== +v
})
export const isEmailType = (colData: []) =>
colData.some((v: any) => {
export const isEmailType = (colData: [], col?: number) =>
colData.some((r: any) => {
const v = getColVal(r, col)
return v && validateEmail(v)
})
export const isUrlType = (colData: []) =>
colData.some((v: any) => {
export const isUrlType = (colData: [], col?: number) =>
colData.some((r: any) => {
const v = getColVal(r, col)
return v && isValidURL(v)
})

Loading…
Cancel
Save