From c5b1a25581e1c693ce1d8270db86c27f855bd49f Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 25 Mar 2023 00:26:49 +0300 Subject: [PATCH] feat: undo/redo grid menu actions Signed-off-by: mertmit --- .../components/smartsheet/header/Menu.vue | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/components/smartsheet/header/Menu.vue b/packages/nc-gui/components/smartsheet/header/Menu.vue index 457c6046cf..0de1a9a24a 100644 --- a/packages/nc-gui/components/smartsheet/header/Menu.vue +++ b/packages/nc-gui/components/smartsheet/header/Menu.vue @@ -20,6 +20,7 @@ import { useSmartsheetStoreOrThrow, useUndoRedo, } from '#imports' +import { UndoRedoAction } from '~~/lib'; const { virtual = false } = defineProps<{ virtual?: boolean }>() @@ -122,11 +123,37 @@ const setAsDisplayValue = async () => { const sortByColumn = async (direction: 'asc' | 'desc') => { try { $e('a:sort:add', { from: 'column-menu' }) - await $api.dbTableSort.create(view.value?.id as string, { + const data: any = await $api.dbTableSort.create(view.value?.id as string, { fk_column_id: column!.value.id, direction, push_to_top: true, }) + + addUndo({ + redo: { + fn: async function redo(this: UndoRedoAction) { + const data: any = await $api.dbTableSort.create(view.value?.id as string, { + fk_column_id: column!.value.id, + direction, + push_to_top: true, + }) + this.undo.args = [data.id] + eventBus.emit(SmartsheetStoreEvents.SORT_RELOAD) + reloadDataHook?.trigger() + }, + args: [], + }, + undo: { + fn: async function undo(id: string) { + await $api.dbTableSort.delete(id) + eventBus.emit(SmartsheetStoreEvents.SORT_RELOAD) + reloadDataHook?.trigger() + }, + args: [data.id], + }, + scope: view.value?.title, + }) + eventBus.emit(SmartsheetStoreEvents.SORT_RELOAD) reloadDataHook?.trigger() } catch (e: any) { @@ -244,6 +271,24 @@ const hideField = async () => { await $api.dbViewColumn.update(view.value!.id!, currentColumn!.id!, { show: false }) eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) + + addUndo({ + redo: { + fn: async function redo(id: string) { + await $api.dbViewColumn.update(view.value!.id!, id, { show: false }) + eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) + }, + args: [currentColumn!.id], + }, + undo: { + fn: async function undo(id: string) { + await $api.dbViewColumn.update(view.value!.id!, id, { show: true }) + eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) + }, + args: [currentColumn!.id], + }, + scope: view.value?.title, + }) }