diff --git a/web/src/components/ui/table/AppDataGrid/AppDataGrid2.stories.tsx b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.stories.tsx similarity index 66% rename from web/src/components/ui/table/AppDataGrid/AppDataGrid2.stories.tsx rename to web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.stories.tsx index 91926a773..20007a64a 100644 --- a/web/src/components/ui/table/AppDataGrid/AppDataGrid2.stories.tsx +++ b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.stories.tsx @@ -1,9 +1,10 @@ import type { Meta, StoryObj } from '@storybook/react'; -import { AppDataGrid2 } from './AppDataGrid2'; +import { TanStackDataGrid } from './TanStackDataGrid'; +import { faker } from '@faker-js/faker'; -const meta: Meta = { - title: 'UI/Table/AppDataGrid2', - component: AppDataGrid2, +const meta: Meta = { + title: 'UI/Table/TanStackDataGrid', + component: TanStackDataGrid, parameters: { layout: 'fullscreen' }, @@ -11,52 +12,15 @@ const meta: Meta = { }; export default meta; -type Story = StoryObj; +type Story = StoryObj; -const sampleData = [ - { - id: 1, - name: 'John Doe', - age: 30, - email: 'john@example.com', - joinDate: new Date('2023-01-15').toISOString() - }, - { - id: 2, - name: 'Jane Smith', - age: 25, - email: 'jane@example.com', - joinDate: new Date('2023-02-20').toISOString() - }, - { - id: 3, - name: 'Bob Johnson', - age: 35, - email: 'bob@example.com', - joinDate: new Date('2023-03-10').toISOString() - }, - { - id: 4, - name: 'Alice Brown', - age: 28, - email: 'alice@example.com', - joinDate: new Date('2023-04-05').toISOString() - }, - { - id: 5, - name: 'Michael Wilson', - age: 42, - email: 'michael@example.com', - joinDate: new Date('2023-05-12').toISOString() - }, - { - id: 6, - name: 'Sarah Davis', - age: 31, - email: 'sarah@example.com', - joinDate: new Date('2023-06-08').toISOString() - } -]; +const sampleData = Array.from({ length: 1000 }, (_, index) => ({ + id: index + 1, + name: faker.person.fullName(), + age: faker.number.int({ min: 18, max: 90 }), + email: faker.internet.email(), + joinDate: faker.date.past().toISOString() +})); export const Default: Story = { args: { @@ -66,8 +30,8 @@ export const Default: Story = { sortable: true }, render: (args) => ( -
- +
+
) }; diff --git a/web/src/components/ui/table/AppDataGrid/AppDataGrid2.tsx b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx similarity index 77% rename from web/src/components/ui/table/AppDataGrid/AppDataGrid2.tsx rename to web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx index 530bb14d7..eabdfaf67 100644 --- a/web/src/components/ui/table/AppDataGrid/AppDataGrid2.tsx +++ b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx @@ -16,7 +16,6 @@ import { KeyboardSensor, useSensor, useSensors, - closestCenter, pointerWithin, DragEndEvent, DragOverlay, @@ -27,13 +26,13 @@ import { } from '@dnd-kit/core'; import { arrayMove } from '@dnd-kit/sortable'; import sampleSize from 'lodash/sampleSize'; -import { defaultCellFormat, defaultHeaderFormat } from './helpers'; +import { defaultCellFormat, defaultHeaderFormat } from '../helpers'; import { cn } from '@/lib/classMerge'; import { restrictToHorizontalAxis } from '@dnd-kit/modifiers'; import { useMemoizedFn } from '@/hooks'; -import { CaretDown, CaretUp } from '../../icons/NucleoIconFilled'; +import { CaretDown, CaretUp } from '../../../icons/NucleoIconFilled'; -export interface AppDataGridProps { +export interface TanStackDataGridProps { className?: string; resizable?: boolean; sortable?: boolean; @@ -95,22 +94,23 @@ const DraggableHeader: React.FC = React.memo( }; return ( -
- + {flexRender(header.column.columnDef.header, header.getContext())} {header.column.getIsSorted() === 'asc' && ( @@ -140,7 +140,7 @@ const DraggableHeader: React.FC = React.memo( />
)} -
+ ); } ); @@ -170,7 +170,7 @@ const HeaderDragOverlay = ({ ); }; -export const AppDataGrid2: React.FC = React.memo( +export const TanStackDataGrid: React.FC = React.memo( ({ className = '', resizable = true, @@ -355,82 +355,75 @@ export const AppDataGrid2: React.FC = React.memo( const rowVirtualizer = useVirtualizer({ count: table.getRowModel().rows.length, getScrollElement: () => parentRef.current, - estimateSize: () => 35, // estimated row height + estimateSize: () => 36, // estimated row height overscan: 5 }); - // Create a reference to measure header height - const headerRef = useRef(null); - const [headerHeight, setHeaderHeight] = useState(36); // Default height - - // Measure the actual header height once mounted - useEffect(() => { - if (headerRef.current) { - const height = headerRef.current.getBoundingClientRect().height; - if (height > 0) { - setHeaderHeight(height); - } - } - }, []); - return (
- {/* Header */} -
- -
- {table - .getHeaderGroups()[0] - ?.headers.map((header) => ( - - ))} -
+ + {/* Header */} + + + + {table + .getHeaderGroups()[0] + ?.headers.map((header) => ( + + ))} + - {/* Drag Overlay */} - - {activeId && activeHeader && } - - - - {/* Body */} -
- {rowVirtualizer.getVirtualItems().map((virtualRow) => { - const row = table.getRowModel().rows[virtualRow.index]; - return ( -
- {row.getVisibleCells().map((cell) => ( -
- ))} - - ); - })} - + {/* Drag Overlay */} + + {activeId && activeHeader && } + + + + + {/* Body */} + + {rowVirtualizer.getVirtualItems().map((virtualRow) => { + const row = table.getRowModel().rows[virtualRow.index]; + return ( + + {row.getVisibleCells().map((cell) => ( + + ))} + + ); + })} + +
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
); } ); -AppDataGrid2.displayName = 'AppDataGrid2'; +TanStackDataGrid.displayName = 'TanStackDataGrid';