import { useI18n } from '@solid-primitives/i18n' import type { DragEventHandler, Draggable, Droppable, } from '@thisbeyond/solid-dnd' import { DragDropProvider, DragDropSensors, DragOverlay, SortableProvider, closestCenter, createSortable, useDragDropContext, } from '@thisbeyond/solid-dnd' import { Component, For, Show, createSignal } from 'solid-js' import { Button } from '~/components' import { CONNECTIONS_TABLE_ACCESSOR_KEY, CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER, CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY, } from '~/constants' type ColumnVisibility = Partial> type ColumnOrder = CONNECTIONS_TABLE_ACCESSOR_KEY[] export const ConnectionsTableOrderingModal = (props: { order: ColumnOrder visible: ColumnVisibility onOrderChange: (value: ColumnOrder) => void onVisibleChange: (value: ColumnVisibility) => void }) => { const [t] = useI18n() const [activeKey, setActiveKey] = createSignal(null) const onDragStart = ({ draggable }: { draggable: Draggable }) => setActiveKey(draggable.id as CONNECTIONS_TABLE_ACCESSOR_KEY) const onDragEnd = ({ draggable, droppable, }: { draggable: Draggable droppable: Droppable }) => { if (draggable && droppable) { const currentItems = props.order const fromIndex = currentItems.indexOf( draggable.id as CONNECTIONS_TABLE_ACCESSOR_KEY, ) const toIndex = currentItems.indexOf( droppable.id as CONNECTIONS_TABLE_ACCESSOR_KEY, ) if (fromIndex !== toIndex) { const updatedItems = currentItems.slice() updatedItems.splice(toIndex, 0, ...updatedItems.splice(fromIndex, 1)) props.onOrderChange(updatedItems) } } } const FormRow: Component<{ key: CONNECTIONS_TABLE_ACCESSOR_KEY }> = ({ key }) => { const sortable = createSortable(key) const [state] = useDragDropContext()! return (
{t(key)} { props.onVisibleChange({ ...props.visible, [key]: e.target.checked, }) }} />
) } return ( ) }