-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathTimesStopsOutput.tsx
61 lines (56 loc) · 1.97 KB
/
TimesStopsOutput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import cx from 'classnames';
import type {
PathPropertiesFormatted,
SimulationResponseSuccess,
} from 'applications/operationalStudies/types';
import type { PathfindingResultSuccess, TrainScheduleResult } from 'common/api/osrdEditoastApi';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import { NO_BREAK_SPACE } from 'utils/strings';
import useOutputTableData from './hooks/useOutputTableData';
import TimesStops from './TimesStops';
import { TableType, type TimesStopsRow } from './types';
type TimesStopsOutputProps = {
simulatedTrain?: SimulationResponseSuccess;
trainSummary?: TrainScheduleWithDetails;
operationalPoints?: PathPropertiesFormatted['operationalPoints'];
selectedTrainSchedule?: TrainScheduleResult;
path?: PathfindingResultSuccess;
dataIsLoading: boolean;
};
const TimesStopsOutput = ({
simulatedTrain,
trainSummary,
operationalPoints,
selectedTrainSchedule,
path,
dataIsLoading,
}: TimesStopsOutputProps) => {
const enrichedOperationalPoints = useOutputTableData(
simulatedTrain?.final_output,
trainSummary,
operationalPoints,
selectedTrainSchedule,
path
);
return (
<TimesStops
rows={enrichedOperationalPoints}
tableType={TableType.Output}
cellClassName={({ rowData: rowData_, columnId }) => {
const rowData = rowData_ as TimesStopsRow;
const arrivalScheduleNotRespected = rowData.arrival?.time
? rowData.calculatedArrival !== rowData.arrival.time
: false;
const negativeDiffMargins = Number(rowData.diffMargins?.split(NO_BREAK_SPACE)[0]) < 0;
return cx({
'warning-schedule': arrivalScheduleNotRespected,
'warning-margin': negativeDiffMargins,
'secondary-code-column': columnId === 'ch',
});
}}
headerRowHeight={40}
dataIsLoading={dataIsLoading || !trainSummary || !operationalPoints || !selectedTrainSchedule}
/>
);
};
export default TimesStopsOutput;