From ddebff3cc1db5d2496bdccd546c8255940efad65 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 29 Nov 2022 13:46:47 +0100 Subject: [PATCH] feat: Shrink published chart when metadata panel is opened --- app/components/chart-published.tsx | 252 +++++++++++++++-------------- 1 file changed, 130 insertions(+), 122 deletions(-) diff --git a/app/components/chart-published.tsx b/app/components/chart-published.tsx index 44d7dab5c4..7278903060 100644 --- a/app/components/chart-published.tsx +++ b/app/components/chart-published.tsx @@ -3,6 +3,7 @@ import { Box, Theme, Typography } from "@mui/material"; import { makeStyles } from "@mui/styles"; import * as React from "react"; import { useEffect, useMemo, useRef } from "react"; +import { useStore } from "zustand"; import { ChartDataFilters } from "@/charts/shared/chart-data-filters"; import { isUsingImputation } from "@/charts/shared/imputation"; @@ -32,6 +33,7 @@ import { PublishedConfiguratorStateProvider, } from "@/configurator"; import { DataSetTable } from "@/configurator/components/datatable"; +import { DRAWER_WIDTH } from "@/configurator/components/drawer"; import { flag } from "@/configurator/components/flag"; import { parseDate } from "@/configurator/components/ui-helpers"; import { @@ -59,34 +61,35 @@ export const ChartPublished = ({ chartConfig: ChartConfig; configKey: string; }) => { - const metadataPanelStore = useMemo(() => createMetadataPanelStore(), []); - return ( - - - + ); }; -const useStyles = makeStyles((theme: Theme) => ({ - root: { - position: "relative", - display: "flex", - flexGrow: 1, - flexDirection: "column", - padding: theme.spacing(5), - color: theme.palette.grey[800], - overflowX: "auto", - }, -})); +const useStyles = makeStyles( + (theme) => ({ + root: { + position: "relative", + display: "flex", + flexGrow: 1, + flexDirection: "column", + padding: theme.spacing(5), + paddingLeft: ({ metadataPanelOpen }) => + `calc(${theme.spacing(5)} + ${metadataPanelOpen ? DRAWER_WIDTH : 0}px)`, + color: theme.palette.grey[800], + overflowX: "auto", + transition: "padding 0.25s ease", + }, + }) +); export const ChartPublishedInner = ({ dataSet, @@ -101,7 +104,10 @@ export const ChartPublishedInner = ({ chartConfig: ChartConfig; configKey: string; }) => { - const classes = useStyles(); + const metadataPanelStore = useMemo(() => createMetadataPanelStore(), []); + const metadataPanelOpen = useStore(metadataPanelStore, (state) => state.open); + + const classes = useStyles({ metadataPanelOpen }); const locale = useLocale(); const isTrustedDataSource = useIsTrustedDataSource(dataSource); @@ -140,109 +146,111 @@ export const ChartPublishedInner = ({ }, [metaData?.dataCubeByIri?.dimensions, metaData?.dataCubeByIri?.measures]); return ( - - - {metaData?.dataCubeByIri?.publicationStatus === - DataCubePublicationStatus.Draft && ( - - - - Careful, this dataset is only a draft. -
- Don't use for reporting! -
-
-
- )} - {metaData?.dataCubeByIri?.expires && ( - - - - Careful, the data for this chart has expired. -
- Don't use for reporting! -
-
-
- )} - {!isTrustedDataSource && ( - - - - This chart is not using a trusted data source. - - - - )} - {isUsingImputation(chartConfig) && ( - - - - Some data in this dataset is missing and has been interpolated - to fill the gaps. - - - - )} - - - {meta.title[locale]} - - - {flag("metadata") && ( - + + + + {metaData?.dataCubeByIri?.publicationStatus === + DataCubePublicationStatus.Draft && ( + + + + Careful, this dataset is only a draft. +
+ Don't use for reporting! +
+
+
+ )} + {metaData?.dataCubeByIri?.expires && ( + + + + Careful, the data for this chart has expired. +
+ Don't use for reporting! +
+
+
+ )} + {!isTrustedDataSource && ( + + + + This chart is not using a trusted data source. + + + )} -
+ {isUsingImputation(chartConfig) && ( + + + + Some data in this dataset is missing and has been interpolated + to fill the gaps. + + + + )} + + + {meta.title[locale]} + - {meta.description[locale] && ( - - {meta.description[locale]} - - )} - - - - {isTablePreview ? ( - - ) : ( - - )} - + {flag("metadata") && ( + + )} - {chartConfig && ( - + + {meta.description[locale] && ( + + {meta.description[locale]} + )} - -
-
+ + + + {isTablePreview ? ( + + ) : ( + + )} + + + {chartConfig && ( + + )} + + + + ); };