Skip to content

Commit

Permalink
front: try fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Jan 22, 2025
1 parent ce5bb6f commit 58be440
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions front/src/reducers/osrdconf/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { feature, point } from '@turf/helpers';
import { compact, last, pick } from 'lodash';
import { v4 as uuidV4 } from 'uuid';

import { calculateDistanceAlongTrack } from 'applications/editor/tools/utils';
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import { pathStepMatchesOp } from 'modules/pathfinding/utils';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import { addElementAtIndex } from 'utils/array';
import nextId from 'utils/react-id';

import type { OperationalStudiesConfState } from './operationalStudiesConf';
import type { PathStep } from './types';
Expand Down Expand Up @@ -77,7 +77,7 @@ export function upsertPathStep(statePathSteps: (PathStep | null)[], op: Suggeste
'theoreticalMargin',
'stopFor',
]),
id: uuidV4(),
id: nextId(),
...(op.uic
? { uic: op.uic, secondary_code: op.ch }
: {
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,5 @@
import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
import type { Draft } from 'immer';
import { v4 as uuidV4 } from 'uuid';

import {
ArrivalTimeTypes,
Expand All @@ -12,20 +11,21 @@ import { defaultCommonConf, buildCommonConfReducers } from 'reducers/osrdconf/os
import type { OsrdStdcmConfState, StdcmPathStep } from 'reducers/osrdconf/types';
import { addElementAtIndex } from 'utils/array';
import { isArrivalDateInSearchTimeWindow } from 'utils/date';
import nextId from 'utils/react-id';
import type { ArrayElement, PickAndNonNullableFields } from 'utils/types';

const DEFAULT_TOLERANCE = 1800; // 30min

export const stdcmConfInitialState: OsrdStdcmConfState = {
stdcmPathSteps: [
{
id: uuidV4(),
id: nextId(),
isVia: false,
arrivalType: ArrivalTimeTypes.PRECISE_TIME,
tolerances: { before: DEFAULT_TOLERANCE, after: DEFAULT_TOLERANCE },
},
{
id: uuidV4(),
id: nextId(),
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: uuidV4(),
id: nextId(),
stopType: StdcmStopTypes.PASSAGE_TIME,
isVia: true,
});
Expand Down
9 changes: 9 additions & 0 deletions front/src/utils/react-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { v4 as uuidV4 } from 'uuid';

/**
* Generate a unique id for react components
* @returns a unique id
*/
export default function nextId() {
return `id-${uuidV4()}`;
}

0 comments on commit 58be440

Please sign in to comment.