From 507780a09862f55bd8d97bfe6c3d6aee2e78cf6e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Fri, 14 Oct 2022 17:02:44 +0530 Subject: [PATCH] fix(gui): wait until inserting record to avoid duplicate row insertion Signed-off-by: Pranav C --- packages/nc-gui/components/smartsheet/Grid.vue | 2 +- packages/nc-gui/composables/useViewData.ts | 8 ++++++-- .../index/index/[type]/[title]/[[viewTitle]].vue | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 5f3ad8fdd4..616c2c3c47 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -705,7 +705,7 @@ watch( .nc-expand { &:not(.nc-comment) { - //@apply hidden; + @apply hidden; } &.nc-comment { diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index d8b4093fab..853f9d01ab 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -11,6 +11,7 @@ import { message, populateInsertObject, ref, + until, useApi, useGlobal, useI18n, @@ -224,8 +225,8 @@ export function useViewData( insertObj, ) - formattedData.value?.splice(rowIndex ?? 0, 1, { - row: insertedData, + Object.assign(formattedData.value[rowIndex], { + row: { ...insertedData, ...row }, rowMeta: { ...row.rowMeta, new: undefined }, oldRow: { ...insertedData }, }) @@ -287,6 +288,9 @@ export function useViewData( ltarState?: Record, args: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, ) { + // if new row and save is in progress then wait until the save is complete + await until(() => !(row.rowMeta.new && row.rowMeta.saving)).toMatch((v) => v) + if (row.rowMeta.new) { return await insertRow(row.row, formattedData.value.indexOf(row), ltarState, args) } else { diff --git a/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue b/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue index 8bee4c0dbc..71ddda5dcb 100644 --- a/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue +++ b/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue @@ -32,7 +32,7 @@ watch(