Skip to content

Commit

Permalink
fix limit reduction form
Browse files Browse the repository at this point in the history
Signed-off-by: jamal-khey <myjamal89@gmail.com>
  • Loading branch information
jamal-khey committed Dec 19, 2024
1 parent 6c3832f commit b2fc612
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
} from 'utils/config-params';
import yup from '../../../../utils/yup-config';
import { NumberSchema } from 'yup';

export const LIMIT_REDUCTIONS_FORM = 'limitReductionsForm';
export const VOLTAGE_LEVELS_FORM = 'voltageLevelsForm';
Expand Down Expand Up @@ -78,6 +79,22 @@ export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS = [
},
];

//TODO: a cleaner solution can be done by using yup.array()
// Instead of creating a schema for each limit duration individually,
// we can use yup.array() to define an array of limit durations directly.
const getLimitDurationsFormSchema = (nbLimits: number) => {
let limitDurationsFormSchema: Record<string, NumberSchema> = {};
for (let i = 0; i < nbLimits; i++) {
limitDurationsFormSchema[LIMIT_DURATION_FORM + i] = yup
.number()
.min(0, 'RealPercentage')
.max(1, 'RealPercentage')
.nullable()
.required();
}
return limitDurationsFormSchema;
};

export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
return yup
.object()
Expand All @@ -86,11 +103,7 @@ export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
yup.object().shape({
[VOLTAGE_LEVELS_FORM]: yup.string(),
[IST_FORM]: yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required(),
[LIMIT_DURATION_FORM]: yup
.array()
.length(nbTemporaryLimits)
.of(yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required())
.required(),
...getLimitDurationsFormSchema(nbTemporaryLimits),
})
),
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/dialogs/parameters/load-flow-parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import ParameterLineSlider from './widget/parameter-line-slider';
import {
ILimitReductionsByVoltageLevel,
IST_FORM,
LIMIT_DURATION_FORM,
LIMIT_REDUCTIONS_FORM,
TAB_INFO,
TAB_VALUES,
getLimitReductionsFormSchema,
LIMIT_DURATION_FORM,
} from './common/limitreductions/columns-definitions';
import LimitReductionsTableForm from './common/limitreductions/limit-reductions-table-form';
import { useForm } from 'react-hook-form';
Expand Down Expand Up @@ -627,6 +627,7 @@ export const LoadFlowParameters: FunctionComponent<LoadFlowParametersProps> = ({
vlLimits.temporaryLimitReductions.forEach((temporaryLimit, index) => {
vlLNewLimits.temporaryLimitReductions[index] = {
...temporaryLimit,
// @ts-expect-error
reduction: formLimits[indexVl][LIMIT_DURATION_FORM][index],
};
});
Expand Down

0 comments on commit b2fc612

Please sign in to comment.