diff --git a/packages/nc-gui/components/dashboard/TreeView.vue b/packages/nc-gui/components/dashboard/TreeView.vue index 2d71d433ab..881c835e63 100644 --- a/packages/nc-gui/components/dashboard/TreeView.vue +++ b/packages/nc-gui/components/dashboard/TreeView.vue @@ -45,11 +45,11 @@ const [searchActive, toggleSearchActive] = useToggle() const toggleDialog = inject(ToggleDialogInj, () => {}) -let key = $ref(0) +const keys = $ref>({}) const activeKey = ref([]) -const menuRef = $ref() +const menuRefs = $ref() let filterQuery = $ref('') @@ -69,14 +69,18 @@ const filteredTables = $computed(() => ), ) -let sortable: Sortable +const sortables: Record = {} // todo: replace with vuedraggable const initSortable = (el: Element) => { - if (sortable) sortable.destroy() - sortable = Sortable.create(el as HTMLLIElement, { + const base_id = el.getAttribute('nc-base') + if (!base_id) return + if (sortables[base_id]) sortables[base_id].destroy() + Sortable.create(el as HTMLLIElement, { handle: '.nc-drag-icon', onEnd: async (evt) => { + const offset = tables.value.findIndex((table) => table.base_id === base_id) + const { newIndex = 0, oldIndex = 0 } = evt const itemEl = evt.item as HTMLLIElement @@ -106,10 +110,14 @@ const initSortable = (el: Element) => { } // update the order of the moved item - tables.value?.splice(newIndex, 0, ...tables.value?.splice(oldIndex, 1)) + tables.value?.splice(newIndex + offset, 0, ...tables.value?.splice(oldIndex + offset, 1)) // force re-render the list - key++ + if (keys[base_id]) { + keys[base_id] = keys[base_id] + 1 + } else { + keys[base_id] = 1 + } // update the item order await $api.dbTable.reorder(item.id as string, { @@ -121,8 +129,10 @@ const initSortable = (el: Element) => { } watchEffect(() => { - if (menuRef) { - initSortable(menuRef) + if (menuRefs) { + for (const menuRef of menuRefs) { + initSortable(menuRef) + } } }) @@ -353,21 +363,6 @@ useEventListener(document, 'keydown', async (e: KeyboardEvent) => { - - - - - {{ $t('labels.requestDataSource') }} - - - - -
@@ -394,15 +389,35 @@ useEventListener(document, 'keydown', async (e: KeyboardEvent) => {
+ + + + + + + + {{ $t('labels.requestDataSource') }} + +
-
-
-
+
+
+
{ accordion ghost > - +
-
- - -
-
-
- -
- {{ table.title }} +
+
+ + +
+
+
+ +
+ {{ table.title }} +
+ + + + + +
- - - - - - -
- + +