Skip to content

Commit

Permalink
menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sirmmo committed Oct 22, 2024
1 parent 92257b9 commit bd08a9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/app/components/MapMenuBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface MapMenuBar {
current_map?: any;
foundLayers: number;
setCurrentMap: Function;
openError: Function;
}

const MAP_MODES = {
Expand All @@ -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'] : {},
Expand Down Expand Up @@ -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]);
Expand Down
26 changes: 21 additions & 5 deletions src/app/pages/MapPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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];
}
}
}
Expand Down Expand Up @@ -436,6 +451,7 @@ export function MapPage(props: MapPageProps) {
current_map={currentMap}
foundLayers={foundLayers}
setCurrentMap={setCurrentMap}
openError={openError}
/>

<Map
Expand Down

0 comments on commit bd08a9c

Please sign in to comment.