-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: highlight train not keep timetable
- Loading branch information
Showing
10 changed files
with
138 additions
and
43 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
30 changes: 20 additions & 10 deletions
30
front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/formatMargin.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 |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import type { Margin } from 'modules/trainschedule/components/ManageTrainSchedule/types'; | ||
import type { PathStep } from 'reducers/osrdconf/types'; | ||
|
||
const formatMargin = (pathSteps: PathStep[]): Margin => { | ||
const margins: Margin = { | ||
boundaries: [], | ||
values: [], | ||
}; | ||
const formatMargin = (pathSteps: PathStep[]): Margin | undefined => { | ||
const boundaries: string[] = []; | ||
const values: string[] = []; | ||
|
||
pathSteps.forEach((step, index) => { | ||
if (index === 0) { | ||
margins.values.push(step.theoreticalMargin || 'none'); | ||
} else if (step.theoreticalMargin !== pathSteps[index - 1].theoreticalMargin) { | ||
margins.boundaries.push(step.id); | ||
margins.values.push(step.theoreticalMargin || 'none'); | ||
values.push(step.theoreticalMargin || 'none'); | ||
} else if (index === pathSteps.length - 1) { | ||
if (values.length === 1 && values[0] !== 'none') { | ||
boundaries.push(step.id); | ||
values.push('none'); | ||
} | ||
} | ||
|
||
// for the other steps, we add the margin if it's different from the previous one | ||
else if (step.theoreticalMargin && step.theoreticalMargin !== values[values.length - 1]) { | ||
boundaries.push(step.id); | ||
values.push(step.theoreticalMargin); | ||
} | ||
}); | ||
return margins; | ||
|
||
if (values.length === 1) { | ||
return undefined; | ||
} | ||
return { boundaries, values }; | ||
}; | ||
|
||
export default formatMargin; |
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
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
Oops, something went wrong.