From 2eb7c73ecb92ffd3ab3443469adefffcf2cf60db Mon Sep 17 00:00:00 2001 From: zccz14 Date: Mon, 24 Feb 2025 16:34:44 +0800 Subject: [PATCH] feat(ui): refactor DataView and ListView to improve layout and remove topSlot prop --- ui/web/src/modules/Interactive/DataView.tsx | 7 +- ui/web/src/modules/Interactive/ListView.tsx | 61 +++--- ui/web/src/modules/Interactive/TableView.tsx | 217 +++++++++---------- 3 files changed, 139 insertions(+), 146 deletions(-) diff --git a/ui/web/src/modules/Interactive/DataView.tsx b/ui/web/src/modules/Interactive/DataView.tsx index 7582b71c..fb8cffc3 100644 --- a/ui/web/src/modules/Interactive/DataView.tsx +++ b/ui/web/src/modules/Interactive/DataView.tsx @@ -229,8 +229,11 @@ export function DataView(props: { return (
- {actualLayoutMode === 'table' && } - {actualLayoutMode === 'list' && } + + {topSlot} + + {actualLayoutMode === 'table' && } + {actualLayoutMode === 'list' && }
); } diff --git a/ui/web/src/modules/Interactive/ListView.tsx b/ui/web/src/modules/Interactive/ListView.tsx index 90183127..fe330a4c 100644 --- a/ui/web/src/modules/Interactive/ListView.tsx +++ b/ui/web/src/modules/Interactive/ListView.tsx @@ -2,40 +2,35 @@ import { Descriptions, List, Space } from '@douyinfe/semi-ui'; import { Table, flexRender } from '@tanstack/react-table'; import React from 'react'; -export function ListView(props: { table: Table; topSlot?: React.ReactNode }) { +export function ListView(props: { table: Table }) { const { table } = props; return ( - - - {props.topSlot} - - - {table.getRowModel().rows.map((row) => ( - - - {table.getHeaderGroups().map((headerGroup) => - headerGroup.headers.map((header, idx) => { - return ( - - {row - .getVisibleCells() - .filter((cell) => cell.column.id === header.column.id) - .map((cell) => flexRender(cell.column.columnDef.cell, cell.getContext()))} - - ); - }), - )} - - - ))} - - + + {table.getRowModel().rows.map((row) => ( + + + {table.getHeaderGroups().map((headerGroup) => + headerGroup.headers.map((header, idx) => { + return ( + + {row + .getVisibleCells() + .filter((cell) => cell.column.id === header.column.id) + .map((cell) => flexRender(cell.column.columnDef.cell, cell.getContext()))} + + ); + }), + )} + + + ))} + ); } diff --git a/ui/web/src/modules/Interactive/TableView.tsx b/ui/web/src/modules/Interactive/TableView.tsx index ebad09b2..d4f90ef0 100644 --- a/ui/web/src/modules/Interactive/TableView.tsx +++ b/ui/web/src/modules/Interactive/TableView.tsx @@ -12,127 +12,122 @@ import { import { Button, Dropdown, DropdownItem, DropdownMenu, Input, Space } from '@douyinfe/semi-ui'; import { Table, flexRender } from '@tanstack/react-table'; -export function TableView(props: { table: Table; topSlot?: React.ReactNode }) { +export function TableView(props: { table: Table }) { const { table } = props; return ( - - - {props.topSlot} - - - - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => ( - + ))} + + + {table.getFooterGroups().map((footerGroup) => ( + + {footerGroup.headers.map((header) => ( + + ))} + + ))} + +
- - - {header.isPlaceholder - ? null - : flexRender(header.column.columnDef.header, header.getContext())} + + + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + ))} + + ))} + + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => { + return ( + - ))} - - - {table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell) => { - return ( - - ); - })} - - ))} - - - {table.getFooterGroups().map((footerGroup) => ( - - {footerGroup.headers.map((header) => ( - - ))} - - ))} - -
+ + + {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} - {header.column.getCanSort() ? ( -
+ {cell.getIsGrouped() ? ( + +
- {cell.getIsGrouped() ? ( - -
- {header.isPlaceholder - ? null - : flexRender(header.column.columnDef.footer, header.getContext())} -
-
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} ({row.subRows.length}) +
+ ) : cell.getIsAggregated() ? ( + flexRender( + cell.column.columnDef.aggregatedCell ?? cell.column.columnDef.cell, + cell.getContext(), + ) + ) : cell.getIsPlaceholder() ? null : ( + flexRender(cell.column.columnDef.cell, cell.getContext()) + )} + + ); + })} +
+ {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.footer, header.getContext())} +
); }