6
6
*/
7
7
8
8
import {
9
+ APPLICABIlITY ,
10
+ CURRENT_LIMITS ,
9
11
ID ,
12
+ NAME ,
10
13
OPERATIONAL_LIMITS_GROUPS ,
14
+ PERMANENT_LIMIT ,
11
15
SELECTED_LIMITS_GROUP_1 ,
12
16
SELECTED_LIMITS_GROUP_2 ,
13
17
} from '../../utils/field-constants' ;
@@ -21,6 +25,7 @@ import { useIntl } from 'react-intl';
21
25
import { PopoverProps } from '@mui/material/Popover' ;
22
26
import { APPLICABILITY } from '../../network/constants' ;
23
27
import { OperationalLimitsGroupFormInfos } from '../network-modifications/line/modification/line-modification-type' ;
28
+ import { CurrentLimits } from '../../../services/network-modification-types' ;
24
29
25
30
export interface LimitsGroupsContextualMenuProps {
26
31
parentFormName : string ;
@@ -33,6 +38,7 @@ export interface LimitsGroupsContextualMenuProps {
33
38
selectedLimitsGroups1 : string ;
34
39
selectedLimitsGroups2 : string ;
35
40
isModification : boolean ;
41
+ currentLimitsToModify : CurrentLimits [ ] ;
36
42
}
37
43
38
44
export function LimitsGroupsContextualMenu ( {
@@ -46,6 +52,7 @@ export function LimitsGroupsContextualMenu({
46
52
selectedLimitsGroups1,
47
53
selectedLimitsGroups2,
48
54
isModification,
55
+ currentLimitsToModify,
49
56
} : Readonly < LimitsGroupsContextualMenuProps > ) {
50
57
const intl = useIntl ( ) ;
51
58
const operationalLimitsGroupsFormName : string = `${ parentFormName } .${ OPERATIONAL_LIMITS_GROUPS } ` ;
@@ -89,6 +96,15 @@ export function LimitsGroupsContextualMenu({
89
96
...duplicatedLimits1 ,
90
97
[ ID ] : newName ,
91
98
} ;
99
+ // if the permanent limit is undefined in the form we try to get the previous value of the corresponding current limit
100
+ if ( ! newLimitsGroup1 [ CURRENT_LIMITS ] [ PERMANENT_LIMIT ] ) {
101
+ newLimitsGroup1 [ CURRENT_LIMITS ] [ PERMANENT_LIMIT ] =
102
+ currentLimitsToModify . find (
103
+ ( cl : CurrentLimits ) =>
104
+ cl . id === duplicatedLimits1 [ NAME ] && cl . applicability === duplicatedLimits1 [ APPLICABIlITY ]
105
+ ) ?. permanentLimit ?? null ;
106
+ }
107
+
92
108
appendToLimitsGroups ( newLimitsGroup1 ) ;
93
109
setIndexSelectedLimitSet ( getValues ( `${ operationalLimitsGroupsFormName } ` ) . length - 1 ) ;
94
110
}
0 commit comments