@@ -2,7 +2,7 @@ import { Trans } from "@lingui/macro";
22import { Box , Theme } from "@mui/material" ;
33import { makeStyles } from "@mui/styles" ;
44import clsx from "clsx" ;
5- import { useCallback , useEffect , useMemo , useRef } from "react" ;
5+ import { forwardRef , useCallback , useEffect , useMemo , useRef } from "react" ;
66import { useStore } from "zustand" ;
77
88import { 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+
6088export 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
161189const 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