From 7a2d2279ca2038fc90706ab2f6d0be9f95e7d24d Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 1 Sep 2022 21:52:18 +0800 Subject: [PATCH 1/2] fix(gui-v2): missing data in quick import after renaming table --- .../nc-gui-v2/components/template/Editor.vue | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/template/Editor.vue b/packages/nc-gui-v2/components/template/Editor.vue index 512a094783..87c87c612c 100644 --- a/packages/nc-gui-v2/components/template/Editor.vue +++ b/packages/nc-gui-v2/components/template/Editor.vue @@ -128,9 +128,16 @@ const isValid = computed(() => { return true }) +const prevEditableTn = ref([]) + onMounted(() => { parseAndLoadTemplate() + // used to record the previous EditableTn values + // for checking the table duplication in current import + // and updating the key in importData + prevEditableTn.value = data.tables.map((t) => t.ref_table_name) + nextTick(() => { inputRefs.value[0]?.focus() }) @@ -508,6 +515,22 @@ onMounted(() => { mapDefaultColumns() } }) + +function handleEditableTnChange(idx: number) { + const oldValue = prevEditableTn.value[idx] + const newValue = data.tables[idx].ref_table_name + if (data.tables.filter((t) => t.ref_table_name === newValue).length > 1) { + message.warn('Duplicate Table Name') + data.tables[idx].ref_table_name = oldValue + } else { + prevEditableTn.value[idx] = newValue + if (oldValue != newValue) { + // update the key name of importData + delete Object.assign(importData, { [newValue]: importData[oldValue] })[oldValue] + } + } + setEditableTn(idx, false) +}