1
- import { useEffect , useRef , useState } from 'react' ;
1
+ import { useEffect , useMemo , useRef , useState } from 'react' ;
2
2
3
3
import { Blocked , ChevronLeft , Pencil , X } from '@osrd-project/ui-icons' ;
4
4
import { useTranslation } from 'react-i18next' ;
5
5
6
- import type { InfraWithState , ScenarioResponse } from 'common/api/osrdEditoastApi' ;
6
+ import {
7
+ osrdEditoastApi ,
8
+ type InfraWithState ,
9
+ type ScenarioResponse ,
10
+ } from 'common/api/osrdEditoastApi' ;
7
11
import { useModal } from 'common/BootstrapSNCF/ModalSNCF' ;
8
12
import AddAndEditScenarioModal from 'modules/scenario/components/AddOrEditScenarioModal' ;
9
13
import useOutsideClick from 'utils/hooks/useOutsideClick' ;
@@ -30,6 +34,15 @@ const ScenarioDescription = ({
30
34
const collapsedDescriptionRef = useRef < HTMLDivElement | null > ( null ) ;
31
35
const [ isTooLongDescription , setIsTooLongDescription ] = useState < boolean > ( false ) ;
32
36
37
+ const { data : electricalProfileSets } =
38
+ osrdEditoastApi . endpoints . getElectricalProfileSet . useQuery ( ) ;
39
+
40
+ const electricalProfileSet = useMemo (
41
+ ( ) =>
42
+ electricalProfileSets ?. find ( ( profile ) => profile . id === scenario . electrical_profile_set_id ) ,
43
+ [ electricalProfileSets ]
44
+ ) ;
45
+
33
46
const toggleDescription = ( ) => {
34
47
setIsOpenedDescription ( ! isOpenedDescription ) ;
35
48
} ;
@@ -115,7 +128,7 @@ const ScenarioDescription = ({
115
128
</ div >
116
129
< div className = "scenario-details-electrical-profile-set" >
117
130
{ scenario . electrical_profile_set_id
118
- ? scenario . electrical_profile_set_id
131
+ ? electricalProfileSet ?. name || ''
119
132
: t ( 'noElectricalProfileSet' ) }
120
133
</ div >
121
134
0 commit comments