From b1a57a4b072c21c3631aa2930d9a063b8612a31c Mon Sep 17 00:00:00 2001 From: theocrsb Date: Fri, 20 Dec 2024 12:09:47 +0100 Subject: [PATCH 1/3] front: rename renderpopup to addpathsteppopup Signed-off-by: theocrsb --- .../{RenderPopup.tsx => AddPathStepPopup.tsx} | 6 +++--- .../trainschedule/components/ManageTrainSchedule/Map.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/{RenderPopup.tsx => AddPathStepPopup.tsx} (97%) diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx similarity index 97% rename from front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx rename to front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx index a7a6047f19c..9e0dd09f53a 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx @@ -25,11 +25,11 @@ type FeatureInfoClickType = { feature?: any; }; -type RenderPopupProps = { +type AddPathStepPopupProps = { pathProperties?: ManageTrainSchedulePathProperties; }; -function RenderPopup({ pathProperties }: RenderPopupProps) { +function AddPathStepPopup({ pathProperties }: AddPathStepPopupProps) { const { getFeatureInfoClick, getInfraID, getOrigin, getDestination } = useOsrdConfSelectors(); const { launchPathfinding } = useManageTrainScheduleContext(); const osrdConfActions = useOsrdConfActions(); @@ -167,4 +167,4 @@ function RenderPopup({ pathProperties }: RenderPopupProps) { ); } -export default React.memo(RenderPopup); +export default React.memo(AddPathStepPopup); diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx index d027a6b7a46..58a9d853120 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx @@ -44,7 +44,7 @@ import { computeBBoxViewport } from 'common/Map/WarpedMap/core/helpers'; import { useInfraID, useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext'; import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder'; import VirtualLayers from 'modules/simulationResult/components/SimulationResultsMap/VirtualLayers'; -import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup'; +import AddPathStepPopup from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup'; import { updateViewport } from 'reducers/map'; import type { Viewport } from 'reducers/map'; import { getMap, getTerrain3DExaggeration } from 'reducers/map/selectors'; @@ -391,7 +391,7 @@ const Map = ({ layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]} infraID={infraID} /> - {!showStdcmAssets && } + {!showStdcmAssets && } )} Date: Fri, 20 Dec 2024 13:49:46 +0100 Subject: [PATCH 2/3] front: use featureinfoclick from state instead of redux store Signed-off-by: theocrsb --- .../AddPathStepPopup.tsx | 26 +++++----- .../ManageTrainScheduleMap/setPointIti.ts | 8 +-- .../components/ManageTrainSchedule/Map.tsx | 50 +++++++++---------- .../components/ManageTrainSchedule/types.ts | 4 +- front/src/reducers/index.ts | 1 - .../__tests__/commonConfBuilder.ts | 31 +----------- .../osrdConfCommon/__tests__/utils.ts | 10 ---- .../reducers/osrdconf/osrdConfCommon/index.ts | 7 --- .../osrdconf/osrdConfCommon/selectors.ts | 1 - front/src/reducers/osrdconf/types.ts | 3 +- 10 files changed, 47 insertions(+), 94 deletions(-) diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx index 9e0dd09f53a..b1413f7166a 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx @@ -15,26 +15,26 @@ import { calculateDistanceAlongTrack } from 'applications/editor/tools/utils'; import { useManageTrainScheduleContext } from 'applications/operationalStudies/hooks/useManageTrainScheduleContext'; import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types'; import { osrdEditoastApi } from 'common/api/osrdEditoastApi'; -import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext'; +import { useOsrdConfSelectors } from 'common/osrdContext'; import { setPointIti } from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti'; import type { PathStep } from 'reducers/osrdconf/types'; -type FeatureInfoClickType = { - displayPopup: boolean; - coordinates?: number[]; - feature?: any; -}; +import type { FeatureInfoClick } from '../types'; type AddPathStepPopupProps = { pathProperties?: ManageTrainSchedulePathProperties; + featureInfoClick: FeatureInfoClick; + setFeatureInfoClick: React.Dispatch>; }; -function AddPathStepPopup({ pathProperties }: AddPathStepPopupProps) { - const { getFeatureInfoClick, getInfraID, getOrigin, getDestination } = useOsrdConfSelectors(); +function AddPathStepPopup({ + pathProperties, + featureInfoClick, + setFeatureInfoClick, +}: AddPathStepPopupProps) { + const { getInfraID, getOrigin, getDestination } = useOsrdConfSelectors(); const { launchPathfinding } = useManageTrainScheduleContext(); - const osrdConfActions = useOsrdConfActions(); const { t } = useTranslation(['operationalStudies/manageTrainSchedule']); - const featureInfoClick: FeatureInfoClickType = useSelector(getFeatureInfoClick); const infraId = useSelector(getInfraID); const origin = useSelector(getOrigin); const destination = useSelector(getDestination); @@ -127,7 +127,7 @@ function AddPathStepPopup({ pathProperties }: AddPathStepPopupProps) { className="btn btn-sm btn-success" type="button" onClick={() => - setPointIti('origin', pathStepProperties, osrdConfActions, launchPathfinding) + setPointIti('origin', pathStepProperties, launchPathfinding, setFeatureInfoClick) } > @@ -141,8 +141,8 @@ function AddPathStepPopup({ pathProperties }: AddPathStepPopupProps) { setPointIti( 'via', pathStepProperties, - osrdConfActions, launchPathfinding, + setFeatureInfoClick, pathProperties ) } @@ -156,7 +156,7 @@ function AddPathStepPopup({ pathProperties }: AddPathStepPopupProps) { className="btn btn-sm btn-warning" type="button" onClick={() => - setPointIti('destination', pathStepProperties, osrdConfActions, launchPathfinding) + setPointIti('destination', pathStepProperties, launchPathfinding, setFeatureInfoClick) } > diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts index 02a75a13cb9..ccf27a24e8a 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts @@ -1,19 +1,19 @@ /* eslint-disable import/prefer-default-export */ import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types'; import { insertViaFromMap } from 'reducers/osrdconf/helpers'; -import type { ConfSliceActions } from 'reducers/osrdconf/osrdConfCommon'; import type { PathStep } from 'reducers/osrdconf/types'; import { store } from 'store'; import { addElementAtIndex, replaceElementAtIndex } from 'utils/array'; +import type { FeatureInfoClick } from '../types'; + export function setPointIti( pointType: 'origin' | 'destination' | 'via', pathStep: PathStep, - actions: ConfSliceActions, launchPathfinding: (newPathSteps: (PathStep | null)[]) => void, + setFeatureInfoClick: React.Dispatch>, pathProperties?: ManageTrainSchedulePathProperties ) { - const { updateFeatureInfoClick } = actions; const { pathSteps } = store.getState().operationalStudiesConf; let newPathSteps: (PathStep | null)[]; @@ -32,6 +32,6 @@ export function setPointIti( newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep); } } - store.dispatch(updateFeatureInfoClick({ displayPopup: false })); + setFeatureInfoClick({ displayPopup: false }); launchPathfinding(newPathSteps); } diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx index 58a9d853120..f0069831bf8 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx @@ -41,7 +41,7 @@ import TracksGeographic from 'common/Map/Layers/TracksGeographic'; import TracksOSM from 'common/Map/Layers/TracksOSM'; import { removeSearchItemMarkersOnMap } from 'common/Map/utils'; import { computeBBoxViewport } from 'common/Map/WarpedMap/core/helpers'; -import { useInfraID, useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext'; +import { useInfraID } from 'common/osrdContext'; import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder'; import VirtualLayers from 'modules/simulationResult/components/SimulationResultsMap/VirtualLayers'; import AddPathStepPopup from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup'; @@ -55,6 +55,7 @@ import ItineraryLayer from './ManageTrainScheduleMap/ItineraryLayer'; import ItineraryMarkers, { type MarkerInformation, } from './ManageTrainScheduleMap/ItineraryMarkers'; +import type { FeatureInfoClick } from './types'; type MapProps = { pathProperties?: ManageTrainSchedulePathProperties; @@ -118,19 +119,16 @@ const Map = ({ bottom: 20, }; - const { getFeatureInfoClick } = useOsrdConfSelectors(); - const featureInfoClick = useSelector(getFeatureInfoClick); - - const { updateFeatureInfoClick } = useOsrdConfActions(); + const [featureInfoClick, setFeatureInfoClick] = useState({ + displayPopup: false, + }); const closeFeatureInfoClickPopup = useCallback(() => { if (featureInfoClick.displayPopup) { - dispatch( - updateFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }) - ); + setFeatureInfoClick({ + displayPopup: false, + feature: undefined, + }); } }, [featureInfoClick]); @@ -151,20 +149,16 @@ const Map = ({ result.feature.properties.id && result.feature.geometry.type === 'LineString' ) { - dispatch( - updateFeatureInfoClick({ - displayPopup: true, - feature: result.feature, - coordinates: result.nearest, - }) - ); + setFeatureInfoClick({ + displayPopup: true, + feature: result.feature, + coordinates: result.nearest, + }); } else { - dispatch( - updateFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }) - ); + setFeatureInfoClick({ + displayPopup: false, + feature: undefined, + }); } removeSearchItemMarkersOnMap(dispatch); }; @@ -391,7 +385,13 @@ const Map = ({ layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]} infraID={infraID} /> - {!showStdcmAssets && } + {!showStdcmAssets && ( + + )} )} ( key: slice.name, storage, transforms: [stdcmPathStepsDateTransform, operationalStudiesDateTransform], - blacklist: ['featureInfoClick'], }); export const persistConfig = { diff --git a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/commonConfBuilder.ts b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/commonConfBuilder.ts index 28ab8290c7c..353670acaf5 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/commonConfBuilder.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/commonConfBuilder.ts @@ -1,37 +1,8 @@ -import type { Feature } from 'geojson'; - import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types'; -import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types'; +import type { PathStep } from 'reducers/osrdconf/types'; export default function commonConfBuilder() { return { - buildFeatureInfoClick: ( - featureInfoClickFields?: Partial - ): OsrdConfState['featureInfoClick'] => ({ - displayPopup: true, - feature: { - type: 'Feature', - _geometry: { - type: 'LineString', - coordinates: [12, 45], - }, - properties: { - title: 'test', - toto: 'toto', - }, - id: 'test', - _vectorTileFeature: { - id: 10, - type: 1, - extent: 15, - properties: { - name: 'test', - }, - }, - } as unknown as Feature, - ...featureInfoClickFields, - }), - buildPathSteps: (): PathStep[] => [ { uic: 474007, diff --git a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts index e8e4b5b5767..afcac946f94 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts @@ -1,4 +1,3 @@ -import { omit } from 'lodash'; import { describe, beforeEach, it, expect } from 'vitest'; import { StdcmStopTypes } from 'applications/stdcm/types'; @@ -207,15 +206,6 @@ const testCommonConfReducers = (slice: OperationalStudiesConfSlice | StdcmConfSl expect(state.pathSteps[1]?.stopType).toEqual('serviceStop'); }); - it('should handle updateFeatureInfoClick', () => { - const newFeatureClick = testDataBuilder.buildFeatureInfoClick(); - defaultStore.dispatch(slice.actions.updateFeatureInfoClick(newFeatureClick)); - const state = defaultStore.getState()[slice.name]; - const feature = omit(newFeatureClick.feature, ['_vectorTileFeature']); - const expected = { ...newFeatureClick, feature }; - expect(state.featureInfoClick).toStrictEqual(expected); - }); - it('should handle updateGridMarginBefore', () => { const newGridMarginBefore = 5; defaultStore.dispatch(slice.actions.updateGridMarginBefore(newGridMarginBefore)); diff --git a/front/src/reducers/osrdconf/osrdConfCommon/index.ts b/front/src/reducers/osrdconf/osrdConfCommon/index.ts index ff01e62d064..9fb4b27a188 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/index.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/index.ts @@ -1,6 +1,5 @@ import type { CaseReducer, PayloadAction } from '@reduxjs/toolkit'; import type { Draft } from 'immer'; -import { omit } from 'lodash'; import { type StdcmStopTypes } from 'applications/stdcm/types'; import { type InfraStateReducers, buildInfraStateReducers, infraState } from 'reducers/infra'; @@ -33,7 +32,6 @@ export const defaultCommonConf: OsrdConfState = { gridMarginBefore: undefined, gridMarginAfter: undefined, ...infraState, - featureInfoClick: { displayPopup: false }, // Corresponds to origin and destination not defined pathSteps: [null, null], rollingStockComfort: 'STANDARD' as const, @@ -62,7 +60,6 @@ interface CommonConfReducers extends InfraStateReducers >; ['updateGridMarginBefore']: CaseReducer>; ['updateGridMarginAfter']: CaseReducer>; - ['updateFeatureInfoClick']: CaseReducer>; ['updatePathSteps']: CaseReducer>; ['replaceItinerary']: CaseReducer>; ['deleteItinerary']: CaseReducer; @@ -146,10 +143,6 @@ export function buildCommonConfReducers(): CommonConfRe updateGridMarginAfter(state: Draft, action: PayloadAction) { state.gridMarginAfter = action.payload; }, - updateFeatureInfoClick(state: Draft, action: PayloadAction) { - const feature = omit(action.payload.feature, ['_vectorTileFeature']); - state.featureInfoClick = { ...action.payload, feature }; - }, // update path steps without changing the itinerary (only add vias on the existing pathfinding, // add schedules, margins or power restrictions) updatePathSteps(state: Draft, action: PayloadAction) { diff --git a/front/src/reducers/osrdconf/osrdConfCommon/selectors.ts b/front/src/reducers/osrdconf/osrdConfCommon/selectors.ts index e10df286d1c..028ff6bd59b 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/selectors.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/selectors.ts @@ -47,7 +47,6 @@ const buildCommonConfSelectors = ( getGridMarginBefore: makeOsrdConfSelector('gridMarginBefore'), getGridMarginAfter: makeOsrdConfSelector('gridMarginAfter'), getPowerRestriction: makeOsrdConfSelector('powerRestriction'), - getFeatureInfoClick: makeOsrdConfSelector('featureInfoClick'), getPathSteps, getOrigin: (state: RootState) => { const pathSteps = getPathSteps(state); diff --git a/front/src/reducers/osrdconf/types.ts b/front/src/reducers/osrdconf/types.ts index b65c347f8a8..5179206b930 100644 --- a/front/src/reducers/osrdconf/types.ts +++ b/front/src/reducers/osrdconf/types.ts @@ -1,4 +1,4 @@ -import type { Feature, Position } from 'geojson'; +import type { Position } from 'geojson'; import type { PowerRestriction } from 'applications/operationalStudies/types'; import type { @@ -39,7 +39,6 @@ export interface OsrdConfState extends InfraState { initialSpeed?: number; gridMarginBefore?: number; gridMarginAfter?: number; - featureInfoClick: { displayPopup: boolean; feature?: Feature; coordinates?: number[] }; pathSteps: (PathStep | null)[]; rollingStockComfort: Comfort; startTime: Date; From 455faf6e71c3c54e642bf388034f47560e60f664 Mon Sep 17 00:00:00 2001 From: theocrsb Date: Fri, 20 Dec 2024 14:26:23 +0100 Subject: [PATCH 3/3] front: remove displaypopup property in featureinfoclick type and allow it to be undefined Signed-off-by: theocrsb --- .../AddPathStepPopup.tsx | 30 +++++-------------- .../ManageTrainScheduleMap/setPointIti.ts | 6 ++-- .../components/ManageTrainSchedule/Map.tsx | 25 +++++++--------- .../components/ManageTrainSchedule/types.ts | 2 +- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx index b1413f7166a..3f479d42e5e 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx @@ -24,13 +24,13 @@ import type { FeatureInfoClick } from '../types'; type AddPathStepPopupProps = { pathProperties?: ManageTrainSchedulePathProperties; featureInfoClick: FeatureInfoClick; - setFeatureInfoClick: React.Dispatch>; + resetFeatureInfoClick: () => void; }; function AddPathStepPopup({ pathProperties, featureInfoClick, - setFeatureInfoClick, + resetFeatureInfoClick, }: AddPathStepPopupProps) { const { getInfraID, getOrigin, getDestination } = useOsrdConfSelectors(); const { launchPathfinding } = useManageTrainScheduleContext(); @@ -46,13 +46,7 @@ function AddPathStepPopup({ useEffect(() => { const calculateOffset = async () => { - if ( - !featureInfoClick.feature || - !featureInfoClick.feature.properties || - !featureInfoClick.coordinates - ) - return; - const trackId = featureInfoClick.feature.properties.id; + const trackId = featureInfoClick.feature.properties?.id; const result = await getTrackEntity({ infraId: infraId!, objectType: 'TrackSection', @@ -73,18 +67,10 @@ function AddPathStepPopup({ setTrackOffset(offset); }; - if (featureInfoClick.displayPopup) { - calculateOffset(); - } + calculateOffset(); }, [featureInfoClick]); - if ( - !featureInfoClick.displayPopup || - !featureInfoClick.feature || - !featureInfoClick.feature.properties || - !featureInfoClick.coordinates - ) - return null; + if (!featureInfoClick.feature.properties) return null; const { properties: trackProperties } = featureInfoClick.feature; const coordinates = featureInfoClick.coordinates.slice(0, 2); @@ -127,7 +113,7 @@ function AddPathStepPopup({ className="btn btn-sm btn-success" type="button" onClick={() => - setPointIti('origin', pathStepProperties, launchPathfinding, setFeatureInfoClick) + setPointIti('origin', pathStepProperties, launchPathfinding, resetFeatureInfoClick) } > @@ -142,7 +128,7 @@ function AddPathStepPopup({ 'via', pathStepProperties, launchPathfinding, - setFeatureInfoClick, + resetFeatureInfoClick, pathProperties ) } @@ -156,7 +142,7 @@ function AddPathStepPopup({ className="btn btn-sm btn-warning" type="button" onClick={() => - setPointIti('destination', pathStepProperties, launchPathfinding, setFeatureInfoClick) + setPointIti('destination', pathStepProperties, launchPathfinding, resetFeatureInfoClick) } > diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts index ccf27a24e8a..65c2b31d5e2 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts @@ -5,13 +5,11 @@ import type { PathStep } from 'reducers/osrdconf/types'; import { store } from 'store'; import { addElementAtIndex, replaceElementAtIndex } from 'utils/array'; -import type { FeatureInfoClick } from '../types'; - export function setPointIti( pointType: 'origin' | 'destination' | 'via', pathStep: PathStep, launchPathfinding: (newPathSteps: (PathStep | null)[]) => void, - setFeatureInfoClick: React.Dispatch>, + resetFeatureInfoClick: () => void, pathProperties?: ManageTrainSchedulePathProperties ) { const { pathSteps } = store.getState().operationalStudiesConf; @@ -32,6 +30,6 @@ export function setPointIti( newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep); } } - setFeatureInfoClick({ displayPopup: false }); + resetFeatureInfoClick(); launchPathfinding(newPathSteps); } diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx index f0069831bf8..b7581ad554e 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx @@ -119,16 +119,15 @@ const Map = ({ bottom: 20, }; - const [featureInfoClick, setFeatureInfoClick] = useState({ - displayPopup: false, - }); + const [featureInfoClick, setFeatureInfoClick] = useState(); + + const resetFeatureInfoClick = useCallback(() => { + setFeatureInfoClick(undefined); + }, []); const closeFeatureInfoClickPopup = useCallback(() => { - if (featureInfoClick.displayPopup) { - setFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }); + if (featureInfoClick) { + setFeatureInfoClick(undefined); } }, [featureInfoClick]); @@ -150,15 +149,11 @@ const Map = ({ result.feature.geometry.type === 'LineString' ) { setFeatureInfoClick({ - displayPopup: true, feature: result.feature, coordinates: result.nearest, }); } else { - setFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }); + setFeatureInfoClick(undefined); } removeSearchItemMarkersOnMap(dispatch); }; @@ -385,11 +380,11 @@ const Map = ({ layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]} infraID={infraID} /> - {!showStdcmAssets && ( + {!showStdcmAssets && featureInfoClick && ( )} diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts index ec5232da747..562190e8008 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts @@ -69,4 +69,4 @@ export type ValidConfig = { speedLimitByTag?: string; }; -export type FeatureInfoClick = { displayPopup: boolean; feature?: Feature; coordinates?: number[] }; +export type FeatureInfoClick = { feature: Feature; coordinates: number[] };