Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/services/appsMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Metadata, StudyMetadata } from '../utils';
import { BaseVoltage, Metadata, StudyMetadata } from '../utils';

// https://github.com/gridsuite/deployment/blob/main/docker-compose/docker-compose.base.yml
// https://github.com/gridsuite/deployment/blob/main/k8s/resources/common/config/apps-metadata.json
Expand Down Expand Up @@ -39,14 +39,21 @@ export function isStudyMetadata(metadata: Metadata): metadata is StudyMetadata {

export async function fetchStudyMetadata(): Promise<StudyMetadata> {
console.info(`Fetching study metadata...`);
const studyMetadata = (await fetchAppsMetadata()).filter(isStudyMetadata);
const studyMetadata = (await fetchAppsMetadata()).find(isStudyMetadata);
if (!studyMetadata) {
throw new Error('Study entry could not be found in metadata');
} else {
return studyMetadata[0]; // There should be only one study metadata
return studyMetadata; // There should be only one study metadata
}
}

export async function fetchBaseVoltages(): Promise<BaseVoltage[]> {
console.info(`Fetching apps' base voltages...`);
const env = await fetchEnv();
const res = await fetch(`${env.appsMetadataServerUrl}/apps-metadata-base-voltages.json`);
return res.json();
}

export async function fetchFavoriteAndDefaultCountries(): Promise<{
favoriteCountries: string[];
defaultCountry?: string;
Expand Down
18 changes: 18 additions & 0 deletions src/utils/types/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ export type StudyMetadata = Metadata & {
favoriteCountries?: string[];
substationPropertiesGlobalFilters?: Map<string, string[]>; // used to generate user specific global filters
};

type ThemeColors = Record<string, string>;
type SldAndNadColors = {
darkThemeColors: ThemeColors;
lightThemeColors: ThemeColors;
};

export type BaseVoltageConfig = {
// used when calling powsybl server
name: string;
minValue: number;
maxValue: number;
};
export type BaseVoltage = BaseVoltageConfig & {
// used to define the voltage ranges and their colors
networkMapColor: string;
sldAndNadColors: SldAndNadColors;
};
Loading