Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: lmr fix intermediate op id collision #10445

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const StdcmOperationalPoint = ({ location, pathStepId, disabled }: StdcmOperatio
<div className="col-9 ci-input">
<ComboBox
id={`${pathStepId}-ci`}
data-testid="operational-point-ci"
label={t('trainPath.ci')}
value={selectedCi}
suggestions={ciSuggestions}
Expand All @@ -184,6 +185,7 @@ const StdcmOperationalPoint = ({ location, pathStepId, disabled }: StdcmOperatio
<Select
label={t('trainPath.ch')}
id={`${pathStepId}-ch`}
data-testid="operational-point-ch"
value={selectedCh}
onChange={handleChSelect}
options={chSuggestions}
Expand Down
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
24 changes: 14 additions & 10 deletions front/tests/pages/stdcm-page-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ class STDCMPage {
this.maxSpeedField = page.locator('#maxSpeed');
this.addViaButton = page.locator('.stdcm-vias-list button .stdcm-card__body.add-via');
this.launchSimulationButton = page.getByTestId('launch-simulation-button');
this.originChField = this.originCard.locator('[id^="id"][id$="-ch"]');
this.destinationChField = this.destinationCard.locator('[id^="id"][id$="-ch"]');
this.originCiField = this.originCard.locator('[id^="id"][id$="-ci"]');
this.destinationCiField = this.destinationCard.locator('[id^="id"][id$="-ci"]');
this.originChField = this.originCard.locator('[data-testid="operational-point-ch"]');
this.destinationChField = this.destinationCard.locator('[data-testid="operational-point-ch"]');
this.originCiField = this.originCard.locator('[data-testid="operational-point-ci"]');
this.destinationCiField = this.destinationCard.locator('[data-testid="operational-point-ci"]');
this.viaIcon = page.locator('.stdcm-via-icons');
this.viaDeleteButton = page.getByTestId('delete-via-button');
this.originArrival = page.locator('#select-origin-arrival');
Expand Down Expand Up @@ -213,10 +213,14 @@ class STDCMPage {
hasText: 'MWS Mid_West_station',
});

this.dynamicOriginCh = this.originCard.locator('[id^="id"][id$="-ch"]');
this.dynamicDestinationCh = this.destinationCard.locator('[id^="id"][id$="-ch"]');
this.dynamicOriginCi = this.originCard.locator('[id^="id"][id$="-ci"]');
this.dynamicDestinationCi = this.destinationCard.locator('[id^="id"][id$="-ci"]');
this.dynamicOriginCh = this.originCard.locator('[data-testid="operational-point-ch"]');
this.dynamicDestinationCh = this.destinationCard.locator(
'[data-testid="operational-point-ch"]'
);
this.dynamicOriginCi = this.originCard.locator('[data-testid="operational-point-ci"]');
this.dynamicDestinationCi = this.destinationCard.locator(
'[data-testid="operational-point-ci"]'
);
this.simulationStatus = page.getByTestId('simulation-status');
this.simulationList = page.locator('.stdcm-results .simulation-list');
this.incrementButton = page.locator('.minute-button', { hasText: '+1mn' });
Expand Down Expand Up @@ -244,11 +248,11 @@ class STDCMPage {
}

private getViaCH(viaNumber: number): Locator {
return this.getViaCard(viaNumber).locator('[id^="id"][id$="-ch"]');
return this.getViaCard(viaNumber).locator('[data-testid="operational-point-ch"]');
}

private getViaCI(viaNumber: number): Locator {
return this.getViaCard(viaNumber).locator('[id^="id"][id$="-ci"]');
return this.getViaCard(viaNumber).locator('[data-testid="operational-point-ci"]');
}

private getViaType(viaNumber: number): Locator {
Expand Down
Loading