Skip to content

Commit

Permalink
fix modification creation cspr form (#2329)
Browse files Browse the repository at this point in the history
Signed-off-by: REHILI Ghazwa <ghazwarhili@gmail.com>
  • Loading branch information
ghazwarhili authored Oct 18, 2024
1 parent 885a183 commit 242fd30
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from 'components/utils/field-constants';
import yup from '../../../../utils/yup-config';
import { REGULATION_TYPES } from '../../../../network/constants';
import { computeQAtNominalV } from '../../../../utils/utils';
import { Schema } from 'yup';

export const getReactiveFormEmptyFormData = (id = SETPOINTS_LIMITS) => ({
Expand Down Expand Up @@ -140,20 +139,17 @@ export const getReactiveFormData = ({
equipmentId: any;
}) => ({
[SETPOINTS_LIMITS]: {
[CHARACTERISTICS_CHOICE]: maxSusceptance
? CHARACTERISTICS_CHOICES.SUSCEPTANCE.id
: CHARACTERISTICS_CHOICES.Q_AT_NOMINAL_V.id,
[CHARACTERISTICS_CHOICE]:
nominalV !== null || minSusceptance === null
? CHARACTERISTICS_CHOICES.Q_AT_NOMINAL_V.id
: CHARACTERISTICS_CHOICES.SUSCEPTANCE.id,
[VOLTAGE_REGULATION_MODE]: regulationMode,
[MAX_SUSCEPTANCE]: maxSusceptance,
[MIN_SUSCEPTANCE]: minSusceptance,
[MAX_Q_AT_NOMINAL_V]:
nominalV !== null && maxSusceptance !== null
? computeQAtNominalV(maxSusceptance, nominalV)
: maxQAtNominalV,
nominalV !== null && maxSusceptance !== null ? maxSusceptance * Math.pow(nominalV, 2) : maxQAtNominalV,
[MIN_Q_AT_NOMINAL_V]:
nominalV !== null && minSusceptance !== null
? computeQAtNominalV(minSusceptance, nominalV)
: minQAtNominalV,
nominalV !== null && minSusceptance !== null ? minSusceptance * Math.pow(nominalV, 2) : minQAtNominalV,
[VOLTAGE_SET_POINT]: voltageSetpoint,
[REACTIVE_POWER_SET_POINT]: reactivePowerSetpoint,
[VOLTAGE_REGULATION_TYPE]: voltageRegulationType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import {
HIGH_VOLTAGE_THRESHOLD,
LOW_VOLTAGE_SET_POINT,
LOW_VOLTAGE_THRESHOLD,
MAX_Q_AUTOMATON,
MAX_S_AUTOMATON,
MIN_Q_AUTOMATON,
MIN_S_AUTOMATON,
Q0,
STAND_BY_AUTOMATON,
VOLTAGE_REGULATION_MODE,
VOLTAGE_REGULATION_MODES,
} from 'components/utils/field-constants';
import yup from '../../../../utils/yup-config';
import { Schema } from 'yup';

export const getStandbyAutomatonEmptyFormData = (id = AUTOMATON) => ({
[id]: {
Expand All @@ -32,6 +35,10 @@ export const getStandbyAutomatonEmptyFormData = (id = AUTOMATON) => ({
[LOW_VOLTAGE_THRESHOLD]: null,
[HIGH_VOLTAGE_THRESHOLD]: null,
[CHARACTERISTICS_CHOICE_AUTOMATON]: CHARACTERISTICS_CHOICES.Q_AT_NOMINAL_V.id,
[MIN_Q_AUTOMATON]: null,
[MAX_Q_AUTOMATON]: null,
[MIN_S_AUTOMATON]: null,
[MAX_S_AUTOMATON]: null,
[B0]: null,
[Q0]: null,
},
Expand All @@ -43,20 +50,26 @@ const requiredIfAddStandbyAutomaton = (yup: any) =>
then: (schema: any) => schema.required(),
});

const requiredWhenSusceptanceChoice = (schema: Schema) =>
const requiredWhenSusceptanceChoice = (schema: any) =>
schema.when([ADD_STAND_BY_AUTOMATON, CHARACTERISTICS_CHOICE_AUTOMATON], {
is: (addStandbyAutomaton: boolean, characteristicsChoiceAutomaton: string) =>
addStandbyAutomaton && characteristicsChoiceAutomaton === CHARACTERISTICS_CHOICES.SUSCEPTANCE.id,
then: (schema: any) => schema.required(),
otherwise: (schema) => schema.notRequired(),
then: (schema: any) =>
schema
.min(yup.ref(MIN_S_AUTOMATON), 'StaticVarCompensatorErrorSFixLessThanSMin')
.max(yup.ref(MAX_S_AUTOMATON), 'StaticVarCompensatorErrorSFixGreaterThanSMax')
.required(),
});

const requiredWhenQatNominalVChoice = (schema: Schema) =>
const requiredWhenQatNominalVChoice = (schema: any) =>
schema.when([ADD_STAND_BY_AUTOMATON, CHARACTERISTICS_CHOICE_AUTOMATON], {
is: (addStandbyAutomaton: boolean, characteristicsChoiceAutomaton: string) =>
addStandbyAutomaton && characteristicsChoiceAutomaton === CHARACTERISTICS_CHOICES.Q_AT_NOMINAL_V.id,
then: (schema) => schema.required(),
otherwise: (schema) => schema.notRequired(),
then: (schema: any) =>
schema
.min(yup.ref(MIN_Q_AUTOMATON), 'StaticVarCompensatorErrorQFixLessThanQMin')
.max(yup.ref(MAX_Q_AUTOMATON), 'StaticVarCompensatorErrorQFixGreaterThanQMax')
.required(),
});

export const getStandbyAutomatonFormValidationSchema = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Grid from '@mui/material/Grid';
import {
ADD_STAND_BY_AUTOMATON,
AUTOMATON,
CHARACTERISTICS_CHOICE,
CHARACTERISTICS_CHOICES,
HIGH_VOLTAGE_SET_POINT,
HIGH_VOLTAGE_THRESHOLD,
LOW_VOLTAGE_SET_POINT,
Expand All @@ -21,7 +19,7 @@ import {
VOLTAGE_REGULATION_MODES,
} from 'components/utils/field-constants';
import { CheckboxInput, FloatInput, SwitchInput } from '@gridsuite/commons-ui';
import { SusceptanceAdornment, VoltageAdornment } from '../../../dialogUtils';
import { VoltageAdornment } from '../../../dialogUtils';
import { Box } from '@mui/system';
import { useEffect, useMemo, useState } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
Expand All @@ -48,13 +46,6 @@ export const StandbyAutomatonForm = () => {
?.label;
}, [watchVoltageMode]);

const watchChoiceAutomaton = useWatch({ name: `${SETPOINTS_LIMITS}.${CHARACTERISTICS_CHOICE}` });
const watchChoiceAutomatonLabel = useMemo(() => {
return Object.values(CHARACTERISTICS_CHOICES).find(
(choiceAutomaton) => choiceAutomaton.id === watchChoiceAutomaton
)?.label;
}, [watchChoiceAutomaton]);

const standbyDisabled = useMemo(() => {
return watchVoltageMode !== VOLTAGE_REGULATION_MODES.VOLTAGE.id;
}, [watchVoltageMode]);
Expand Down Expand Up @@ -124,13 +115,13 @@ export const StandbyAutomatonForm = () => {
FloatInput,
`${id}.${LOW_VOLTAGE_THRESHOLD}`,
'LowVoltageThreshold',
SusceptanceAdornment
VoltageAdornment
),
hVoltageThreshold: createField(
FloatInput,
`${id}.${HIGH_VOLTAGE_THRESHOLD}`,
'HighVoltageThreshold',
SusceptanceAdornment
VoltageAdornment
),
};

Expand All @@ -153,16 +144,6 @@ export const StandbyAutomatonForm = () => {
);
})}
</Grid>

<Grid container spacing={2} padding={2}>
<Grid item xs={6}>
<TextField
value={intl.formatMessage({ id: watchChoiceAutomatonLabel })}
disabled={true}
size={'small'}
/>
</Grid>
</Grid>
<Grid container spacing={2} padding={2}>
<SusceptanceArea />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const StaticVarCompensatorCreationDialog: FC<any> = ({
busbarSectionName: undefined,
connectionDirection: staticCompensator.connectablePosition.connectionDirection ?? null,
connectionName: staticCompensator.connectablePosition.connectionName ?? null,
connectionPosition: staticCompensator.connectablePosition.connectionPosition ?? null,
connectionPosition: undefined,
terminalConnected: undefined,
isEquipmentModification: false,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import {
CHARACTERISTICS_CHOICE_AUTOMATON,
CHARACTERISTICS_CHOICES,
MAX_Q_AT_NOMINAL_V,
MAX_Q_AUTOMATON,
MAX_S_AUTOMATON,
MAX_SUSCEPTANCE,
MIN_Q_AT_NOMINAL_V,
MIN_Q_AUTOMATON,
MIN_S_AUTOMATON,
MIN_SUSCEPTANCE,
Q0,
SETPOINTS_LIMITS,
Expand All @@ -37,7 +41,11 @@ export const SusceptanceArea = () => {
// CHARACTERISTICS_CHOICE_AUTOMATON used only to validate the schema (work around)
useEffect(() => {
setValue(`${id}.${CHARACTERISTICS_CHOICE_AUTOMATON}`, watchChoiceAutomaton);
}, [setValue, id, watchChoiceAutomaton]);
setValue(`${id}.${MIN_Q_AUTOMATON}`, minQ);
setValue(`${id}.${MAX_Q_AUTOMATON}`, maxQ);
setValue(`${id}.${MIN_S_AUTOMATON}`, minS);
setValue(`${id}.${MAX_S_AUTOMATON}`, maxS);
}, [setValue, id, watchChoiceAutomaton, minQ, maxQ, maxS, minS]);

const minSusceptanceField = (
<TextField
Expand Down Expand Up @@ -66,47 +74,47 @@ export const SusceptanceArea = () => {
const minQAtNominalVField = (
<TextField
value={minQ}
label={<FormattedMessage id={'minQ'} />}
label={<FormattedMessage id={'minQAtNominalV'} />}
disabled={true}
size={'small'}
InputProps={{
endAdornment: <InputAdornment position="start">MVA</InputAdornment>,
endAdornment: <InputAdornment position="start">MVar</InputAdornment>,
}}
/>
);

const maxQAtNominalVField = (
<TextField
value={maxQ}
label={<FormattedMessage id={'maxQ'} />}
label={<FormattedMessage id={'maxQAtVnominal'} />}
disabled={true}
size={'small'}
InputProps={{
endAdornment: <InputAdornment position="start">MVA</InputAdornment>,
endAdornment: <InputAdornment position="start">MVar</InputAdornment>,
}}
/>
);

const susceptanceField = <FloatInput name={`${id}.${B0}`} label="b0" adornment={SusceptanceAdornment} />;

const qAtNominalVField = (
<FloatInput name={`${id}.${Q0}`} label="ConstantQWithoutUnit" adornment={ReactivePowerAdornment} />
<FloatInput name={`${id}.${Q0}`} label="fixQAtNominalV" adornment={ReactivePowerAdornment} />
);

return (
<Grid container spacing={2} padding={2}>
{watchChoiceAutomaton === CHARACTERISTICS_CHOICES.SUSCEPTANCE.id && (
<>
{gridItem(minSusceptanceField, 3)}
{gridItem(minSusceptanceField, 4)}
{gridItem(susceptanceField, 3)}
{gridItem(maxSusceptanceField, 3)}
{gridItem(maxSusceptanceField, 4)}
</>
)}
{watchChoiceAutomaton === CHARACTERISTICS_CHOICES.Q_AT_NOMINAL_V.id && (
<>
{gridItem(minQAtNominalVField, 3)}
{gridItem(minQAtNominalVField, 4)}
{gridItem(qAtNominalVField, 3)}
{gridItem(maxQAtNominalVField, 3)}
{gridItem(maxQAtNominalVField, 4)}
</>
)}
</Grid>
Expand Down
4 changes: 4 additions & 0 deletions src/components/utils/field-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,8 @@ export const HIGH_VOLTAGE_SET_POINT = 'highVoltageSetpoint';
export const LOW_VOLTAGE_THRESHOLD = 'lowVoltageThreshold';
export const HIGH_VOLTAGE_THRESHOLD = 'highVoltageThreshold';
export const CHARACTERISTICS_CHOICE_AUTOMATON = 'characteristicsChoiceAutomaton';
export const MIN_Q_AUTOMATON = 'minQAutomaton';
export const MAX_Q_AUTOMATON = 'maxQAutomaton';
export const MIN_S_AUTOMATON = 'minSAutomaton';
export const MAX_S_AUTOMATON = 'maxSAutomaton';
export const STAND_BY_AUTOMATON = 'StandbyAutomaton';
5 changes: 5 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@
"ShuntCompensatorErrorCurrentLessThanZero": "Current number of sections should be greater than or equal to 0",
"ShuntCompensatorErrorCurrentLessThanMaximum": "Current number of sections should be less than or equal to the maximum",
"ShuntCompensatorErrorQAtNominalVoltageLessThanZero": "Q at nominal voltage value should be greater than or equal to 0",
"StaticVarCompensatorErrorQFixGreaterThanQMax": "Q Fixed value should be less than Q maximum value",
"StaticVarCompensatorErrorQFixLessThanQMin": "Q Fixed value should be greater than Q minimum value",
"StaticVarCompensatorErrorSFixGreaterThanSMax": "Susceptance Fixed value should be less than susceptance maximum value",
"StaticVarCompensatorErrorSFixLessThanSMin": "Susceptance Fixed value should be greater than susceptance minimum value",
"ModifyShuntCompensator": "Modify shunt compensator (Linear)",
"MaximumSectionCountMustBeGreaterOrEqualToOne": "Maximum section count must be greater than or equal to 1",
"SectionCountMustBeBetweenZeroAndMaximumSectionCount": "Section count must be between 0 and and Maximum section count",
Expand All @@ -809,6 +813,7 @@
"maxSusceptance": "Maximal susceptance available",
"maxQAtVnominal": "Q max at nominal voltage",
"minQAtNominalV": "Q min at nominal voltage",
"fixQAtNominalV": "Q fixed",
"maxQ": "Q max",
"minQ": "Q min",
"maximumSusceptance": "Susceptance max",
Expand Down
5 changes: 5 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@
"ShuntCompensatorErrorCurrentLessThanZero": "Le nombre de sections utilisées doit être supérieur ou égal à 0",
"ShuntCompensatorErrorCurrentLessThanMaximum": "Le nombre de sections utilisées doit être inférieur ou égal au nombre maximum",
"ShuntCompensatorErrorQAtNominalVoltageLessThanZero": "La valeur de Q à Unom doit être supérieure ou égale à 0",
"StaticVarCompensatorErrorQFixGreaterThanQMax": "La valeur de Q Fixe doit être inférieure à la valeur de Q maximum",
"StaticVarCompensatorErrorQFixLessThanQMin": "La valeur de Q Fixe doit être supérieure à la valeur de Q minimum",
"StaticVarCompensatorErrorSFixGreaterThanSMax": "La valeur de Susceptance Fixe doit être inférieure à la valeur de susceptance maximum",
"StaticVarCompensatorErrorSFixLessThanSMin": "La valeur de Susceptance Fixe doit être supérieure à la valeur de susceptance minimum",
"ModifyShuntCompensator": "Modifier un moyen de compensation statique (Linéaire)",
"MaximumSectionCountMustBeGreaterOrEqualToOne": "Le nombre de gradins doit être supérieur ou égal à 1",
"SectionCountMustBeBetweenZeroAndMaximumSectionCount": "La valeur de la prise courante doit être comprise entre 0 et le nombre de gradins",
Expand All @@ -809,6 +813,7 @@
"maxSusceptance": "Susceptance installée",
"maxQAtVnominal": "Q max à tension nominale",
"minQAtNominalV": "Q min à tension nominale",
"fixQAtNominalV": "Q fixe",
"maxQ": "Q max",
"minQ": "Q min",
"maximumSusceptance": "Susceptance max",
Expand Down

0 comments on commit 242fd30

Please sign in to comment.