@@ -12,16 +12,16 @@ import signalsIcon from 'assets/pictures/layersicons/layer_signal.svg';
12
12
import pslsIcon from 'assets/pictures/layersicons/layer_tivs.svg' ;
13
13
14
14
import SwitchSNCF from 'common/BootstrapSNCF/SwitchSNCF/SwitchSNCF' ;
15
- import { useModal , Modal } from 'common/BootstrapSNCF/ModalSNCF' ;
15
+ import { Modal } from 'common/BootstrapSNCF/ModalSNCF' ;
16
16
import MapSettingsBackgroundSwitches from 'common/Map/Settings/MapSettingsBackgroundSwitches' ;
17
17
import { GiElectric } from 'react-icons/gi' ;
18
- import { LayerType , EDITOAST_TO_LAYER_DICT , EditoastType } from '.. /tools/types' ;
19
- import { selectLayers } from '../../../ reducers/editor' ;
20
- import { EditorEntity } from '../../../ types' ;
21
- import { getMap } from '../../../ reducers/map/selectors' ;
22
- import { getInfraID } from '../../../ reducers/osrdconf/selectors' ;
23
- import { osrdEditoastApi } from '../../../ common/api/osrdEditoastApi' ;
24
- import { updateLayersSettings } from '../../../ reducers/map' ;
18
+ import { LayerType , EDITOAST_TO_LAYER_DICT , EditoastType } from 'applications/editor /tools/types' ;
19
+ import { selectLayers } from 'reducers/editor' ;
20
+ import { EditorEntity } from 'types' ;
21
+ import { getMap } from 'reducers/map/selectors' ;
22
+ import { getInfraID } from 'reducers/osrdconf/selectors' ;
23
+ import { osrdEditoastApi } from 'common/api/osrdEditoastApi' ;
24
+ import { updateLayersSettings } from 'reducers/map' ;
25
25
26
26
export const LAYERS : Array < { layers : LayerType [ ] ; icon : string | JSX . Element } > = [
27
27
{ layers : [ 'track_sections' ] , icon : trackSectionsIcon } ,
@@ -40,17 +40,16 @@ interface LayersModalProps {
40
40
initialLayers : Set < LayerType > ;
41
41
selection ?: EditorEntity [ ] ;
42
42
frozenLayers ?: Set < LayerType > ;
43
- onSubmit : ( args : { newLayers : Set < LayerType > } ) => void ;
43
+ onChange : ( args : { newLayers : Set < LayerType > } ) => void ;
44
44
}
45
45
const LayersModal : FC < LayersModalProps > = ( {
46
46
initialLayers,
47
47
selection,
48
48
frozenLayers,
49
- onSubmit ,
49
+ onChange ,
50
50
} ) => {
51
51
const dispatch = useDispatch ( ) ;
52
52
const { t } = useTranslation ( ) ;
53
- const { closeModal } = useModal ( ) ;
54
53
const { layersSettings } = useSelector ( getMap ) ;
55
54
const [ selectedLayers , setSelectedLayers ] = useState < Set < LayerType > > ( initialLayers ) ;
56
55
const [ speedLimitTag , setSpeedLimitTag ] = useState < string | undefined > (
@@ -123,24 +122,31 @@ const LayersModal: FC<LayersModalProps> = ({
123
122
const layerKey = layers . join ( '-' ) ;
124
123
const count = sum ( layers . map ( ( id ) => selectionCounts [ id ] || 0 ) ) ;
125
124
const disabled = frozenLayers && layers . some ( ( id ) => frozenLayers . has ( id ) ) ;
125
+ const checked = layers . every ( ( id ) => selectedLayers . has ( id ) ) ;
126
126
return (
127
127
< div className = "col-lg-6" key = { `${ layerKey } -${ count } -${ disabled } ` } >
128
128
< div className = "d-flex align-items-center mt-2" >
129
129
< SwitchSNCF
130
130
type = "switch"
131
- onChange = { ( ) =>
132
- setSelectedLayers ( ( set ) => {
133
- const newSet = new Set ( set ) ;
134
- layers . forEach ( ( id ) => {
135
- if ( newSet . has ( id ) ) newSet . delete ( id ) ;
136
- else newSet . add ( id ) ;
137
- } ) ;
138
- return newSet ;
139
- } )
140
- }
131
+ onChange = { ( ) => {
132
+ const newSelectedLayersList = layers . reduce ( ( result , layer ) => {
133
+ if ( result . has ( layer ) ) result . delete ( layer ) ;
134
+ else result . add ( layer ) ;
135
+ return result ;
136
+ } , new Set ( selectedLayers ) ) ;
137
+ setSelectedLayers ( newSelectedLayersList ) ;
138
+ dispatch ( selectLayers ( newSelectedLayersList ) ) ;
139
+ dispatch (
140
+ updateLayersSettings ( {
141
+ ...layersSettings ,
142
+ speedlimittag : speedLimitTag as string ,
143
+ } )
144
+ ) ;
145
+ onChange ( { newLayers : newSelectedLayersList } ) ;
146
+ } }
141
147
name = { `editor-layer-${ layerKey } ` }
142
148
id = { `editor-layer-${ layerKey } ` }
143
- checked = { layers . every ( ( id ) => selectedLayers . has ( id ) ) }
149
+ checked = { checked }
144
150
disabled = { disabled }
145
151
/>
146
152
{ isString ( icon ) ? (
@@ -150,7 +156,7 @@ const LayersModal: FC<LayersModalProps> = ({
150
156
) }
151
157
< div className = "d-flex flex-column" >
152
158
< div > { t ( `Editor.layers.${ layerKey } ` ) } </ div >
153
- { ! ! count && (
159
+ { ! ! count && checked && (
154
160
< div className = "small text-muted font-italic" >
155
161
{ t ( 'Editor.layers-modal.layer-selected-items' , {
156
162
count,
@@ -198,26 +204,6 @@ const LayersModal: FC<LayersModalProps> = ({
198
204
{ t ( 'Editor.layers-modal.selection-warning' , { count : unselectCount } ) }
199
205
</ div >
200
206
) }
201
- < button type = "button" className = "btn btn-danger mr-2" onClick = { closeModal } >
202
- { t ( 'common.cancel' ) }
203
- </ button >
204
- < button
205
- type = "button"
206
- className = "btn btn-primary"
207
- onClick = { ( ) => {
208
- dispatch ( selectLayers ( selectedLayers ) ) ;
209
- dispatch (
210
- updateLayersSettings ( {
211
- ...layersSettings ,
212
- speedlimittag : speedLimitTag as string ,
213
- } )
214
- ) ;
215
- onSubmit ( { newLayers : selectedLayers } ) ;
216
- closeModal ( ) ;
217
- } }
218
- >
219
- { t ( 'common.confirm' ) }
220
- </ button >
221
207
</ div >
222
208
</ Modal >
223
209
) ;
0 commit comments