Browse Source

fix: kanban undo/redo card insert

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
2de2a2852f
  1. 21
      packages/nc-gui/composables/useExpandedFormStore.ts
  2. 12
      packages/nc-gui/composables/useKanbanViewStore.ts

21
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) 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) { if (!undo) {
const id = extractPkFromRow(data, meta.value?.columns as ColumnType[]) const id = extractPkFromRow(data, meta.value?.columns as ColumnType[])
const pkData = rowPkData(row.value.row, meta.value?.columns as ColumnType[])
// TODO remove linked record // TODO remove linked record
addUndo({ addUndo({
redo: { redo: {
fn: async function redo(this: UndoRedoAction, row: Row) { fn: async function redo(this: UndoRedoAction, rowData: any) {
const pkData = rowPkData(row.row, meta.value?.columns as ColumnType[]) await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, { ...pkData, ...rowData })
row.row = { ...pkData, ...row.row }
await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, row.row)
if (activeView.value?.type === ViewTypes.KANBAN) { if (activeView.value?.type === ViewTypes.KANBAN) {
const { loadKanbanData } = useKanbanViewStoreOrThrow() const { loadKanbanData } = useKanbanViewStoreOrThrow()
await loadKanbanData() await loadKanbanData()
} }
reloadTrigger?.trigger() reloadTrigger?.trigger()
}, },
args: [clone(row.value)], args: [clone(insertObj)],
}, },
undo: { undo: {
fn: async function undo(this: UndoRedoAction, id: string) { fn: async function undo(this: UndoRedoAction, id: string) {
@ -201,12 +206,6 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
scope: defineViewScope({ view: activeView.value }), scope: defineViewScope({ view: activeView.value }),
}) })
} }
Object.assign(row.value, {
row: data,
rowMeta: {},
oldRow: { ...data },
})
} else { } else {
const updateOrInsertObj = [...changedColumns.value].reduce((obj, col) => { const updateOrInsertObj = [...changedColumns.value].reduce((obj, col) => {
obj[col] = row.value.row[col] obj[col] = row.value.row[col]

12
packages/nc-gui/composables/useKanbanViewStore.ts

@ -369,14 +369,14 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
}, },
scope: defineViewScope({ view: viewMeta.value as ViewType }), 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 return insertedData
} catch (error: any) { } catch (error: any) {
message.error(await extractSdkResponseErrorMsg(error)) message.error(await extractSdkResponseErrorMsg(error))

Loading…
Cancel
Save