Skip to content

Commit bcef41a

Browse files
committed
more typing
Signed-off-by: David BRAQUART <david.braquart@rte-france.com>
1 parent f2cfd7d commit bcef41a

6 files changed

Lines changed: 67 additions & 32 deletions

File tree

src/components/dialogs/network-modifications/equipment-deletion/equipement-deletion-dialog.type.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
*/
77
import { EquipmentType, ModificationType } from '@gridsuite/commons-ui';
88
import { UUID } from 'node:crypto';
9-
import { LccShuntCompensatorInfos } from '../../../../services/network-modification-types';
9+
10+
export interface LccShuntCompensatorConnectionInfos {
11+
id: string;
12+
connectedToHvdc: boolean;
13+
}
1014

1115
export interface EquipmentDeletionSpecificInfos {
1216
specificType: string;
1317
// below is specific to HVDC-LCC deletion (then specificType = HVDC_LINE_LCC_DELETION_SPECIFIC_TYPE)
14-
mcsOnSide1: LccShuntCompensatorInfos[];
15-
mcsOnSide2: LccShuntCompensatorInfos[];
18+
mcsOnSide1: LccShuntCompensatorConnectionInfos[];
19+
mcsOnSide2: LccShuntCompensatorConnectionInfos[];
1620
}
1721

