Skip to content

Commit 93579fd

Browse files
authored
Enhance shunt compensator comments and warnings for conflicting inputs (#3039)
Signed-off-by: achour94 <[email protected]>
1 parent 9a0e9ef commit 93579fd

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

src/components/dialogs/network-modifications/tabular-creation/tabular-creation-form.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
import { useCallback, useEffect, useMemo, useState } from 'react';
99
import { FormattedMessage, useIntl } from 'react-intl';
1010
import { useFormContext, useWatch } from 'react-hook-form';
11-
import { AutocompleteInput, CustomAGGrid, ErrorInput, FieldErrorAlert, LANG_FRENCH } from '@gridsuite/commons-ui';
11+
import {
12+
AutocompleteInput,
13+
CustomAGGrid,
14+
ErrorInput,
15+
FieldErrorAlert,
16+
LANG_FRENCH,
17+
useSnackMessage,
18+
} from '@gridsuite/commons-ui';
1219
import { CREATIONS_TABLE, EQUIPMENT_ID, TYPE } from 'components/utils/field-constants';
1320
import { EQUIPMENT_TYPES } from 'components/utils/equipment-types';
1421
import CsvDownloader from 'react-csv-downloader';
@@ -38,12 +45,17 @@ export interface TabularCreationFormProps {
3845

3946
export function TabularCreationForm({ dataFetching }: Readonly<TabularCreationFormProps>) {
4047
const intl = useIntl();
48+
const { snackWarning } = useSnackMessage();
4149
const language = useSelector((state: AppState) => state.computedLanguage);
4250
const [isFetching, setIsFetching] = useState<boolean>(dataFetching);
4351
const { setValue, clearErrors, setError, getValues } = useFormContext();
4452

4553
const getTypeLabel = useCallback((type: string) => intl.formatMessage({ id: type }), [intl]);
4654

55+
const equipmentType = useWatch({
56+
name: TYPE,
57+
});
58+
4759
const handleComplete = useCallback(
4860
(results: Papa.ParseResult<any>) => {
4961
clearErrors(CREATIONS_TABLE);
@@ -112,6 +124,19 @@ export function TabularCreationForm({ dataFetching }: Readonly<TabularCreationFo
112124
});
113125
}
114126
setIsFetching(false);
127+
// For shunt compensators, display a warning message if maxSusceptance is set along with shuntCompensatorType or maxQAtNominalV
128+
if (
129+
equipmentType === EQUIPMENT_TYPES.SHUNT_COMPENSATOR &&
130+
results.data.some(
131+
(creation) =>
132+
creation.maxSusceptance != null &&
133+
(creation.shuntCompensatorType || creation.maxQAtNominalV != null)
134+
)
135+
) {
136+
snackWarning({
137+
messageId: 'TabularCreationShuntWarning',
138+
});
139+
}
115140
setFieldTypeError(
116141
fieldTypeInError,
117142
expectedTypeForFieldInError,
@@ -124,13 +149,9 @@ export function TabularCreationForm({ dataFetching }: Readonly<TabularCreationFo
124149
setIsFetching(false);
125150
setValue(CREATIONS_TABLE, results.data, { shouldDirty: true });
126151
},
127-
[clearErrors, setValue, getValues, setError, intl]
152+
[clearErrors, setValue, getValues, equipmentType, setError, intl, snackWarning]
128153
);
129154

130-
const equipmentType = useWatch({
131-
name: TYPE,
132-
});
133-
134155
const csvColumns = useMemo(() => {
135156
return TABULAR_CREATION_FIELDS[equipmentType]?.map((field: TabularCreationField) => {
136157
return field.id;

src/components/dialogs/network-modifications/tabular-modification/tabular-modification-form.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function TabularModificationForm({ dataFetching }: Readonly<TabularModifi
5151

5252
const getTypeLabel = useCallback((type: string) => intl.formatMessage({ id: type }), [intl]);
5353

54+
const equipmentType = useWatch({
55+
name: TYPE,
56+
});
57+
5458
const handleComplete = useCallback(
5559
(results: Papa.ParseResult<any>) => {
5660
clearErrors(MODIFICATIONS_TABLE);
@@ -87,22 +91,19 @@ export function TabularModificationForm({ dataFetching }: Readonly<TabularModifi
8791
setIsFetching(false);
8892
// For shunt compensators, display a warning message if maxSusceptance is modified along with shuntCompensatorType or maxQAtNominalV
8993
if (
94+
equipmentType === EQUIPMENT_TYPES.SHUNT_COMPENSATOR &&
9095
results.data.some(
9196
(modification) =>
92-
modification.maxSusceptance &&
93-
(modification.shuntCompensatorType || modification.maxQAtNominalV)
97+
modification.maxSusceptance != null &&
98+
(modification.shuntCompensatorType || modification.maxQAtNominalV != null)
9499
)
95100
) {
96101
snackWarning({ messageId: 'TabularModificationShuntWarning' });
97102
}
98103
},
99-
[clearErrors, setValue, snackWarning, getValues, setError, intl]
104+
[clearErrors, setValue, equipmentType, getValues, setError, intl, snackWarning]
100105
);
101106

102-
const equipmentType = useWatch({
103-
name: TYPE,
104-
});
105-
106107
const csvColumns = useMemo(
107108
() => TABULAR_MODIFICATION_FIELDS[equipmentType]?.map((field: TabularModificationField) => field.id),
108109
[equipmentType]

src/translations/dynamic/csv-locale-en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const csv_locale_en = {
2323
'TabularModificationSkeletonComment.SUBSTATION':
2424
'#,,2-letter code from ISO 3166-1 standard (FR ES PT IT CH DE BE LU NL GB ...)',
2525
'TabularCreationSkeletonComment.SHUNT_COMPENSATOR':
26-
'#,,,,true | false,,TOP | BOTTOM,,,,REACTOR | CAPACITOR | required if maxQAtNominalV is set,,,',
26+
'#For each shunt compensator it is possible to modify either the maximum reactive power (and the type) or the maximum susceptance. In case of conflicting input the maximum susceptance will be ignored.,,,,true | false,,TOP | BOTTOM,,,,REACTOR | CAPACITOR | required if maxQAtNominalV is set,,,',
2727
'TabularModificationSkeletonComment.SHUNT_COMPENSATOR':
2828
'#For each shunt compensator it is possible to modify either the maximum reactive power (and the type) or the maximum susceptance. In case of conflicting input the maximum susceptance will be ignored.,,true | false,,TOP | BOTTOM,,,,REACTOR | CAPACITOR,,',
2929
};

src/translations/dynamic/csv-locale-fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const csv_locale_fr = {
2323
'TabularModificationSkeletonComment.SUBSTATION':
2424
'#;;Code à 2 lettres de la norme ISO 3166-1 (FR ES PT IT CH DE BE LU NL GB ...)',
2525
'TabularCreationSkeletonComment.SHUNT_COMPENSATOR':
26-
'#;;;;true | false;;TOP | BOTTOM;;;;REACTOR | CAPACITOR | requis si maxQAtNominalV est définit;;;',
26+
'#Pour chaque MCS il est possible de modifier soit la puissance réactive installée (et le type) soit la susceptance installée. En cas de conflit la susceptance installée sera ignorée.;;;;true | false;;TOP | BOTTOM;;;;REACTOR | CAPACITOR | requis si maxQAtNominalV est définit;;;',
2727
'TabularModificationSkeletonComment.SHUNT_COMPENSATOR':
2828
'#Pour chaque MCS il est possible de modifier soit la puissance réactive installée (et le type) soit la susceptance installée. En cas de conflit la susceptance installée sera ignorée.;;true | false;;TOP | BOTTOM;;;;REACTOR | CAPACITOR;;',
2929
};

src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@
583583
"ImportModifications": "Import modifications",
584584
"TabularModificationError": "Error while creating tabular modification",
585585
"TabularModificationShuntWarning": "Both maximum reactive power (and/or type) and maximum susceptance have been submitted for the same shunt compensator. Maximum susceptance will thus be ignored.",
586+
"TabularCreationShuntWarning": "Both maximum reactive power (and/or type) and maximum susceptance have been submitted for the same shunt compensator. Maximum susceptance will thus be ignored.",
586587
"equipmentId": "ID",
587588
"substationName": "Substation name",
588589
"activePower": "p (MW)",

src/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@
580580
"ImportModifications": "Importer des modifications",
581581
"TabularModificationError": "Erreur lors de la modification tabulaire",
582582
"TabularModificationShuntWarning": "La modification tabulaire contient des valeurs pour la puissance réactive installée (et/ou le type) et la susceptance installée d'un même MCS. La susceptance installée sera donc ignorée.",
583+
"TabularCreationShuntWarning": "La création tabulaire contient des valeurs pour la puissance réactive installée (et/ou le type) et la susceptance installée d'un même MCS. La susceptance installée sera donc ignorée.",
583584
"equipmentId": "ID",
584585
"substationName": "Nom du site",
585586
"activePower": "p (MW)",

0 commit comments

Comments
 (0)