From 68434c63d79b250b140f457ea3d201c0e03e6666 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 12 Sep 2022 15:14:12 +0530 Subject: [PATCH] fix(gui): remove row if user is not saving record from expanded form Signed-off-by: Pranav C --- packages/nc-gui/components/smartsheet/Grid.vue | 15 +++++++++++---- packages/nc-gui/composables/useViewData.ts | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index f92b93351c..8beddeef37 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -91,7 +91,7 @@ const { deleteRow, deleteSelectedRows, selectedAllRecords, - removeLastEmptyRow, + removeRowIfNew, } = useViewData(meta, view as any, xWhere) const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view as any) @@ -113,15 +113,18 @@ reloadViewDataHook?.on(async () => { await loadData() }) -const expandForm = (row: Row, state?: Record) => { +const skipRowRemovalOnCancel = ref(false) + +const expandForm = (row: Row, state?: Record, fromToolbar = false) => { expandedFormRow.value = row expandedFormRowState.value = state expandedFormDlg.value = true + skipRowRemovalOnCancel.value = !fromToolbar } openNewRecordFormHook?.on(async () => { const newRow = await addEmptyRow() - expandForm(newRow) + expandForm(newRow, undefined, true) }) const selectCell = (row: number, col: number) => { @@ -576,7 +579,11 @@ onBeforeUnmount(async () => { :row="expandedFormRow" :state="expandedFormRowState" :meta="meta" - @cancel="removeLastEmptyRow" + @update:model-value=" + () => { + if (!skipRowRemovalOnCancel) removeRowIfNew(expandedFormRow) + } + " /> diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index c9422d59bc..1e0c7941e4 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -382,6 +382,14 @@ export function useViewData( } } + const removeRowIfNew = (row: Row) => { + const index = formattedData.value.indexOf(row) + + if (index > -1 && row.rowMeta.new) { + formattedData.value.splice(index, 1) + } + } + return { error, isLoading, @@ -408,5 +416,6 @@ export function useViewData( aggCommentCount, loadAggCommentsCount, removeLastEmptyRow, + removeRowIfNew, } }