Skip to content

Commit

Permalink
front: fix space time chart warning display
Browse files Browse the repository at this point in the history
Add a new boolean allTrainsProjected and display the warning "Projecting..." only if this boolean is not truthy.
  • Loading branch information
clarani committed Sep 16, 2024
1 parent 782d245 commit fd57bf9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const ScenarioContent = ({
trainScheduleUsedForProjection,
trainIdUsedForProjection,
projectedTrains,
allTrainsProjected,
simulationResults,
conflicts,
upsertTrainSchedules,
Expand Down Expand Up @@ -230,6 +231,7 @@ const ScenarioContent = ({
trainScheduleUsedForProjection={trainScheduleUsedForProjection}
trainIdUsedForProjection={trainIdUsedForProjection}
infraId={infra.id}
allTrainsProjected={allTrainsProjected}
timetableTrainNb={timetable.train_ids.length}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const useLazyLoadTrains = ({

const trainSchedulesById = useMemo(() => mapBy(trainSchedules, 'id'), [trainSchedules]);

const { projectedTrainsById, setProjectedTrainsById } = useLazyProjectTrains({
const { projectedTrainsById, setProjectedTrainsById, allTrainsProjected } = useLazyProjectTrains({
infraId,
trainIdsToProject,
path,
Expand Down Expand Up @@ -125,6 +125,7 @@ const useLazyLoadTrains = ({
projectedTrainsById,
setTrainScheduleSummariesById,
setProjectedTrainsById,
allTrainsProjected,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const useScenarioData = (
projectedTrainsById,
setTrainScheduleSummariesById,
setProjectedTrainsById,
allTrainsProjected,
} = useLazyLoadTrains({
infraId: scenario.infra_id,
trainIdsToFetch,
Expand Down Expand Up @@ -187,6 +188,7 @@ const useScenarioData = (
trainScheduleUsedForProjection,
trainIdUsedForProjection,
projectedTrains,
allTrainsProjected,
simulationResults,
conflicts,
removeTrains,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type SimulationResultsProps = {
trainIdUsedForProjection?: number;
simulationResults: SimulationResultsData;
timetableTrainNb: number;
allTrainsProjected: boolean;
};

const SimulationResults = ({
Expand All @@ -58,6 +59,7 @@ const SimulationResults = ({
path,
},
timetableTrainNb,
allTrainsProjected,
}: SimulationResultsProps) => {
const { t } = useTranslation('simulation');
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -170,7 +172,7 @@ const SimulationResults = ({

<div className="osrd-simulation-container d-flex flex-grow-1 flex-shrink-1">
<div className="chart-container">
{spaceTimeData.length !== timetableTrainNb && (
{!allTrainsProjected && (
<ProjectionLoadingMessage
projectedTrainsNb={spaceTimeData.length}
totalTrains={timetableTrainNb}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const useLazyProjectTrains = ({
const [projectedTrainsById, setProjectedTrainsById] = useState<Map<number, TrainSpaceTimeData>>(
new Map()
);
const [allTrainsProjected, setAllTrainsProjected] = useState(false);

const requestedProjectedTrainIds = useRef<Set<number>>(new Set());
const projectionSeqNum = useRef(0);
Expand Down Expand Up @@ -96,6 +97,10 @@ const useLazyProjectTrains = ({
(trainId) => !requestedProjectedTrainIds.current.has(trainId)
);

if (allTrainsProjected && shouldProjectIds.length > 0) {
setAllTrainsProjected(false);
}

for (let i = 0; i < shouldProjectIds.length; i += BATCH_SIZE) {
// If projection parameters have changed, bail out
if (projectionSeqNum.current !== seqNum) break;
Expand Down Expand Up @@ -125,6 +130,7 @@ const useLazyProjectTrains = ({
) {
setTrainIdsToProject([]);
requestedProjectedTrainIds.current = new Set();
setAllTrainsProjected(true);
}
}, [moreTrainsToCome, projectedTrainsById]);

Expand All @@ -143,6 +149,7 @@ const useLazyProjectTrains = ({
return {
projectedTrainsById,
setProjectedTrainsById,
allTrainsProjected,
};
};

Expand Down

0 comments on commit fd57bf9

Please sign in to comment.