Skip to content

Commit 84893c3

Browse files
authored
Merge pull request #1469 from visualize-admin/fix/dashboard-layout-with-interactive-filters
fix: ChartPreview with Tall dashboard layout in edit mode and interactive filters active
2 parents 1214303 + 7f4837c commit 84893c3

File tree

3 files changed

+48
-39
lines changed

3 files changed

+48
-39
lines changed

app/components/chart-preview.tsx

+10-19
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
useDroppable,
88
} from "@dnd-kit/core";
99
import { Trans } from "@lingui/macro";
10-
import { Box, Theme } from "@mui/material";
11-
import { makeStyles } from "@mui/styles";
10+
import { Box } from "@mui/material";
1211
import Head from "next/head";
1312
import React from "react";
1413

@@ -28,8 +27,9 @@ import {
2827
ChartTablePreviewProvider,
2928
useChartTablePreview,
3029
} from "@/components/chart-table-preview";
30+
import { useChartStyles } from "@/components/chart-utils";
3131
import { ChartWithFilters } from "@/components/chart-with-filters";
32-
import DebugPanel, { shouldShowDebugPanel } from "@/components/debug-panel";
32+
import DebugPanel from "@/components/debug-panel";
3333
import Flex from "@/components/flex";
3434
import { Checkbox } from "@/components/form";
3535
import { HintYellow } from "@/components/hint";
@@ -301,19 +301,6 @@ const SingleURLsPreview = (props: SingleURLsPreviewProps) => {
301301
);
302302
};
303303

