Skip to content

Commit

Permalink
front: simplify rolling stock form type
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Khoudli <[email protected]>
  • Loading branch information
Synar committed Feb 6, 2025
1 parent c2135ea commit 673ab84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
15 changes: 7 additions & 8 deletions front/src/modules/rollingStock/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,17 @@ export const checkRollingStockFormValidity = (
return acc;
}, {});
const invalidFields = Object.keys(RS_REQUIRED_FIELDS).filter((field) => {
// We consider fields invalid if they are required and either absent or nullish
const conditionForFieldBeingRequired = conditions[field];
const paramValue = rollingStockForm[field];
const isFieldInvalid =
!has(rollingStockForm, field) ||
isNil(isMultiUnitsParam(paramValue) ? paramValue.value : paramValue);
const isRequired = conditionForFieldBeingRequired
? conditionForFieldBeingRequired(effortCurves)
: true;
if (isRequired) {
return isFieldInvalid;
}
return false;
if (!isRequired) return false;

if (!has(rollingStockForm, field)) return true;

const paramValue = rollingStockForm[field as keyof RollingStockParametersValues];
return isNil(isMultiUnitsParam(paramValue) ? paramValue.value : paramValue);
});

let invalidEffortCurves: string[] = [];
Expand Down
11 changes: 1 addition & 10 deletions front/src/modules/rollingStock/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ export type RollingStockParametersValidValues = {
};

export type RollingStockParametersValues = {
// TODO: remove this line in the type
[key: string]:
| string
| number
| null
| RollingStock['power_restrictions']
| undefined
| string[]
| MultiUnitsParameter;
railjsonVersion: string;
name: string;
detail: string;
Expand Down Expand Up @@ -102,7 +93,7 @@ export type MultiUnit =
| 'kN/(km/h)²/t';

export type SchemaProperty = {
title: string;
title: keyof RollingStockParametersValues;
type: string;
side: string;
format?: string;
Expand Down

0 comments on commit 673ab84

Please sign in to comment.