mirror of https://github.com/buster-so/buster.git
make a few refernces more stable
This commit is contained in:
parent
c7311dafd5
commit
5796ebf222
|
@ -25,10 +25,8 @@ export const OverviewData: React.FC<{
|
||||||
) : !isEmpty(data) ? (
|
) : !isEmpty(data) ? (
|
||||||
<AppDataGrid
|
<AppDataGrid
|
||||||
rows={data || []}
|
rows={data || []}
|
||||||
headerFormat={isAdmin ? (v) => String(v) : undefined}
|
headerFormat={isAdmin ? stableHeaderFormat : undefined}
|
||||||
cellFormat={defaultCellFormatter}
|
cellFormat={defaultCellFormatter}
|
||||||
resizable={true}
|
|
||||||
sortable={false}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EmptyState />
|
<EmptyState />
|
||||||
|
@ -54,3 +52,7 @@ const LoadingState: React.FC<{}> = () => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const stableHeaderFormat = (value: string | number | Date | null, key: string): string => {
|
||||||
|
return String(value);
|
||||||
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const DataContainer: React.FC<{
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{hasData ? (
|
{hasData ? (
|
||||||
<AppDataGrid rows={data} resizable={true} sortable={false} />
|
<AppDataGrid rows={data} />
|
||||||
) : (
|
) : (
|
||||||
<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'}
|
||||||
|
|
|
@ -85,6 +85,7 @@ const BusterTableChartBase: React.FC<
|
||||||
columnWidths={tableColumnWidths || undefined}
|
columnWidths={tableColumnWidths || undefined}
|
||||||
sortable={!readOnly}
|
sortable={!readOnly}
|
||||||
resizable={!readOnly}
|
resizable={!readOnly}
|
||||||
|
draggable={!readOnly}
|
||||||
onReady={onReady}
|
onReady={onReady}
|
||||||
headerFormat={onFormatHeader}
|
headerFormat={onFormatHeader}
|
||||||
cellFormat={onFormatCell}
|
cellFormat={onFormatCell}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { CSSProperties } from 'react';
|
import React, { CSSProperties } from 'react';
|
||||||
import { DragOverlay, useDraggable, useDroppable } from '@dnd-kit/core';
|
import { useDraggable, useDroppable } from '@dnd-kit/core';
|
||||||
import { Header, Table } from '@tanstack/react-table';
|
import { Header, Table } from '@tanstack/react-table';
|
||||||
import { flexRender } from '@tanstack/react-table';
|
import { flexRender } from '@tanstack/react-table';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
|
@ -16,8 +16,13 @@ interface DraggableHeaderProps {
|
||||||
draggable: boolean;
|
draggable: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DraggableHeader: React.FC<DraggableHeaderProps> = React.memo(
|
const DraggableHeader: React.FC<DraggableHeaderProps> = ({
|
||||||
({ header, sortable, resizable, isOverTarget, draggable }) => {
|
header,
|
||||||
|
sortable,
|
||||||
|
resizable,
|
||||||
|
isOverTarget,
|
||||||
|
draggable
|
||||||
|
}) => {
|
||||||
// Set up dnd-kit's useDraggable for this header cell
|
// Set up dnd-kit's useDraggable for this header cell
|
||||||
const {
|
const {
|
||||||
attributes,
|
attributes,
|
||||||
|
@ -65,6 +70,9 @@ const DraggableHeader: React.FC<DraggableHeaderProps> = React.memo(
|
||||||
<span className="text-gray-dark text-base font-normal">
|
<span className="text-gray-dark text-base font-normal">
|
||||||
{flexRender(header.column.columnDef.header, header.getContext())}
|
{flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
{sortable && (
|
||||||
|
<>
|
||||||
{header.column.getIsSorted() === 'asc' && (
|
{header.column.getIsSorted() === 'asc' && (
|
||||||
<span className="text-icon-color text-xs">
|
<span className="text-icon-color text-xs">
|
||||||
<CaretUp />
|
<CaretUp />
|
||||||
|
@ -75,6 +83,8 @@ const DraggableHeader: React.FC<DraggableHeaderProps> = React.memo(
|
||||||
<CaretDown />
|
<CaretDown />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
{resizable && (
|
{resizable && (
|
||||||
<span
|
<span
|
||||||
|
@ -94,8 +104,7 @@ const DraggableHeader: React.FC<DraggableHeaderProps> = React.memo(
|
||||||
)}
|
)}
|
||||||
</th>
|
</th>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
);
|
|
||||||
|
|
||||||
DraggableHeader.displayName = 'DraggableHeader';
|
DraggableHeader.displayName = 'DraggableHeader';
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,22 @@ export const NonDraggable: Story = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const NonResizable: Story = {
|
||||||
|
args: {
|
||||||
|
...meta.args,
|
||||||
|
rows: sampleData,
|
||||||
|
resizable: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NonSortable: Story = {
|
||||||
|
args: {
|
||||||
|
...meta.args,
|
||||||
|
rows: sampleData,
|
||||||
|
sortable: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const CustomColumnOrder: Story = {
|
export const CustomColumnOrder: Story = {
|
||||||
args: {
|
args: {
|
||||||
...meta.args,
|
...meta.args,
|
||||||
|
|
Loading…
Reference in New Issue