From 44897b363bbb0cbab201b50b2270f6339162e004 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 16 Aug 2022 12:13:49 +0530 Subject: [PATCH] fix(gui-v2): handle linked row delete in proper way if it's a new record Signed-off-by: Pranav C --- .../virtual-cell/components/ListChildItems.vue | 8 +++++++- .../components/virtual-cell/components/ListItems.vue | 2 ++ packages/nc-gui-v2/composables/useLTARStore.ts | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue b/packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue index 187d536aef..a8e9fba8b6 100644 --- a/packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue +++ b/packages/nc-gui-v2/components/virtual-cell/components/ListChildItems.vue @@ -59,6 +59,12 @@ const unlinkRow = async (row: Record) => { } } +const unlinkIfNewRow = async (row: Record) => { + if (isNew.value) { + removeLTARRef(row, column?.value as ColumnType) + } +} + const container = computed(() => isForm?.value ? h('div', { @@ -112,7 +118,7 @@ const expandedFormRow = ref() /> diff --git a/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue b/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue index 241ad11770..00c8680f09 100644 --- a/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue +++ b/packages/nc-gui-v2/components/virtual-cell/components/ListItems.vue @@ -47,8 +47,10 @@ const linkRow = async (row: Record) => { vModel.value = false } +/** reload list on modal open */ watch(vModel, (nextVal, prevVal) => { if (nextVal && !prevVal) { + /** reset query and limit */ childrenExcludedListPagination.query = '' childrenExcludedListPagination.page = 1 loadChildrenExcludedList() diff --git a/packages/nc-gui-v2/composables/useLTARStore.ts b/packages/nc-gui-v2/composables/useLTARStore.ts index b89ab6896b..6904f9f43f 100644 --- a/packages/nc-gui-v2/composables/useLTARStore.ts +++ b/packages/nc-gui-v2/composables/useLTARStore.ts @@ -139,7 +139,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState( } } - const deleteRelatedRow = async (row: Record) => { + const deleteRelatedRow = async (row: Record, onSuccess?: (row: Record) => void) => { Modal.confirm({ title: 'Do you want to delete the record?', type: 'warning', @@ -148,7 +148,12 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState( try { $api.dbTableRow.delete(NOCO, project.value.id as string, relatedTableMeta.value.id as string, id as string) reloadData?.() - await loadChildrenList() + + /** reload child list if not a new row */ + if (!isNewRow?.value) { + await loadChildrenList() + } + onSuccess?.(row) } catch (e: any) { message.error(`Delete failed: ${await extractSdkResponseErrorMsg(e)}`) }