Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
* 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 { Parameters, ColumnsDef, ID, NAME, DESCRIPTION, ACTIVATED } from '../parameter-table';
import { ElementType } from '../../../../utils';
import {
Parameters,
ColumnsDef,
DESCRIPTION,
ACTIVATED,
NAME,
ID,
CONTAINER_NAME,
CONTAINER_ID,
} from '../parameter-table';
import { ElementType, EquipmentsContainer } from '../../../../utils';
import { CONTINGENCY_LISTS_INFOS, CONTINGENCY_LISTS } from '../constants';
import yup from '../../../../utils/yupConfig';
import { IdName, ContingencyListsInfos } from './types';
import { ContingencyListsInfosEnriched } from './types';

export const COLUMNS_DEFINITIONS_CONTINGENCY_LISTS_INFOS: ColumnsDef[] = [
{
Expand Down Expand Up @@ -58,7 +67,10 @@ export const getContingencyListsInfosFormSchema = () => {
})
)
.required()
.min(1, 'FieldIsRequired'),
.when([ACTIVATED], {
is: (activated: boolean) => activated,
then: (schema) => schema.min(1, 'FieldIsRequired'),
}),
[DESCRIPTION]: yup.string(),
[ACTIVATED]: yup.boolean().required(),
})
Expand All @@ -67,15 +79,17 @@ export const getContingencyListsInfosFormSchema = () => {
.required();
};

