From 2eb9ea42d813b9e0830b11d5c306d2021f4f8b7d Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 13 Sep 2022 16:23:16 +0800 Subject: [PATCH] feat(nc-gui): add stack reorder logic --- .../nc-gui/components/smartsheet/Kanban.vue | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vue index 0a891feec9..79c025516b 100644 --- a/packages/nc-gui/components/smartsheet/Kanban.vue +++ b/packages/nc-gui/components/smartsheet/Kanban.vue @@ -37,6 +37,7 @@ const { kanbanMetaData, formattedData, updateOrSaveRow, + updateKanbanMeta, addEmptyRow, groupingFieldColOptions, groupingField, @@ -113,6 +114,27 @@ const expandFormClick = async (e: MouseEvent, row: RowType) => { } } +/** Block dragging the stack to first index (reserved for Uncategorized) **/ +function onMoveCallback(event: any) { + if (event.draggedContext.futureIndex === 0) { + return false + } +} + +async function onMoveStack(event: any) { + if (event.moved) { + const { oldIndex, newIndex } = event.moved + const { grp_column_id, stack_meta } = kanbanMetaData.value + groupingFieldColOptions.value[oldIndex].order = newIndex + groupingFieldColOptions.value[newIndex].order = oldIndex + const stackMetaObj = JSON.parse(stack_meta as string) || {} + stackMetaObj[grp_column_id as string] = groupingFieldColOptions.value + await updateKanbanMeta({ + stack_meta: stackMetaObj, + }) + } +} + async function onMove(event: any, stackKey: string) { if (event.added) { const ele = event.added.element @@ -142,6 +164,8 @@ openNewRecordFormHook?.on(async () => { group="kanban-stack" draggable=".nc-kanban-stack" filter=".not-draggable" + :move="onMoveCallback" + @change="onMoveStack($event)" >