From 2de2a2852f556e15d08918c559806689edad29e1 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 28 Mar 2023 00:59:32 +0300 Subject: [PATCH] fix: kanban undo/redo card insert Signed-off-by: mertmit --- .../composables/useExpandedFormStore.ts | 21 +++++++++---------- .../nc-gui/composables/useKanbanViewStore.ts | 12 +++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.ts index 4b521ed111..98e5769445 100644 --- a/packages/nc-gui/composables/useExpandedFormStore.ts +++ b/packages/nc-gui/composables/useExpandedFormStore.ts @@ -160,23 +160,28 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m data = await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, insertObj) + Object.assign(row.value, { + row: data, + rowMeta: {}, + oldRow: { ...data }, + }) + if (!undo) { const id = extractPkFromRow(data, meta.value?.columns as ColumnType[]) + const pkData = rowPkData(row.value.row, meta.value?.columns as ColumnType[]) // TODO remove linked record addUndo({ redo: { - fn: async function redo(this: UndoRedoAction, row: Row) { - const pkData = rowPkData(row.row, meta.value?.columns as ColumnType[]) - row.row = { ...pkData, ...row.row } - await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, row.row) + fn: async function redo(this: UndoRedoAction, rowData: any) { + await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, { ...pkData, ...rowData }) if (activeView.value?.type === ViewTypes.KANBAN) { const { loadKanbanData } = useKanbanViewStoreOrThrow() await loadKanbanData() } reloadTrigger?.trigger() }, - args: [clone(row.value)], + args: [clone(insertObj)], }, undo: { fn: async function undo(this: UndoRedoAction, id: string) { @@ -201,12 +206,6 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m scope: defineViewScope({ view: activeView.value }), }) } - - Object.assign(row.value, { - row: data, - rowMeta: {}, - oldRow: { ...data }, - }) } else { const updateOrInsertObj = [...changedColumns.value].reduce((obj, col) => { obj[col] = row.value.row[col] diff --git a/packages/nc-gui/composables/useKanbanViewStore.ts b/packages/nc-gui/composables/useKanbanViewStore.ts index e2fa224ac0..048663706f 100644 --- a/packages/nc-gui/composables/useKanbanViewStore.ts +++ b/packages/nc-gui/composables/useKanbanViewStore.ts @@ -369,14 +369,14 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState( }, scope: defineViewScope({ view: viewMeta.value as ViewType }), }) - - formattedData.value.get(null)?.splice(rowIndex ?? 0, 1, { - row: insertedData, - rowMeta: {}, - oldRow: { ...insertedData }, - }) } + formattedData.value.get(null)?.splice(rowIndex ?? 0, 1, { + row: insertedData, + rowMeta: {}, + oldRow: { ...insertedData }, + }) + return insertedData } catch (error: any) { message.error(await extractSdkResponseErrorMsg(error))