Browse Source

feat(nc-gui): validate each table after pre-import

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
5e412f15a5
  1. 97
      packages/nc-gui/components/template/Editor.vue

97
packages/nc-gui/components/template/Editor.vue

@ -290,8 +290,6 @@ function fieldsValidation(record: Record<string, any>) {
return true return true
} }
const tableName = meta.value?.title || ''
if (!record.destCn) { if (!record.destCn) {
message.error(`${t('msg.error.columnDescriptionNotFound')} ${record.srcCn}`) message.error(`${t('msg.error.columnDescriptionNotFound')} ${record.srcCn}`)
return false return false
@ -304,63 +302,62 @@ function fieldsValidation(record: Record<string, any>) {
const v = columns.value.find((c) => c.title === record.destCn) as Record<string, any> const v = columns.value.find((c) => c.title === record.destCn) as Record<string, any>
// check if the input contains null value for a required column for (const tableName of Object.keys(importData)) {
if (v.pk ? !v.ai && !v.cdf : !v.cdf && v.rqd) { // check if the input contains null value for a required column
if ( if (v.pk ? !v.ai && !v.cdf : !v.cdf && v.rqd) {
importData[tableName]
.slice(0, maxRowsToParse)
.some((r: Record<string, any>) => r[record.srcCn] === null || r[record.srcCn] === undefined || r[record.srcCn] === '')
) {
message.error(t('msg.error.nullValueViolatesNotNull'))
}
}
switch (v.uidt) {
case UITypes.Number:
if ( if (
importData[tableName] importData[tableName]
.slice(0, maxRowsToParse) .slice(0, maxRowsToParse)
.some( .some((r: Record<string, any>) => r[record.srcCn] === null || r[record.srcCn] === undefined || r[record.srcCn] === '')
(r: Record<string, any>) => r[record.sourceCn] !== null && r[record.srcCn] !== undefined && isNaN(+r[record.srcCn]),
)
) { ) {
message.error(t('msg.error.sourceHasInvalidNumbers')) message.error(t('msg.error.nullValueViolatesNotNull'))
return false
} }
}
break switch (v.uidt) {
case UITypes.Checkbox: case UITypes.Number:
if ( if (
importData[tableName].slice(0, maxRowsToParse).some((r: Record<string, any>) => { importData[tableName]
if (r[record.srcCn] !== null && r[record.srcCn] !== undefined) { .slice(0, maxRowsToParse)
let input = r[record.srcCn] .some(
if (typeof input === 'string') { (r: Record<string, any>) => r[record.sourceCn] !== null && r[record.srcCn] !== undefined && isNaN(+r[record.srcCn]),
input = input.replace(/["']/g, '').toLowerCase().trim() )
return !( ) {
input === 'false' || message.error(t('msg.error.sourceHasInvalidNumbers'))
input === 'no' || return false
input === 'n' || }
input === '0' ||
input === 'true' ||
input === 'yes' ||
input === 'y' ||
input === '1'
)
}
return input !== 1 && input !== 0 && input !== true && input !== false break
} case UITypes.Checkbox:
if (
importData[tableName].slice(0, maxRowsToParse).some((r: Record<string, any>) => {
if (r[record.srcCn] !== null && r[record.srcCn] !== undefined) {
let input = r[record.srcCn]
if (typeof input === 'string') {
input = input.replace(/["']/g, '').toLowerCase().trim()
return !(
input === 'false' ||
input === 'no' ||
input === 'n' ||
input === '0' ||
input === 'true' ||
input === 'yes' ||
input === 'y' ||
input === '1'
)
}
return input !== 1 && input !== 0 && input !== true && input !== false
}
return false
})
) {
message.error(t('msg.error.sourceHasInvalidBoolean'))
return false return false
}) }
) { break
message.error(t('msg.error.sourceHasInvalidBoolean')) }
return false
}
break
} }
return true return true
} }
@ -541,7 +538,7 @@ function mapDefaultColumns() {
for (const col of importColumns[0]) { for (const col of importColumns[0]) {
const o = { srcCn: col.column_name, destCn: '', enabled: true } const o = { srcCn: col.column_name, destCn: '', enabled: true }
if (columns.value) { if (columns.value) {
const tableColumn = columns.value.find((c: Record<string, any>) => c.title === col.column_name) const tableColumn = columns.value.find((c) => c.column_name === col.column_name)
if (tableColumn) { if (tableColumn) {
o.destCn = tableColumn.title as string o.destCn = tableColumn.title as string
} else { } else {

Loading…
Cancel
Save