Skip to content

Commit 7a548a0

Browse files
committed
- create TimetableItemAction
1 parent cd57922 commit 7a548a0

File tree

5 files changed

+117
-40
lines changed

5 files changed

+117
-40
lines changed

front/src/modules/trainschedule/components/Timetable/PacedTrain/PacedTrainItem.tsx

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22

33
import { Checkbox } from '@osrd-project/ui-core';
4-
import { ChevronDown, Manchette } from '@osrd-project/ui-icons';
4+
import { ChevronDown, Clock, Flame, Manchette, Moon } from '@osrd-project/ui-icons';
55
import cx from 'classnames';
66

7+
import TimetableItemActions from '../TimetableItemActions';
78
import type { TrainScheduleWithDetails } from '../types';
9+
import { Duration } from 'utils/duration';
10+
import { ms2min } from 'utils/timeManipulation';
811

912
export type PacedTrain = TrainScheduleWithDetails & {
1013
paced: {
@@ -31,6 +34,12 @@ const PacedTrainItem = ({
3134
const [isOpened, setIsOpened] = useState(false);
3235

3336
const toggle = () => setIsOpened((open) => !open);
37+
const selectPathProjection = async () => {};
38+
const duplicatePacedTrain = async () => {};
39+
const editPacedTrain = () => {};
40+
const deletePacedTrain = async () => {};
41+
42+
const stepDuration = Duration.parse(pacedTrain.paced.step);
3443

3544
return (
3645
<div
@@ -66,6 +75,33 @@ const PacedTrainItem = ({
6675
<span className="train-name">{pacedTrain.trainName}</span>
6776
</div>
6877
</div>
78+
{!pacedTrain.invalidReason && (
79+
<div className="train-time">
80+
<div className="status-icon after-midnight">{true && <Moon />}</div>
81+
{pacedTrain.isValid && (
82+
<div className="scenario-timetable-train-departure">
83+
{`- ${ms2min(stepDuration.ms)} min`}
84+
</div>
85+
)}
86+
<div className="status-icon not-honored-or-too-fast">
87+
{pacedTrain.notHonoredReason &&
88+
(pacedTrain.notHonoredReason === 'scheduleNotHonored' ? <Clock /> : <Flame />)}
89+
</div>
90+
<div
91+
className={cx('status-dot', {
92+
'not-honored-or-too-fast':
93+
pacedTrain.notHonoredReason === 'scheduleNotHonored' ||
94+
pacedTrain.notHonoredReason === 'trainTooFast',
95+
})}
96+
/>
97+
</div>
98+
)}
99+
<TimetableItemActions
100+
selectPathProjection={selectPathProjection}
101+
duplicateTimetableItem={duplicatePacedTrain}
102+
editTimetableItem={editPacedTrain}
103+
deleteTimetableItem={deletePacedTrain}
104+
/>
69105
</div>
70106
<div className="occurancies" />
71107
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// import React from 'react';
2+
3+
import { Duplicate, Pencil, Trash } from '@osrd-project/ui-icons';
4+
import { useTranslation } from 'react-i18next';
5+
import { GiPathDistance } from 'react-icons/gi';
6+
7+
type TimetableItemActionsProps = {
8+
selectPathProjection: () => Promise<void>;
9+
duplicateTimetableItem: () => Promise<void>;
10+
editTimetableItem: () => void;
11+
deleteTimetableItem: () => Promise<void>;
12+
};
13+
14+
const TimetableItemActions = ({
15+
selectPathProjection,
16+
duplicateTimetableItem,
17+
editTimetableItem,
18+
deleteTimetableItem,
19+
}: TimetableItemActionsProps) => {
20+
const { t } = useTranslation(['operationalStudies/scenario']);
21+
return (
22+
<div className="action-buttons">
23+
<button
24+
type="button"
25+
aria-label={t('timetable.choosePath')}
26+
title={t('timetable.choosePath')}
27+
onClick={selectPathProjection}
28+
>
29+
<GiPathDistance />
30+
</button>
31+
<button
32+
type="button"
33+
aria-label={t('timetable.duplicate')}
34+
title={t('timetable.duplicate')}
35+
onClick={duplicateTimetableItem}
36+
>
37+
<Duplicate />
38+
</button>
39+
<button
40+
type="button"
41+
aria-label={t('timetable.update')}
42+
title={t('timetable.update')}
43+
onClick={editTimetableItem}
44+
data-testid="edit-train"
45+
>
46+
<Pencil />
47+
</button>
48+
<button
49+
type="button"
50+
aria-label={t('timetable.delete')}
51+
title={t('timetable.delete')}
52+
onClick={deleteTimetableItem}
53+
>
54+
<Trash />
55+
</button>
56+
</div>
57+
);
58+
};
59+
60+
export default TimetableItemActions;

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

+8-37
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from 'react';
22

33
import { Checkbox } from '@osrd-project/ui-core';
4-
import { Duplicate, Pencil, Trash, Clock, Flame, Moon, Manchette } from '@osrd-project/ui-icons';
4+
import { Clock, Flame, Moon, Manchette } from '@osrd-project/ui-icons';
55
import cx from 'classnames';
66
import dayjs from 'dayjs';
77
import { omit } from 'lodash';
88
import { useTranslation } from 'react-i18next';
9-
import { GiPathDistance } from 'react-icons/gi';
109

1110
import { MANAGE_TRAIN_SCHEDULE_TYPES } from 'applications/operationalStudies/consts';
1211
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
@@ -20,6 +19,7 @@ import { useAppDispatch } from 'store';
2019
import { formatToIsoDate, isoDateToMs } from 'utils/date';
2120
import { castErrorToFailure } from 'utils/error';
2221

22+
import TimetableItemActions from './TimetableItemActions';
2323
import type { TrainScheduleWithDetails } from './types';
2424

2525
type TimetableTrainCardProps = {
@@ -254,41 +254,12 @@ const TimetableTrainCard = ({
254254
</div>
255255
)}
256256
</div>
257-
<div className="action-buttons">
258-
<button
259-
type="button"
260-
aria-label={t('timetable.choosePath')}
261-
title={t('timetable.choosePath')}
262-
onClick={selectPathProjection}
263-
>
264-
<GiPathDistance />
265-
</button>
266-
<button
267-
type="button"
268-
aria-label={t('timetable.duplicate')}
269-
title={t('timetable.duplicate')}
270-
onClick={duplicateTrain}
271-
>
272-
<Duplicate />
273-
</button>
274-
<button
275-
type="button"
276-
aria-label={t('timetable.update')}
277-
title={t('timetable.update')}
278-
onClick={editTrainSchedule}
279-
data-testid="edit-train"
280-
>
281-
<Pencil />
282-
</button>
283-
<button
284-
type="button"
285-
aria-label={t('timetable.delete')}
286-
title={t('timetable.delete')}
287-
onClick={deleteTrain}
288-
>
289-
<Trash />
290-
</button>
291-
</div>
257+
<TimetableItemActions
258+
selectPathProjection={selectPathProjection}
259+
duplicateTimetableItem={duplicateTrain}
260+
editTimetableItem={editTrainSchedule}
261+
deleteTimetableItem={deleteTrain}
262+
/>
292263
</div>
293264
);
294265
};

front/src/styles/scss/applications/operationalStudies/_scenario.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
}
215215
}
216216
}
217+
217218
.scenario-details-electrical-profile-set {
218219
font-size: 0.75rem;
219220
font-weight: 400;
@@ -334,6 +335,10 @@
334335
margin-left: 8px;
335336
position: relative;
336337
line-height: 24px;
338+
339+
.custom-checkbox.small {
340+
margin-right: 9px;
341+
}
337342
}
338343

339344
.no-train {
@@ -483,11 +488,12 @@
483488

484489
.toggle-icon{
485490
transition: all 0.3s;
491+
margin-right: 7.5px;
486492
}
487493

488494
.base-info{
489495
height: 48px;
490-
align-items: center;
496+
align-items: center;
491497
}
492498

493499

front/src/utils/timeManipulation.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export function ms2sec(ms: number) {
1616
return ms / 1000;
1717
}
1818

19+
export function ms2min(ms: number) {
20+
return ms / 1000 / 60;
21+
}
22+
1923
export function minToMs(min: number) {
2024
return min * 60 * 1000;
2125
}

0 commit comments

Comments
 (0)