-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathScenarioDescription.tsx
103 lines (95 loc) · 3.24 KB
/
ScenarioDescription.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Blocked, ChevronLeft, Pencil } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';
import type { InfraWithState, ScenarioResponse } from 'common/api/osrdEditoastApi';
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
import AddAndEditScenarioModal from 'modules/scenario/components/AddOrEditScenarioModal';
import InfraLoadingState from './InfraLoadingState';
type ScenarioDescriptionProps = {
scenario: ScenarioResponse;
infra?: InfraWithState;
infraReloadCount: number;
collapseTimetable: () => void;
};
const ScenarioDescription = ({
scenario,
infra,
infraReloadCount,
collapseTimetable,
}: ScenarioDescriptionProps) => {
const { t } = useTranslation('operationalStudies/scenario');
const { openModal } = useModal();
return (
<div>
<div className="scenario-details-name">
<span className="flex-grow-1 scenario-name text-truncate" title={scenario.name}>
{scenario.name}
</span>
</div>
<div className="scenario-description">
{scenario.description && (
<div className="scenario-details-description">{scenario.description}</div>
)}
<div className="flex justify-end">
<button
type="button"
className="scenario-collapse-button"
aria-label={t('toggleTimetable')}
onClick={() => collapseTimetable()}
>
<ChevronLeft />
</button>
</div>
<button
data-testid="editScenario"
className="update-scenario"
type="button"
aria-label={t('editScenario')}
onClick={() =>
openModal(
<AddAndEditScenarioModal editionMode scenario={scenario} />,
'xl',
'no-close-modal'
)
}
title={t('editScenario')}
>
<Pencil />
</button>
</div>
<div className="scenario-details-electrical-profile-set">
{scenario.electrical_profile_set_id
? scenario.electrical_profile_set_id
: t('noElectricalProfileSet')}
</div>
<div className="scenario-details-infra-name">
{t('infrastructure')} :
{infra && <InfraLoadingState infra={infra} />}
<span className="scenario-infra-name">{scenario.infra_name}</span> | ID
{scenario.infra_id}
</div>
{infra &&
infra.state === 'TRANSIENT_ERROR' &&
(infraReloadCount <= 5 ? (
<div className="scenario-details-infra-error">
<Blocked variant="fill" />
<span className="error-description">
{t('errorMessages.unableToLoadInfra', { infraReloadCount })}
</span>
</div>
) : (
<div className="scenario-details-infra-error">
<Blocked variant="fill" />
<span className="error-description">{t('errorMessages.softErrorInfra')}</span>
</div>
))}
{infra && infra.state === 'ERROR' && (
<div className="scenario-details-infra-error">
<Blocked variant="fill" />
<span className="error-description">{t('errorMessages.hardErrorInfra')}</span>
</div>
)}
</div>
);
};
export default ScenarioDescription;