Skip to content

Commit 7dedece

Browse files
authored
move baseMapOptions to metadata (#970)
Signed-off-by: Etienne LESOT <[email protected]>
1 parent 508203a commit 7dedece

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/components/parameters/network-visualizations/constants.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
import {
8-
MAP_BASEMAP_CARTO,
9-
MAP_BASEMAP_CARTO_NOLABEL,
10-
MAP_BASEMAP_ETALAB,
11-
MAP_BASEMAP_MAPBOX,
12-
NadPositionsGenerationMode,
13-
SubstationLayout,
14-
} from './network-visualizations.types';
7+
import { NadPositionsGenerationMode, SubstationLayout } from './network-visualizations.types';
158

169
// Defined in powsybl/network-viewer, duplicated here
1710
export enum LineFlowMode {
@@ -61,25 +54,6 @@ export const INTL_LINE_FLOW_MODE_OPTIONS = [
6154
},
6255
];
6356

64-
export const INTL_MAP_BASE_MAP_OPTIONS = [
65-
{
66-
id: MAP_BASEMAP_MAPBOX,
67-
label: 'Mapbox',
68-
},
69-
{
70-
id: MAP_BASEMAP_CARTO,
71-
label: 'Carto',
72-
},
73-
{
74-
id: MAP_BASEMAP_CARTO_NOLABEL,
75-
label: 'CartoNoLabel',
76-
},
77-
{
78-
id: MAP_BASEMAP_ETALAB,
79-
label: 'Etalab',
80-
},
81-
];
82-
8357
export const INTL_SUBSTATION_LAYOUT_OPTIONS = [
8458
{
8559
id: SubstationLayout.HORIZONTAL,

src/components/parameters/network-visualizations/map-parameters.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,48 @@
66
*/
77
import { Grid } from '@mui/material';
88
import { FormattedMessage } from 'react-intl';
9+
import { useEffect, useState } from 'react';
910
import {
1011
INTL_LINE_FLOW_MODE_OPTIONS,
11-
INTL_MAP_BASE_MAP_OPTIONS,
1212
LINE_FLOW_MODE,
13+
LineFlowMode,
1314
MAP_BASE_MAP,
1415
MAP_MANUAL_REFRESH,
15-
PARAM_LINE_FULL_PATH,
16-
PARAM_MAP_BASEMAP,
1716
NetworkVisualizationTabValues as TabValues,
18-
PARAM_LINE_PARALLEL_PATH,
1917
PARAM_LINE_FLOW_MODE,
18+
PARAM_LINE_FULL_PATH,
19+
PARAM_LINE_PARALLEL_PATH,
20+
PARAM_MAP_BASEMAP,
2021
PARAM_MAP_MANUAL_REFRESH,
21-
LineFlowMode,
2222
} from './constants';
2323
import { LineSeparator } from '../common';
2424
import { parametersStyles } from '../parameters-style';
2525
import { MuiSelectInput, SwitchInput } from '../../inputs';
26+
import { fetchStudyMetadata } from '../../../services';
27+
import { snackWithFallback } from '../../../utils';
28+
import { useSnackMessage } from '../../../hooks';
29+
30+
const fetchMapBaseOption = async (): Promise<{ id: string; label: string }[] | undefined> => {
31+
const studyMetadata = await fetchStudyMetadata();
32+
return studyMetadata.baseMapOptions;
33+
};
2634

2735
export function MapParameters() {
2836
// fields definition
37+
const [baseMapOptions, setBaseMapOptions] = useState<{ id: string; label: string }[]>([]);
38+
const { snackError } = useSnackMessage();
39+
useEffect(() => {
40+
fetchMapBaseOption()
41+
.then((p) => {
42+
if (p !== undefined) {
43+
setBaseMapOptions(p);
44+
}
45+
})
46+
.catch((error) => {
47+
snackWithFallback(snackError, error);
48+
});
49+
}, [setBaseMapOptions, snackError]);
50+
2951
const lineSwitch = (name: string, label: string) => (
3052
<>
3153
<Grid item xs={8} sx={parametersStyles.parameterName}>
@@ -63,7 +85,7 @@ export function MapParameters() {
6385
fullWidth
6486
name={`${TabValues.MAP}.${PARAM_MAP_BASEMAP}`}
6587
size="small"
66-
options={Object.values(INTL_MAP_BASE_MAP_OPTIONS)?.map((option) => option)}
88+
options={Object.values(baseMapOptions)?.map((option) => option)}
6789
/>
6890
</Grid>
6991
</>

src/utils/types/metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type StudyMetadata = Metadata & {
3030
defaultCountry?: string;
3131
favoriteCountries?: string[];
3232
substationPropertiesGlobalFilters?: Map<string, string[]>; // used to generate user specific global filters
33+
baseMapOptions?: { id: string; label: string }[];
3334
};
3435

3536
type ThemeColors = Record<string, string>;

0 commit comments

Comments
 (0)