diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx similarity index 78% rename from front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx rename to front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/AddPathStepPopup.tsx index a7a6047f19c..3f479d42e5e 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.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 RenderPopupProps = { +type AddPathStepPopupProps = { pathProperties?: ManageTrainSchedulePathProperties; + featureInfoClick: FeatureInfoClick; + resetFeatureInfoClick: () => void; }; -function RenderPopup({ pathProperties }: RenderPopupProps) { - const { getFeatureInfoClick, getInfraID, getOrigin, getDestination } = useOsrdConfSelectors(); +function AddPathStepPopup({ + pathProperties, + featureInfoClick, + resetFeatureInfoClick, +}: 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); @@ -46,13 +46,7 @@ function RenderPopup({ pathProperties }: RenderPopupProps) { 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 RenderPopup({ pathProperties }: RenderPopupProps) { 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 RenderPopup({ pathProperties }: RenderPopupProps) { className="btn btn-sm btn-success" type="button" onClick={() => - setPointIti('origin', pathStepProperties, osrdConfActions, launchPathfinding) + setPointIti('origin', pathStepProperties, launchPathfinding, resetFeatureInfoClick) } > @@ -141,8 +127,8 @@ function RenderPopup({ pathProperties }: RenderPopupProps) { setPointIti( 'via', pathStepProperties, - osrdConfActions, launchPathfinding, + resetFeatureInfoClick, pathProperties ) } @@ -156,7 +142,7 @@ function RenderPopup({ pathProperties }: RenderPopupProps) { className="btn btn-sm btn-warning" type="button" onClick={() => - setPointIti('destination', pathStepProperties, osrdConfActions, launchPathfinding) + setPointIti('destination', pathStepProperties, launchPathfinding, resetFeatureInfoClick) } > @@ -167,4 +153,4 @@ function RenderPopup({ pathProperties }: RenderPopupProps) { ); } -export default React.memo(RenderPopup); +export default React.memo(AddPathStepPopup); diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts index 02a75a13cb9..65c2b31d5e2 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts @@ -1,7 +1,6 @@ /* 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'; @@ -9,11 +8,10 @@ import { addElementAtIndex, replaceElementAtIndex } from 'utils/array'; export function setPointIti( pointType: 'origin' | 'destination' | 'via', pathStep: PathStep, - actions: ConfSliceActions, launchPathfinding: (newPathSteps: (PathStep | null)[]) => void, + resetFeatureInfoClick: () => void, pathProperties?: ManageTrainSchedulePathProperties ) { - const { updateFeatureInfoClick } = actions; const { pathSteps } = store.getState().operationalStudiesConf; let newPathSteps: (PathStep | null)[]; @@ -32,6 +30,6 @@ export function setPointIti( newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep); } } - store.dispatch(updateFeatureInfoClick({ 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 d027a6b7a46..b7581ad554e 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx @@ -41,10 +41,10 @@ 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 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'; @@ -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,15 @@ const Map = ({ bottom: 20, }; - const { getFeatureInfoClick } = useOsrdConfSelectors(); - const featureInfoClick = useSelector(getFeatureInfoClick); + const [featureInfoClick, setFeatureInfoClick] = useState(); - const { updateFeatureInfoClick } = useOsrdConfActions(); + const resetFeatureInfoClick = useCallback(() => { + setFeatureInfoClick(undefined); + }, []); const closeFeatureInfoClickPopup = useCallback(() => { - if (featureInfoClick.displayPopup) { - dispatch( - updateFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }) - ); + if (featureInfoClick) { + setFeatureInfoClick(undefined); } }, [featureInfoClick]); @@ -151,20 +148,12 @@ const Map = ({ result.feature.properties.id && result.feature.geometry.type === 'LineString' ) { - dispatch( - updateFeatureInfoClick({ - displayPopup: true, - feature: result.feature, - coordinates: result.nearest, - }) - ); + setFeatureInfoClick({ + feature: result.feature, + coordinates: result.nearest, + }); } else { - dispatch( - updateFeatureInfoClick({ - displayPopup: false, - feature: undefined, - }) - ); + setFeatureInfoClick(undefined); } removeSearchItemMarkersOnMap(dispatch); }; @@ -391,7 +380,13 @@ const Map = ({ layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]} infraID={infraID} /> - {!showStdcmAssets && } + {!showStdcmAssets && featureInfoClick && ( + + )} )} ( 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;