Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow duplication of charts in layouting step #1770

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions app/components/chart-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@ const DashboardPreview = ({

if (layoutType === "canvas") {
return (
<ChartPanelLayout
chartConfigs={state.chartConfigs}
renderChart={renderChart}
layoutType={layoutType}
className={classes.canvasChartPanelLayout}
/>
// Force re-rendering of the canvas layout when the chart configs change
// to properly initialize the height of the new charts
<div key={state.chartConfigs.map((c) => c.key).join(",")}>
<ChartPanelLayout
chartConfigs={state.chartConfigs}
renderChart={renderChart}
layoutType={layoutType}
className={classes.canvasChartPanelLayout}
/>
</div>
);
}

Expand Down
16 changes: 9 additions & 7 deletions app/configurator/configurator-state/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ const reducer_: Reducer<ConfiguratorState, ConfiguratorStateAction> = (
return draft;

case "CHART_CONFIG_ADD":
if (isConfiguring(draft)) {
if (isConfiguring(draft) || isLayouting(draft)) {
const chartConfig =
createDraft(action.value.chartConfig) ?? getChartConfig(draft);
const dataCubesComponents = getCachedComponents({
Expand Down Expand Up @@ -1175,20 +1175,21 @@ export function ensureDashboardLayoutIsCorrect(
draft.layout.type === "dashboard" &&
draft.layout.layout === "canvas"
) {
const layouts = draft.layout.layouts;
const chartConfigKeys = draft.chartConfigs.map((c) => c.key).sort();

const breakpoints = Object.keys(FREE_CANVAS_BREAKPOINTS);
const xlCanvasLayouts = draft.layout.layouts[breakpoints[0]];
const xlLayoutConfigKeys = xlCanvasLayouts.map((c) => c.i).sort();
const layoutConfigKeys = Array.from(
new Set(breakpoints.flatMap((bp) => layouts[bp].map((c) => c.i)))
).sort();

const newConfigs = draft.chartConfigs.filter(
(x) => !xlLayoutConfigKeys.includes(x.key)
(x) => !layoutConfigKeys.includes(x.key)
);

if (!isEqual(chartConfigKeys, xlLayoutConfigKeys)) {
if (!isEqual(chartConfigKeys, layoutConfigKeys)) {
for (const bp of breakpoints) {
const canvasLayouts = draft.layout.layouts[bp];
draft.layout.layouts[bp] = canvasLayouts.filter((c) =>
const canvasLayouts = draft.layout.layouts[bp].filter((c) =>
chartConfigKeys.includes(c.i)
);

Expand Down Expand Up @@ -1216,6 +1217,7 @@ export function ensureDashboardLayoutIsCorrect(
curY += chartH;
}
}

draft.layout.layouts[bp] = canvasLayouts;
}
}
Expand Down
Loading