From d36da815ddebe180370ae688da506daaf0dc2ea9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 23 Dec 2024 12:25:59 +0100 Subject: [PATCH] front: use Duration instead of string in PathStep.arrival Signed-off-by: Simon Ser --- .../useSetupItineraryForTrainUpdate.spec.ts | 13 +++++++------ front/src/modules/pathfinding/utils.ts | 4 +--- .../helpers/__tests__/formatSchedule.spec.ts | 5 +++-- .../ManageTrainSchedule/helpers/formatSchedule.ts | 2 +- .../trainschedule/helpers/computeBasePathStep.ts | 3 ++- front/src/reducers/osrdconf/helpers.ts | 2 +- .../__tests__/operationalStudiesConfReducer.spec.ts | 6 ++---- front/src/reducers/osrdconf/types.ts | 4 ++-- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/front/src/applications/operationalStudies/hooks/__tests__/useSetupItineraryForTrainUpdate.spec.ts b/front/src/applications/operationalStudies/hooks/__tests__/useSetupItineraryForTrainUpdate.spec.ts index 785044bb175..38fb7c4201f 100644 --- a/front/src/applications/operationalStudies/hooks/__tests__/useSetupItineraryForTrainUpdate.spec.ts +++ b/front/src/applications/operationalStudies/hooks/__tests__/useSetupItineraryForTrainUpdate.spec.ts @@ -1,6 +1,7 @@ import { describe, it, expect } from 'vitest'; import type { PathfindingResult } from 'common/api/osrdEditoastApi'; +import { Duration } from 'utils/duration'; import { updatePathStepsFromOperationalPoints } from '../useSetupItineraryForTrainUpdate'; @@ -154,7 +155,7 @@ describe('updatePathStepsFrom', () => { uic: 87747006, secondary_code: 'P2', name: '87747006', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), stopFor: null, }, { @@ -198,7 +199,7 @@ describe('updatePathStepsFrom', () => { uic: 87747006, secondary_code: 'P2', // should not be BV here, it has the same uic but not the same ch name: 'Grenadille', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), stopFor: null, kp: '129+952', positionOnPath: 586000, @@ -234,7 +235,7 @@ describe('updatePathStepsFrom', () => { trigram: 'GE', secondary_code: 'P2', name: '87747006', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), }, { id: 'who-0', @@ -272,7 +273,7 @@ describe('updatePathStepsFrom', () => { trigram: 'GE', secondary_code: 'P2', name: 'Grenadille', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), kp: '129+952', positionOnPath: 586000, coordinates: [5.711846462951984, 45.19643525506182], @@ -303,7 +304,7 @@ describe('updatePathStepsFrom', () => { trigram: 'GE', secondary_code: 'P2', name: '87747006', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), }, { id: 'who-0', @@ -341,7 +342,7 @@ describe('updatePathStepsFrom', () => { secondary_code: 'P2', trigram: 'GE', name: '87747006', - arrival: '15:00:00', + arrival: Duration.parse('PT60S'), kp: undefined, positionOnPath: 586000, coordinates: [5.711846462951984, 45.19643525506182], diff --git a/front/src/modules/pathfinding/utils.ts b/front/src/modules/pathfinding/utils.ts index 2f7c13027e9..5238b73c57b 100644 --- a/front/src/modules/pathfinding/utils.ts +++ b/front/src/modules/pathfinding/utils.ts @@ -12,7 +12,6 @@ import { getSupportedElectrification, isThermal } from 'modules/rollingStock/hel import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; import type { PathStep } from 'reducers/osrdconf/types'; import { addElementAtIndex } from 'utils/array'; -import { Duration } from 'utils/duration'; import { getPointCoordinates } from 'utils/geometry'; import getStepLocation from './helpers/getStepLocation'; @@ -92,8 +91,7 @@ export const getPathfindingQuery = ({ export const upsertPathStepsInOPs = (ops: SuggestedOP[], pathSteps: PathStep[]): SuggestedOP[] => { let updatedOPs = [...ops]; pathSteps.forEach((step) => { - const { stopFor, receptionSignal, theoreticalMargin } = step; - const arrival = step.arrival ? Duration.parse(step.arrival) : null; + const { arrival, stopFor, receptionSignal, theoreticalMargin } = step; // We check only for pathSteps added by map click if ('track' in step) { const formattedStep: SuggestedOP = { diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts index 404af3191de..a2f581bd556 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; import type { PathStep } from 'reducers/osrdconf/types'; +import { Duration } from 'utils/duration'; import formatSchedule from '../formatSchedule'; @@ -31,7 +32,7 @@ describe('formatSchedule', () => { kp: '117+422', name: 'V', positionOnPath: 13116000, - arrival: 'PT60S', + arrival: Duration.parse('PT60S'), stopFor: '0', locked: false, receptionSignal: 'OPEN', @@ -40,7 +41,7 @@ describe('formatSchedule', () => { const result = formatSchedule(pathSteps); expect(result).toEqual([ { - arrival: 'PT60S', + arrival: 'PT1M', at: 'id332', locked: false, reception_signal: 'OPEN', diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/formatSchedule.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/formatSchedule.ts index e200838eee6..48e35c5d6f5 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/formatSchedule.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/formatSchedule.ts @@ -9,7 +9,7 @@ const formatSchedule = (pathSteps: PathStep[]): TrainScheduleBase['schedule'] => if (step?.arrival || step.stopFor) { return { at: step.id, - arrival: step.arrival ?? undefined, + arrival: step.arrival?.toString() ?? undefined, locked: step.locked, reception_signal: step.receptionSignal, stop_for: diff --git a/front/src/modules/trainschedule/helpers/computeBasePathStep.ts b/front/src/modules/trainschedule/helpers/computeBasePathStep.ts index 800c7065bbc..3490a99d6c7 100644 --- a/front/src/modules/trainschedule/helpers/computeBasePathStep.ts +++ b/front/src/modules/trainschedule/helpers/computeBasePathStep.ts @@ -1,5 +1,6 @@ import type { TrainScheduleResult } from 'common/api/osrdEditoastApi'; import type { PathStep } from 'reducers/osrdconf/types'; +import { Duration } from 'utils/duration'; import { mmToM } from 'utils/physics'; import { ISO8601Duration2sec } from 'utils/timeManipulation'; @@ -51,7 +52,7 @@ const computeBasePathStep = ( ...step, ...('track' in step ? { offset: mmToM(step.offset) } : null), name, - arrival, // ISODurationString + arrival: arrival ? Duration.parse(arrival) : null, stopFor: stopFor ? ISO8601Duration2sec(stopFor).toString() : stopFor, locked, receptionSignal, diff --git a/front/src/reducers/osrdconf/helpers.ts b/front/src/reducers/osrdconf/helpers.ts index 3c150dc9a65..0af704eec02 100644 --- a/front/src/reducers/osrdconf/helpers.ts +++ b/front/src/reducers/osrdconf/helpers.ts @@ -61,13 +61,13 @@ export function upsertPathStep(statePathSteps: (PathStep | null)[], op: Suggeste 'name', 'kp', 'stopFor', + 'arrival', 'locked', 'deleted', 'receptionSignal', 'theoreticalMargin', ]), id: nextId(), - arrival: op.arrival?.toString(), ...(op.uic ? { uic: op.uic, secondary_code: op.ch } : { diff --git a/front/src/reducers/osrdconf/operationalStudiesConf/__tests__/operationalStudiesConfReducer.spec.ts b/front/src/reducers/osrdconf/operationalStudiesConf/__tests__/operationalStudiesConfReducer.spec.ts index 0651f54e4c4..2a30c2ee1c0 100644 --- a/front/src/reducers/osrdconf/operationalStudiesConf/__tests__/operationalStudiesConfReducer.spec.ts +++ b/front/src/reducers/osrdconf/operationalStudiesConf/__tests__/operationalStudiesConfReducer.spec.ts @@ -70,8 +70,7 @@ describe('simulationConfReducer', () => { uic: 123, name: '123', theoreticalMargin: '10%', - ch: undefined, - arrival: undefined, + arrival: null, stopFor: undefined, locked: undefined, receptionSignal: undefined, @@ -81,8 +80,7 @@ describe('simulationConfReducer', () => { uic: 234, name: '234', theoreticalMargin: undefined, - ch: undefined, - arrival: undefined, + arrival: null, stopFor: undefined, locked: undefined, receptionSignal: undefined, diff --git a/front/src/reducers/osrdconf/types.ts b/front/src/reducers/osrdconf/types.ts index f233790b917..f2b02ea5e61 100644 --- a/front/src/reducers/osrdconf/types.ts +++ b/front/src/reducers/osrdconf/types.ts @@ -12,8 +12,8 @@ import type { PathItemLocation, ReceptionSignal, } from 'common/api/osrdEditoastApi'; -import type { IsoDurationString } from 'common/types'; import type { InfraState } from 'reducers/infra'; +import type { Duration } from 'utils/duration'; export type OsrdConfState = InfraState & { projectID?: number; @@ -55,7 +55,7 @@ export type PathStep = PathItemLocation & { It's useful for soft deleting the point (waiting to fix / remove all references) If true, the train schedule is consider as invalid and must be edited */ deleted?: boolean; - arrival?: IsoDurationString | null; + arrival?: Duration | null; arrivalType?: ArrivalTimeTypes; arrivalToleranceBefore?: number; arrivalToleranceAfter?: number;