Skip to content

Commit

Permalink
front: timetable performance
Browse files Browse the repository at this point in the history
timetable with virtualized list to limit the number of elements in the DOM

Signed-off-by: Valentin Chanas <[email protected]>
  • Loading branch information
anisometropie committed Jan 20, 2025
1 parent eb04d34 commit 1fe0918
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
35 changes: 34 additions & 1 deletion front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"remark-gfm": "^4.0.0",
"reselect": "^5.1.0",
"uuid": "^11.0.5",
"viewport-mercator-project": "^7.0.4"
"viewport-mercator-project": "^7.0.4",
"virtua": "^0.39.3"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.1",
Expand Down
51 changes: 27 additions & 24 deletions front/src/modules/trainschedule/components/Timetable/Timetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cx from 'classnames';
import dayjs from 'dayjs';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { Virtualizer } from 'virtua';

import { MANAGE_TRAIN_SCHEDULE_TYPES } from 'applications/operationalStudies/consts';
import type { Conflict, InfraState, TrainScheduleResult } from 'common/api/osrdEditoastApi';
Expand Down Expand Up @@ -145,30 +146,32 @@ const Timetable = ({
trainSchedules={trainSchedules}
isInSelection={selectedTrainIds.length > 0}
/>
{displayedTrainSchedules.map((train: TrainScheduleWithDetails, index) => (
<div key={`timetable-train-card-${train.id}-${train.trainName}`}>
{showDepartureDates[index] && (
<div className="scenario-timetable-departure-date">
{currentDepartureDates[index]}
</div>
)}
<TimetableTrainCard
isInSelection={selectedTrainIds.includes(train.id)}
handleSelectTrain={handleSelectTrain}
train={train}
isSelected={infraState === 'CACHED' && selectedTrainId === train.id}
isModified={train.id === trainIdToEdit}
setDisplayTrainScheduleManagement={setDisplayTrainScheduleManagement}
upsertTrainSchedules={upsertTrainSchedules}
setTrainIdToEdit={setTrainIdToEdit}
removeTrains={removeAndUnselectTrains}
projectionPathIsUsed={
infraState === 'CACHED' && trainIdUsedForProjection === train.id
}
dtoImport={dtoImport}
/>
</div>
))}
<Virtualizer overscan={15}>
{displayedTrainSchedules.map((train: TrainScheduleWithDetails, index) => (
<div key={`timetable-train-card-${train.id}-${train.trainName}`}>
{showDepartureDates[index] && (
<div className="scenario-timetable-departure-date">
{currentDepartureDates[index]}
</div>
)}
<TimetableTrainCard
isInSelection={selectedTrainIds.includes(train.id)}
handleSelectTrain={handleSelectTrain}
train={train}
isSelected={infraState === 'CACHED' && selectedTrainId === train.id}
isModified={train.id === trainIdToEdit}
setDisplayTrainScheduleManagement={setDisplayTrainScheduleManagement}
upsertTrainSchedules={upsertTrainSchedules}
setTrainIdToEdit={setTrainIdToEdit}
removeTrains={removeAndUnselectTrains}
projectionPathIsUsed={
infraState === 'CACHED' && trainIdUsedForProjection === train.id
}
dtoImport={dtoImport}
/>
</div>
))}
</Virtualizer>
<div
className={cx('bottom-timetables-trains', {
'empty-list': trainSchedulesWithDetails.length === 0,
Expand Down

0 comments on commit 1fe0918

Please sign in to comment.