Skip to content

Commit

Permalink
front: lmr fix intermediate op id collision
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Jan 21, 2025
1 parent 74a2bcb commit 99e2f7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions front/src/reducers/osrdconf/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { feature, point } from '@turf/helpers';
import { compact, last, pick } from 'lodash';
import nextId from 'react-id-generator';
import { v4 as uuidV4 } from 'uuid';

import { calculateDistanceAlongTrack } from 'applications/editor/tools/utils';
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
Expand Down Expand Up @@ -77,7 +77,7 @@ export function upsertPathStep(statePathSteps: (PathStep | null)[], op: Suggeste
'theoreticalMargin',
'stopFor',
]),
id: nextId(),
id: uuidV4(),
...(op.uic
? { uic: op.uic, secondary_code: op.ch }
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,21 @@ describe('simulationConfReducer', () => {
};

const insertedVia: PathStep = {
id: 'id3', // the id generated by nextId()
id: 'id1',
positionOnPath: 200,
uic: 396002,
coordinates: [47.99542250806296, 0.1918181738752042],
};

store.dispatch(operationalStudiesConfSlice.actions.upsertViaFromSuggestedOP(newVia));
const state = store.getState()[operationalStudiesConfSlice.name];
expect(state.pathSteps).toEqual([brest, rennes, insertedVia, paris, strasbourg]);
expect(state.pathSteps).toEqual([
brest,
rennes,
{ ...insertedVia, id: state.pathSteps[2]?.id },
paris,
strasbourg,
]);
});

it('should update an existing via if it comes from the "times and step" table and has been added by selecting it on the map', () => {
Expand Down
8 changes: 4 additions & 4 deletions front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
import type { Draft } from 'immer';
import nextId from 'react-id-generator';
import { v4 as uuidV4 } from 'uuid';

import {
ArrivalTimeTypes,
Expand All @@ -19,13 +19,13 @@ const DEFAULT_TOLERANCE = 1800; // 30min
export const stdcmConfInitialState: OsrdStdcmConfState = {
stdcmPathSteps: [
{
id: nextId(),
id: uuidV4(),
isVia: false,
arrivalType: ArrivalTimeTypes.PRECISE_TIME,
tolerances: { before: DEFAULT_TOLERANCE, after: DEFAULT_TOLERANCE },
},
{
id: nextId(),
id: uuidV4(),
isVia: false,
arrivalType: ArrivalTimeTypes.ASAP,
tolerances: { before: DEFAULT_TOLERANCE, after: DEFAULT_TOLERANCE },
Expand Down Expand Up @@ -209,7 +209,7 @@ export const stdcmConfSlice = createSlice({
addStdcmVia(state: Draft<OsrdStdcmConfState>, action: PayloadAction<number>) {
// Index takes count of the origin in the array
state.stdcmPathSteps = addElementAtIndex(state.stdcmPathSteps, action.payload, {
id: nextId(),
id: uuidV4(),
stopType: StdcmStopTypes.PASSAGE_TIME,
isVia: true,
});
Expand Down

0 comments on commit 99e2f7a

Please sign in to comment.