diff --git a/package.json b/package.json index 333b2cdf..cdff4807 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@tabler/icons-solidjs": "^2.32.0", "@tanstack/solid-table": "^8.9.3", "@tanstack/solid-virtual": "3.0.0-beta.6", + "@thisbeyond/solid-dnd": "^0.7.4", "@types/byte-size": "^8.1.0", "@types/node": "^20.5.7", "@types/uuid": "^9.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e1f2b21b..29636efa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ dependencies: '@tanstack/solid-virtual': specifier: 3.0.0-beta.6 version: 3.0.0-beta.6 + '@thisbeyond/solid-dnd': + specifier: ^0.7.4 + version: 0.7.4(solid-js@1.7.11) '@types/byte-size': specifier: ^8.1.0 version: 8.1.0 @@ -1296,6 +1299,17 @@ packages: engines: { node: '>=12' } dev: false + /@thisbeyond/solid-dnd@0.7.4(solid-js@1.7.11): + resolution: + { + integrity: sha512-jgV9EtR3gAtVsILG8p1OAGrhHIgnK4W04YxpyLgJRCDKEFYQWuDrMdUe8F5Kc6pcVXlC4IMXr4cB8fS2Ut3/Ow==, + } + peerDependencies: + solid-js: ^1.5 + dependencies: + solid-js: 1.7.11 + dev: false + /@tsconfig/node10@1.0.9: resolution: { diff --git a/src/components/ConnectionsModal.tsx b/src/components/ConnectionsModal.tsx index 7bdd4ae4..a9194b8e 100644 --- a/src/components/ConnectionsModal.tsx +++ b/src/components/ConnectionsModal.tsx @@ -1,41 +1,105 @@ -import { For } from 'solid-js' +import type { + DragEventHandler, + Draggable, + Droppable, +} from '@thisbeyond/solid-dnd' +import { + DragDropProvider, + DragDropSensors, + DragOverlay, + SortableProvider, + closestCenter, + createSortable, + useDragDropContext, +} from '@thisbeyond/solid-dnd' +import { For, createSignal } from 'solid-js' import { AccessorKey } from '~/config/connection' type ColumnVisibility = Partial> +type ColumnOrder = AccessorKey[] export default (props: { - data: ColumnVisibility - onChange: (value: ColumnVisibility) => void + order: ColumnOrder + visible: ColumnVisibility + onOrderChange: (value: ColumnOrder) => void + onVisibleChange: (value: ColumnVisibility) => void }) => { - const { onChange } = props + const [activeKey, setActiveKey] = createSignal(null) + const onDragStart = ({ draggable }: { draggable: Draggable }) => + setActiveKey(draggable.id as AccessorKey) + const onDragEnd = ({ + draggable, + droppable, + }: { + draggable: Draggable + droppable: Droppable + }) => { + if (draggable && droppable) { + const currentItems = props.order + const fromIndex = currentItems.indexOf(draggable.id as AccessorKey) + const toIndex = currentItems.indexOf(droppable.id as AccessorKey) + + if (fromIndex !== toIndex) { + const updatedItems = currentItems.slice() + + updatedItems.splice(toIndex, 0, ...updatedItems.splice(fromIndex, 1)) + props.onOrderChange(updatedItems) + } + } + } + + const FormRow = (p: { key: AccessorKey }) => { + const key = p.key + const sortable = createSortable(key) + const [state] = useDragDropContext()! + + return ( +
+
+ {key} + { + props.onVisibleChange({ + ...props.visible, + [key]: e.target.checked, + }) + }} + /> +
+
+ ) + } return ( <>