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,49 @@ export const ChartWrapper = forwardRef<HTMLDivElement, ChartWrapperProps>(
4850 ( props , ref ) => {
4951 const { children, editing, layoutType, ...rest } = props ;
5052 const classes = useStyles ( ) ;
53+ const [ state , dispatch ] = 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 : chartConfig . cubes . map ( ( cube ) => ( {
70+ iri : cube . iri ,
71+ componentIris,
72+ filters : cube . filters ,
73+ joinBy : cube . joinBy ,
74+ } ) ) ,
75+ } ,
76+ } ) ;
77+ const dimensionsByIri = useMemo ( ( ) => {
78+ return keyBy (
79+ [
80+ ...( components ?. dataCubesComponents . dimensions ?? [ ] ) ,
81+ ...( components ?. dataCubesComponents . measures ?? [ ] ) ,
82+ ] ,
83+ ( x ) => x . iri
84+ ) ;
85+ } , [ components ?. dataCubesComponents ] ) ;
86+
5187 return (
5288 < Box
5389 ref = { ref }
5490 { ...rest }
5591 className = { clsx ( classes . chartWrapper , props . className ) }
5692 >
57- { ( editing || layoutType === "tab" ) && < ChartSelectionTabs /> }
93+ { ( editing || layoutType === "tab" ) && (
94+ < ChartSelectionTabs dimensionsByIri = { dimensionsByIri } />
95+ ) }
5896 < Box
5997 className = { classes . chartWrapperInner }
6098 sx = { { minHeight : [ 150 , 300 , 500 ] } }
0 commit comments