304-
const useStyles = makeStyles<Theme>((theme) => ({
305-
root: {
306-
display: "grid",
307-
gridTemplateRows: "subgrid",
308-
gridRow: shouldShowDebugPanel() ? "span 5" : "span 4",
309-
backgroundColor: theme.palette.background.paper,
310-
color: theme.palette.grey[800],
311-
padding: theme.spacing(6),
312-
border: "1px solid",
313-
borderColor: theme.palette.divider,
314-
},
315-
}));
316-
317304
type ChartPreviewInnerProps = ChartPreviewProps & {
318305
chartKey?: string | null;
319306
actionElementSlot?: React.ReactNode;
@@ -327,7 +314,7 @@ export const ChartPreviewInner = (props: ChartPreviewInnerProps) => {
327314
const configuring = isConfiguring(state);
328315
const chartConfig = getChartConfig(state, chartKey);
329316
const locale = useLocale();
330-
const classes = useStyles();
317+
const chartClasses = useChartStyles();
331318
const commonQueryVariables = {
332319
sourceType: dataSource.type,
333320
sourceUrl: dataSource.url,
@@ -369,7 +356,7 @@ export const ChartPreviewInner = (props: ChartPreviewInnerProps) => {
369356
}, [dimensions, measures]);
370357

371358
return (
372-
<Box className={classes.root}>
359+
<Box className={chartClasses.root}>
373360
<ChartErrorBoundary resetKeys={[state]}>
374361
{/* FIXME: adapt to design */}
375362
{metadata?.dataCubesMetadata.some(
@@ -459,11 +446,15 @@ export const ChartPreviewInner = (props: ChartPreviewInnerProps) => {
459446
// title and the chart (subgrid layout)
460447
<span />
461448
)}
462-
{chartConfig.interactiveFiltersConfig?.dataFilters.active && (
449+
{chartConfig.interactiveFiltersConfig?.dataFilters.active ? (
463450
<ChartDataFilters
464451
dataSource={dataSource}
465452
chartConfig={chartConfig}
466453
/>
454+
) : (
455+
// We need to have a span here to keep the space between the
456+
// description and the chart (subgrid layout)
457+
<span />
467458
)}
468459
<div
469460
ref={containerRef}

app/components/chart-published.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Trans } from "@lingui/macro";
22
import { Box, Theme } from "@mui/material";
33
import { makeStyles } from "@mui/styles";
4+
import clsx from "clsx";
45
import React, { useEffect, useMemo, useRef } from "react";
56
import { useStore } from "zustand";
67

@@ -20,8 +21,8 @@ import {
2021
ChartTablePreviewProvider,
2122
useChartTablePreview,
2223
} from "@/components/chart-table-preview";
24+
import { useChartStyles } from "@/components/chart-utils";
2325
import { ChartWithFilters } from "@/components/chart-with-filters";
24-
import { shouldShowDebugPanel } from "@/components/debug-panel";
2526
import Flex from "@/components/flex";
2627
import { HintBlue, HintRed, HintYellow } from "@/components/hint";
2728
import { MetadataPanel } from "@/components/metadata-panel";
@@ -141,22 +142,17 @@ export const ChartPublished = (props: ChartPublishedProps) => {
141142
);
142143
};
143144

144-
const useStyles = makeStyles<Theme, { shrink: boolean }>((theme) => ({
145-
root: {
146-
position: "relative",
147-
display: "grid",
148-
gridTemplateRows: "subgrid",
149-
gridRow: shouldShowDebugPanel() ? "span 6" : "span 5",
150-
backgroundColor: theme.palette.background.paper,
151-
border: "1px solid",
152-
borderColor: theme.palette.divider,
153-
padding: theme.spacing(6),
154-
paddingLeft: ({ shrink }) =>
155-
`calc(${theme.spacing(5)} + ${shrink ? DRAWER_WIDTH : 0}px)`,
156-
color: theme.palette.grey[800],
157-
transition: "padding 0.25s ease",
158-
},
159-
}));
145+
const usePublishedChartStyles = makeStyles<Theme, { shrink: boolean }>(
146+
(theme) => ({
147+
root: {
148+
// Needed for the metadata panel to be contained inside the root.
149+
position: "relative",
150+
paddingLeft: ({ shrink }) =>
151+
`calc(${theme.spacing(5)} + ${shrink ? DRAWER_WIDTH : 0}px)`,
152+
transition: "padding 0.25s ease",
153+
},
154+
})
155+
);
160156

161157
type ChartPublishInnerProps = {
162158
dataSource: DataSource | undefined;
@@ -203,7 +199,8 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
203199
return () => unsubscribe();
204200
});
205201

206-
const classes = useStyles({
202+
const chartClasses = useChartStyles();
203+
const publishedChartClasses = usePublishedChartStyles({
207204
shrink: shouldShrink,
208205
});
209206
const locale = useLocale();
@@ -246,7 +243,10 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
246243

247244
return (
248245
<MetadataPanelStoreContext.Provider value={metadataPanelStore}>
249-
<Box className={classes.root} ref={rootRef}>
246+
<Box
247+
className={clsx(chartClasses.root, publishedChartClasses.root)}
248+
ref={rootRef}
249+
>
250250
<ChartErrorBoundary resetKeys={[chartConfig]}>
251251
{metadata?.some(
252252
(d) => d.publicationStatus === DataCubePublicationStatus.Draft
@@ -329,7 +329,7 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
329329
/>
330330
) : (
331331
// We need to have a span here to keep the space between the
332-
// title and the chart (subgrid layout)
332+
// description and the chart (subgrid layout)
333333
<span />
334334
)}
335335
<div

app/components/chart-utils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Theme } from "@mui/material";
2+
import { makeStyles } from "@mui/styles";
3+
4+
import { shouldShowDebugPanel } from "@/components/debug-panel";
5+
6+
/** Generic styles shared between `ChartPreview` and `ChartPublished`. */
7+
export const useChartStyles = makeStyles<Theme>((theme) => ({
8+
root: {
9+
display: "grid",
10+
gridTemplateRows: "subgrid",
11+
gridRow: shouldShowDebugPanel() ? "span 6" : "span 5",
12+
padding: theme.spacing(6),
13+
backgroundColor: theme.palette.background.paper,
14+
border: "1px solid",
15+
borderColor: theme.palette.divider,
16+
color: theme.palette.grey[800],
17+
},
18+
}));

0 commit comments

Comments
 (0)