mirror of https://github.com/buster-so/buster.git
move to new component
This commit is contained in:
parent
8d11b86d6d
commit
815d64d7f7
|
@ -1,6 +1,6 @@
|
||||||
import type { IDataResult } from '@/api/asset_interfaces';
|
import type { IDataResult } from '@/api/asset_interfaces';
|
||||||
import { ShimmerText } from '@/components/ui/typography/ShimmerText';
|
import { ShimmerText } from '@/components/ui/typography/ShimmerText';
|
||||||
import AppDataGrid from '@/components/ui/table/AppDataGrid';
|
import { AppDataGrid } from '@/components/ui/table/AppDataGrid';
|
||||||
import { useUserConfigContextSelector } from '@/context/Users';
|
import { useUserConfigContextSelector } from '@/context/Users';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Text } from '@/components/ui/typography';
|
import { Text } from '@/components/ui/typography';
|
||||||
|
@ -25,11 +25,10 @@ export const OverviewData: React.FC<{
|
||||||
) : !isEmpty(data) ? (
|
) : !isEmpty(data) ? (
|
||||||
<AppDataGrid
|
<AppDataGrid
|
||||||
rows={data || []}
|
rows={data || []}
|
||||||
headerFormat={isAdmin ? (v) => v : undefined}
|
headerFormat={isAdmin ? (v) => String(v) : undefined}
|
||||||
cellFormat={defaultCellFormatter}
|
cellFormat={defaultCellFormatter}
|
||||||
resizable={true}
|
resizable={true}
|
||||||
draggable={false}
|
sortable={false}
|
||||||
animate={false}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EmptyState />
|
<EmptyState />
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const DataContainer: React.FC<{
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{hasData ? (
|
{hasData ? (
|
||||||
<AppDataGrid rows={data} resizable={true} draggable={false} animate={false} />
|
<AppDataGrid rows={data} resizable={true} sortable={false} />
|
||||||
) : (
|
) : (
|
||||||
<div className="flex h-full items-center justify-center">
|
<div className="flex h-full items-center justify-center">
|
||||||
{fetchingData ? 'Loading data...' : 'No data returned'}
|
{fetchingData ? 'Loading data...' : 'No data returned'}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
} from '@/api/asset_interfaces/metric';
|
} from '@/api/asset_interfaces/metric';
|
||||||
import { useMemoizedFn } from '@/hooks';
|
import { useMemoizedFn } from '@/hooks';
|
||||||
import { useChartWrapperContextSelector } from '../chartHooks/useChartWrapperProvider';
|
import { useChartWrapperContextSelector } from '../chartHooks/useChartWrapperProvider';
|
||||||
import AppDataGrid from '@/components/ui/table/AppDataGrid/AppDataGrid';
|
import { AppDataGrid } from '@/components/ui/table/AppDataGrid';
|
||||||
import './TableChart.css';
|
import './TableChart.css';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
|
|
||||||
|
@ -84,10 +84,9 @@ const BusterTableChartBase: React.FC<
|
||||||
className={cn('buster-table-chart', className)}
|
className={cn('buster-table-chart', className)}
|
||||||
key={data.length}
|
key={data.length}
|
||||||
rows={data}
|
rows={data}
|
||||||
initialWidth={containerWidth}
|
|
||||||
columnOrder={tableColumnOrder || undefined}
|
columnOrder={tableColumnOrder || undefined}
|
||||||
columnWidths={tableColumnWidths || undefined}
|
columnWidths={tableColumnWidths || undefined}
|
||||||
draggable={!readOnly}
|
sortable={!readOnly}
|
||||||
resizable={!readOnly}
|
resizable={!readOnly}
|
||||||
onReady={onReady}
|
onReady={onReady}
|
||||||
headerFormat={onFormatHeader}
|
headerFormat={onFormatHeader}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import type { Meta, StoryObj } from '@storybook/react';
|
import type { Meta, StoryObj } from '@storybook/react';
|
||||||
import { AppDataGrid } from './AppDataGrid';
|
import { ReactDataGrid } from './ReactDataGrid';
|
||||||
|
|
||||||
const meta: Meta<typeof AppDataGrid> = {
|
const meta: Meta<typeof ReactDataGrid> = {
|
||||||
title: 'UI/Table/AppDataGrid',
|
title: 'UI/Table/ReactDataGrid',
|
||||||
component: AppDataGrid,
|
component: ReactDataGrid,
|
||||||
parameters: {
|
parameters: {
|
||||||
layout: 'fullscreen'
|
layout: 'fullscreen'
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ const meta: Meta<typeof AppDataGrid> = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default meta;
|
export default meta;
|
||||||
type Story = StoryObj<typeof AppDataGrid>;
|
type Story = StoryObj<typeof ReactDataGrid>;
|
||||||
|
|
||||||
const sampleData = [
|
const sampleData = [
|
||||||
{ id: 1, name: 'John Doe', age: 30, email: 'john@example.com', joinDate: new Date('2023-01-15') },
|
{ id: 1, name: 'John Doe', age: 30, email: 'john@example.com', joinDate: new Date('2023-01-15') },
|
|
@ -14,21 +14,21 @@ import isString from 'lodash/isString';
|
||||||
import { Text } from '@/components/ui/typography';
|
import { Text } from '@/components/ui/typography';
|
||||||
import round from 'lodash/round';
|
import round from 'lodash/round';
|
||||||
import { ErrorBoundary } from '@/components/ui/error';
|
import { ErrorBoundary } from '@/components/ui/error';
|
||||||
import { CaretDown } from '../../icons/NucleoIconFilled';
|
import { CaretDown } from '../../../icons/NucleoIconFilled';
|
||||||
import styles from './AppDataGrid.module.css';
|
import styles from './AppDataGrid.module.css';
|
||||||
|
|
||||||
//https://www.npmjs.com/package/react-spreadsheet-grid#live-playground
|
//https://www.npmjs.com/package/react-spreadsheet-grid#live-playground
|
||||||
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useDebounceEffect, useDebounceFn, useMemoizedFn, useMount, useSize } from '@/hooks';
|
import { useDebounceFn, useMemoizedFn, useMount, useSize } from '@/hooks';
|
||||||
import sampleSize from 'lodash/sampleSize';
|
import sampleSize from 'lodash/sampleSize';
|
||||||
import isEmpty from 'lodash/isEmpty';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
import { cn } from '@/lib/classMerge';
|
||||||
import {
|
import {
|
||||||
createInitialColumnWidths,
|
createInitialColumnWidths,
|
||||||
defaultCellFormat,
|
defaultCellFormat,
|
||||||
defaultHeaderFormat,
|
defaultHeaderFormat,
|
||||||
MIN_WIDTH
|
MIN_WIDTH
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
import { cn } from '@/lib/classMerge';
|
|
||||||
|
|
||||||
type Row = Record<string, string | number | null | Date>;
|
type Row = Record<string, string | number | null | Date>;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ const DEFAULT_COLUMN_WIDTH = {
|
||||||
// maxWidth: columnsOrder.length <= 2 ? undefined : MAX_WIDTH
|
// maxWidth: columnsOrder.length <= 2 ? undefined : MAX_WIDTH
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface AppDataGridProps {
|
export interface ReactDataGridProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
initialWidth?: number;
|
initialWidth?: number;
|
||||||
animate?: boolean;
|
animate?: boolean;
|
||||||
|
@ -60,7 +60,7 @@ export interface AppDataGridProps {
|
||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppDataGrid: React.FC<AppDataGridProps> = React.memo(
|
export const ReactDataGrid: React.FC<ReactDataGridProps> = React.memo(
|
||||||
({
|
({
|
||||||
className = '',
|
className = '',
|
||||||
resizable = true,
|
resizable = true,
|
||||||
|
@ -355,7 +355,7 @@ export const AppDataGrid: React.FC<AppDataGridProps> = React.memo(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(prevProps, nextProps) => {
|
(prevProps, nextProps) => {
|
||||||
const keysToCheck: (keyof AppDataGridProps)[] = [
|
const keysToCheck: (keyof ReactDataGridProps)[] = [
|
||||||
'cellFormat',
|
'cellFormat',
|
||||||
'headerFormat',
|
'headerFormat',
|
||||||
'columnOrder',
|
'columnOrder',
|
||||||
|
@ -366,7 +366,7 @@ export const AppDataGrid: React.FC<AppDataGridProps> = React.memo(
|
||||||
return keysToCheck.every((key) => prevProps[key] === nextProps[key]);
|
return keysToCheck.every((key) => prevProps[key] === nextProps[key]);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
AppDataGrid.displayName = 'AppDataGrid';
|
ReactDataGrid.displayName = 'AppDataGrid';
|
||||||
|
|
||||||
const HeaderCell: React.FC<
|
const HeaderCell: React.FC<
|
||||||
RenderHeaderCellProps<Row, unknown> & {
|
RenderHeaderCellProps<Row, unknown> & {
|
||||||
|
@ -406,4 +406,4 @@ const GridCell: React.FC<
|
||||||
});
|
});
|
||||||
GridCell.displayName = 'GridCell';
|
GridCell.displayName = 'GridCell';
|
||||||
|
|
||||||
export default AppDataGrid;
|
export default ReactDataGrid;
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { CSSProperties, useEffect, useRef, useState } from 'react';
|
import React, { CSSProperties, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
DragOverlay,
|
DragOverlay,
|
||||||
|
@ -67,8 +67,8 @@ const DraggableHeader: React.FC<DraggableHeaderProps> = React.memo(
|
||||||
ref={setDropNodeRef}
|
ref={setDropNodeRef}
|
||||||
style={style}
|
style={style}
|
||||||
className={cn(
|
className={cn(
|
||||||
'group relative border-r select-none last:border-r-0',
|
'group bg-background relative border-r select-none last:border-r-0',
|
||||||
header.column.getIsResizing() && 'bg-primary/8',
|
header.column.getIsResizing() ? 'bg-primary/8' : 'hover:bg-item-hover',
|
||||||
isOverTarget &&
|
isOverTarget &&
|
||||||
'bg-primary/10 border-primary inset rounded-sm border border-r border-dashed'
|
'bg-primary/10 border-primary inset rounded-sm border border-r border-dashed'
|
||||||
)}
|
)}
|
||||||
|
@ -169,6 +169,8 @@ export const DataGridHeader: React.FC<DataGridHeaderProps> = ({
|
||||||
// Reference to the style element for cursor handling
|
// Reference to the style element for cursor handling
|
||||||
const styleRef = useRef<HTMLStyleElement | null>(null);
|
const styleRef = useRef<HTMLStyleElement | null>(null);
|
||||||
|
|
||||||
|
const memoizedModifiers = useMemo(() => [restrictToHorizontalAxis], []);
|
||||||
|
|
||||||
const sensors = useSensors(
|
const sensors = useSensors(
|
||||||
useSensor(MouseSensor, {
|
useSensor(MouseSensor, {
|
||||||
activationConstraint: {
|
activationConstraint: {
|
||||||
|
@ -257,15 +259,15 @@ export const DataGridHeader: React.FC<DataGridHeaderProps> = ({
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<thead className="bg-background sticky top-0 z-10 w-full" suppressHydrationWarning>
|
<thead className="bg-background sticky top-0 z-10 w-full border-b" suppressHydrationWarning>
|
||||||
<DndContext
|
<DndContext
|
||||||
sensors={sensors}
|
sensors={sensors}
|
||||||
modifiers={[restrictToHorizontalAxis]}
|
modifiers={memoizedModifiers}
|
||||||
collisionDetection={pointerWithin}
|
collisionDetection={pointerWithin}
|
||||||
onDragStart={onDragStart}
|
onDragStart={onDragStart}
|
||||||
onDragOver={onDragOver}
|
onDragOver={onDragOver}
|
||||||
onDragEnd={onDragEnd}>
|
onDragEnd={onDragEnd}>
|
||||||
<tr className="flex border-b">
|
<tr className="flex">
|
||||||
{table
|
{table
|
||||||
.getHeaderGroups()[0]
|
.getHeaderGroups()[0]
|
||||||
?.headers.map(
|
?.headers.map(
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
SortingState
|
SortingState
|
||||||
} from '@tanstack/react-table';
|
} from '@tanstack/react-table';
|
||||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||||
import { defaultCellFormat, defaultHeaderFormat } from '../helpers';
|
import { defaultCellFormat, defaultHeaderFormat } from './defaultFormat';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
import { DataGridHeader } from './DataGridHeader';
|
import { DataGridHeader } from './DataGridHeader';
|
||||||
import { DataGridRow } from './DataGridRow';
|
import { DataGridRow } from './DataGridRow';
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { makeHumanReadble } from '@/lib/text';
|
||||||
|
|
||||||
|
export const defaultHeaderFormat = (v: any) => makeHumanReadble(v);
|
||||||
|
export const defaultCellFormat = (v: any) => v;
|
|
@ -1,4 +1,3 @@
|
||||||
import AppDataGrid from './AppDataGrid';
|
import { TanStackDataGrid } from './TanStackDataGrid';
|
||||||
export { AppDataGrid };
|
|
||||||
|
|
||||||
export default AppDataGrid;
|
export { TanStackDataGrid as AppDataGrid };
|
||||||
|
|
Loading…
Reference in New Issue