From 4c8b38f7563b6c8c38c8295ff0a30ec995c88257 Mon Sep 17 00:00:00 2001 From: kunish Date: Wed, 6 Sep 2023 00:15:22 +0800 Subject: [PATCH] feat(connections): connections table now supports grouping --- src/pages/Connections.tsx | 154 +++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 37 deletions(-) diff --git a/src/pages/Connections.tsx b/src/pages/Connections.tsx index 3a587a7..81eb73a 100644 --- a/src/pages/Connections.tsx +++ b/src/pages/Connections.tsx @@ -8,14 +8,19 @@ import { IconSettings, IconSortAscending, IconSortDescending, + IconZoomInFilled, + IconZoomOutFilled, } from '@tabler/icons-solidjs' import { ColumnDef, + GroupingState, SortingState, createSolidTable, flexRender, getCoreRowModel, + getExpandedRowModel, getFilteredRowModel, + getGroupedRowModel, getSortedRowModel, } from '@tanstack/solid-table' import byteSize from 'byte-size' @@ -44,22 +49,8 @@ type ColumnOrder = CONNECTIONS_TABLE_ACCESSOR_KEY[] export default () => { const [t] = useI18n() - const [columnVisibility, setColumnVisibility] = makePersisted( - createSignal(CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY), - { - name: 'columnVisibility', - storage: localStorage, - }, - ) - const [columnOrder, setColumnOrder] = makePersisted( - createSignal(CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER), - { - name: 'columnOrder', - storage: localStorage, - }, - ) - const request = useRequest() + const [search, setSearch] = createSignal('') const ws = createReconnectingWS( @@ -111,11 +102,27 @@ export default () => { const onCloseConnection = (id: string) => request.delete(`connections/${id}`) + const [columnVisibility, setColumnVisibility] = makePersisted( + createSignal(CONNECTIONS_TABLE_INITIAL_COLUMN_VISIBILITY), + { + name: 'columnVisibility', + storage: localStorage, + }, + ) + const [columnOrder, setColumnOrder] = makePersisted( + createSignal(CONNECTIONS_TABLE_INITIAL_COLUMN_ORDER), + { + name: 'columnOrder', + storage: localStorage, + }, + ) + const columns: ColumnDef[] = [ { - accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.Close, + header: () => t('close'), + enableGrouping: false, enableSorting: false, - header: () => {t('close')}, + accessorKey: CONNECTIONS_TABLE_ACCESSOR_KEY.Close, cell: ({ row }) => (
+ ) : null} + +
+ {flexRender( header.column.columnDef.header, header.getContext(), - ) - ) : ( - {t(header.column.id)} - )} + )} +
+ {{ asc: , desc: , @@ -346,9 +392,43 @@ export default () => { void writeClipboard(cell.renderValue() as string) }} > - {flexRender( - cell.column.columnDef.cell, - cell.getContext(), + {cell.getIsGrouped() ? ( + + ) : cell.getIsAggregated() ? ( + flexRender( + cell.column.columnDef.aggregatedCell ?? + cell.column.columnDef.cell, + cell.getContext(), + ) + ) : cell.getIsPlaceholder() ? null : ( + flexRender( + cell.column.columnDef.cell, + cell.getContext(), + ) )} )}