Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DirectoryItemSelector } from '../../../components/ui/directoryItemSelec
import { PopupConfirmationDialog } from '../../../components/ui/dialogs';
import {
toFormValues,
toParamsInfos,
toParamsEnriched,
useDynamicSimulationParametersForm,
} from './use-dynamic-simulation-parameters-form';
import { DynamicSimulationForm } from './dynamic-simulation-parameters-form';
Expand Down Expand Up @@ -83,7 +83,7 @@ export function DynamicSimulationInline({
const onSubmit = useCallback(
(formData: FieldValues) => {
// update params after convert form representation to dto representation
updateParameters(toParamsInfos(formData, getDefaultParams()));
updateParameters(toParamsEnriched(formData, getDefaultParams()));
},
Comment on lines 89 to 93
[updateParameters, getDefaultParams]
);
Expand Down Expand Up @@ -142,7 +142,7 @@ export function DynamicSimulationInline({
open={openCreateParameterDialog}
onClose={() => setOpenCreateParameterDialog(false)}
parameterValues={getValues}
parameterFormatter={(formData) => toParamsInfos(formData, getDefaultParams())}
parameterFormatter={(formData) => toParamsEnriched(formData, getDefaultParams())}
parameterType={ElementType.DYNAMIC_SIMULATION_PARAMETERS}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
*/
import * as yup from 'yup';
import { MAPPING } from './mapping-parameters-constants';
import { ID, NAME } from '../../common/parameter-table-field';

export const mappingFormSchema = yup.object().shape({
[MAPPING]: yup.string().required(),
[MAPPING]: yup
.object()
.shape({
[ID]: yup.string().required(),
[NAME]: yup.string().required(),
})
.required(),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
});

export const mappingEmptyFormData = {
[MAPPING]: '',
[MAPPING]: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Grid } from '@mui/material';
import { useEffect, useMemo, useState } from 'react';
import { ParameterType, SpecificParameterInfos } from '../../../../utils/types/parameters.type';
import { MappingInfos } from '../../../../utils/types/dynamic-simulation.type';
import ParameterField from '../../common/parameter-field';
import { MAPPING } from './mapping-parameters-constants';
import { getDynamicMappings } from '../../../../services';
import { snackWithFallback } from '../../../../utils';
import { useSnackMessage } from '../../../../hooks';
import { ElementType } from '../../../../utils';
import { ParameterLineDirectoryItemsInput } from '../../common';

interface MappingParametersProps {
path: string;
}

export function MappingParameters({ path }: Readonly<MappingParametersProps>) {
const { snackError } = useSnackMessage();
const [mappings, setMappings] = useState<MappingInfos[]>([]);

useEffect(() => {
getDynamicMappings()
.then((_mappings) => {
setMappings(_mappings);
})
.catch((error: Error) => {
snackWithFallback(snackError, error, {
headerId: `DynamicSimulationMappingsError`,
});
});
}, [setMappings, snackError]);

const mappingOptions = useMemo(() => {
return mappings?.map((elem) => elem.name) ?? [];
}, [mappings]);

const params: SpecificParameterInfos[] = useMemo(
() => [
{
name: MAPPING,
type: ParameterType.STRING,
label: 'DynamicSimulationMapping',
possibleValues: mappingOptions,
sx: { width: '100%' },
},
],
[mappingOptions]
);

return (
<Grid container>
{params.map((param: SpecificParameterInfos) => {
const { name, type, ...otherParams } = param;
return (
<ParameterField key={param.name} id={path} name={param.name} type={param.type} {...otherParams} />
);
})}
<ParameterLineDirectoryItemsInput
name={`${path}.${MAPPING}`}
elementType={ElementType.DYNAMIC_SIMULATION_MAPPING}
label="DynamicSimulationMapping"
hideErrorMessage
/>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</Grid>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import { FieldValues } from 'react-hook-form';
import * as yup from 'yup';
import { UseComputationParametersFormReturn } from '../common/utils';
import { DynamicSimulationParametersInfos, SolverInfos } from '../../../utils/types/dynamic-simulation.type';
import {
DynamicSimulationParametersEnriched,
DynamicSimulationParametersInfos,
SolverInfos,
} from '../../../utils/types/dynamic-simulation.type';
import { TabValues } from './dynamic-simulation.type';
import { PROVIDER } from '../common/constants';
import { timeDelayEmptyFormData, timeDelayFormSchema } from './time-delay/time-delay-parameters-utils';
Expand Down Expand Up @@ -40,7 +44,7 @@ const emptyFormData = {
[TabValues.TAB_CURVE]: curveEmptyFormData,
};

export const toFormValues = (_params: DynamicSimulationParametersInfos): FieldValues => ({
export const toFormValues = (_params: DynamicSimulationParametersEnriched): FieldValues => ({
[ID]: _params.id, // not show in form
[PROVIDER]: _params.provider,
[TabValues.TAB_TIME_DELAY]: {
Expand All @@ -62,10 +66,10 @@ export const toFormValues = (_params: DynamicSimulationParametersInfos): FieldVa
},
});

export const toParamsInfos = (
export const toParamsEnriched = (
_formData: FieldValues,
defaultParams: DynamicSimulationParametersInfos | null
): DynamicSimulationParametersInfos => ({
defaultParams: DynamicSimulationParametersEnriched | null
): DynamicSimulationParametersEnriched => ({
provider: _formData[PROVIDER],
startTime: _formData[TabValues.TAB_TIME_DELAY][TimeDelay.START_TIME],
stopTime: _formData[TabValues.TAB_TIME_DELAY][TimeDelay.STOP_TIME],
Expand Down
4 changes: 2 additions & 2 deletions src/services/dynamic-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { backendFetchJson } from './utils';
import { DynamicSimulationModelInfos, MappingInfos } from '../utils';
import { DynamicSimulationModelInfos, IdName } from '../utils';

const PREFIX_DYNAMIC_MAPPING_SERVER_QUERIES = `${import.meta.env.VITE_API_GATEWAY}/dynamic-mapping`;

function getDynamicMappingUrl() {
return `${PREFIX_DYNAMIC_MAPPING_SERVER_QUERIES}/`;
}

export function getDynamicMappings(): Promise<MappingInfos[]> {
export function getDynamicMappings(): Promise<IdName[]> {
console.info(`Fetching dynamic mappings ...`);
const url = `${getDynamicMappingUrl()}mappings/`;
console.debug(url);
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en/businessErrorsEn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const businessErrorsEn = {
'securityAnalysis.contingencyListConfigEmpty': 'The configuration does not contain any contingency.',
'securityAnalysis.missingContingencyList':
'The configuration contains one or more contingency lists that have been deleted.',
'dynamicMapping.mappingNameNotProvided': 'Mapping name not provided',
'dynamicMapping.mappingNotProvided': 'Mapping not provided',
'dynamicSecurityAnalysis.providerNotFound': 'Dynamic security analysis provider not found.',
'dynamicSecurityAnalysis.contingenciesNotFound': 'No contingencies provided.',
'dynamicSecurityAnalysis.contingencyListEmpty': 'Contingency list parameter must not be null or empty.',
Expand Down
2 changes: 1 addition & 1 deletion src/translations/fr/businessErrorsFr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const businessErrorsFr = {
'securityAnalysis.contingencyListConfigEmpty': 'La configuration ne contient aucun aléas.',
'securityAnalysis.missingContingencyList':
"La configuration contient une ou des listes d'aléas qui ont été supprimées.",
'dynamicMapping.mappingNameNotProvided': 'Nom du mapping non fourni',
'dynamicMapping.mappingNotProvided': 'Mapping non fourni',
'dynamicSecurityAnalysis.providerNotFound': "Simulateur d'analyse de sécurité dynamique non trouvé.",
'dynamicSecurityAnalysis.contingenciesNotFound': 'Aucun aléa fourni.',
'dynamicSecurityAnalysis.contingencyListEmpty': "La liste d'aléas fournie ne doit pas être nulle ou vide.",
Expand Down
5 changes: 2 additions & 3 deletions src/utils/types/dynamic-margin-calculation.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { UUID } from 'node:crypto';
import { IdName } from './types';

export enum CalculationType {
GLOBAL_MARGIN = 'GLOBAL_MARGIN',
Expand All @@ -17,11 +18,9 @@ export enum LoadModelsRule {
TARGETED_LOADS = 'TARGETED_LOADS',
}

export type IdNameInfos = { id: UUID; name?: string };

export type LoadsVariationInfos = {
id?: UUID; // persisted id of the info to be modified
loadFilters?: IdNameInfos[];
loadFilters?: IdName[];
variation: number;
active: boolean;
};
Expand Down
22 changes: 17 additions & 5 deletions src/utils/types/dynamic-simulation.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import type { UUID } from 'node:crypto';
import { EquipmentType } from './equipmentType';
import { IdName } from './types';

export enum SolverType {
IDA = 'IDA',
Expand Down Expand Up @@ -83,22 +84,33 @@ type CurveInfos = {

export type SolverInfos = IdaSolverInfos | SimSolverInfos;

export type MappingInfos = {
name: string;
};

export type DynamicSimulationParametersInfos = {
id?: UUID;
provider?: string;
startTime?: number;
stopTime?: number;
mapping?: string;
mappingId?: UUID;
solver: SolverType;
solvers?: SolverInfos[];
network?: NetworkInfos;
curves?: CurveInfos[] | null;
};

export type DynamicSimulationParametersEnriched = Omit<DynamicSimulationParametersInfos, 'mappingId'> & {
mapping?: IdName;
};

export function mapDynamicSimulationParameters(
parameters: DynamicSimulationParametersEnriched
): DynamicSimulationParametersInfos {
const newParameters = {
...parameters,
mappingId: parameters.mapping?.id,
};
delete newParameters.mapping;
return newParameters;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// --- Types related to model/variables --- //

export type ModelVariableDefinitionInfos = {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/types/parameters.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ComputingType } from '../../features/parameters/common/computing-type';
import { LoadFlowParametersInfos } from './loadflow.type';
import { DynamicSecurityAnalysisParametersFetchReturn } from './dynamic-security-analysis.type';
import type { ILimitReductionsByVoltageLevel } from '../../features/parameters/common/limitreductions/columns-definitions';
import { DynamicSimulationParametersInfos } from './dynamic-simulation.type';
import { DynamicSimulationParametersEnriched } from './dynamic-simulation.type';
import { SensitivityAnalysisParametersInfosEnriched } from './sensitivity-analysis.type';
import { type ShortCircuitParametersInfos } from '../../features/parameters/short-circuit/short-circuit-parameters.type';
import { SAParametersEnriched } from './security-analysis.type';
Expand Down Expand Up @@ -47,7 +47,7 @@ export type ParametersInfos<T extends ComputingType> = T extends ComputingType.S
: T extends ComputingType.LOAD_FLOW
? LoadFlowParametersInfos
: T extends ComputingType.DYNAMIC_SIMULATION
? DynamicSimulationParametersInfos
? DynamicSimulationParametersEnriched
: T extends ComputingType.DYNAMIC_SECURITY_ANALYSIS
? DynamicSecurityAnalysisParametersFetchReturn
Comment on lines -43 to 52
: T extends ComputingType.DYNAMIC_MARGIN_CALCULATION
Expand Down
Loading