Skip to content

Commit 313c555

Browse files
committed
front: rework layer activation
1 parent c2b9acd commit 313c555

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

front/public/locales/en/map-settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"detectors": "Detectors",
77
"jdz": "Zone junction",
88
"layers": "Data layers",
9-
"lights": "Light signals",
109
"mapSettings": "Map settings",
1110
"mapstyles": {
1211
"blueprint": "Blueprint",
@@ -18,6 +17,7 @@
1817
"routes": "Train blocks",
1918
"signalingtype": "Signalling block type",
2019
"signalisation": "Signaling",
20+
"signals": "Light signals",
2121
"showIGNBDORTHO": "BD Ortho photo ©IGN",
2222
"showIGNSCAN25": "SCAN PLAN/25/100 ©IGN",
2323
"showIGNCadastre": "Cadastre ©IGN",

front/public/locales/fr/map-settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"detectors": "Détecteurs",
77
"jdz": "Joints de zone",
88
"layers": "Couches de données",
9-
"lights": "Signaux lumineux",
109
"mapSettings": "Paramètres cartographie",
1110
"mapstyles": {
1211
"blueprint": "Blueprint",
@@ -18,6 +17,7 @@
1817
"routes": "Cantons",
1918
"signalingtype": "Type de block",
2019
"signalisation": "Signalisation",
20+
"signals": "Signaux lumineux",
2121
"showIGNBDORTHO": "BD Ortho photo ©IGN",
2222
"showIGNSCAN25": "SCAN PLAN/25/100 ©IGN",
2323
"showIGNCadastre": "Cadastre ©IGN",

front/src/applications/editor/Editor.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'common/Map/Map.scss';
1111

1212
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
1313
import { LoaderState } from 'common/Loader';
14-
import { loadDataModel, updateTotalsIssue } from 'reducers/editor';
14+
import { loadDataModel, selectLayers, updateTotalsIssue } from 'reducers/editor';
1515
import { updateInfraID } from 'reducers/osrdconf';
1616
import { updateViewport, Viewport } from 'reducers/map';
1717
import { getInfraID } from 'reducers/osrdconf/selectors';
@@ -27,7 +27,6 @@ import {
2727
EditorContextType,
2828
ExtendedEditorContextType,
2929
FullTool,
30-
ReadOnlyEditorContextType,
3130
Reducer,
3231
} from './tools/editorContextTypes';
3332
import { switchProps } from './tools/switchProps';
@@ -182,6 +181,13 @@ const Editor: FC = () => {
182181
// eslint-disable-next-line react-hooks/exhaustive-deps
183182
}, [toolAndState.tool]);
184183

184+
useEffect(() => {
185+
const layersList = toolAndState.tool.requiredLayers
186+
? new Set([...editorState.editorLayers, ...toolAndState.tool.requiredLayers])
187+
: editorState.editorLayers;
188+
dispatch(selectLayers(layersList));
189+
}, [toolAndState.tool]);
190+
185191
return (
186192
<EditorContext.Provider value={extendedContext as EditorContextType<unknown>}>
187193
<main
@@ -191,7 +197,7 @@ const Editor: FC = () => {
191197
<div className="tool-box bg-primary">
192198
{Object.values(TOOL_TYPES).map((toolType: TOOL_TYPES) => {
193199
const tool = TOOLS[toolType];
194-
const { id, icon: IconComponent, labelTranslationKey, isDisabled } = tool;
200+
const { id, icon: IconComponent, labelTranslationKey } = tool;
195201
const label = t(labelTranslationKey);
196202

197203
return (
@@ -206,10 +212,6 @@ const Editor: FC = () => {
206212
onClick={() => {
207213
switchTool({ toolType, toolState: {} });
208214
}}
209-
disabled={
210-
// TODO: clarify the type of extendedContext
211-
isDisabled && isDisabled(extendedContext as ReadOnlyEditorContextType<any>)
212-
}
213215
>
214216
<span className="sr-only">{label}</span>
215217
<IconComponent />

front/src/applications/editor/components/LayersModal.tsx

+16-15
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ interface LayersModalProps {
4040
initialLayers: Set<LayerType>;
4141
selection?: EditorEntity[];
4242
frozenLayers?: Set<LayerType>;
43-
onSubmit: (args: { newLayers: Set<LayerType> }) => void;
43+
onChange: (args: { newLayers: Set<LayerType> }) => void;
4444
}
4545
const LayersModal: FC<LayersModalProps> = ({
4646
initialLayers,
4747
selection,
4848
frozenLayers,
49-
onSubmit,
49+
onChange,
5050
}) => {
5151
const dispatch = useDispatch();
5252
const { t } = useTranslation();
@@ -128,16 +128,25 @@ const LayersModal: FC<LayersModalProps> = ({
128128
<div className="d-flex align-items-center mt-2">
129129
<SwitchSNCF
130130
type="switch"
131-
onChange={() =>
132-
setSelectedLayers((set) => {
133-
const newSet = new Set(set);
131+
onChange={() => {
132+
const newSelectedLayersList = () => {
133+
const newSet = new Set(selectedLayers);
134134
layers.forEach((id) => {
135135
if (newSet.has(id)) newSet.delete(id);
136136
else newSet.add(id);
137137
});
138138
return newSet;
139-
})
140-
}
139+
};
140+
setSelectedLayers(newSelectedLayersList());
141+
dispatch(selectLayers(newSelectedLayersList()));
142+
dispatch(
143+
updateLayersSettings({
144+
...layersSettings,
145+
speedlimittag: speedLimitTag as string,
146+
})
147+
);
148+
onChange({ newLayers: newSelectedLayersList() });
149+
}}
141150
name={`editor-layer-${layerKey}`}
142151
id={`editor-layer-${layerKey}`}
143152
checked={layers.every((id) => selectedLayers.has(id))}
@@ -205,14 +214,6 @@ const LayersModal: FC<LayersModalProps> = ({
205214
type="button"
206215
className="btn btn-primary"
207216
onClick={() => {
208-
dispatch(selectLayers(selectedLayers));
209-
dispatch(
210-
updateLayersSettings({
211-
...layersSettings,
212-
speedlimittag: speedLimitTag as string,
213-
})
214-
);
215-
onSubmit({ newLayers: selectedLayers });
216217
closeModal();
217218
}}
218219
>

front/src/applications/editor/nav.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const NavButtons: NavButton[][] = [
127127
? (toolState as unknown as SelectionState).selection
128128
: undefined
129129
}
130-
onSubmit={({ newLayers }) => {
130+
onChange={({ newLayers }) => {
131131
if (activeTool.id === 'select-items') {
132132
const currentState = toolState as unknown as SelectionState;
133133
(setToolState as unknown as (newState: SelectionState) => void)({

0 commit comments

Comments
 (0)