Browse Source

feat(nc-gui): add stack reorder logic

pull/3818/head
Wing-Kam Wong 2 years ago
parent
commit
2eb9ea42d8
  1. 24
      packages/nc-gui/components/smartsheet/Kanban.vue

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

@ -37,6 +37,7 @@ const {
kanbanMetaData, kanbanMetaData,
formattedData, formattedData,
updateOrSaveRow, updateOrSaveRow,
updateKanbanMeta,
addEmptyRow, addEmptyRow,
groupingFieldColOptions, groupingFieldColOptions,
groupingField, 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) { async function onMove(event: any, stackKey: string) {
if (event.added) { if (event.added) {
const ele = event.added.element const ele = event.added.element
@ -142,6 +164,8 @@ openNewRecordFormHook?.on(async () => {
group="kanban-stack" group="kanban-stack"
draggable=".nc-kanban-stack" draggable=".nc-kanban-stack"
filter=".not-draggable" filter=".not-draggable"
:move="onMoveCallback"
@change="onMoveStack($event)"
> >
<template #item="{ element: stack, index }"> <template #item="{ element: stack, index }">
<a-card <a-card

Loading…
Cancel
Save