Browse Source

fix(nc-gui): infinite import validation errors

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
4f731a8887
  1. 28
      packages/nc-gui/components/template/Editor.vue

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

@ -123,12 +123,16 @@ const validators = computed(() =>
const { validate, validateInfos } = useForm(data, validators) const { validate, validateInfos } = useForm(data, validators)
// TODO(import): show error message once const isValid = ref(false)
const isValid = computed(() => {
watch(
() => srcDestMapping.value,
() => {
let res = true
if (importDataOnly) { if (importDataOnly) {
for (const tn of Object.keys(srcDestMapping.value)) { for (const tn of Object.keys(srcDestMapping.value)) {
if (!atLeastOneEnabledValidation(tn)) { if (!atLeastOneEnabledValidation(tn)) {
return false res = false
} }
for (const record of srcDestMapping.value[tn]) { for (const record of srcDestMapping.value[tn]) {
if (!fieldsValidation(record, tn)) { if (!fieldsValidation(record, tn)) {
@ -140,13 +144,15 @@ const isValid = computed(() => {
for (const [_, o] of Object.entries(validateInfos)) { for (const [_, o] of Object.entries(validateInfos)) {
if (o?.validateStatus) { if (o?.validateStatus) {
if (o.validateStatus === 'error') { if (o.validateStatus === 'error') {
return false res = false
} }
} }
} }
} }
return true isValid.value = res
}) },
{ deep: true },
)
const prevEditableTn = ref<string[]>([]) const prevEditableTn = ref<string[]>([])
@ -158,6 +164,10 @@ onMounted(() => {
// and updating the key in importData // and updating the key in importData
prevEditableTn.value = data.tables.map((t) => t.table_name) prevEditableTn.value = data.tables.map((t) => t.table_name)
if (importDataOnly) {
mapDefaultColumns()
}
nextTick(() => { nextTick(() => {
inputRefs.value[0]?.focus() inputRefs.value[0]?.focus()
}) })
@ -569,12 +579,6 @@ defineExpose({
isValid, isValid,
}) })
onMounted(() => {
if (importDataOnly) {
mapDefaultColumns()
}
})
function handleEditableTnChange(idx: number) { function handleEditableTnChange(idx: number) {
const oldValue = prevEditableTn.value[idx] const oldValue = prevEditableTn.value[idx]
const newValue = data.tables[idx].table_name const newValue = data.tables[idx].table_name

Loading…
Cancel
Save