diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx index 051bc4d73ffb780eceff010f71b235f579a9060c..3123479dc68eef7240064e75591ec8274ccdb07b 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx @@ -5,6 +5,7 @@ import { import { StoreType } from '@/redux/store'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { act, render, screen, within } from '@testing-library/react'; +import { MODELS_MOCK } from '@/redux/compartmentPathways/compartmentPathways.mock'; import { MapNavigation } from './MapNavigation.component'; const MAIN_MAP_ID = 5053; @@ -101,7 +102,7 @@ describe('MapNavigation - component', () => { expect(modelId).toBe(MAIN_MAP_ID); }); - it('should close map and open main map if closed currently selected map', async () => { + it('should close currently selected map map and open main map', async () => { const { store } = renderComponent({ map: { data: { @@ -112,6 +113,11 @@ describe('MapNavigation - component', () => { loading: 'succeeded', error: { message: '', name: '' }, }, + models: { + loading: 'succeeded', + error: { message: '', name: '' }, + data: MODELS_MOCK, + }, }); const histamineMapButton = screen.getByRole('button', { name: 'Histamine signaling' }); diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx index 293fba3afa23d0b794be74c90a7fe10966f011d8..f6c77f047caeaefa31ecca3bc90f03e2eec1ff8d 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx @@ -4,6 +4,7 @@ import { MAIN_MAP } from '@/redux/map/map.constants'; import { mapModelIdSelector, mapOpenedMapsSelector } from '@/redux/map/map.selectors'; import { closeMap, closeMapAndSetMainMapActive, setActiveMap } from '@/redux/map/map.slice'; import { OppenedMap } from '@/redux/map/map.types'; +import { mainMapModelSelector } from '@/redux/models/models.selectors'; import { Button } from '@/shared/Button'; import { Icon } from '@/shared/Icon'; import { MouseEvent } from 'react'; @@ -13,6 +14,7 @@ export const MapNavigation = (): JSX.Element => { const dispatch = useAppDispatch(); const openedMaps = useAppSelector(mapOpenedMapsSelector); const currentModelId = useAppSelector(mapModelIdSelector); + const mainMapModel = useAppSelector(mainMapModelSelector); const isActive = (modelId: number): boolean => currentModelId === modelId; const isNotMainMap = (modelName: string): boolean => modelName !== MAIN_MAP; @@ -20,7 +22,12 @@ export const MapNavigation = (): JSX.Element => { const onCloseSubmap = (event: MouseEvent<HTMLDivElement>, map: OppenedMap): void => { event.stopPropagation(); if (isActive(map.modelId)) { - dispatch(closeMapAndSetMainMapActive({ modelId: map.modelId })); + dispatch( + closeMapAndSetMainMapActive({ + modelId: mainMapModel.idObject, + currentModelId: map.modelId, + }), + ); } else { dispatch(closeMap({ modelId: map.modelId })); } diff --git a/src/redux/map/map.reducers.ts b/src/redux/map/map.reducers.ts index eef6f9324c56ef85ab70d4c61ccf5f9320f82fd6..50220ebedf74c382c0813811c92d50a8a5a8aa47 100644 --- a/src/redux/map/map.reducers.ts +++ b/src/redux/map/map.reducers.ts @@ -1,8 +1,6 @@ -import { ZERO } from '@/constants/common'; import { DEFAULT_ZOOM } from '@/constants/map'; import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import { getPointMerged } from '../../utils/object/getPointMerged'; -import { MAIN_MAP } from './map.constants'; import { initMapBackground, initMapPosition, @@ -11,6 +9,7 @@ import { } from './map.thunks'; import { CloseMapAction, + CloseMapActionAndSetMainMapActive, MapState, OpenMapAndSetActiveAction, SetActiveMapAction, @@ -91,13 +90,12 @@ export const closeMapReducer = (state: MapState, action: CloseMapAction): void = export const closeMapAndSetMainMapActiveReducer = ( state: MapState, - action: CloseMapAction, + action: CloseMapActionAndSetMainMapActive, ): void => { state.openedMaps = state.openedMaps.filter( - openedMap => openedMap.modelId !== action.payload.modelId, + openedMap => openedMap.modelId !== action.payload.currentModelId, ); - state.data.modelId = - state.openedMaps.find(openedMap => openedMap.modelName === MAIN_MAP)?.modelId || ZERO; + state.data.modelId = action.payload.modelId; }; export const setMapBackgroundReducer = (state: MapState, action: SetBackgroundAction): void => { diff --git a/src/redux/map/map.types.ts b/src/redux/map/map.types.ts index 3d15719aa783b34b5796321c166e30c02a2d9eb6..b11c5cfefe794fb850de5629934e181c4f94877d 100644 --- a/src/redux/map/map.types.ts +++ b/src/redux/map/map.types.ts @@ -64,6 +64,12 @@ export type CloseMapActionPayload = Pick<OppenedMap, 'modelId'>; export type CloseMapAction = PayloadAction<CloseMapActionPayload>; +export type CloseMapActionAndSetMainMapActive = PayloadAction< + { + currentModelId: number; + } & Pick<OppenedMap, 'modelId'> +>; + export type InitMapDataActionParams = { queryData: QueryData }; export type InitMapDataAction = PayloadAction<SetMapDataAction>;