From 7d0f1f05042c1a536f50d6aab76c444eeb910195 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 25 Mar 2023 15:19:02 +0300 Subject: [PATCH] feat: undo/redo for kanban view stacked by Signed-off-by: mertmit --- .../smartsheet/toolbar/StackedBy.vue | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue b/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue index fc9079547a..3b64a2b48d 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/StackedBy.vue @@ -14,6 +14,7 @@ import { ref, useKanbanViewStoreOrThrow, useMenuCloseOnEsc, + useUndoRedo, useViewColumns, watch, } from '#imports' @@ -32,6 +33,8 @@ const { fields, loadViewColumns, metaColumnById } = useViewColumns(activeView, m const { kanbanMetaData, loadKanbanMeta, loadKanbanData, updateKanbanMeta, groupingField } = useKanbanViewStoreOrThrow() +const { addUndo } = useUndoRedo() + const open = ref(false) useMenuCloseOnEsc(open) @@ -46,16 +49,31 @@ watch( { immediate: true }, ) +const updateGroupingField = async (v: string) => { + await updateKanbanMeta({ + fk_grp_col_id: v, + }) + await loadKanbanMeta() + await loadKanbanData() + ;(activeView.value?.view as KanbanType).fk_grp_col_id = v +} + const groupingFieldColumnId = computed({ get: () => kanbanMetaData.value.fk_grp_col_id, set: async (val) => { if (val) { - await updateKanbanMeta({ - fk_grp_col_id: val, + addUndo({ + undo: { + fn: await updateGroupingField, + args: [kanbanMetaData.value.fk_grp_col_id], + }, + redo: { + fn: await updateGroupingField, + args: [val], + }, }) - await loadKanbanMeta() - await loadKanbanData() - ;(activeView.value?.view as KanbanType).fk_grp_col_id = val + + await updateGroupingField(val) } }, })