11import { Box , BoxProps , Theme } from "@mui/material" ;
22import { makeStyles } from "@mui/styles" ;
33import clsx from "clsx" ;
4- import React , { HTMLProps , forwardRef } from "react" ;
4+ import keyBy from "lodash/keyBy" ;
5+ import React , { forwardRef , HTMLProps , useMemo } from "react" ;
56
67import ChartPanelLayoutCanvas , {
78 chartPanelLayoutGridClasses ,
@@ -12,7 +13,8 @@ import { ChartSelectionTabs } from "@/components/chart-selection-tabs";
1213import { DashboardInteractiveFilters } from "@/components/dashboard-interactive-filters" ;
1314import { ChartConfig , Layout , LayoutDashboard } from "@/config-types" ;
1415import { hasChartConfigs } from "@/configurator" ;
15- import { useConfiguratorState } from "@/src" ;
16+ import { useDataCubesComponentsQuery } from "@/graphql/hooks" ;
17+ import { useConfiguratorState , useLocale } from "@/src" ;
1618
1719const useStyles = makeStyles ( ( theme : Theme ) => ( {
1820 panelLayout : {
@@ -48,13 +50,50 @@ export const ChartWrapper = forwardRef<HTMLDivElement, ChartWrapperProps>(
4850 ( props , ref ) => {
4951 const { children, editing, layoutType, ...rest } = props ;
5052 const classes = useStyles ( ) ;
53+ const [ state ] = useConfiguratorState ( hasChartConfigs ) ;
54+ const dataSource = state . dataSource ;
55+ const locale = useLocale ( ) ;
56+ const commonQueryVariables = {
57+ sourceType : dataSource . type ,
58+ sourceUrl : dataSource . url ,
59+ locale,
60+ } ;
61+
62+ const componentIris = undefined ;
63+ const chartConfig = state . chartConfigs . find (
64+ ( x ) => x . key === state . activeChartKey
65+ ) ;
66+ const [ { data : components } ] = useDataCubesComponentsQuery ( {
67+ variables : {
68+ ...commonQueryVariables ,
69+ cubeFilters :
70+ chartConfig ?. cubes . map ( ( cube ) => ( {
71+ iri : cube . iri ,
72+ componentIris,
73+ filters : cube . filters ,
74+ joinBy : cube . joinBy ,
75+ } ) ) ?? [ ] ,
76+ } ,
77+ } ) ;
78+ const dimensionsByIri = useMemo ( ( ) => {
79+ return keyBy (
80+ [
81+ ...( components ?. dataCubesComponents . dimensions ?? [ ] ) ,
82+ ...( components ?. dataCubesComponents . measures ?? [ ] ) ,
83+ ] ,
84+ ( x ) => x . iri
85+ ) ;
86+ } , [ components ?. dataCubesComponents ] ) ;
87+
5188 return (
5289 < Box
5390 ref = { ref }
5491 { ...rest }
5592 className = { clsx ( classes . chartWrapper , props . className ) }
5693 >
57- { ( editing || layoutType === "tab" ) && < ChartSelectionTabs /> }
94+ { ( editing || layoutType === "tab" ) && (
95+ < ChartSelectionTabs dimensionsByIri = { dimensionsByIri } />
96+ ) }
5897 < Box
5998 className = { classes . chartWrapperInner }
6099 sx = { { minHeight : [ 150 , 300 , 500 ] } }
0 commit comments