Skip to content

Commit 2ed39a8

Browse files
committed
front: rework layer activation
1 parent b0dfe9f commit 2ed39a8

File tree

9 files changed

+59
-73
lines changed

9 files changed

+59
-73
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",
@@ -19,6 +18,7 @@
1918
"signals": "Signals",
2019
"signalingtype": "Signalling block type",
2120
"signalisation": "Signaling",
21+
"signals": "Light signals",
2222
"showIGNBDORTHO": "BD Ortho photo ©IGN",
2323
"showIGNSCAN25": "SCAN PLAN/25/100 ©IGN",
2424
"showIGNCadastre": "Cadastre ©IGN",

front/public/locales/en/translation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@
167167
"frozen-layer": "needed for the active tool",
168168
"layer-selected-items_one": "One item selected",
169169
"layer-selected-items_other": "{{count}} items selected",
170-
"selection-warning_one": "An element will be deselected during confirmation.",
171-
"selection-warning_other": "{{count}} elements will be deselected during confirmation.",
170+
"selection-warning_one": "An element has been deselected.",
171+
"selection-warning_other": "{{count}} elements have been deselected.",
172172
"no-speed-limit-tag": "No composition code"
173173
},
174174
"linear-metadata": {

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",
@@ -19,6 +18,7 @@
1918
"signals": "Signals",
2019
"signalingtype": "Type de block",
2120
"signalisation": "Signalisation",
21+
"signals": "Signaux lumineux",
2222
"showIGNBDORTHO": "BD Ortho photo ©IGN",
2323
"showIGNSCAN25": "SCAN PLAN/25/100 ©IGN",
2424
"showIGNCadastre": "Cadastre ©IGN",

front/public/locales/fr/translation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@
167167
"frozen-layer": "nécessaire pour l'outil actif",
168168
"layer-selected-items_one": "Un élément sélectionné",
169169
"layer-selected-items_other": "{{count}} éléments sélectionnés",
170-
"selection-warning_one": "Un élément sera désélectionné lors de la confirmation.",
171-
"selection-warning_other": "{{count}} éléments seront désélectionnés lors de la confirmation.",
170+
"selection-warning_one": "Un élément a été désélectionné.",
171+
"selection-warning_other": "{{count}} éléments ont été désélectionnés.",
172172
"no-speed-limit-tag": "Aucun code de composition"
173173
},
174174
"linear-metadata": {

front/src/applications/editor/Editor.tsx

+7-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';
@@ -176,6 +175,11 @@ const Editor: FC = () => {
176175
useEffect(() => {
177176
if (toolAndState.tool.onMount) toolAndState.tool.onMount(extendedContext);
178177

178+
const layersList = toolAndState.tool.requiredLayers
179+
? new Set([...editorState.editorLayers, ...toolAndState.tool.requiredLayers])
180+
: editorState.editorLayers;
181+
dispatch(selectLayers(layersList));
182+
179183
return () => {
180184
if (toolAndState.tool.onUnmount) toolAndState.tool.onUnmount(extendedContext);
181185
};
@@ -191,7 +195,7 @@ const Editor: FC = () => {
191195
<div className="tool-box bg-primary">
192196
{Object.values(TOOL_TYPES).map((toolType: TOOL_TYPES) => {
193197
const tool = TOOLS[toolType];
194-
const { id, icon: IconComponent, labelTranslationKey, isDisabled } = tool;
198+
const { id, icon: IconComponent, labelTranslationKey } = tool;
195199
const label = t(labelTranslationKey);
196200

197201
return (
@@ -206,10 +210,6 @@ const Editor: FC = () => {
206210
onClick={() => {
207211
switchTool({ toolType, toolState: {} });
208212
}}
209-
disabled={
210-
// TODO: clarify the type of extendedContext
211-
isDisabled && isDisabled(extendedContext as ReadOnlyEditorContextType<any>)
212-
}
213213
>
214214
<span className="sr-only">{label}</span>
215215
<IconComponent />

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

+29-43
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import signalsIcon from 'assets/pictures/layersicons/layer_signal.svg';
1212
import pslsIcon from 'assets/pictures/layersicons/layer_tivs.svg';
1313

1414
import SwitchSNCF from 'common/BootstrapSNCF/SwitchSNCF/SwitchSNCF';
15-
import { useModal, Modal } from 'common/BootstrapSNCF/ModalSNCF';
15+
import { Modal } from 'common/BootstrapSNCF/ModalSNCF';
1616
import MapSettingsBackgroundSwitches from 'common/Map/Settings/MapSettingsBackgroundSwitches';
1717
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';
2525

2626
export const LAYERS: Array<{ layers: LayerType[]; icon: string | JSX.Element }> = [
2727
{ layers: ['track_sections'], icon: trackSectionsIcon },
@@ -40,17 +40,16 @@ 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();
53-
const { closeModal } = useModal();
5453
const { layersSettings } = useSelector(getMap);
5554
const [selectedLayers, setSelectedLayers] = useState<Set<LayerType>>(initialLayers);
5655
const [speedLimitTag, setSpeedLimitTag] = useState<string | undefined>(
@@ -123,24 +122,31 @@ const LayersModal: FC<LayersModalProps> = ({
123122
const layerKey = layers.join('-');
124123
const count = sum(layers.map((id) => selectionCounts[id] || 0));
125124
const disabled = frozenLayers && layers.some((id) => frozenLayers.has(id));
125+
const checked = layers.every((id) => selectedLayers.has(id));
126126
return (
127127
<div className="col-lg-6" key={`${layerKey}-${count}-${disabled}`}>
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);
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+
}}
141147
name={`editor-layer-${layerKey}`}
142148
id={`editor-layer-${layerKey}`}
143-
checked={layers.every((id) => selectedLayers.has(id))}
149+
checked={checked}
144150
disabled={disabled}
145151
/>
146152
{isString(icon) ? (
@@ -150,7 +156,7 @@ const LayersModal: FC<LayersModalProps> = ({
150156
)}
151157
<div className="d-flex flex-column">
152158
<div>{t(`Editor.layers.${layerKey}`)}</div>
153-
{!!count && (
159+
{!!count && checked && (
154160
<div className="small text-muted font-italic">
155161
{t('Editor.layers-modal.layer-selected-items', {
156162
count,
@@ -198,26 +204,6 @@ const LayersModal: FC<LayersModalProps> = ({
198204
{t('Editor.layers-modal.selection-warning', { count: unselectCount })}
199205
</div>
200206
)}
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>
221207
</div>
222208
</Modal>
223209
);

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)({

front/src/applications/editor/tools/rangeEdition/catenary/CatenaryEditionLayers.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import GeoJSONs, { SourcesDefinitionsIndex } from 'common/Map/Layers/GeoJSONs';
1313
import { getEntities, getEntity } from 'applications/editor/data/api';
1414
import { mapValues } from 'lodash';
1515
import { Layer, Popup, Source } from 'react-map-gl/maplibre';
16-
import { getTrackRangeFeatures, isOnModeMove } from '../utils';
17-
import { RangeEditionState, TrackState } from '../types';
18-
import { ExtendedEditorContextType } from '../../editorContextTypes';
19-
import EntitySumUp from '../../../components/EntitySumUp';
20-
import { LayerType } from '../../types';
16+
import EntitySumUp from 'applications/editor/components/EntitySumUp';
17+
import { getTrackRangeFeatures, isOnModeMove } from 'applications/editor/tools/rangeEdition/utils';
18+
import { RangeEditionState, TrackState } from 'applications/editor/tools/rangeEdition/types';
19+
import { ExtendedEditorContextType } from 'applications/editor/tools/editorContextTypes';
2120

2221
export const CatenaryEditionLayers: FC = () => {
2322
const dispatch = useDispatch();
2423
const { t } = useTranslation();
2524
const {
25+
editorState: { editorLayers },
2626
renderingFingerprint,
2727
state: { entity, trackSectionsCache, hoveredItem, interactionState, mousePosition },
2828
setState,
@@ -76,8 +76,6 @@ export const CatenaryEditionLayers: FC = () => {
7676
return SourcesDefinitionsIndex.catenaries(context, 'rangeEditors/catenaries/');
7777
}, [mapStyle, showIGNBDORTHO, layersSettings, issuesSettings]);
7878

79-
const layers = useMemo(() => new Set(['track_sections']) as Set<LayerType>, []);
80-
8179
// Here is where we handle loading the TrackSections attached to the speed section:
8280
useEffect(() => {
8381
const trackIDs = entity.properties?.track_ranges?.map((range) => range.track) || [];
@@ -185,7 +183,7 @@ export const CatenaryEditionLayers: FC = () => {
185183
<>
186184
<GeoJSONs
187185
colors={colors[mapStyle]}
188-
layers={layers}
186+
layers={editorLayers}
189187
selection={selection}
190188
fingerprint={renderingFingerprint}
191189
layersSettings={layersSettings}

front/src/applications/editor/tools/rangeEdition/speedSection/SpeedSectionEditionLayers.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ import {
1818
getTrackRangeFeatures,
1919
isOnModeMove,
2020
speedSectionIsPsl,
21-
} from '../utils';
22-
import { PslSignFeature, RangeEditionState, TrackState } from '../types';
23-
import { ExtendedEditorContextType } from '../../editorContextTypes';
24-
import EntitySumUp from '../../../components/EntitySumUp';
25-
import { LayerType } from '../../types';
21+
} from 'applications/editor/tools/rangeEdition/utils';
22+
import {
23+
PslSignFeature,
24+
RangeEditionState,
25+
TrackState,
26+
} from 'applications/editor/tools/rangeEdition/types';
27+
import { ExtendedEditorContextType } from 'applications/editor/tools/editorContextTypes';
28+
import EntitySumUp from 'applications/editor/components/EntitySumUp';
2629

2730
export const SpeedSectionEditionLayers: FC = () => {
2831
const dispatch = useDispatch();
2932
const { t } = useTranslation();
3033
const {
34+
editorState: { editorLayers },
3135
renderingFingerprint,
3236
state: { entity, trackSectionsCache, hoveredItem, interactionState, mousePosition },
3337
setState,
@@ -97,8 +101,6 @@ export const SpeedSectionEditionLayers: FC = () => {
97101
return [...pslLayers, ...pslSignLayers];
98102
}, [isPSL, mapStyle, showIGNBDORTHO, layersSettings, issuesSettings]);
99103

100-
const layers = useMemo(() => new Set(['track_sections']) as Set<LayerType>, []);
101-
102104
// Here is where we handle loading the TrackSections attached to the speed section:
103105
useEffect(() => {
104106
const trackIDs = entity.properties?.track_ranges?.map((range) => range.track) || [];
@@ -217,7 +219,7 @@ export const SpeedSectionEditionLayers: FC = () => {
217219
<>
218220
<GeoJSONs
219221
colors={colors[mapStyle]}
220-
layers={layers}
222+
layers={editorLayers}
221223
selection={selection}
222224
fingerprint={renderingFingerprint}
223225
layersSettings={layersSettings}

0 commit comments

Comments
 (0)