diff --git a/front/src/modules/trainschedule/components/TimetableV2/TimetableToolbar.tsx b/front/src/modules/trainschedule/components/TimetableV2/TimetableToolbar.tsx index 185ad37358f..1514eb32efe 100644 --- a/front/src/modules/trainschedule/components/TimetableV2/TimetableToolbar.tsx +++ b/front/src/modules/trainschedule/components/TimetableV2/TimetableToolbar.tsx @@ -1,6 +1,6 @@ import React, { useContext, useState } from 'react'; -import { Filter, Trash } from '@osrd-project/ui-icons'; +import { Filter, Trash, Download } from '@osrd-project/ui-icons'; import cx from 'classnames'; import { isEmpty } from 'lodash'; import { useTranslation } from 'react-i18next'; @@ -58,6 +58,8 @@ const TimetableToolbar = ({ const [validityFilter, setValidityFilter] = useState('both'); const [selectedTags, setSelectedTags] = useState>(new Set()); + const [getV2TrainSchedule] = osrdEditoastApi.endpoints.getV2TrainSchedule.useLazyQuery(); + const debouncedFilter = useDebounce(filter, 500); const debouncedRollingstockFilter = useDebounce(rollingStockFilter, 500); @@ -114,6 +116,31 @@ const TimetableToolbar = ({ }); }; + const exportSchedules = async (selectedTrainIdsFromClick: number[]) => { + const trainScheduleResults = await getV2TrainSchedule({ ids: selectedTrainIdsFromClick }) + .unwrap() + .then((results) => + results.map((result) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { id, ...trainSchedule } = result; + return trainSchedule; + }) + ) + .catch((e) => { + dispatch(setFailure(castErrorToFailure(e))); + }); + + if (!trainScheduleResults) return; + + const jsonString = JSON.stringify({ trainScheduleResults }); + const blob = new Blob([jsonString], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'train_schedules.json'; + a.click(); + }; + return ( <>
@@ -143,6 +170,15 @@ const TimetableToolbar = ({ > + )}
diff --git a/front/src/styles/scss/applications/operationalStudies/_scenario.scss b/front/src/styles/scss/applications/operationalStudies/_scenario.scss index 3b297af09df..3e4b3105228 100644 --- a/front/src/styles/scss/applications/operationalStudies/_scenario.scss +++ b/front/src/styles/scss/applications/operationalStudies/_scenario.scss @@ -160,6 +160,10 @@ background-color: rgba(var(--secondary-rgb), 0.5); } } + .multiselect-download { + @extend .multiselect-delete; + background-color: var(--primary); + } .scenario-timetable-toolbar { display: flex; align-items: center;