Skip to content

Commit

Permalink
front: use Duration instead of string in PathStep.arrival
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ser <contact@emersion.fr>
  • Loading branch information
emersion committed Jan 3, 2025
1 parent da85d4b commit 611cda7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -154,7 +155,7 @@ describe('updatePathStepsFrom', () => {
uic: 87747006,
secondary_code: 'P2',
name: '87747006',
arrival: '15:00:00',
arrival: Duration.parse('PT60S'),
stopFor: null,
},
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -234,7 +235,7 @@ describe('updatePathStepsFrom', () => {
trigram: 'GE',
secondary_code: 'P2',
name: '87747006',
arrival: '15:00:00',
arrival: Duration.parse('PT60S'),
},
{
id: 'who-0',
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -303,7 +304,7 @@ describe('updatePathStepsFrom', () => {
trigram: 'GE',
secondary_code: 'P2',
name: '87747006',
arrival: '15:00:00',
arrival: Duration.parse('PT60S'),
},
{
id: 'who-0',
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 1 addition & 3 deletions front/src/modules/pathfinding/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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',
Expand All @@ -40,7 +41,7 @@ describe('formatSchedule', () => {
const result = formatSchedule(pathSteps);
expect(result).toEqual([
{
arrival: 'PT60S',
arrival: 'PT1M',
at: 'id332',
locked: false,
reception_signal: 'OPEN',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion front/src/reducers/osrdconf/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ describe('simulationConfReducer', () => {
uic: 123,
name: '123',
theoreticalMargin: '10%',
ch: undefined,
arrival: undefined,
arrival: null,
stopFor: undefined,
locked: undefined,
receptionSignal: undefined,
Expand All @@ -81,8 +80,7 @@ describe('simulationConfReducer', () => {
uic: 234,
name: '234',
theoreticalMargin: undefined,
ch: undefined,
arrival: undefined,
arrival: null,
stopFor: undefined,
locked: undefined,
receptionSignal: undefined,
Expand Down
4 changes: 2 additions & 2 deletions front/src/reducers/osrdconf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 611cda7

Please sign in to comment.