-
Notifications
You must be signed in to change notification settings - Fork 46
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: add, get and delete paced trains #10966
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## dev #10966 +/- ##
===========================================
+ Coverage 80.63% 87.58% +6.94%
===========================================
Files 1101 31 -1070
Lines 112360 1538 -110822
Branches 747 0 -747
===========================================
- Hits 90602 1347 -89255
+ Misses 21715 191 -21524
+ Partials 43 0 -43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4cb8276
to
5cf88dd
Compare
Signed-off-by: SharglutDev <[email protected]>
Signed-off-by: SharglutDev <[email protected]>
5cf88dd
to
77ebbd0
Compare
Diff for the 2 new files : - useLadyLoadTimetableItems : copy of useLadyLoadTrains. Changes are to get item ids (reduce l.72) and merge paced train and train schedule summaries in one map. - formatTimetableItemSummaries : as typescript don't get that the mapping of items work combines properly ids and items with details, had to first create 2 arrays for each type of item and then merge them in a map. Signed-off-by: SharglutDev <[email protected]>
…hem in the timetable Signed-off-by: SharglutDev <[email protected]>
Signed-off-by: SharglutDev <[email protected]>
Signed-off-by: SharglutDev <[email protected]>
77ebbd0
to
9d5a8e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at the first two commits! Will continue the review later.
export default function formatTimetableItemPayload<T extends boolean>( | ||
validConfig: ValidConfig, | ||
{ isPacedTrainMode }: { isPacedTrainMode: T } | ||
): T extends true ? PacedTrainBase : TrainScheduleBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, we do really need generics here? Could we instead have a function to format the common fields, and then separate functions for each type which call the common function?
{ isPacedTrainMode }: { isPacedTrainMode: T } | ||
): T extends true ? PacedTrainBase : TrainScheduleBase { | ||
const { | ||
baseTrainName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me like destructuring isn't buying us much here… The function would be half shorter without it, WDYT?
@@ -0,0 +1,52 @@ | |||
/* eslint-disable @typescript-eslint/no-unused-vars */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to disable this one? Which variables are unused?
upsertTrainSchedules([formattedNewTrainSchedule]); | ||
} | ||
} catch (e) { | ||
setIsWorking(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid repetition, this could be moved to a finally
block.
}) | ||
); | ||
setIsWorking(false); | ||
dtoImport(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid repetition, dtoImport()
could be moved outside of the if
/else
.
if (showPacedTrains) { | ||
// Prevent to block the train creation if a paced train field is invalid but we want to add a train schedule | ||
if (isPacedTrainMode) { | ||
if (cadence.total('minute') < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: adding .total('minute')
belongs to the previous commit, where the type of cadence
is changed. (TypeScript missed this because Duration
has a valueOf()
method, which makes comparison operators work between Duration
values… maybe it wasn't such a bright idea to implement this method…)
@@ -49,7 +58,15 @@ const useScenarioData = (scenario: ScenarioResponse, infra: InfraWithState) => { | |||
osrdEditoastApi.endpoints.getAllTimetableByIdTrainSchedules.useQuery( | |||
{ timetableId: scenario?.timetable_id }, | |||
{ | |||
skip: !scenario, | |||
skip: !scenario || showPacedTrains, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum I think you should fetch the paced trains even if we need to show the paced trains no ?
skip: !scenario || showPacedTrains, | |
skip: !scenario, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was I thinking 🙃
@@ -58,6 +75,9 @@ const useScenarioData = (scenario: ScenarioResponse, infra: InfraWithState) => { | |||
[fetchedTrainSchedulesResults] | |||
); | |||
|
|||
const pacedTrainsResults = useMemo(() => fetchedPacedTrains || [], [fetchedPacedTrains]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm you can replace pacedTrainResults by these formatted trains, and this way reuse it below, for instance in useEffects (same for trainScheduleResults)
const pacedTrainsResults = useMemo(() => fetchedPacedTrains || [], [fetchedPacedTrains]); | |
const pacedTrains: PacedTrainResultWithPacedTrainId[] = useMemo( | |
() => | |
showPacedTrains | |
? (fetchedPacedTrains || []).map((trainSchedule) => ({ | |
...trainSchedule, | |
id: formatEditoastTrainIdToPacedTrainId(trainSchedule.id), | |
})) | |
: [], | |
[showPacedTrains, fetchedPacedTrains] | |
); |
if (showPacedTrains) { | ||
const formattedRawTrainSchedules: TrainScheduleResultWithTrainId[] = | ||
trainSchedulesResults.map((trainSchedule) => ({ | ||
...trainSchedule, | ||
id: formatEditoastTrainIdToTrainScheduleId(trainSchedule.id), | ||
})); | ||
const formattedRawPacedTrains: PacedTrainResultWithPacedTrainId[] = pacedTrainsResults.map( | ||
(trainSchedule) => ({ | ||
...trainSchedule, | ||
id: formatEditoastTrainIdToPacedTrainId(trainSchedule.id), | ||
}) | ||
); | ||
const sortedTimatableItems = sortBy( | ||
[...formattedRawTrainSchedules, ...formattedRawPacedTrains], | ||
'start_time' | ||
); | ||
setTimetableItems(sortedTimatableItems); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have this above:
const trainSchedules: TrainScheduleResultWithTrainId[] = useMemo(
() =>
(fetchedTrainSchedulesResults || []).map((trainSchedule) => ({
...trainSchedule,
id: formatEditoastTrainIdToTrainScheduleId(trainSchedule.id),
})),
[fetchedTrainSchedulesResults]
);
then, you can simply do (pacedTrains will be empty if !showPacedTrains):
if (showPacedTrains) { | |
const formattedRawTrainSchedules: TrainScheduleResultWithTrainId[] = | |
trainSchedulesResults.map((trainSchedule) => ({ | |
...trainSchedule, | |
id: formatEditoastTrainIdToTrainScheduleId(trainSchedule.id), | |
})); | |
const formattedRawPacedTrains: PacedTrainResultWithPacedTrainId[] = pacedTrainsResults.map( | |
(trainSchedule) => ({ | |
...trainSchedule, | |
id: formatEditoastTrainIdToPacedTrainId(trainSchedule.id), | |
}) | |
); | |
const sortedTimatableItems = sortBy( | |
[...formattedRawTrainSchedules, ...formattedRawPacedTrains], | |
'start_time' | |
); | |
setTimetableItems(sortedTimatableItems); | |
} | |
const sortedTimetableItems = sortBy([...trainSchedules, ...pacedTrains], 'start_time'); | |
setTimetableItems(sortedTimetableItems); | |
} |
Then, you can remove the previous useEffect
const [trainSchedules, setTrainSchedules] = useState<TrainScheduleResultWithTrainId[]>(); | ||
const [trainIdsToFetch, setTrainIdsToFetch] = useState<TrainId[]>(); | ||
const [trainIdsToProject, setTrainIdsToProject] = useState<Set<TrainId>>(new Set()); | ||
const [trainIdsToFetch, setTrainIdsToFetch] = useState<TimetableItemId[]>(); | ||
const [trainIdsToProject, setTrainIdsToProject] = useState<Set<TimetableItemId>>(new Set()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove trainSchedules and trainIdsToFetch and directly use timetableItems
const [trainSchedules, setTrainSchedules] = useState<TrainScheduleResultWithTrainId[]>(); | |
const [trainIdsToFetch, setTrainIdsToFetch] = useState<TrainId[]>(); | |
const [trainIdsToProject, setTrainIdsToProject] = useState<Set<TrainId>>(new Set()); | |
const [trainIdsToFetch, setTrainIdsToFetch] = useState<TimetableItemId[]>(); | |
const [trainIdsToProject, setTrainIdsToProject] = useState<Set<TimetableItemId>>(new Set()); | |
const [trainIdsToProject, setTrainIdsToProject] = useState<Set<TimetableItemId>>(new Set()); |
Signed-off-by: SharglutDev <[email protected]>
9d5a8e6
to
42c86a8
Compare
See commits (will be merged all together)
part of #10615
Warning
PR not testable yet (depend on #11022)
E2E Tests :