-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since recently, when opening the view to edit a train, a pathfinding request is automatically launched. But it is launched before the store update, which creates the bug: the pathfinding is launched with the pathsteps stored in the store (and not the ones of the train we want to edit) and once the pathfinding request is finished, we update the store with the result of the request (and erase the path steps of the currently selected train). To fix this, we can directly update the store before opening the ManageTrainSchedule view. Signed-off-by: Clara Ni <clara.ni@outlook.fr>
- Loading branch information
Showing
7 changed files
with
186 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
front/src/modules/trainschedule/helpers/computeBasePathSteps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { TrainScheduleResult } from 'common/api/osrdEditoastApi'; | ||
import { omit } from 'lodash'; | ||
import type { PathStep } from 'reducers/osrdconf/types'; | ||
import { mmToM } from 'utils/physics'; | ||
import { ISO8601Duration2sec } from 'utils/timeManipulation'; | ||
|
||
const findCorrespondingMargin = ( | ||
stepId: string, | ||
stepIndex: number, | ||
margins: { boundaries: string[]; values: string[] } | ||
) => { | ||
// The first pathStep will never have its id in boundaries | ||
if (stepIndex === 0) return margins.values[0] === 'none' ? undefined : margins.values[0]; | ||
|
||
const marginIndex = margins.boundaries.findIndex((boundaryId) => boundaryId === stepId); | ||
|
||
return marginIndex !== -1 ? margins.values[marginIndex + 1] : undefined; | ||
}; | ||
|
||
/** Given a trainScheduleResult, extract its pathSteps */ | ||
const computeBasePathSteps = ( | ||
trainSchedule: Pick<TrainScheduleResult, 'path' | 'schedule' | 'margins'> | ||
) => | ||
trainSchedule.path.map((step, index) => { | ||
const correspondingSchedule = trainSchedule.schedule?.find( | ||
(schedule) => schedule.at === step.id | ||
); | ||
|
||
const { | ||
arrival, | ||
stop_for: stopFor, | ||
locked, | ||
reception_signal: receptionSignal, | ||
} = correspondingSchedule || {}; | ||
|
||
const stepWithoutSecondaryCode = omit(step, ['secondary_code']); | ||
|
||
if ('track' in stepWithoutSecondaryCode) { | ||
stepWithoutSecondaryCode.offset = mmToM(stepWithoutSecondaryCode.offset!); | ||
} | ||
|
||
let name; | ||
if ('trigram' in step) { | ||
name = step.trigram + (step.secondary_code ? `/${step.secondary_code}` : ''); | ||
} else if ('uic' in step) { | ||
name = step.uic.toString(); | ||
} else if ('operational_point' in step) { | ||
name = step.operational_point; | ||
} | ||
|
||
let theoreticalMargin; | ||
if (trainSchedule.margins && index !== trainSchedule.path.length - 1) { | ||
theoreticalMargin = findCorrespondingMargin(step.id, index, trainSchedule.margins); | ||
} | ||
|
||
return { | ||
...stepWithoutSecondaryCode, | ||
ch: 'secondary_code' in step ? step.secondary_code : undefined, | ||
name, | ||
arrival, // ISODurationString | ||
stopFor: stopFor ? ISO8601Duration2sec(stopFor).toString() : stopFor, | ||
locked, | ||
receptionSignal, | ||
theoreticalMargin, | ||
} as PathStep; | ||
}); | ||
|
||
export default computeBasePathSteps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters