@@ -7,14 +7,14 @@ import { type SearchResultItemOperationalPoint } from 'common/api/osrdEditoastAp
7
7
import useSearchOperationalPoint from 'common/Map/Search/useSearchOperationalPoint' ;
8
8
import { useOsrdConfActions } from 'common/osrdContext' ;
9
9
import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf' ;
10
- import type { StdcmPathStep } from 'reducers/osrdconf/types' ;
10
+ import type { UicPathItemLocation } from 'reducers/osrdconf/types' ;
11
11
import { useAppDispatch } from 'store' ;
12
12
import { normalized } from 'utils/strings' ;
13
13
import { createFixedSelectOptions } from 'utils/uiCoreHelpers' ;
14
14
15
15
type StdcmOperationalPointProps = {
16
- point : StdcmPathStep ;
17
- opPointId : string ;
16
+ location ?: UicPathItemLocation ;
17
+ pathStepId : string ;
18
18
disabled ?: boolean ;
19
19
} ;
20
20
@@ -24,12 +24,15 @@ function formatChCode(chCode: string) {
24
24
return chCode === '' ? 'BV' : chCode ;
25
25
}
26
26
27
- const StdcmOperationalPoint = ( { point , opPointId , disabled } : StdcmOperationalPointProps ) => {
27
+ const StdcmOperationalPoint = ( { location , pathStepId , disabled } : StdcmOperationalPointProps ) => {
28
28
const { t } = useTranslation ( 'stdcm' ) ;
29
29
const dispatch = useAppDispatch ( ) ;
30
30
31
31
const { searchTerm, chCodeFilter, sortedSearchResults, setSearchTerm, setChCodeFilter } =
32
- useSearchOperationalPoint ( { initialSearchTerm : point . name , initialChCodeFilter : point . ch } ) ;
32
+ useSearchOperationalPoint ( {
33
+ initialSearchTerm : location ?. name ,
34
+ initialChCodeFilter : location ?. secondary_code || undefined ,
35
+ } ) ;
33
36
34
37
const { updateStdcmPathStep } = useOsrdConfActions ( ) as StdcmConfSliceActions ;
35
38
@@ -71,20 +74,21 @@ const StdcmOperationalPoint = ({ point, opPointId, disabled }: StdcmOperationalP
71
74
} ,
72
75
[ ] as { label : string ; id : string } [ ]
73
76
) ,
74
- [ point , sortedSearchResults ]
77
+ [ location , sortedSearchResults ]
75
78
) ;
76
79
77
80
const dispatchNewPoint = ( p ?: SearchResultItemOperationalPoint ) => {
78
- if ( p && p . ch === point . ch && 'uic' in point && p . uic === point . uic ) return ;
79
- const newPoint = p
81
+ if ( p && p . ch === location ?. secondary_code && 'uic' in location && p . uic === location . uic )
82
+ return ;
83
+ const newLocation = p
80
84
? {
81
85
name : p . name ,
82
- ch : p . ch ,
86
+ secondary_code : p . ch ,
83
87
uic : p . uic ,
84
- coordinates : p . geographic . coordinates ,
88
+ coordinates : p . geographic . coordinates as [ number , number ] ,
85
89
}
86
- : { name : undefined , ch : undefined , uic : - 1 , coordinates : undefined } ;
87
- dispatch ( updateStdcmPathStep ( { id : point . id , updates : newPoint } ) ) ;
90
+ : undefined ;
91
+ dispatch ( updateStdcmPathStep ( { id : pathStepId , updates : { location : newLocation } } ) ) ;
88
92
} ;
89
93
90
94
const updateSelectedPoint = (
@@ -110,8 +114,8 @@ const StdcmOperationalPoint = ({ point, opPointId, disabled }: StdcmOperationalP
110
114
111
115
const onSelectChCodeFilter = ( selectedChCode ?: { id : string } ) => {
112
116
setChCodeFilter ( selectedChCode ?. id ) ;
113
- if ( point && 'uic' in point )
114
- updateSelectedPoint ( sortedSearchResults , point . uic , selectedChCode ?. id ) ;
117
+ if ( location && 'uic' in location )
118
+ updateSelectedPoint ( sortedSearchResults , location . uic , selectedChCode ?. id ) ;
115
119
} ;
116
120
117
121
const onInputChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -122,20 +126,20 @@ const StdcmOperationalPoint = ({ point, opPointId, disabled }: StdcmOperationalP
122
126
} ;
123
127
124
128
useEffect ( ( ) => {
125
- if ( point ) {
126
- setSearchTerm ( point . name || '' ) ;
127
- setChCodeFilter ( point . ch || '' ) ;
129
+ if ( location ) {
130
+ setSearchTerm ( location . name || '' ) ;
131
+ setChCodeFilter ( location . secondary_code || '' ) ;
128
132
} else {
129
133
setSearchTerm ( '' ) ;
130
134
setChCodeFilter ( undefined ) ;
131
135
}
132
- } , [ point ] ) ;
136
+ } , [ location ] ) ;
133
137
134
138
return (
135
139
< div className = "location-line" >
136
140
< div className = "col-9 ci-input" >
137
141
< ComboBox
138
- id = { `${ opPointId } -ci` }
142
+ id = { `${ pathStepId } -ci` }
139
143
label = { t ( 'trainPath.ci' ) }
140
144
value = { searchTerm }
141
145
onChange = { onInputChange }
@@ -150,7 +154,7 @@ const StdcmOperationalPoint = ({ point, opPointId, disabled }: StdcmOperationalP
150
154
< div className = "col-3 p-0" >
151
155
< Select
152
156
label = { t ( 'trainPath.ch' ) }
153
- id = { `${ opPointId } -ch` }
157
+ id = { `${ pathStepId } -ch` }
154
158
value = { chCodeFilter ? { label : formatChCode ( chCodeFilter ) , id : chCodeFilter } : undefined }
155
159
onChange = { ( e ) => onSelectChCodeFilter ( e ) }
156
160
{ ...createFixedSelectOptions ( sortedChOptions ) }
0 commit comments