export const toFormValuesContingencyListsInfos = (contingencyListsInfos: ContingencyListsInfos[]) => {
export const toFormValuesContingencyListsInfos = (contingencyListsInfos: ContingencyListsInfosEnriched[]) => {
return {
[CONTINGENCY_LISTS_INFOS]: contingencyListsInfos?.map((contingencyListInfos: ContingencyListsInfos) => ({
[CONTINGENCY_LISTS]: contingencyListInfos[CONTINGENCY_LISTS]?.map((c: IdName) => ({
[NAME]: c[NAME],
[ID]: c[ID],
})),
[DESCRIPTION]: contingencyListInfos[DESCRIPTION],
[ACTIVATED]: contingencyListInfos[ACTIVATED],
})),
[CONTINGENCY_LISTS_INFOS]: contingencyListsInfos?.map(
(contingencyListInfos: ContingencyListsInfosEnriched) => ({
[CONTINGENCY_LISTS]: contingencyListInfos[CONTINGENCY_LISTS]?.map((c: EquipmentsContainer) => ({
[NAME]: c[CONTAINER_NAME],
[ID]: c[CONTAINER_ID],
})),
[DESCRIPTION]: contingencyListInfos[DESCRIPTION],
[ACTIVATED]: contingencyListInfos[ACTIVATED],
})
),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { FieldValues, useWatch } from 'react-hook-form';
import { UUID } from 'node:crypto';
import { useCreateRowData, useSnackMessage } from '../../../../hooks';
import { ColumnsDef, ID, ACTIVATED, ParameterTable } from '../parameter-table';
import { ColumnsDef, ACTIVATED, ParameterTable, CONTAINER_ID } from '../parameter-table';
import { CONTINGENCY_LISTS, CONTINGENCY_LISTS_INFOS } from '../constants';
import { COLUMNS_DEFINITIONS_CONTINGENCY_LISTS_INFOS, ParamContingencyLists } from './columns-definitions';
import { ContingencyCount, ContingencyListsInfos } from './types';
import { ContingencyCount, ContingencyListsInfosEnriched } from './types';
import { DEFAULT_TIMEOUT_MS, IGNORE_SIGNAL } from '../../../../services';
import { snackWithFallback } from '../../../../utils';

Expand All @@ -29,7 +29,7 @@ export function ContingencyTable({
const intl = useIntl();
const [simulatedContingencyCount, setSimulatedContingencyCount] = useState<ContingencyCount | null>(null);
const [rowData, useFieldArrayOutput] = useCreateRowData(ParamContingencyLists);
const contingencyListsInfos: ContingencyListsInfos[] = useWatch({ name: CONTINGENCY_LISTS_INFOS });
const contingencyListsInfos: ContingencyListsInfosEnriched[] = useWatch({ name: CONTINGENCY_LISTS_INFOS });
const [isLoading, setIsLoading] = useState(false);
const { snackError } = useSnackMessage();

Expand Down Expand Up @@ -78,7 +78,9 @@ export function ContingencyTable({
fetchContingencyCount?.(
contingencyListsInfos
.filter((lists) => lists[ACTIVATED])
.flatMap((lists) => lists[CONTINGENCY_LISTS]?.map((contingencyList) => contingencyList[ID])),
.flatMap((lists) =>
lists[CONTINGENCY_LISTS]?.map((contingencyList) => contingencyList[CONTAINER_ID] as UUID)
),
abortSignal
)
.then((contingencyCount) => {
Expand Down
14 changes: 9 additions & 5 deletions src/components/parameters/common/contingency-table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { UUID } from 'node:crypto';
import { ACTIVATED, DESCRIPTION, ID, NAME } from '../parameter-table/constants';
import { ACTIVATED, DESCRIPTION } from '../parameter-table/constants';
import { CONTINGENCY_LISTS } from '../constants';

export interface IdName {
[ID]: UUID;
[NAME]: string;
import { EquipmentsContainer } from '../../../../utils';

export interface ContingencyListsInfosEnriched {
[CONTINGENCY_LISTS]: EquipmentsContainer[];
[DESCRIPTION]: string;
[ACTIVATED]: boolean;
}

export interface ContingencyListsInfos {
[CONTINGENCY_LISTS]: IdName[];
[CONTINGENCY_LISTS]: UUID[];
[DESCRIPTION]: string;
[ACTIVATED]: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/parameters/common/parameter-table/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const NAME = 'name';
export const ID = 'id';
export const ACTIVATED = 'activated';
export const DESCRIPTION = 'description';
export const CONTAINER_ID = 'containerId';
export const CONTAINER_NAME = 'containerName';
23 changes: 17 additions & 6 deletions src/components/parameters/pcc-min/pcc-min-form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,41 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { PccMinParameters } from '../../../services';
import { FILTER_ID, FILTER_NAME, FILTERS, ID } from '../../../utils/constants/filterConstant';
import { NAME } from '../../inputs';
import { UUID } from 'node:crypto';
import { FILTERS, ID } from '../../../utils/constants/filterConstant';
import { NAME } from '../common/parameter-table/constants';
import { EquipmentsContainer } from '../../../utils';

export const fromPccMinParametersFormToParamValues = (newParams: Record<string, any>): PccMinParameters | null => ({
export const fromPccMinParametersFormToParamValues = (
newParams: Record<string, any>
): PccMinParametersEnriched | null => ({
filters:
newParams[FILTERS]?.map((filter: any) => ({
filterId: filter[ID],
filterName: filter[NAME],
})) ?? [],
});

export const fromPccMinParamsDataToFormValues = (parameters: PccMinParameters | null): Record<string, any> => ({
export const fromPccMinParamsDataToFormValues = (parameters: PccMinParametersEnriched | null): Record<string, any> => ({
[FILTERS]:
parameters?.[FILTERS]?.map((filter) => ({
[ID]: filter[FILTER_ID],
[NAME]: filter[FILTER_NAME],
})) ?? [],
});

export const fromStudyPccMinParamsDataToFormValues = (parameters: PccMinParameters | null): Record<string, any> => ({
export const fromStudyPccMinParamsDataToFormValues = (
parameters: PccMinParametersEnriched | null
): Record<string, any> => ({
[FILTERS]:
parameters?.[FILTERS]?.map((filter) => ({
[ID]: filter[FILTER_ID],
[NAME]: filter[FILTER_NAME],
})) ?? [],
});
export type PccMinParametersEnriched = {
[FILTERS]: EquipmentsContainer[];
};
export type PccMinParameters = {
[FILTERS]: UUID[];
};
10 changes: 7 additions & 3 deletions src/components/parameters/pcc-min/pcc-min-parameters-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ import { CreateParameterDialog, LabelledButton } from '../common';
import { PopupConfirmationDialog } from '../../dialogs';
import { UsePccMinParametersForm } from './use-pcc-min-parameters-form';
import { PccMinParametersForm } from './pcc-min-parameters-form';
import { fetchPccMinParameters, PccMinParameters, updatePccMinParameters } from '../../../services/pcc-min';
import { fetchPccMinParameters, updatePccMinParameters } from '../../../services/pcc-min';
import { DirectoryItemSelector } from '../../directoryItemSelector';
import { ElementType, snackWithFallback } from '../../../utils';
import { TreeViewFinderNodeProps } from '../../treeViewFinder';
import { fromPccMinParametersFormToParamValues, fromPccMinParamsDataToFormValues } from './pcc-min-form-utils';
import {
fromPccMinParametersFormToParamValues,
fromPccMinParamsDataToFormValues,
PccMinParametersEnriched,
} from './pcc-min-form-utils';

export function PccMinParametersInLine({
studyUuid,
Expand All @@ -28,7 +32,7 @@ export function PccMinParametersInLine({
}: Readonly<{
studyUuid: UUID | null;
setHaveDirtyFields: (isDirty: boolean) => void;
pccMinParameters: PccMinParameters | null;
pccMinParameters: PccMinParametersEnriched | null;
}>) {
const pccMinMethods = UsePccMinParametersForm({
parametersUuid: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import {
fromPccMinParametersFormToParamValues,
fromPccMinParamsDataToFormValues,
fromStudyPccMinParamsDataToFormValues,
PccMinParametersEnriched,
} from './pcc-min-form-utils';
import { useSnackMessage } from '../../../hooks';
import { DESCRIPTION, NAME } from '../../inputs';
import { FILTERS, ID } from '../../../utils/constants/filterConstant';
import { fetchPccMinParameters, PccMinParameters, updatePccMinParameters } from '../../../services/pcc-min';
import { fetchPccMinParameters, updatePccMinParameters } from '../../../services/pcc-min';
import { updateParameter } from '../../../services';
import { ElementType, snackWithFallback } from '../../../utils';
import { getNameElementEditorEmptyFormData, getNameElementEditorSchema } from '../common/name-element-editor';
Expand All @@ -45,7 +46,7 @@ type UsePccMinParametersFormProps =
name: null;
description: null;
studyUuid: UUID | null;
parameters: PccMinParameters | null;
parameters: PccMinParametersEnriched | null;
};

export const UsePccMinParametersForm = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../common';
import yup from '../../../utils/yupConfig';
import { getNameElementEditorSchema } from '../common/name-element-editor';
import { SAParameters } from './types';
import { SAParametersEnriched } from './types';
import { getContingencyListsInfosFormSchema, toFormValuesContingencyListsInfos } from '../common/contingency-table';

export const getSAParametersFormSchema = (name: string | null, limitReductions?: ILimitReductionsByVoltageLevel[]) => {
Expand Down Expand Up @@ -63,7 +63,7 @@ export const getSAParametersFormSchema = (name: string | null, limitReductions?:
.concat(getNameElementEditorSchema(name));
};

export const toFormValueSaParameters = (params: SAParameters) => ({
export const toFormValueSaParameters = (params: SAParametersEnriched) => ({
[PARAM_SA_PROVIDER]: params[PARAM_SA_PROVIDER],
...toFormValuesContingencyListsInfos(params?.[CONTINGENCY_LISTS_INFOS] ?? []),
...toFormValuesLimitReductions(params?.limitReductions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useSecurityAnalysisParametersForm } from './use-security-analysis-param
import { SecurityAnalysisParametersForm } from './security-analysis-parameters-form';
import { PopupConfirmationDialog } from '../../dialogs';
import { snackWithFallback } from '../../../utils/error';
import { SAParameters } from './types';
import { SAParametersEnriched } from './types';
import { toFormValueSaParameters } from './columns-definitions';
import { ContingencyCount } from '../common/contingency-table/types';

Expand Down Expand Up @@ -71,7 +71,7 @@ export function SecurityAnalysisParametersInline({
if (newParams && newParams.length > 0) {
setOpenSelectParameterDialog(false);
fetchSecurityAnalysisParameters(newParams[0].id)
.then((parameters: SAParameters) => {
.then((parameters: SAParametersEnriched) => {
console.info(`loading the following security analysis parameters : ${parameters.uuid}`);
reset(toFormValueSaParameters(parameters), {
keepDefaultValues: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { Grid, Tab, Tabs } from '@mui/material';
import { ILimitReductionsByVoltageLevel, LimitReductionsTableForm, TAB_INFO, TabPanel, TabValues } from '../common';
import { PARAM_PROVIDER_OPENLOADFLOW } from '../loadflow';
import { ViolationsHidingParameters } from './security-analysis-violations-hiding';
import { SAParameters } from './types';
import { SAParametersEnriched } from './types';

export function SecurityAnalysisParametersSelector({
params,
currentProvider,
isDeveloperMode,
defaultLimitReductions,
}: Readonly<{
params: SAParameters | null;
params: SAParametersEnriched | null;
currentProvider?: string;
isDeveloperMode: boolean;
defaultLimitReductions: ILimitReductionsByVoltageLevel[];
Expand Down
10 changes: 7 additions & 3 deletions src/components/parameters/security-analysis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
PARAM_SA_PROVIDER,
} from '../common/constants';
import { ContingencyListsInfos } from '../common/contingency-table/types';
import { ContingencyListsInfos, ContingencyListsInfosEnriched } from '../common/contingency-table/types';
import { ILimitReductionsByVoltageLevel } from '../common/limitreductions/columns-definitions';

export interface SAParameters {
export type SAParameters = {
uuid?: UUID;
[PARAM_SA_PROVIDER]: string;
[CONTINGENCY_LISTS_INFOS]: ContingencyListsInfos[];
Expand All @@ -28,4 +28,8 @@ export interface SAParameters {
[PARAM_SA_LOW_VOLTAGE_ABSOLUTE_THRESHOLD]: number;
[PARAM_SA_HIGH_VOLTAGE_PROPORTIONAL_THRESHOLD]: number;
[PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: number;
}
};

export type SAParametersEnriched = Omit<SAParameters, typeof CONTINGENCY_LISTS_INFOS> & {
[CONTINGENCY_LISTS_INFOS]: ContingencyListsInfosEnriched[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { yupResolver } from '@hookform/resolvers/yup';
import { ElementType, UseParametersBackendReturnProps } from '../../../utils';
import {
ComputingType,
CONTAINER_ID,
CONTAINER_NAME,
CONTINGENCY_LISTS,
CONTINGENCY_LISTS_INFOS,
ILimitReductionsByVoltageLevel,
Expand All @@ -30,19 +32,19 @@ import { getNameElementEditorEmptyFormData } from '../common/name-element-editor
import { updateParameter } from '../../../services';
import { useSnackMessage } from '../../../hooks';
import { snackWithFallback } from '../../../utils/error';
import { SAParameters } from './types';
import { SAParametersEnriched } from './types';
import { getSAParametersFormSchema, toFormValueSaParameters } from './columns-definitions';
import { ID, NAME, DESCRIPTION, ACTIVATED } from '../common/parameter-table';
import { ContingencyListsInfos } from '../common/contingency-table/types';
import { NAME, DESCRIPTION, ACTIVATED, ID } from '../common/parameter-table';
import { ContingencyListsInfosEnriched } from '../common/contingency-table/types';

export interface UseSecurityAnalysisParametersFormReturn {
formMethods: UseFormReturn;
formSchema: ObjectSchema<any>;
formattedProviders: { id: string; label: string }[];
defaultLimitReductions: ILimitReductionsByVoltageLevel[];
toFormValueSaParameters: (_params: SAParameters) => any;
formatNewParams: (formData: Record<string, any>) => SAParameters;
params: SAParameters | null;
toFormValueSaParameters: (_params: SAParametersEnriched) => any;
formatNewParams: (formData: Record<string, any>) => SAParametersEnriched;
params: SAParametersEnriched | null;
watchProvider: string | undefined;
paramsLoaded: boolean;
onSaveInline: (formData: Record<string, any>) => void;
Expand Down Expand Up @@ -95,15 +97,17 @@ export const useSecurityAnalysisParametersForm = (
const paramsLoaded = useMemo(() => !!params && !!watchProvider, [watchProvider, params]);

const toContingencyListsInfos = useCallback(
(formContingencyListsInfos: Record<string, any>[]): ContingencyListsInfos[] => {
(formContingencyListsInfos: Record<string, any>[]): ContingencyListsInfosEnriched[] => {
if (!formContingencyListsInfos) {
return [];
}
return formContingencyListsInfos.map((contingencyListsInfos) => ({
[CONTINGENCY_LISTS]: contingencyListsInfos[CONTINGENCY_LISTS]?.map((c: Record<string, string>) => ({
[ID]: c[ID],
[NAME]: c[NAME],
})),
[CONTINGENCY_LISTS]: contingencyListsInfos[CONTINGENCY_LISTS]?.map(
(container: Record<string, string>) => ({
[CONTAINER_ID]: container[ID],
[CONTAINER_NAME]: container[NAME],
})
),
[DESCRIPTION]: contingencyListsInfos[DESCRIPTION],
[ACTIVATED]: contingencyListsInfos[ACTIVATED],
}));
Expand Down
Loading
Loading