Browse Source

feat: undo/redo stack move for kanban

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 2 years ago
parent
commit
ccd6787fc5
  1. 26
      packages/nc-gui/components/smartsheet/Kanban.vue

26
packages/nc-gui/components/smartsheet/Kanban.vue

@ -22,6 +22,7 @@ import {
provide, provide,
useAttachment, useAttachment,
useKanbanViewStoreOrThrow, useKanbanViewStoreOrThrow,
useUndoRedo,
} from '#imports' } from '#imports'
import type { Row as RowType } from '~/lib' import type { Row as RowType } from '~/lib'
@ -84,6 +85,8 @@ const { isUIAllowed } = useUIPermission()
const { appInfo } = $(useGlobal()) const { appInfo } = $(useGlobal())
const { addUndo } = useUndoRedo()
provide(IsFormInj, ref(false)) provide(IsFormInj, ref(false))
provide(IsGalleryInj, ref(false)) provide(IsGalleryInj, ref(false))
@ -212,7 +215,7 @@ function onMoveCallback(event: { draggedContext: { futureIndex: number } }) {
} }
} }
async function onMoveStack(event: any) { async function onMoveStack(event: any, undo = false) {
if (event.moved) { if (event.moved) {
const { oldIndex, newIndex } = event.moved const { oldIndex, newIndex } = event.moved
const { fk_grp_col_id, meta: stack_meta } = kanbanMetaData.value const { fk_grp_col_id, meta: stack_meta } = kanbanMetaData.value
@ -223,6 +226,27 @@ async function onMoveStack(event: any) {
await updateKanbanMeta({ await updateKanbanMeta({
meta: stackMetaObj, meta: stackMetaObj,
}) })
if (!undo) {
addUndo({
undo: {
fn: async (e: any) => {
const temp = groupingFieldColOptions.value.splice(e.moved.newIndex, 1)
groupingFieldColOptions.value.splice(e.moved.oldIndex, 0, temp[0])
await onMoveStack(e, true)
},
args: [{ moved: { oldIndex, newIndex } }],
},
redo: {
fn: async (e: any) => {
const temp = groupingFieldColOptions.value.splice(e.moved.oldIndex, 1)
groupingFieldColOptions.value.splice(e.moved.newIndex, 0, temp[0])
await onMoveStack(e, true)
},
args: [{ moved: { oldIndex, newIndex } }, true],
},
scope: view.value?.title,
})
}
} }
} }

Loading…
Cancel
Save