Skip to content

Commit 13426fa

Browse files
committed
front: add train type filter in the timetable
Signed-off-by: SharglutDev <[email protected]>
1 parent 609e6df commit 13426fa

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

front/public/locales/en/operationalStudies/scenario.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
"modifyScenario": "Modify scenario",
2626
"moreDetails": "more details",
2727
"noElectricalProfileSet": "No electrical profile",
28-
"pacedTrain": {
29-
"pacedTrain": "Paced train"
30-
},
3128
"pacedTrain_one": "1 service",
3229
"pacedTrain_other": "{{count}} services",
3330
"pacedTrain_zero": "0 service",
@@ -82,6 +79,7 @@
8279
"noSpeedLimitTags": "Without code",
8380
"noSpeedLimitTagsShort": "None",
8481
"noTrain": "No train",
82+
"pacedTrain": "Service",
8583
"punctuality": "Punctuality",
8684
"rollingStockFilterPlaceholder": "Family, detail, serie",
8785
"scheduledPointsHonoredFilter": "Scheduled points honored",
@@ -96,8 +94,11 @@
9694
"toggleMultiSelection": "Toggle multiselection",
9795
"trainAdded": "Train added",
9896
"trainDeleted": "{{ name }} train has been deleted.",
97+
"trainSchedule": "Unique train",
98+
9999
"trainsSelectionDeletedCount_one": "The train has been deleted.",
100100
"trainsSelectionDeletedCount_other": "The {{count}} trains have been deleted.",
101+
"trainType": "Services, trains",
101102
"update": "Edit",
102103
"validityFilter": "Trains validity"
103104
},

front/public/locales/fr/operationalStudies/scenario.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
"modifyScenario": "Modifier le scénario",
2626
"moreDetails": "plus de détails",
2727
"noElectricalProfileSet": "Pas de profil électrique",
28-
"pacedTrain": {
29-
"pacedTrain": "Mission"
30-
},
3128
"pacedTrain_one": "1 mission",
3229
"pacedTrain_other": "{{count}} missions",
3330
"pacedTrain_zero": "0 mission",
@@ -82,6 +79,7 @@
8279
"noSpeedLimitTags": "Sans code",
8380
"noSpeedLimitTagsShort": "Aucun",
8481
"noTrain": "Aucun train",
82+
"pacedTrain": "Mission",
8583
"punctuality": "Ponctualité",
8684
"rollingStockFilterPlaceholder": "Famille, détail, série",
8785
"scheduledPointsHonoredFilter": "Points horaires honorés",
@@ -96,8 +94,10 @@
9694
"toggleMultiSelection": "Basculer le mode multisélection",
9795
"trainAdded": "Train ajouté",
9896
"trainDeleted": "Le train {{name}} a bien été supprimé.",
97+
"trainSchedule": "Train unique",
9998
"trainsSelectionDeletedCount_one": "Le train a bien été supprimé.",
10099
"trainsSelectionDeletedCount_other": "Les {{count}} trains ont bien été supprimés.",
100+
"trainType": "Missions, trains",
101101
"update": "Modifier",
102102
"validityFilter": "Validité des trains"
103103
},

front/src/common/UserSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const UserSettings = () => {
7676
)
7777
}
7878
/>
79-
<div className="ml-2">{t('operationalStudies/scenario:pacedTrain.pacedTrain')}</div>
79+
<div className="ml-2">{t('operationalStudies/scenario:timetable.pacedTrain')}</div>
8080
</div>
8181
)
8282
}

front/src/modules/trainschedule/components/Timetable/FilterPanel.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { X } from '@osrd-project/ui-icons';
33
import cx from 'classnames';
44
import { useTranslation } from 'react-i18next';
55

6-
import type { ValidityFilter, ScheduledPointsHonoredFilter, TimetableFilters } from './types';
6+
import type {
7+
ValidityFilter,
8+
ScheduledPointsHonoredFilter,
9+
TimetableFilters,
10+
TrainTypeFilter,
11+
} from './types';
712

813
type FilterPanelProps = {
914
toggleFilterPanel: () => void;
@@ -22,6 +27,8 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
2227
setValidityFilter,
2328
scheduledPointsHonoredFilter,
2429
setScheduledPointsHonoredFilter,
30+
trainTypeFilter,
31+
setTrainTypeFilter,
2532
uniqueTags,
2633
selectedTags,
2734
setSelectedTags,
@@ -39,6 +46,12 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
3946
{ value: 'notHonored', label: t('timetable.showNotHonoredTrains') },
4047
];
4148

49+
const trainTypeOptions: { value: TrainTypeFilter; label: string }[] = [
50+
{ value: 'both', label: t('timetable.showAllTrains') },
51+
{ value: 'pacedTrain', label: t('timetable.pacedTrain') },
52+
{ value: 'trainSchedule', label: t('timetable.trainSchedule') },
53+
];
54+
4255
const toggleTagSelection = (tag: string | null) => {
4356
setSelectedTags((prevSelectedTags) => {
4457
const newSelectedTags = new Set(prevSelectedTags);
@@ -92,8 +105,23 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
92105
validityOptions[0]
93106
}
94107
/>
108+
<Select
109+
getOptionLabel={(option) => option.label}
110+
getOptionValue={(option) => option.value}
111+
id="train-type"
112+
label={t('timetable.trainType')}
113+
onChange={(selectedOption) => {
114+
if (selectedOption) {
115+
setTrainTypeFilter(selectedOption.value);
116+
}
117+
}}
118+
options={trainTypeOptions}
119+
value={
120+
trainTypeOptions.find((option) => option.value === trainTypeFilter) ||
121+
trainTypeOptions[0]
122+
}
123+
/>
95124
</div>
96-
97125
<div id="schedule-point-honored-and-rollingstock">
98126
<Input
99127
type="text"

front/src/modules/trainschedule/components/Timetable/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type ValidityFilter = 'both' | 'valid' | 'invalid';
1212

1313
export type ScheduledPointsHonoredFilter = 'both' | 'honored' | 'notHonored';
1414

15+
export type TrainTypeFilter = 'both' | 'pacedTrain' | 'trainSchedule';
16+
1517
type SimulationSummaryResultSuccess = Extract<SimulationSummaryResult, { status: 'success' }>;
1618

1719
type TimetableItemWithDetails = Omit<
@@ -70,6 +72,8 @@ export type TimetableFilters = {
7072
setScheduledPointsHonoredFilter: (
7173
scheduledPointsHonoredFilter: ScheduledPointsHonoredFilter
7274
) => void;
75+
trainTypeFilter: TrainTypeFilter;
76+
setTrainTypeFilter: (trainType: TrainTypeFilter) => void;
7377
selectedTags: Set<string | null>;
7478
setSelectedTags: React.Dispatch<React.SetStateAction<Set<string | null>>>;
7579
};

front/src/modules/trainschedule/components/Timetable/useFilterTimetableItems.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { useMemo, useState } from 'react';
33
import { uniq } from 'lodash';
44

55
import { useDebounce } from 'utils/helpers';
6+
import { isPacedTrain, isTrainSchedule } from 'utils/trainId';
67

78
import type {
89
ScheduledPointsHonoredFilter,
910
TimetableFilters,
1011
TimetableItemResult,
12+
TrainTypeFilter,
1113
ValidityFilter,
1214
} from './types';
1315
import { extractTagCode, keepItem } from './utils';
@@ -25,6 +27,7 @@ const useFilterTimetableItems = (
2527
const [validityFilter, setValidityFilter] = useState<ValidityFilter>('both');
2628
const [scheduledPointsHonoredFilter, setScheduledPointsHonoredFilter] =
2729
useState<ScheduledPointsHonoredFilter>('both');
30+
const [trainTypeFilter, setTrainTypeFilter] = useState<TrainTypeFilter>('both');
2831
const [selectedTags, setSelectedTags] = useState<Set<string | null>>(new Set());
2932

3033
const debouncedNameLabelFilter = useDebounce(nameLabelFilter, 500);
@@ -60,6 +63,12 @@ const useFilterTimetableItems = (
6063
}
6164
}
6265

66+
// Apply train type filter
67+
if (trainTypeFilter !== 'both') {
68+
if (trainTypeFilter === 'pacedTrain' && isTrainSchedule(timetableItem.id)) return false;
69+
if (trainTypeFilter === 'trainSchedule' && isPacedTrain(timetableItem.id)) return false;
70+
}
71+
6372
// Apply tag filter
6473
if (
6574
selectedTags.size > 0 &&
@@ -93,6 +102,7 @@ const useFilterTimetableItems = (
93102
debouncedRollingstockFilter,
94103
validityFilter,
95104
scheduledPointsHonoredFilter,
105+
trainTypeFilter,
96106
selectedTags,
97107
]
98108
);
@@ -108,6 +118,8 @@ const useFilterTimetableItems = (
108118
setValidityFilter,
109119
scheduledPointsHonoredFilter,
110120
setScheduledPointsHonoredFilter,
121+
trainTypeFilter,
122+
setTrainTypeFilter,
111123
selectedTags,
112124
setSelectedTags,
113125
};

0 commit comments

Comments
 (0)