Skip to content

Commit 9a9595f

Browse files
committed
fix: Dashboard canvas view works in published mode
- Correctly pass className, children and ref for ChartPublished to work in dashboard canvas - fix: Disable resizing when not in layouting
1 parent 26838e0 commit 9a9595f

3 files changed

Lines changed: 51 additions & 14 deletions

File tree

app/components/chart-panel-layout-grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const ChartPanelLayoutCanvas = (props: ChartPanelLayoutTypeProps) => {
6767
<ChartGridLayout
6868
className={chartPanelLayoutGridClasses.root}
6969
layouts={layouts}
70-
resize
70+
resize={config.state === "LAYOUTING"}
7171
draggableHandle={`.${chartPanelLayoutGridClasses.dragHandle}`}
7272
onLayoutChange={(_l, allLayouts) => handleChangeLayouts(allLayouts)}
7373
>

app/components/chart-panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, BoxProps, Theme } from "@mui/material";
22
import { makeStyles } from "@mui/styles";
33
import clsx from "clsx";
4-
import React, { forwardRef, HTMLProps } from "react";
4+
import React, { HTMLProps, forwardRef } from "react";
55

66
import ChartPanelLayoutCanvas, {
77
chartPanelLayoutGridClasses,

app/components/chart-published.tsx

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Trans } from "@lingui/macro";
22
import { Box, Theme } from "@mui/material";
33
import { makeStyles } from "@mui/styles";
44
import clsx from "clsx";
5-
import { useCallback, useEffect, useMemo, useRef } from "react";
5+
import { forwardRef, useCallback, useEffect, useMemo, useRef } from "react";
66
import { useStore } from "zustand";
77

88
import { DataSetTable } from "@/browse/datatable";
@@ -57,23 +57,48 @@ type ChartPublishedProps = {
5757
configKey?: string;
5858
};
5959

60+
type ChartPublishedIndividualChartProps = ChartPublishInnerProps;
61+
62+
const ChartPublishedIndividualChart = forwardRef<
63+
HTMLDivElement,
64+
ChartPublishedIndividualChartProps
65+
>(({ dataSource, state, chartConfig, configKey, children, ...rest }, ref) => {
66+
return (
67+
<ChartTablePreviewProvider key={chartConfig.key}>
68+
<ChartWrapper
69+
key={chartConfig.key}
70+
layoutType={state.layout.type}
71+
ref={ref}
72+
{...rest}
73+
>
74+
<ChartPublishedInner
75+
key={chartConfig.key}
76+
dataSource={dataSource}
77+
state={state}
78+
chartConfig={chartConfig}
79+
configKey={configKey}
80+
>
81+
{children}
82+
</ChartPublishedInner>
83+
</ChartWrapper>
84+
</ChartTablePreviewProvider>
85+
);
86+
});
87+
6088
export const ChartPublished = (props: ChartPublishedProps) => {
6189
const { configKey } = props;
6290
const [state] = useConfiguratorState(isPublished);
6391
const { dataSource } = state;
6492
const locale = useLocale();
6593
const renderChart = useCallback(
6694
(chartConfig: ChartConfig) => (
67-
<ChartTablePreviewProvider key={chartConfig.key}>
68-
<ChartWrapper key={chartConfig.key} layoutType={state.layout.type}>
69-
<ChartPublishedInner
70-
dataSource={dataSource}
71-
state={state}
72-
chartConfig={chartConfig}
73-
configKey={configKey}
74-
/>
75-
</ChartWrapper>
76-
</ChartTablePreviewProvider>
95+
<ChartPublishedIndividualChart
96+
key={chartConfig.key}
97+
dataSource={dataSource}
98+
state={state}
99+
chartConfig={chartConfig}
100+
configKey={configKey}
101+
/>
77102
),
78103
[configKey, dataSource, state]
79104
);
@@ -98,6 +123,7 @@ export const ChartPublished = (props: ChartPublishedProps) => {
98123
<Description text={state.layout.meta.description[locale]} />
99124
)}
100125
</Box>
126+
101127
<ChartPanelLayout
102128
layoutType={state.layout.layout}
103129
chartConfigs={state.chartConfigs}
@@ -156,6 +182,8 @@ type ChartPublishInnerProps = {
156182
state: ConfiguratorStatePublished;
157183
chartConfig: ChartConfig;
158184
configKey: string | undefined;
185+
className?: string;
186+
children?: React.ReactNode;
159187
};
160188

161189
const ChartPublishedInner = (props: ChartPublishInnerProps) => {
@@ -164,6 +192,8 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
164192
state,
165193
chartConfig,
166194
configKey,
195+
className,
196+
children,
167197
} = props;
168198
const { meta } = chartConfig;
169199
const rootRef = useRef<HTMLDivElement>(null);
@@ -241,9 +271,14 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
241271
return (
242272
<MetadataPanelStoreContext.Provider value={metadataPanelStore}>
243273
<Box
244-
className={clsx(chartClasses.root, publishedChartClasses.root)}
274+
className={clsx(
275+
chartClasses.root,
276+
publishedChartClasses.root,
277+
className
278+
)}
245279
ref={rootRef}
246280
>
281+
{children}
247282
<ChartErrorBoundary resetKeys={[chartConfig]}>
248283
<div>
249284
{metadata?.some(
@@ -334,9 +369,11 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
334369
<div
335370
ref={containerRef}
336371
style={{
372+
// TODO before merging, Align with chart-preview
337373
minWidth: 0,
338374
height: containerHeight.current,
339375
marginTop: 16,
376+
flexGrow: 1,
340377
}}
341378
>
342379
{isTablePreview ? (

0 commit comments

Comments
 (0)