mirror of https://github.com/buster-so/buster.git
table update
This commit is contained in:
parent
861d9b7a7c
commit
de99ea1742
|
@ -11,14 +11,11 @@ import { useMemoizedFn } from '@/hooks';
|
||||||
import { AppDataGrid } from '@/components/ui/table/AppDataGrid';
|
import { AppDataGrid } from '@/components/ui/table/AppDataGrid';
|
||||||
import './TableChart.css';
|
import './TableChart.css';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
|
import { useUpdateMetricChart } from '@/context/Metrics';
|
||||||
|
|
||||||
export interface BusterTableChartProps extends BusterTableChartConfig, BusterChartPropsBase {}
|
export interface BusterTableChartProps extends BusterTableChartConfig, BusterChartPropsBase {}
|
||||||
|
|
||||||
const BusterTableChartBase: React.FC<
|
const BusterTableChartBase: React.FC<BusterTableChartProps> = ({
|
||||||
BusterTableChartProps & {
|
|
||||||
onChangeConfig?: (config: Partial<IBusterMetricChartConfig>) => void;
|
|
||||||
}
|
|
||||||
> = ({
|
|
||||||
className = '',
|
className = '',
|
||||||
onMounted,
|
onMounted,
|
||||||
data,
|
data,
|
||||||
|
@ -27,13 +24,39 @@ const BusterTableChartBase: React.FC<
|
||||||
tableColumnWidths = DEFAULT_CHART_CONFIG.tableColumnWidths,
|
tableColumnWidths = DEFAULT_CHART_CONFIG.tableColumnWidths,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
onInitialAnimationEnd,
|
onInitialAnimationEnd,
|
||||||
onChangeConfig,
|
|
||||||
//TODO
|
//TODO
|
||||||
tableHeaderBackgroundColor,
|
tableHeaderBackgroundColor,
|
||||||
tableHeaderFontColor,
|
tableHeaderFontColor,
|
||||||
animate,
|
animate,
|
||||||
tableColumnFontColor
|
tableColumnFontColor
|
||||||
}) => {
|
}) => {
|
||||||
|
const { onUpdateMetricChartConfig } = useUpdateMetricChart();
|
||||||
|
|
||||||
|
const onChangeConfig = useMemoizedFn((config: Partial<IBusterMetricChartConfig>) => {
|
||||||
|
if (readOnly) return;
|
||||||
|
onUpdateMetricChartConfig({ chartConfig: config });
|
||||||
|
});
|
||||||
|
|
||||||
|
const onUpdateTableColumnOrder = useMemoizedFn((columns: string[]) => {
|
||||||
|
if (readOnly) return;
|
||||||
|
const config: Partial<IBusterMetricChartConfig> = {
|
||||||
|
tableColumnOrder: columns
|
||||||
|
};
|
||||||
|
|
||||||
|
onChangeConfig(config);
|
||||||
|
});
|
||||||
|
|
||||||
|
const onUpdateTableColumnSize = useMemoizedFn((columns: { key: string; size: number }[]) => {
|
||||||
|
if (readOnly) return;
|
||||||
|
const config: Partial<IBusterMetricChartConfig> = {
|
||||||
|
tableColumnWidths: columns.reduce<Record<string, number>>((acc, { key, size }) => {
|
||||||
|
acc[key] = Number(size.toFixed(1));
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
};
|
||||||
|
onChangeConfig(config);
|
||||||
|
});
|
||||||
|
|
||||||
//THIS MUST BE A USE CALLBACK
|
//THIS MUST BE A USE CALLBACK
|
||||||
const onFormatHeader = useCallback(
|
const onFormatHeader = useCallback(
|
||||||
(value: any, columnName: string) => {
|
(value: any, columnName: string) => {
|
||||||
|
@ -49,28 +72,8 @@ const BusterTableChartBase: React.FC<
|
||||||
[columnLabelFormats]
|
[columnLabelFormats]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onUpdateTableColumnOrder = useMemoizedFn((columns: string[]) => {
|
|
||||||
if (readOnly) return;
|
|
||||||
const config: Partial<IBusterMetricChartConfig> = {
|
|
||||||
tableColumnOrder: columns
|
|
||||||
};
|
|
||||||
|
|
||||||
onChangeConfig?.(config);
|
|
||||||
});
|
|
||||||
|
|
||||||
const onUpdateTableColumnSize = useMemoizedFn((columns: { key: string; size: number }[]) => {
|
|
||||||
if (readOnly) return;
|
|
||||||
const config: Partial<IBusterMetricChartConfig> = {
|
|
||||||
tableColumnWidths: columns.reduce<Record<string, number>>((acc, { key, size }) => {
|
|
||||||
acc[key] = size;
|
|
||||||
return acc;
|
|
||||||
}, {})
|
|
||||||
};
|
|
||||||
onChangeConfig?.(config);
|
|
||||||
});
|
|
||||||
|
|
||||||
const onReady = useMemoizedFn(() => {
|
const onReady = useMemoizedFn(() => {
|
||||||
onMounted?.(); //I decided to remove this because it was causing a double render
|
onMounted?.();
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
onInitialAnimationEnd?.();
|
onInitialAnimationEnd?.();
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,9 @@ export const PopupContainer: React.FC<{
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
exit={{ opacity: 0, y: -3 }}
|
exit={{ opacity: 0, y: -3 }}
|
||||||
transition={{ duration: 0.12 }}>
|
transition={{ duration: 0.12 }}>
|
||||||
<div className="bg-background rounded px-2 py-1.5 shadow">{show && <>{children}</>}</div>
|
<div className="bg-background rounded px-2 py-1.5 shadow-md">
|
||||||
|
{show && <>{children}</>}
|
||||||
|
</div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|
Loading…
Reference in New Issue