diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx index f6a1cbfe164bc1eeda880d4490e52ff858c30d0c..d944235a29d04b7a1c376869c37cdc29e502ed2d 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx @@ -6,6 +6,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 { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { MapNavigation } from './MapNavigation.component'; @@ -104,9 +105,8 @@ 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({ - models: MODELS_DATA_MOCK_WITH_MAIN_MAP, map: { data: { ...initialMapDataFixture, @@ -116,6 +116,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 bab3d90aede6a9df3860d67ab25c4a10c546d8d7..c1d4d1206263c5392b481c06f990f482b9f62b16 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx @@ -23,7 +23,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, + }), + ); PluginsEventBus.dispatchEvent('onSubmapClose', map.modelId); PluginsEventBus.dispatchEvent('onSubmapOpen', mainMapModel.idObject); diff --git a/src/redux/map/map.reducers.ts b/src/redux/map/map.reducers.ts index de06329e34159742ad61042ffbcb0c658542fc83..362745fc00327c7fff640f6d74c388b85400bb07 100644 --- a/src/redux/map/map.reducers.ts +++ b/src/redux/map/map.reducers.ts @@ -1,9 +1,7 @@ -import { ZERO } from '@/constants/common'; import { DEFAULT_ZOOM } from '@/constants/map'; import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { getPointMerged } from '../../utils/object/getPointMerged'; -import { MAIN_MAP } from './map.constants'; import { initMapBackground, initMapPosition, @@ -12,6 +10,7 @@ import { } from './map.thunks'; import { CloseMapAction, + CloseMapActionAndSetMainMapActive, MapState, OpenMapAndSetActiveAction, SetActiveMapAction, @@ -99,13 +98,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>;