From bd08a9c87bd21c2da3e8eaab9d54db18acdab838 Mon Sep 17 00:00:00 2001 From: Marco Montanari Date: Tue, 22 Oct 2024 03:02:14 +0200 Subject: [PATCH] menu --- src/app/components/MapMenuBar/index.tsx | 5 ++++- src/app/pages/MapPage/index.tsx | 26 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/app/components/MapMenuBar/index.tsx b/src/app/components/MapMenuBar/index.tsx index 3f733dd..9969bb9 100644 --- a/src/app/components/MapMenuBar/index.tsx +++ b/src/app/components/MapMenuBar/index.tsx @@ -62,6 +62,7 @@ export interface MapMenuBar { current_map?: any; foundLayers: number; setCurrentMap: Function; + openError: Function; } const MAP_MODES = { @@ -81,6 +82,7 @@ export function MapMenuBar(props: MapMenuBar) { const foundLayers = props.foundLayers; const setCurrentmap = props.setCurrentMap; const combinations = props.combinations || []; + const openError = props.openError; const activeCombinations = useRef( Object.keys(combinations).length > 0 ? combinations['tas::30yr'] : {}, @@ -298,7 +300,8 @@ export function MapMenuBar(props: MapMenuBar) { }; useEffect(() => { - if (foundLayers === 0) { + if (foundLayers !== 1) { + openError('wrong_config'); setActiveCombinations(combinations[current_map.climatological_variable]); } }, [foundLayers]); diff --git a/src/app/pages/MapPage/index.tsx b/src/app/pages/MapPage/index.tsx index d4bb1c1..a4b4f4c 100644 --- a/src/app/pages/MapPage/index.tsx +++ b/src/app/pages/MapPage/index.tsx @@ -149,7 +149,10 @@ export function MapPage(props: MapPageProps) { 'tasmax', 'tasmin', 'tr', + 'fd', ]; + + const changeables = ['measure', 'year_period', 'time_window']; api.getAttributes().then(x => { let combos = x.combinations.reduce((prev, cur) => { for (let k of Object.keys(defaultMap)) { @@ -244,21 +247,33 @@ export function MapPage(props: MapPageProps) { setCurrentLayerConfig(conf); }); } else { - openError('wrong_config'); let nm = { ...currentMap }; - const kk = currentMap.climatological_variable; + let kk = currentMap.climatological_variable; + let pkk = kk + '::' + currentMap.aggregation_period; + let mkk = kk + '::' + currentMap.measure; if (kk in combinations) { let opts = combinations[kk]; + if (pkk in combinations) { + opts = combinations[pkk]; + } else if (mkk in combinations) { + } console.log(opts); if (opts) { for (let k of Object.keys(currentMap)) { - if (k !== 'climatological_variable') { - if (opts[k].indexOf(currentMap[k]) < 0) { + if (changeables.indexOf(k) >= 0) { + if ( + opts[k].indexOf(currentMap[k]) < 0 && + opts[k].indexOf('measure') >= 0 + ) { if (opts[k].length > 0) { - nm[k] = opts[k][0]; + nm[k] = opts[k][opts[k].length - 1]; } else { nm[k] = null; } + } else { + opts[k] = all_meas.filter( + x => x !== currentMap.measure, + )[0]; } } } @@ -436,6 +451,7 @@ export function MapPage(props: MapPageProps) { current_map={currentMap} foundLayers={foundLayers} setCurrentMap={setCurrentMap} + openError={openError} />