Skip to content

Commit

Permalink
front: fix nge sync with dtoImport
Browse files Browse the repository at this point in the history
When calling the dtoImport, we ask the transchedule state to the
database
  • Loading branch information
sim51 committed Dec 13, 2024
1 parent 8715331 commit 0cd0959
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import useScenarioData from 'applications/operationalStudies/hooks/useScenarioDa
import ImportTrainSchedule from 'applications/operationalStudies/views/ImportTrainSchedule';
import ManageTrainSchedule from 'applications/operationalStudies/views/ManageTrainSchedule';
import SimulationResults from 'applications/operationalStudies/views/SimulationResults';
import type {
InfraWithState,
ScenarioResponse,
TimetableDetailedResult,
TrainScheduleResult,
import {
osrdEditoastApi,
type InfraWithState,
type ScenarioResponse,
type TimetableDetailedResult,
type TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
import ScenarioLoaderMessage from 'modules/scenario/components/ScenarioLoaderMessage';
import TimetableManageTrainSchedule from 'modules/trainschedule/components/ManageTrainSchedule/TimetableManageTrainSchedule';
Expand Down Expand Up @@ -66,13 +67,29 @@ const ScenarioContent = ({
const macroEditorState = useRef<MacroEditorState>();
const [ngeDto, setNgeDto] = useState<NetzgrafikDto>();

const dtoImport = async () => {
const state = new MacroEditorState(scenario, trainSchedules || []);
const dtoImport = useCallback(async () => {
const timetablePromise = dispatch(
osrdEditoastApi.endpoints.getTimetableById.initiate(
{ id: timetable.timetable_id },
{ forceRefetch: true, subscribe: false }
)
);
const { train_ids } = await timetablePromise.unwrap();
const trainSchedulesPromise = dispatch(
osrdEditoastApi.endpoints.postTrainSchedule.initiate(
{ body: { ids: train_ids } },
{ forceRefetch: true, subscribe: false }
)
);
const schedules = (await trainSchedulesPromise.unwrap()).filter(
(trainSchedule) => trainSchedule.path.length >= 2
);
const state = new MacroEditorState(scenario, schedules || []);
await loadAndIndexNge(state, dispatch);
const dto = getNgeDto(state);
macroEditorState.current = state;
setNgeDto(dto);
};
}, [dispatch, scenario, timetable.timetable_id]);

const toggleMicroMacroButton = useCallback(
(isMacroMode: boolean) => {
Expand Down

0 comments on commit 0cd0959

Please sign in to comment.