1822
export type EquipmentDeletionInfos = {

src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-dialog.tsx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modi
1717
import { FORM_LOADING_DELAY } from 'components/network/constants';
1818
import { deleteEquipment } from '../../../../services/study/network-modifications';
1919
import { UUID } from 'node:crypto';
20-
import { CurrentTreeNode } from 'components/graph/tree-node.type';
2120
import { FetchStatus } from 'services/utils.type';
2221
import { DeepNullable } from 'components/utils/ts-utils';
2322
import { EquipmentDeletionInfos } from './equipement-deletion-dialog.type';
23+
import { NetworkModificationDialogProps } from '../../../graph/menus/network-modifications/network-modification-menu.type';
24+
import { getHvdcLccDeletionSchema } from './hvdc-lcc-deletion/hvdc-lcc-deletion-utils';
2425

2526
const formSchema = yup
2627
.object()
2728
.shape({
2829
[EQUIPMENT_ID]: yup.string().nullable().required(),
2930
[TYPE]: yup.mixed<EquipmentType>().oneOf(Object.values(EquipmentType)).nullable().required(),
30-
[DELETION_SPECIFIC_DATA]: yup.string().nullable(),
31+
[DELETION_SPECIFIC_DATA]: getHvdcLccDeletionSchema(),
3132
})
3233
.required();
3334

@@ -39,18 +40,12 @@ const emptyFormData: EquipmentDeletionFormInfos = {
3940
[DELETION_SPECIFIC_DATA]: null,
4041
};
4142

42-
interface EquipmentDeletionDialogProps {
43-
studyUuid: UUID;
44-
currentNode: CurrentTreeNode;
45-
currentRootNetworkUuid: UUID;
43+
type EquipmentDeletionDialogProps = NetworkModificationDialogProps & {
4644
editData?: EquipmentDeletionInfos;
47-
isUpdate: boolean;
4845
defaultIdValue?: UUID;
4946
equipmentType: EquipmentType;
5047
editDataFetchStatus?: FetchStatus;
51-
onClose?: () => void;
52-
onValidated?: () => void;
53-
}
48+
};
5449

5550
/**
5651
* Dialog to delete equipment from its type and ID.
@@ -95,6 +90,7 @@ const EquipmentDeletionDialog = ({
9590
reset({
9691
[TYPE]: editData.equipmentType,
9792
[EQUIPMENT_ID]: editData.equipmentId,
93+
[DELETION_SPECIFIC_DATA]: null,
9894
});
9995
},
10096
[reset]
@@ -139,18 +135,16 @@ const EquipmentDeletionDialog = ({
139135

140136
const onSubmit = useCallback(
141137
(formData: EquipmentDeletionFormInfos) => {
142-
if (formData[EQUIPMENT_ID]) {
143-
deleteEquipment({
144-
studyUuid,
145-
nodeUuid: currentNodeUuid,
146-
uuid: editData?.uuid,
147-
equipmentId: formData[EQUIPMENT_ID] as UUID,
148-
equipmentType: formData[TYPE],
149-
equipmentSpecificInfos: formData[DELETION_SPECIFIC_DATA],
150-
}).catch((error) => {
151-
snackWithFallback(snackError, error, { headerId: 'UnableToDeleteEquipment' });
152-
});
153-
}
138+
deleteEquipment({
139+
studyUuid,
140+
nodeUuid: currentNodeUuid,
141+
uuid: editData?.uuid,
142+
equipmentId: formData[EQUIPMENT_ID] as UUID,
143+
equipmentType: formData[TYPE],
144+
equipmentSpecificInfos: formData[DELETION_SPECIFIC_DATA] ?? undefined,
145+
}).catch((error) => {
146+
snackWithFallback(snackError, error, { headerId: 'UnableToDeleteEquipment' });
147+
});
154148
},
155149
[currentNodeUuid, editData, snackError, studyUuid]
156150
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2026, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import yup from '../../../../utils/yup-config';
9+
10+
const getMscConnectionsSchema = () =>
11+
yup
12+
.array()
13+
.of(
14+
yup.object().shape({
15+
id: yup.string().required(),
16+
connectedToHvdc: yup.boolean().required(),
17+
})
18+
)
19+
.required();
20+
21+
export const getHvdcLccDeletionSchema = () =>
22+
yup
23+
.object()
24+
.shape({
25+
specificType: yup.string().required(),
26+
mcsOnSide1: getMscConnectionsSchema(),
27+
mcsOnSide2: getMscConnectionsSchema(),
28+
})
29+
.optional()
30+
.nullable();

src/components/dialogs/network-modifications/equipment-deletion/hvdc-lcc-deletion/shunt-compensator-selection-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2023, RTE (http://www.rte-france.com)
2+
* Copyright (c) 2026, RTE (http://www.rte-france.com)
33
* This Source Code Form is subject to the terms of the Mozilla Public
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/.

src/components/dialogs/network-modifications/equipment-deletion/hvdc-lcc-deletion/use-hvdc-lcc-deletion.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ import { useCallback } from 'react';
1616
import { useFieldArray, useFormContext } from 'react-hook-form';
1717
import { snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui';
1818
import { fetchHvdcLineWithShuntCompensators } from '../../../../../services/study/network-map';
19-
import { EquipmentDeletionInfos, HvdcLccDeletionInfos } from '../equipement-deletion-dialog.type';
19+
import {
20+
EquipmentDeletionInfos,
21+
HvdcLccDeletionInfos,
22+
LccShuntCompensatorConnectionInfos,
23+
} from '../equipement-deletion-dialog.type';
2024
import { UUID } from 'node:crypto';
21-
import { LccShuntCompensatorInfos } from '../../../../../services/network-modification-types';
2225

2326
const useHvdcLccDeletion = () => {
2427
const { replace: replaceMcsList1 } = useFieldArray({
@@ -32,7 +35,10 @@ const useHvdcLccDeletion = () => {
3235

3336
const updateMcsLists = useCallback(
3437
(hvdcLineData: HvdcLccDeletionInfos, editData?: EquipmentDeletionInfos) => {
35-
function mergeMcsLists(dynamicList: LccShuntCompensatorInfos[], editList: LccShuntCompensatorInfos[]) {
38+
function mergeMcsLists(
39+
dynamicList: LccShuntCompensatorConnectionInfos[],
40+
editList: LccShuntCompensatorConnectionInfos[]
41+
) {
3642
if (!dynamicList && !editList) {
3743
return [];
3844
} else if (!dynamicList) {
@@ -41,7 +47,7 @@ const useHvdcLccDeletion = () => {
4147
} else if (!editList) {
4248
return dynamicList;
4349
}
44-
const mergedList: LccShuntCompensatorInfos[] = dynamicList.map((obj) => {
50+
const mergedList: LccShuntCompensatorConnectionInfos[] = dynamicList.map((obj) => {
4551
return { ...obj, connectedToHvdc: false };
4652
});
4753
// now overwrite dynamic values with edited modification values

src/services/study/network-modifications.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
OLGS_MODIFICATION_TYPE,
6868
OPERATIONAL_LIMITS_GROUPS_MODIFICATION_TYPE,
6969
} from '../../components/utils/field-constants';
70+
import { EquipmentDeletionSpecificInfos } from '../../components/dialogs/network-modifications/equipment-deletion/equipement-deletion-dialog.type';
7071

7172
function getNetworkModificationUrl(studyUuid: string | null | undefined, nodeUuid: string | undefined) {
7273
return getStudyUrlWithNodeUuid(studyUuid, nodeUuid) + '/network-modifications';
@@ -1701,12 +1702,12 @@ export function deleteAttachingLine({
17011702
}
17021703

17031704
export interface DeleteEquipmentInfo {
1704-
studyUuid: string;
1705+
studyUuid: UUID;
17051706
nodeUuid: UUID;
17061707
uuid?: UUID;
17071708
equipmentId: UUID;
17081709
equipmentType: EquipmentType;
1709-
equipmentSpecificInfos?: any;
1710+
equipmentSpecificInfos?: EquipmentDeletionSpecificInfos;
17101711
}
17111712

17121713
export function deleteEquipment({

0 commit comments

Comments
 (0)