diff --git a/app/components/chart-panel.tsx b/app/components/chart-panel.tsx index d445fd16cb..67d9474441 100644 --- a/app/components/chart-panel.tsx +++ b/app/components/chart-panel.tsx @@ -1,7 +1,8 @@ import { Box, BoxProps, Theme } from "@mui/material"; import { makeStyles } from "@mui/styles"; import clsx from "clsx"; -import React, { forwardRef, HTMLProps } from "react"; +import keyBy from "lodash/keyBy"; +import React, { forwardRef, HTMLProps, useMemo } from "react"; import ChartPanelLayoutCanvas, { chartPanelLayoutGridClasses, @@ -12,7 +13,8 @@ import { ChartSelectionTabs } from "@/components/chart-selection-tabs"; import { DashboardInteractiveFilters } from "@/components/dashboard-interactive-filters"; import { ChartConfig, Layout, LayoutDashboard } from "@/config-types"; import { hasChartConfigs } from "@/configurator"; -import { useConfiguratorState } from "@/src"; +import { useDataCubesComponentsQuery } from "@/graphql/hooks"; +import { useConfiguratorState, useLocale } from "@/src"; const useStyles = makeStyles((theme: Theme) => ({ panelLayout: { @@ -48,13 +50,50 @@ export const ChartWrapper = forwardRef( (props, ref) => { const { children, editing, layoutType, ...rest } = props; const classes = useStyles(); + const [state] = useConfiguratorState(hasChartConfigs); + const dataSource = state.dataSource; + const locale = useLocale(); + const commonQueryVariables = { + sourceType: dataSource.type, + sourceUrl: dataSource.url, + locale, + }; + + const componentIris = undefined; + const chartConfig = state.chartConfigs.find( + (x) => x.key === state.activeChartKey + ); + const [{ data: components }] = useDataCubesComponentsQuery({ + variables: { + ...commonQueryVariables, + cubeFilters: + chartConfig?.cubes.map((cube) => ({ + iri: cube.iri, + componentIris, + filters: cube.filters, + joinBy: cube.joinBy, + })) ?? [], + }, + }); + const dimensionsByIri = useMemo(() => { + return keyBy( + [ + ...(components?.dataCubesComponents.dimensions ?? []), + ...(components?.dataCubesComponents.measures ?? []), + ], + (x) => x.iri + ); + }, [components?.dataCubesComponents]); + return ( - {(editing || layoutType === "tab") && } + {(editing || layoutType === "tab") && ( + + )} { // we switch tabs in the configurator, otherwise we end up with the wrong // data in the downstream hooks (useDataCubesMetadataQuery, etc.) + {state.state !== "CONFIGURING_CHART" ? ( + x.key).join(",")} + /> + ) : null} diff --git a/app/components/chart-published.tsx b/app/components/chart-published.tsx index 1e61f62db7..fbd8da2830 100644 --- a/app/components/chart-published.tsx +++ b/app/components/chart-published.tsx @@ -19,6 +19,7 @@ import { } from "@/components/chart-table-preview"; import { useChartStyles } from "@/components/chart-utils"; import { ChartWithFilters } from "@/components/chart-with-filters"; +import { DashboardInteractiveFilters } from "@/components/dashboard-interactive-filters"; import Flex from "@/components/flex"; import { HintBlue, HintRed, HintYellow } from "@/components/hint"; import { @@ -149,6 +150,7 @@ export const ChartPublished = (props: ChartPublishedProps) => { )} + ) => { ); }; -export const ChartSelectionTabs = () => { +export const ChartSelectionTabs = ({ + dimensionsByIri, +}: { + dimensionsByIri: Record; +}) => { const [state] = useConfiguratorState(hasChartConfigs); const editable = isConfiguring(state) || isLayouting(state) || isPublishing(state); @@ -123,7 +129,7 @@ export const ChartSelectionTabs = () => { ? d.meta.title[locale] : d.meta.title[defaultLocale] !== "" ? d.meta.title[defaultLocale] - : t({ id: "annotation.add.title" }), + : generateChartTitle(d, dimensionsByIri), }; }); @@ -936,14 +942,16 @@ const TabContent = (props: TabContentProps) => { {label ? ( - + + + ) : null} {editable && (