Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down
32 changes: 21 additions & 11 deletions src/components/dialogs/set-points/set-points-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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
);
},
}),
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading