Skip to content

Commit 9cffe1e

Browse files
committed
feat: Recompute container height on change of metadata panel
1 parent fa65b1b commit 9cffe1e

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

app/components/chart-published.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export const ChartPublishedInner = ({
109109
setState: setIsTablePreview,
110110
containerRef,
111111
containerHeight,
112+
computeContainerHeight,
112113
} = useChartTablePreview();
113114

114115
const metadataPanelStore = useMemo(() => createMetadataPanelStore(), []);
@@ -124,6 +125,12 @@ export const ChartPublishedInner = ({
124125
return metadataPanelOpen && rootWidth > DRAWER_WIDTH * 2;
125126
}, [metadataPanelOpen]);
126127

128+
useEffect(() => {
129+
metadataPanelStore.subscribe(() => {
130+
computeContainerHeight();
131+
});
132+
});
133+
127134
const classes = useStyles({
128135
shrink: shouldShrink,
129136
});

app/components/chart-table-preview.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Context = {
1717
setStateRaw: Dispatch<SetStateAction<boolean>>;
1818
containerRef: RefObject<HTMLDivElement>;
1919
containerHeight: RefObject<"auto" | number>;
20+
computeContainerHeight: () => void;
2021
};
2122

2223
const ChartTablePreviewContext = createContext<Context>({
@@ -25,6 +26,7 @@ const ChartTablePreviewContext = createContext<Context>({
2526
setStateRaw: () => {},
2627
containerRef: { current: null },
2728
containerHeight: { current: "auto" },
29+
computeContainerHeight: () => undefined,
2830
});
2931

3032
export const useChartTablePreview = () => {
@@ -52,13 +54,16 @@ export const ChartTablePreviewProvider = ({
5254
const [state, setStateRaw] = useState<boolean>(false);
5355
const containerHeight = useRef("auto" as "auto" | number);
5456
const containerRef = useRef<HTMLDivElement>(null);
57+
const computeContainerHeight = () => {
58+
if (!containerRef.current) {
59+
return;
60+
}
61+
const bcr = containerRef.current.getBoundingClientRect();
62+
containerHeight.current = bcr.height;
63+
};
5564
const setState = useCallback(
5665
(v) => {
57-
if (!containerRef.current) {
58-
return;
59-
}
60-
const bcr = containerRef.current.getBoundingClientRect();
61-
containerHeight.current = bcr.height;
66+
computeContainerHeight();
6267
return setStateRaw(v);
6368
},
6469
[setStateRaw]
@@ -71,6 +76,7 @@ export const ChartTablePreviewProvider = ({
7176
setStateRaw,
7277
containerRef,
7378
containerHeight,
79+
computeContainerHeight,
7480
};
7581
}, [setState, state, containerRef, containerHeight, setStateRaw]);
7682
return (

0 commit comments

Comments
 (0)