diff --git a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx index 3fc5f63175..6913b4cefa 100644 --- a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx @@ -85,7 +85,11 @@ import { } from '../../../active-power-control/active-power-control-utils'; import { GeneratorCreationInfos } from '../../../../../services/network-modification-types'; import { GeneratorCreationDialogSchemaForm, GeneratorFormInfos } from '../generator-dialog.type'; -import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; +import { + getSetPointsEmptyFormData, + getSetPointsSchema, + testValueWithinPowerInterval, +} from '../../../set-points/set-points-utils'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { getShortCircuitEmptyFormData, @@ -128,7 +132,15 @@ const formSchema = yup .required(), [RATED_NOMINAL_POWER]: yup.number().nullable().min(0, 'mustBeGreaterOrEqualToZero'), ...getShortCircuitFormSchema(), - [PLANNED_ACTIVE_POWER_SET_POINT]: yup.number().nullable(), + [PLANNED_ACTIVE_POWER_SET_POINT]: yup + .number() + .nullable() + .default(null) + .test( + 'activePowerSetPoint', + 'PlannedActivePowerSetPointMustBeBetweenMinAndMaxActivePower', + testValueWithinPowerInterval + ), [MARGINAL_COST]: yup.number().nullable(), [PLANNED_OUTAGE_RATE]: yup.number().nullable().min(0, 'RealPercentage').max(1, 'RealPercentage'), [FORCED_OUTAGE_RATE]: yup.number().nullable().min(0, 'RealPercentage').max(1, 'RealPercentage'), diff --git a/src/components/dialogs/set-points/set-points-utils.ts b/src/components/dialogs/set-points/set-points-utils.ts index 1452b307db..6c0855ecde 100644 --- a/src/components/dialogs/set-points/set-points-utils.ts +++ b/src/components/dialogs/set-points/set-points-utils.ts @@ -13,6 +13,7 @@ import { VOLTAGE_REGULATION, } from 'components/utils/field-constants'; import yup from 'components/utils/yup-config'; +import { TestContext } from 'yup'; export const getSetPointsEmptyFormData = (_isEquipmentModification = false) => ({ [ACTIVE_POWER_SET_POINT]: null, @@ -34,6 +35,25 @@ export const getReactivePowerSetPointSchema = (isEquipmentModification = false) }), }); +const testValueWithinPowerIntervalOrEqualToZero = (value: number, context: TestContext) => { + if (value === 0) { + return true; + } + return testValueWithinPowerInterval(value, context); +}; + +export const testValueWithinPowerInterval = (value: number | null, context: TestContext) => { + const minActivePower = context.parent[MINIMUM_ACTIVE_POWER]; + const maxActivePower = context.parent[MAXIMUM_ACTIVE_POWER]; + if (value === null || value === undefined) { + return true; + } + if (minActivePower === null || maxActivePower === null) { + return false; + } + return value >= minActivePower && value <= maxActivePower; +}; + export const getActivePowerSetPointSchema = (isEquipmentModification = false) => ({ [ACTIVE_POWER_SET_POINT]: yup .number() @@ -52,17 +72,7 @@ export const getActivePowerSetPointSchema = (isEquipmentModification = false) => .test( 'activePowerSetPoint', 'ActivePowerMustBeZeroOrBetweenMinAndMaxActivePower', - (value, context) => { - const minActivePower = context.parent[MINIMUM_ACTIVE_POWER]; - const maxActivePower = context.parent[MAXIMUM_ACTIVE_POWER]; - if (value === 0) { - return true; - } - if (minActivePower === null || maxActivePower === null) { - return false; - } - return value >= minActivePower && value <= maxActivePower; - } + testValueWithinPowerIntervalOrEqualToZero ); }, }), diff --git a/src/translations/en.json b/src/translations/en.json index 7b098d202f..f3f56a6b09 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -746,6 +746,7 @@ "forcedOutageRate": "Forced outage rate", "MinActivePowerMustBeLessOrEqualToMaxActivePower": "Minimum active power value must be less than or equal to maximum active power value", "ActivePowerMustBeZeroOrBetweenMinAndMaxActivePower": "Active power value must be equal to 0 or between minimum and maximum active power values", + "PlannedActivePowerSetPointMustBeBetweenMinAndMaxActivePower": "Planned active power set point must be between minimum and maximum active power values", "RatedNominalPowerMustBeGreaterThanZero": "The rated nominal power value must be greater than 0", "NormalizedPercentage": "This percentage must be between 0 and 100", "RealPercentage": "This value must be between 0 and 1", diff --git a/src/translations/fr.json b/src/translations/fr.json index 21f155c63e..2281b05c00 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -741,6 +741,7 @@ "forcedOutageRate": "Indisponibilité fortuite", "MinActivePowerMustBeLessOrEqualToMaxActivePower": "La valeur de la puissance active min doit être inférieure ou égale à la valeur de la puissance active max", "ActivePowerMustBeZeroOrBetweenMinAndMaxActivePower": "La valeur de la puissance active doit être égale à 0 ou comprise entre la valeur de la puissance active min et la valeur de la puissance active max", + "PlannedActivePowerSetPointMustBeBetweenMinAndMaxActivePower": "La valeur de la puissance imposée doit être comprise entre la valeur de la puissance active min et la valeur de la puissance active max", "RatedNominalPowerMustBeGreaterThanZero": "La valeur de la puissance nominale doit être supérieure à 0", "NormalizedPercentage": "Ce pourcentage doit être compris entre 0 et 100", "RealPercentage": "Cette valeur doit être comprise entre 0 et 1",