[Dashboards] - refactor - pie chart (#14526)

This is the third PR from the split of
https://github.com/twentyhq/twenty/pull/14458 - refactoring only the
PieChart widget.

Plus small performance improvements on already refactored widgets
This commit is contained in:
nitin
2025-09-16 21:14:31 +05:30
committed by GitHub
parent 3b868c3d2a
commit ba3cbd1676
22 changed files with 927 additions and 235 deletions
@@ -6,19 +6,19 @@ import { isDefined } from 'twenty-shared/utils';
type BarChartEndLinesProps = {
bars: readonly ComputedBarDatum<BarChartDataItem>[];
enrichedKeys: BarChartEnrichedKey[];
enrichedKeysMap: Map<string, BarChartEnrichedKey>;
layout: 'vertical' | 'horizontal';
};
export const BarChartEndLines = ({
bars,
enrichedKeys,
enrichedKeysMap,
layout,
}: BarChartEndLinesProps) => {
return (
<g>
{bars.map((bar: ComputedBarDatum<BarChartDataItem>, index: number) => {
const enrichedKey = enrichedKeys.find((k) => k.key === bar.data.id);
const enrichedKey = enrichedKeysMap.get(String(bar.data.id));
if (!isDefined(enrichedKey)) {
return null;
}
@@ -87,7 +87,7 @@ export const GraphWidgetBarChart = ({
const chartTheme = useBarChartTheme();
const { barConfigs, enrichedKeys, defs } = useBarChartData({
const { barConfigs, enrichedKeys, enrichedKeysMap, defs } = useBarChartData({
data,
indexBy,
keys,
@@ -138,7 +138,7 @@ export const GraphWidgetBarChart = ({
return (
<BarChartEndLines
bars={props.bars}
enrichedKeys={enrichedKeys}
enrichedKeysMap={enrichedKeysMap}
layout={layout}
/>
);
@@ -72,6 +72,11 @@ export const useBarChartData = ({
};
});
const enrichedKeysMap = useMemo(
() => new Map(enrichedKeys.map((item) => [item.key, item])),
[enrichedKeys],
);
const defs = barConfigs.map((bar) => {
const isHovered =
hoveredBar?.key === bar.key && hoveredBar?.indexValue === bar.indexValue;
@@ -88,6 +93,7 @@ export const useBarChartData = ({
seriesConfigMap,
barConfigs,
enrichedKeys,
enrichedKeysMap,
defs,
};
};