Skip to content

Commit

Permalink
front: move useSimulationResults in SimulationResults
Browse files Browse the repository at this point in the history
Moving this hook in SimulationResults avoids unnecessary renders and bring the code closer to where it is used.

Signed-off-by: Clara Ni <clara.ni@outlook.fr>
  • Loading branch information
clarani committed Dec 5, 2024
1 parent 419a315 commit 418d712
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const ScenarioContent = ({
const [isMacro, setIsMacro] = useState(false);
const {
selectedTrainId,
selectedTrainSummary,
trainScheduleSummaries,
trainSchedules,
projectionData,
simulationResults,
conflicts,
upsertTrainSchedules,
removeTrains,
Expand Down Expand Up @@ -209,9 +209,9 @@ const ScenarioContent = ({
scenarioData={{ name: scenario.name, infraName: scenario.infra_name }}
collapsedTimetable={collapsedTimetable}
projectionData={projectionData}
simulationResults={simulationResults}
infraId={infra.id}
conflicts={conflicts}
selectedTrainSummary={selectedTrainSummary}
/>
)
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { mapBy } from 'utils/types';
import useAutoUpdateProjection from './useAutoUpdateProjection';
import useLazyLoadTrains from './useLazyLoadTrains';
import usePathProjection from './usePathProjection';
import useSimulationResults from './useSimulationResults';

const useScenarioData = (
scenario: ScenarioResponse,
Expand All @@ -45,8 +44,6 @@ const useScenarioData = (

const projectionPath = usePathProjection(infra);

const simulationResults = useSimulationResults();

const {
trainScheduleSummariesById,
projectedTrainsById,
Expand Down Expand Up @@ -165,6 +162,9 @@ const useScenarioData = (

return {
selectedTrainId,
selectedTrainSummary: selectedTrainId
? trainScheduleSummariesById.get(selectedTrainId)
: undefined,
trainScheduleSummaries,
trainSchedules,
projectionData:
Expand All @@ -179,12 +179,6 @@ const useScenarioData = (
},
}
: undefined,
simulationResults: {
...simulationResults,
selectedTrainSummary: selectedTrainId
? trainScheduleSummariesById.get(selectedTrainId)
: undefined,
},
conflicts,
removeTrains,
upsertTrainSchedules,
Expand Down
2 changes: 0 additions & 2 deletions front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
} from 'common/api/osrdEditoastApi';
import type { RangedValue } from 'common/types';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import type { ArrayElement } from 'utils/types';

export interface Step {
Expand Down Expand Up @@ -163,7 +162,6 @@ export type SimulationResultsData = {
selectedTrainSchedule?: TrainScheduleResult;
selectedTrainRollingStock?: RollingStockWithLiveries;
selectedTrainPowerRestrictions: LayerData<PowerRestrictionValues>[];
selectedTrainSummary?: TrainScheduleWithDetails;
trainSimulation?: SimulationResponseSuccess;
pathProperties?: PathPropertiesFormatted;
pathLength?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ChevronLeft, ChevronRight } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { useTranslation } from 'react-i18next';

import type { SimulationResultsData } from 'applications/operationalStudies/types';
import type { Conflict } from 'common/api/osrdEditoastApi';
import SimulationWarpedMap from 'common/Map/WarpedMap/SimulationWarpedMap';
import ResizableSection from 'common/ResizableSection';
Expand All @@ -21,10 +20,13 @@ import { useFormattedOperationalPoints } from 'modules/simulationResult/hooks/us
import SimulationResultExport from 'modules/simulationResult/SimulationResultExport/SimulationResultsExport';
import type { ProjectionData } from 'modules/simulationResult/types';
import TimesStopsOutput from 'modules/timesStops/TimesStopsOutput';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import { updateViewport, type Viewport } from 'reducers/map';
import { useAppDispatch } from 'store';
import { getPointCoordinates } from 'utils/geometry';

import useSimulationResults from '../hooks/useSimulationResults';

const SPEED_SPACE_CHART_HEIGHT = 521.5;
const HANDLE_TAB_RESIZE_HEIGHT = 20;
const MANCHETTE_HEIGHT_DIFF = 76;
Expand All @@ -33,29 +35,30 @@ type SimulationResultsProps = {
scenarioData: { name: string; infraName: string };
collapsedTimetable: boolean;
infraId?: number;
simulationResults: SimulationResultsData;
projectionData?: ProjectionData;
selectedTrainSummary?: TrainScheduleWithDetails;
conflicts?: Conflict[];
};

const SimulationResults = ({
scenarioData,
collapsedTimetable,
infraId,
simulationResults: {
projectionData,
selectedTrainSummary,
conflicts = [],
}: SimulationResultsProps) => {
const { t } = useTranslation('simulation');
const dispatch = useAppDispatch();

const {
selectedTrainSchedule,
selectedTrainRollingStock,
selectedTrainPowerRestrictions,
selectedTrainSummary,
trainSimulation,
pathProperties,
path,
},
projectionData,
conflicts = [],
}: SimulationResultsProps) => {
const { t } = useTranslation('simulation');
const dispatch = useAppDispatch();
} = useSimulationResults();

const [extViewport, setExtViewport] = useState<Viewport>();
const [showWarpedMap, setShowWarpedMap] = useState(false);
Expand Down

0 comments on commit 418d712

Please sign in to comment.