diff --git a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/DataGridHeader.tsx b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/DataGridHeader.tsx index 79bcfef3b..bbf8828a4 100644 --- a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/DataGridHeader.tsx +++ b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/DataGridHeader.tsx @@ -6,16 +6,18 @@ import { cn } from '@/lib/classMerge'; import { CaretDown, CaretUp } from '../../../icons/NucleoIconFilled'; import { HEADER_HEIGHT } from './constants'; import { useSortColumnContext } from './SortColumnWrapper'; +import { Virtualizer } from '@tanstack/react-virtual'; +import { useMount } from '@/hooks'; interface DraggableHeaderProps { header: Header, unknown>; resizable: boolean; sortable: boolean; - overTargetId: string | null; + isOverTarget: boolean; } const DraggableHeader: React.FC = React.memo( - ({ header, sortable, resizable, overTargetId }) => { + ({ header, sortable, resizable, isOverTarget }) => { // Set up dnd-kit's useDraggable for this header cell const { attributes, @@ -35,8 +37,6 @@ const DraggableHeader: React.FC = React.memo( id: `droppable-${header.id}` }); - const isOverTarget = overTargetId === header.id; - const style: CSSProperties = { position: 'relative', whiteSpace: 'nowrap', @@ -53,8 +53,7 @@ const DraggableHeader: React.FC = React.memo( className={cn( 'group bg-background relative border-r select-none last:border-r-0', header.column.getIsResizing() ? 'bg-primary/8' : 'hover:bg-item-hover', - isOverTarget && - 'bg-primary/10 border-primary inset rounded-sm border border-r border-dashed' + isOverTarget && 'bg-primary/10 border-primary inset border border-r border-dashed' )} // onClick toggles sorting if enabled onClick={header.column.getCanSort() ? header.column.getToggleSortingHandler() : undefined}> @@ -101,65 +100,47 @@ const DraggableHeader: React.FC = React.memo( DraggableHeader.displayName = 'DraggableHeader'; -// Header content component to use in the DragOverlay -const HeaderDragOverlay = ({ - header -}: { - header: Header, unknown>; -}) => { - return ( -
- {flexRender(header.column.columnDef.header, header.getContext())} - {header.column.getIsSorted() === 'asc' && 🔼} - {header.column.getIsSorted() === 'desc' && 🔽} -
- ); -}; - interface DataGridHeaderProps { table: Table>; sortable: boolean; resizable: boolean; + rowVirtualizer: Virtualizer; } -export const DataGridHeader: React.FC = ({ table, sortable, resizable }) => { - const { activeId, overTargetId, activeHeader } = useSortColumnContext((x) => x); +export const DataGridHeader: React.FC = ({ + rowVirtualizer, + table, + sortable, + resizable +}) => { + const overTargetId = useSortColumnContext((x) => x.overTargetId); + + const showScrollShadow = (rowVirtualizer?.scrollOffset || 0) > 10; return ( - - - {table - .getHeaderGroups()[0] - ?.headers.map( - (header: Header, unknown>) => ( - - ) - )} - - - {/* Drag Overlay */} - - {activeId && activeHeader && } - - + <> + + + {table + .getHeaderGroups()[0] + ?.headers.map( + (header: Header, unknown>) => ( + + ) + )} + + + ); }; diff --git a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/SortColumnWrapper.tsx b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/SortColumnWrapper.tsx index 8a46fa3e4..f626e345f 100644 --- a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/SortColumnWrapper.tsx +++ b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/SortColumnWrapper.tsx @@ -9,13 +9,15 @@ import { DragOverEvent, DragEndEvent, DndContext, - pointerWithin + pointerWithin, + DragOverlay } from '@dnd-kit/core'; import { restrictToHorizontalAxis } from '@dnd-kit/modifiers'; import { arrayMove } from '@dnd-kit/sortable'; -import { Header, Table } from '@tanstack/react-table'; +import { flexRender, Header, Table } from '@tanstack/react-table'; import { useState, useRef, useMemo, useEffect } from 'react'; import { useContextSelector, createContext } from 'use-context-selector'; +import { HEADER_HEIGHT } from './constants'; export const SortColumnWrapper: React.FC<{ table: Table>; @@ -136,24 +138,51 @@ export const SortColumnWrapper: React.FC<{ onDragStart={onDragStart} onDragOver={onDragOver} onDragEnd={onDragEnd}> - + {children} + + + {activeId && activeHeader && } + ); }; type SortColumnContextType = { - activeId: string | null; overTargetId: string | null; - activeHeader: Header, unknown> | null; }; export const SortColumnContext = createContext({ - activeId: null, - overTargetId: null, - activeHeader: null + overTargetId: null }); export const useSortColumnContext = (selector: (ctx: SortColumnContextType) => T) => useContextSelector(SortColumnContext, selector); + +// Header content component to use in the DragOverlay +const HeaderDragOverlay = ({ + header +}: { + header: Header, unknown>; +}) => { + return ( +
+ {flexRender(header.column.columnDef.header, header.getContext())} + {header.column.getIsSorted() === 'asc' && 🔼} + {header.column.getIsSorted() === 'desc' && 🔽} +
+ ); +}; diff --git a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx index d6960f47d..da72e8203 100644 --- a/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx +++ b/web/src/components/ui/table/AppDataGrid/TanStackDataGrid/TanStackDataGrid.tsx @@ -126,7 +126,12 @@ export const TanStackDataGrid: React.FC = React.memo( setColOrder={setColOrder} onReorderColumns={onReorderColumns}> - +