diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx index e1839e6627287b38b702bbf9b03216e817d3604c..22c43bc9002867b5657d1e80b72eaf83beb59afc 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx @@ -9,7 +9,6 @@ import { } from '@/utils/testing/getReduxWrapperWithStore'; import { act, render, screen, within } from '@testing-library/react'; import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { Project } from '@/types/models'; import { projectFixture } from '@/models/fixtures/projectFixture'; import { ProjectState } from '@/redux/project/project.types'; @@ -75,7 +74,6 @@ describe('MapNavigation - component', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -96,7 +94,6 @@ describe('MapNavigation - component', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -123,7 +120,6 @@ describe('MapNavigation - component', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -155,7 +151,6 @@ describe('MapNavigation - component', () => { modelId: HISTAMINE_MAP_ID, }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, loading: 'succeeded', error: { message: '', name: '' }, }, @@ -203,7 +198,6 @@ describe('MapNavigation - component', () => { modelId: HISTAMINE_MAP_ID, }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, loading: 'succeeded', error: { message: '', name: '' }, }, @@ -231,7 +225,6 @@ describe('MapNavigation - component', () => { modelId: HISTAMINE_MAP_ID, }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, loading: 'succeeded', error: { message: '', name: '' }, }, @@ -257,7 +250,6 @@ describe('MapNavigation - component', () => { modelId: HISTAMINE_MAP_ID, }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, loading: 'succeeded', error: { message: '', name: '' }, }, diff --git a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts index 33e0afd0f1923344307fa346c7ac6c221d6c7389..4cf7330e1acf738a2af7d35a94a7bf679c6e285b 100644 --- a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts +++ b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.test.ts @@ -17,7 +17,6 @@ import { OverviewImageLink } from '@/types/models'; import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook } from '@testing-library/react'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MAIN_MAP_ID } from '@/constants/mocks'; import { FIRST_ARRAY_ELEMENT, @@ -61,7 +60,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -112,7 +110,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -170,7 +167,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -249,7 +245,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -354,7 +349,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -412,7 +406,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -474,7 +467,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -538,7 +530,6 @@ describe('useOverviewImageLinkActions - hook', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, diff --git a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/ElementsOnMapCell/ElementLink/ElementLink.component.test.tsx b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/ElementsOnMapCell/ElementLink/ElementLink.component.test.tsx index cdd2e42f10a48dafa1af0d41c3f3aac4ea3914fd..ea4fe1f6f76cc3fcfec45cb21decbbb4b02d693d 100644 --- a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/ElementsOnMapCell/ElementLink/ElementLink.component.test.tsx +++ b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/ElementsOnMapCell/ElementLink/ElementLink.component.test.tsx @@ -14,7 +14,6 @@ import { import { render, screen, waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; import { MockStoreEnhanced } from 'redux-mock-store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { isReactionBioEntity } from '@/redux/reactions/isReactionBioentity'; import { ElementLink } from './ElementLink.component'; @@ -203,7 +202,6 @@ describe('ElementLink - component', () => { lastPosition: DEFAULT_POSITION, }, ], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, ); diff --git a/src/components/FunctionalArea/TopBar/TopBar.component.test.tsx b/src/components/FunctionalArea/TopBar/TopBar.component.test.tsx index f87cc56c7303a0402a97b44dc6fb9c41c8a24b01..3f7463f357201bb680f85db24db9b0d69da520ee 100644 --- a/src/components/FunctionalArea/TopBar/TopBar.component.test.tsx +++ b/src/components/FunctionalArea/TopBar/TopBar.component.test.tsx @@ -10,10 +10,6 @@ import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreA import { PROJECT_STATE_INITIAL_MOCK } from '@/redux/project/project.mock'; import { projectFixture } from '@/models/fixtures/projectFixture'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; import { USER_INITIAL_STATE_MOCK } from '@/redux/user/user.mock'; import { SEARCH_STATE_INITIAL_MOCK } from '@/redux/search/search.mock'; @@ -103,7 +99,6 @@ describe('TopBar - component', () => { }, }, map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }); expect(screen.getByText('Browse overview images')).toBeInTheDocument(); }); @@ -121,7 +116,6 @@ describe('TopBar - component', () => { autocompleteSearch: AUTOCOMPLETE_INITIAL_STATE, autocompleteDrug: AUTOCOMPLETE_INITIAL_STATE, autocompleteChemical: AUTOCOMPLETE_INITIAL_STATE, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }); const overviewImageButton = screen.getByText('Browse overview images'); @@ -149,7 +143,6 @@ describe('TopBar - component', () => { }, }, map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }); const overviewImageButton = screen.queryByText('Browse overview images'); diff --git a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx index 267ad43924cfcaf50fcf840802cd121fd05a84a1..84ff3087084fe70ae7ff9ce01b422d00125f4214 100644 --- a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx +++ b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.test.tsx @@ -18,7 +18,6 @@ import { getReduxWrapperWithStore, } from '@/utils/testing/getReduxWrapperWithStore'; import { act, render, screen } from '@testing-library/react'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { AssociatedSubmap } from './AssociatedSubmap.component'; @@ -90,7 +89,6 @@ describe('AssociatedSubmap - component', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, bioEntity: { ...BIOENTITY_INITIAL_STATE_MOCK, @@ -150,7 +148,6 @@ describe('AssociatedSubmap - component', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, bioEntity: { ...BIOENTITY_INITIAL_STATE_MOCK, diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx index 906dd9ee6fe55e9aaea12c5907df5ef2e9204c63..1a60d63dedff3a165c424ddf54228e8d5dc98b44 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx @@ -1,5 +1,4 @@ import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; -import { currentBackgroundSelector } from '@/redux/backgrounds/background.selectors'; import { downloadElements, downloadNetwork } from '@/redux/export/export.thunks'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; @@ -12,6 +11,7 @@ import { ReactNode, useCallback, useMemo, useState } from 'react'; import { activeOverlaysIdSelector } from '@/redux/overlayBioEntity/overlayBioEntity.selector'; import { DownloadCurrentView } from '@/components/Map/Drawer/ExportDrawer/ExportCompound/DownloadCurrentView/DownloadCurrentView.component'; import { getZoom } from '@/services/pluginsManager/map/zoom/getZoom'; +import { mapBackgroundSelector } from '@/redux/map/map.selectors'; import { CheckboxItem } from '../CheckboxFilter/CheckboxFilter.types'; import { Annotations } from './Annotations'; import { DownloadElements } from './DownloadElements/DownloadElements'; @@ -41,7 +41,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { const selectedModelId = useAppSelector(currentModelIdSelector); const currentModels = useAppSelector(modelsDataSelector); - const currentBackground = useAppSelector(currentBackgroundSelector); + const background = useAppSelector(mapBackgroundSelector); const overlays = useAppSelector(activeOverlaysIdSelector); const [annotations, setAnnotations] = useState<CheckboxItem[]>([]); const [includedCompartmentPathways, setIncludedCompartmentPathways] = useState<CheckboxItem[]>( @@ -82,7 +82,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { const model = currentModels.find(currentModel => currentModel.id === Number(modelId)); const url = getGraphicsDownloadUrl({ - backgroundId: currentBackground?.id, + backgroundId: background, modelId: models?.[FIRST_ARRAY_ELEMENT]?.id, handler: imageFormats?.[FIRST_ARRAY_ELEMENT]?.id, zoom: getModelExportZoom(imageSize.width, model), @@ -93,11 +93,11 @@ export const Export = ({ children }: ExportProps): JSX.Element => { if (url) { window.open(url); } - }, [models, imageFormats, currentBackground, currentModels, imageSize.width, overlays]); + }, [models, imageFormats, background, currentModels, imageSize.width, overlays]); const handleDownloadCurrentView = useCallback(async () => { const url = getGraphicsDownloadUrl({ - backgroundId: currentBackground?.id, + backgroundId: background, modelId: `${selectedModelId}`, handler: imageFormats?.[FIRST_ARRAY_ELEMENT]?.id, zoom: getZoom(), @@ -108,7 +108,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { if (url) { window.open(url); } - }, [selectedModelId, imageFormats, currentBackground, overlays]); + }, [selectedModelId, imageFormats, background, overlays]); const globalContextDataValue = useMemo( () => ({ diff --git a/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx b/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx index d1080df9596b209439b1eaed1019bd47e9fef9e7..83ac53a39bf780c3cb40772d845681e080fd3113 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx +++ b/src/components/Map/Drawer/OverlaysDrawer/GeneralOverlays/OverlayListItem/OverlayListItem.component.test.tsx @@ -4,10 +4,6 @@ import { InitialStoreState, getReduxWrapperWithStore, } from '@/utils/testing/getReduxWrapperWithStore'; -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK } from '@/redux/overlayBioEntity/overlayBioEntity.mock'; @@ -19,11 +15,11 @@ import { MODELS_INITIAL_STATE_MOCK } from '@/redux/models/models.mock'; import { parseOverlayBioEntityToOlRenderingFormat } from '@/redux/overlayBioEntity/overlayBioEntity.utils'; import { BASE_API_URL } from '@/constants'; import { MAIN_MAP_ID } from '@/constants/mocks'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; import { OverlayListItem } from './OverlayListItem.component'; const mockedAxiosNewClient = mockNetworkNewAPIResponse(); -const DEFAULT_BACKGROUND_ID = 0; -const EMPTY_BACKGROUND_ID = 15; +const DEFAULT_BACKGROUND_ID = 2; const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); @@ -50,11 +46,10 @@ describe('OverlayListItem - component', () => { }); describe('view overlays', () => { - it('should trigger view overlays on view button click and switch background to Empty if available', async () => { + it('should trigger view overlays on view button click and switch background to Network', async () => { const OVERLAY_ID = 21; const { store } = renderComponent({ map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, overlayBioEntity: OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK, models: { ...MODELS_INITIAL_STATE_MOCK, data: [CORE_PD_MODEL_MOCK] }, }); @@ -69,7 +64,7 @@ describe('OverlayListItem - component', () => { ViewButton.click(); }); - expect(store.getState().map.data.backgroundId).toBe(EMPTY_BACKGROUND_ID); + expect(store.getState().map.data.backgroundId).toBe(MapBackgroundsEnum.NETWORK); expect(store.getState().overlayBioEntity.data).toEqual({ [OVERLAY_ID]: { [MAIN_MAP_ID]: parseOverlayBioEntityToOlRenderingFormat( @@ -84,9 +79,8 @@ describe('OverlayListItem - component', () => { const { store } = renderComponent({ map: { ...initialMapStateFixture, - data: { ...initialMapStateFixture.data, backgroundId: EMPTY_BACKGROUND_ID }, + data: { ...initialMapStateFixture.data, backgroundId: MapBackgroundsEnum.NETWORK }, }, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, overlayBioEntity: { ...OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK, overlaysId: [OVERLAY_ID] }, models: { ...MODELS_INITIAL_STATE_MOCK, data: [CORE_PD_MODEL_MOCK] }, }); @@ -120,9 +114,8 @@ describe('OverlayListItem - component', () => { renderComponent({ map: { ...initialMapStateFixture, - data: { ...initialMapStateFixture.data, backgroundId: EMPTY_BACKGROUND_ID }, + data: { ...initialMapStateFixture.data, backgroundId: MapBackgroundsEnum.SEMANTIC }, }, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, overlayBioEntity: { ...OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK, overlaysId: [OVERLAY_ID] }, models: { ...MODELS_INITIAL_STATE_MOCK, data: [CORE_PD_MODEL_MOCK] }, }); diff --git a/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.test.ts b/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.test.ts deleted file mode 100644 index 9c58dfc3baa4207cb6af954a6662ddeb0a16ea92..0000000000000000000000000000000000000000 --- a/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; -import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; -import { renderHook } from '@testing-library/react'; -import { useEmptyBackground } from './useEmptyBackground'; - -const DEFAULT_BACKGROUND_ID = 0; -const EMPTY_BACKGROUND_ID = 15; - -describe('useEmptyBackground - hook', () => { - describe('returns setEmptyBackground function', () => { - it('should not set background to "Empty" if its not available', () => { - const { Wrapper, store } = getReduxWrapperWithStore({ - map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, - }); - const { result } = renderHook(() => useEmptyBackground(), { wrapper: Wrapper }); - - expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); - - result.current.setBackgroundtoEmptyIfAvailable(); - - expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); - }); - - it('should set background to "Empty" if its available', () => { - const { Wrapper, store } = getReduxWrapperWithStore({ - map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }); - const { result } = renderHook(() => useEmptyBackground(), { wrapper: Wrapper }); - - expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); - - result.current.setBackgroundtoEmptyIfAvailable(); - - expect(store.getState().map.data.backgroundId).toBe(EMPTY_BACKGROUND_ID); - }); - }); -}); diff --git a/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.ts b/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.ts deleted file mode 100644 index 2536fa84e049dd7dc659040a96933d3287639436..0000000000000000000000000000000000000000 --- a/src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { useCallback } from 'react'; -import { emptyBackgroundIdSelector } from '@/redux/backgrounds/background.selectors'; -import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { setMapBackground } from '@/redux/map/map.slice'; - -type UseEmptyBackgroundReturn = { - setBackgroundtoEmptyIfAvailable: () => void; -}; - -export const useEmptyBackground = (): UseEmptyBackgroundReturn => { - const dispatch = useAppDispatch(); - const emptyBackgroundId = useAppSelector(emptyBackgroundIdSelector); - - const setBackgroundtoEmptyIfAvailable = useCallback(() => { - if (emptyBackgroundId) { - dispatch(setMapBackground(emptyBackgroundId)); - } - }, [dispatch, emptyBackgroundId]); - - return { setBackgroundtoEmptyIfAvailable }; -}; diff --git a/src/components/Map/Drawer/OverlaysDrawer/hooks/useOverlay.ts b/src/components/Map/Drawer/OverlaysDrawer/hooks/useOverlay.ts index 084877fd2b80fe6eaf17792bedf2cbfba3f0755f..bca5b9adc34951fca2f95a5c082ec8bad21d7eb1 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/hooks/useOverlay.ts +++ b/src/components/Map/Drawer/OverlaysDrawer/hooks/useOverlay.ts @@ -14,7 +14,8 @@ import { addOverlayToOverlaysId, removeOverlayFromOverlaysId, } from '@/redux/overlayBioEntity/overlayBioEntity.slice'; -import { useEmptyBackground } from './useEmptyBackground'; +import { setMapBackground } from '@/redux/map/map.slice'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; type UseOverlay = { toggleOverlay: () => void; @@ -27,7 +28,6 @@ export const useOverlay = (overlayId: number): UseOverlay => { const dispatch = useAppDispatch(); const isOverlayActive = useAppSelector(state => isOverlayActiveSelector(state, overlayId)); const isOverlayLoading = useAppSelector(state => isOverlayLoadingSelector(state, overlayId)); - const { setBackgroundtoEmptyIfAvailable } = useEmptyBackground(); const overlay = useAppSelector(state => overlaySelector(state, overlayId)); const areOverlayBioEntitiesLoaded = useAppSelector(state => areOverlayBioEntitiesLoadedSelector(state, overlayId), @@ -55,7 +55,7 @@ export const useOverlay = (overlayId: number): UseOverlay => { } else { await dispatch(getOverlayBioEntityForAllModels({ overlayId })); } - setBackgroundtoEmptyIfAvailable(); + dispatch(setMapBackground(MapBackgroundsEnum.NETWORK)); } dispatchPluginEvents(); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx index 62654f694d065b89073cbddd20f82e26078c8163..a93282dbc8057e22d7db0fcdf38bb59f57290fa6 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesSubmapItem/BioEntitiesSubmapItem.component.test.tsx @@ -13,7 +13,6 @@ import { openedMapsInitialValueFixture, openedMapsThreeSubmapsFixture, } from '@/redux/map/map.fixtures'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MAIN_MAP_ID } from '@/constants/mocks'; import { BioEntitiesSubmapItem } from './BioEntitiesSubmapItem.component'; @@ -100,7 +99,6 @@ describe('BioEntitiesSubmapItem - component', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -158,7 +156,6 @@ describe('BioEntitiesSubmapItem - component', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx index b4001c6436f90988a9db48b3ad09e9f5b1ebbe35..ce80ff1c3bee164941694df5993bc573e4bea953 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx @@ -11,7 +11,6 @@ import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/ma import { MODELS_DATA_MOCK_WITH_MAIN_MAP } from '@/redux/models/models.mock'; import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; import { MockStoreEnhanced } from 'redux-mock-store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MAIN_MAP_ID } from '@/constants/mocks'; import { PinTypeWithNone } from '../PinsList.types'; import { PinsListItem } from './PinsListItem.component'; @@ -42,7 +41,6 @@ const INITIAL_STORE_STATE: InitialStoreState = { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }; @@ -175,7 +173,6 @@ describe('PinsListItem - component ', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, ); @@ -209,7 +206,6 @@ describe('PinsListItem - component ', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, ); diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx index cbd6c3b499580262ded0b3ec6a3028c5021be87f..75230b395cae63077dc8e503b3295fec1029e793 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx @@ -1,5 +1,4 @@ import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; -import { backgroundsFixture } from '@/models/fixtures/backgroundsFixture'; import { configurationFixture } from '@/models/fixtures/configurationFixture'; import { modelsFixture } from '@/models/fixtures/modelsFixture'; import { @@ -44,15 +43,6 @@ const getState = (): RootState => ({ }, ], }, - backgrounds: { - ...INITIAL_STORE_STATE_MOCK.backgrounds, - data: [ - { - ...backgroundsFixture[FIRST_ARRAY_ELEMENT], - id: VALID_BACKGROUND_ID, - }, - ], - }, configuration: { ...INITIAL_STORE_STATE_MOCK.configuration, main: { diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts index 971bc84d43dc1520213d870f931aa09d43aa9632..ca0849cbac5b5e120844a2456edf197395b87ba2 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts @@ -1,6 +1,5 @@ import { BASE_API_URL, PROJECT_ID } from '@/constants'; import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; -import { backgroundsFixture } from '@/models/fixtures/backgroundsFixture'; import { modelsFixture } from '@/models/fixtures/modelsFixture'; import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures'; import { RootState } from '@/redux/store'; @@ -45,15 +44,6 @@ const getState = ({ }, ], }, - backgrounds: { - ...INITIAL_STORE_STATE_MOCK.backgrounds, - data: [ - { - ...backgroundsFixture[FIRST_ARRAY_ELEMENT], - id: VALID_BACKGROUND_ID, - }, - ], - }, }); describe('useGetSubmapDownloadUrl - hook', () => { diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts index 34c33260f7b63b39f1ff7655a77c323a06b3144c..bcd25b83ce145d54ae65b9b524c50c22a946b43e 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts @@ -1,6 +1,5 @@ import { BASE_API_URL, PROJECT_ID } from '@/constants'; -import { currentBackgroundSelector } from '@/redux/backgrounds/background.selectors'; -import { mapDataSizeSelector } from '@/redux/map/map.selectors'; +import { mapBackgroundSelector, mapDataSizeSelector } from '@/redux/map/map.selectors'; import { useSelector } from 'react-redux'; export type GetSubmapDownloadUrl = ({ @@ -12,11 +11,11 @@ export type GetSubmapDownloadUrl = ({ }) => string; export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { - const background = useSelector(currentBackgroundSelector); + const background = useSelector(mapBackgroundSelector); const mapSize = useSelector(mapDataSizeSelector); const getSubmapDownloadUrl: GetSubmapDownloadUrl = ({ handler, modelId }) => { - const allParamsValid = [modelId, background?.id, mapSize.maxZoom, handler].reduce( + const allParamsValid = [modelId, background, mapSize.maxZoom, handler].reduce( (a, b) => Boolean(a) && Boolean(b), true, ); @@ -24,7 +23,7 @@ export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { return ''; } - return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; + return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadModel?backgroundOverlayId=${background}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; }; return getSubmapDownloadUrl; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx index 492be6cb5910fe4cd26897c06eb0fbd14429e30b..d4a6e092ac4fcb8dc3ee175e5f894d3a8ac976b0 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.test.tsx @@ -11,7 +11,6 @@ import { openedMapsInitialValueFixture, openedMapsThreeSubmapsFixture, } from '@/redux/map/map.fixtures'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { SubmapsDrawer } from './SubmapsDrawer'; @@ -63,7 +62,6 @@ describe('SubmapsDrawer - component', () => { loading: 'succeeded', error: { name: '', message: '' }, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); @@ -109,7 +107,6 @@ describe('SubmapsDrawer - component', () => { openedMaps: openedMapsThreeSubmapsFixture, loading: 'succeeded', error: { name: '', message: '' }, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); diff --git a/src/components/Map/MapAdditionalActions/MapAdditionalActions.component.test.tsx b/src/components/Map/MapAdditionalActions/MapAdditionalActions.component.test.tsx index 5fe7353f67f070fcc6c6615efc5089824b91fb54..06bd09feed567c3515c7d3f305bc8eecb9426e78 100644 --- a/src/components/Map/MapAdditionalActions/MapAdditionalActions.component.test.tsx +++ b/src/components/Map/MapAdditionalActions/MapAdditionalActions.component.test.tsx @@ -11,7 +11,6 @@ import { import { act, render, screen } from '@testing-library/react'; import Map from 'ol/Map'; import { MockStoreEnhanced } from 'redux-mock-store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MapAdditionalActions } from './MapAdditionalActions.component'; import { useVisibleBioEntitiesPolygonCoordinates } from './utils/useVisibleBioEntitiesPolygonCoordinates'; @@ -146,7 +145,6 @@ describe('MapAdditionalActions - component', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); diff --git a/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts b/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts index a65473f78ad8b2a81a928c70a09d292d72dc70e1..de9d56f1609d35c14207247c86c28699ebf16db3 100644 --- a/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts +++ b/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts @@ -8,7 +8,6 @@ import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreA import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook } from '@testing-library/react'; import Map from 'ol/Map'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { useAddtionalActions } from './useAdditionalActions'; import { useVisibleBioEntitiesPolygonCoordinates } from './useVisibleBioEntitiesPolygonCoordinates'; @@ -95,7 +94,6 @@ describe('useAddtionalActions - hook', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, { diff --git a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.test.tsx b/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.test.tsx deleted file mode 100644 index 8aaf2bd11f3433c42bd3e9bdef76aa3101c4008d..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.test.tsx +++ /dev/null @@ -1,104 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { StoreType } from '@/redux/store'; -import { render, screen } from '@testing-library/react'; -import { act } from 'react-dom/test-utils'; -import { initialMapDataFixture, initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { - InitialStoreState, - getReduxWrapperWithStore, -} from '@/utils/testing/getReduxWrapperWithStore'; -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; -import { BackgroundSelector } from './BackgroundsSelector.component'; - -const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { - const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); - - return ( - render( - <Wrapper> - <BackgroundSelector /> - </Wrapper>, - ), - { - store, - } - ); -}; - -describe('BackgroundSelector - component', () => { - it('should initialy display default value', () => { - renderComponent(); - - const buttonName = screen.getByTestId('background-dropdown-button-name'); - - expect(buttonName.textContent).toBe('Background'); - }); - - it("should display selected value name when it's not main background", async () => { - renderComponent({ - map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }); - - const buttonName = screen.getByTestId('background-dropdown-button-name'); - await act(() => { - buttonName.click(); - }); - expect(buttonName.textContent).toBe('Background'); - - const backgroundButton = screen.getByText('Network'); - await act(() => { - backgroundButton.click(); - }); - - expect(buttonName.textContent).toBe('Network'); - }); - - it('should change redux map state on selecting background', async () => { - const { store } = renderComponent({ - map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }); - expect(store.getState().map.data.modelId).toBe(0); - - const buttonName = screen.getByTestId('background-dropdown-button-name'); - await act(() => { - buttonName.click(); - }); - - const backgroundButton = screen.getByText('Network'); - await act(() => { - backgroundButton.click(); - }); - - expect(store.getState().map.data.backgroundId).toBe(14); - }); - - describe('query params', () => { - it('should display default value when main background id is in query params', async () => { - await renderComponent({ - map: { ...initialMapStateFixture, data: { ...initialMapDataFixture, backgroundId: 13 } }, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }); - - const buttonName = screen.getByTestId('background-dropdown-button-name'); - expect(buttonName.textContent).toBe('Background'); - }); - it('should display correct background when background id is in query params', async () => { - await renderComponent({ - map: { ...initialMapStateFixture, data: { ...initialMapDataFixture, backgroundId: 15 } }, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }); - - const buttonName = screen.getByTestId('background-dropdown-button-name'); - expect(buttonName.textContent).toBe('Empty'); - }); - it.skip('should set backgroundid in query on selecting background', () => { - // TODO e2e - expect(true).toBe(false); - }); - }); -}); diff --git a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.tsx b/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.tsx deleted file mode 100644 index 610cb3719cc4245b23c67f1f42f1ea67f4f03fd1..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { useSelect } from 'downshift'; -import { - backgroundsDataSelector, - currentBackgroundSelector, - mainBackgroundIdSelector, -} from '@/redux/backgrounds/background.selectors'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { twMerge } from 'tailwind-merge'; -import { Icon } from '@/shared/Icon'; -import { MapBackground } from '@/types/models'; -import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import { setMapBackground } from '@/redux/map/map.slice'; - -const DEFAULT_TOGGLE_BUTTON_TEXT = 'Background'; - -export const BackgroundSelector = (): JSX.Element => { - const selectedBackground = useAppSelector(currentBackgroundSelector); - const dispatch = useAppDispatch(); - const backgrounds = useAppSelector(backgroundsDataSelector); - const mainBackgroundId = useAppSelector(mainBackgroundIdSelector); - - const onItemSelect = (background: MapBackground | undefined | null): void => { - if (background) { - dispatch(setMapBackground(background.id)); - } - }; - - const { isOpen, getToggleButtonProps, getMenuProps, highlightedIndex, getItemProps } = useSelect({ - items: backgrounds || [], - selectedItem: selectedBackground, - onSelectedItemChange: ({ selectedItem: newSelectedItem }) => onItemSelect(newSelectedItem), - }); - - const getToggleButtonName = (): string => { - const isSelectedBackgroundMainBackground = selectedBackground?.id === mainBackgroundId; - if (!selectedBackground || isSelectedBackgroundMainBackground) { - return DEFAULT_TOGGLE_BUTTON_TEXT; - } - return selectedBackground.name; - }; - - return ( - <div - data-testid="background-selector" - className={twMerge('rounded-t bg-white text-xs shadow-primary', !isOpen && 'rounded-b')} - > - <div className={twMerge('flex w-[135px] flex-col rounded-t py-2 pl-4 pr-3')}> - <div - className="flex cursor-pointer flex-row items-center justify-between bg-white" - {...getToggleButtonProps()} - > - <span data-testid="background-dropdown-button-name" className="font-medium"> - {getToggleButtonName()} - </span> - <Icon - name="chevron-down" - className={twMerge('arrow-button h-6 w-6 fill-primary-500', isOpen && 'rotate-180')} - /> - </div> - </div> - <ul - className={`absolute z-10 max-h-80 w-[135px] overflow-scroll rounded-b bg-white p-0 ${ - !isOpen && 'hidden' - }`} - {...getMenuProps()} - > - {isOpen && - backgrounds && - backgrounds.map((item, index) => ( - <li - className={twMerge( - 'border-t', - highlightedIndex === index && 'text-primary-500', - selectedBackground === item && 'font-bold', - 'flex flex-col px-4 py-2 shadow-sm', - )} - key={item.id} - {...getItemProps({ item, index })} - > - <span>{item.name}</span> - </li> - ))} - </ul> - </div> - ); -}; diff --git a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/index.ts b/src/components/Map/MapAdditionalOptions/BackgroundsSelector/index.ts deleted file mode 100644 index 0b379515e412b197f8e195c7e0b4e6044437fe21..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/BackgroundsSelector/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { BackgroundSelector } from './BackgroundsSelector.component'; diff --git a/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.test.tsx b/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.test.tsx deleted file mode 100644 index 5b877e38e83b30896fe49261fa6b99c78e4d7734..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.test.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { StoreType } from '@/redux/store'; -import { - InitialStoreState, - getReduxWrapperWithStore, -} from '@/utils/testing/getReduxWrapperWithStore'; -import { render, screen } from '@testing-library/react'; -import { MapAdditionalOptions } from './MapAdditionalOptions.component'; - -const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { - const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); - - return ( - render( - <Wrapper> - <MapAdditionalOptions /> - </Wrapper>, - ), - { - store, - } - ); -}; - -describe('MapAdditionalOptions - component', () => { - it('should display background selector', () => { - renderComponent(); - expect(screen.getByTestId('background-selector')).toBeInTheDocument(); - }); -}); diff --git a/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.tsx b/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.tsx deleted file mode 100644 index ce96a90761bdf9ee6d5600b68d64268e4374225a..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { twMerge } from 'tailwind-merge'; -import { BackgroundSelector } from './BackgroundsSelector'; - -// top-[calc(64px+40px+24px)] -> TOP_BAR_HEIGHT+MAP_NAVIGATION_HEIGHT+DISTANCE_FROM_MAP_NAVIGATION - -export const MapAdditionalOptions = (): JSX.Element => ( - <div className={twMerge('absolute right-6 top-[calc(64px+40px+24px)] z-10 flex')}> - <BackgroundSelector /> - </div> -); diff --git a/src/components/Map/MapAdditionalOptions/index.ts b/src/components/Map/MapAdditionalOptions/index.ts deleted file mode 100644 index ff61a27a2ae3155839070f31146f77fca1b8df2c..0000000000000000000000000000000000000000 --- a/src/components/Map/MapAdditionalOptions/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { MapAdditionalOptions } from './MapAdditionalOptions.component'; diff --git a/src/components/Map/MapVectorBackgroundSelector/MapVectorBackgroundSelector.component.tsx b/src/components/Map/MapVectorBackgroundSelector/MapVectorBackgroundSelector.component.tsx index 97463f278f72d3f5ada520381a5ed101267e6dd7..caea44b9746713de1cae2fcfb97b1e6d6802e89e 100644 --- a/src/components/Map/MapVectorBackgroundSelector/MapVectorBackgroundSelector.component.tsx +++ b/src/components/Map/MapVectorBackgroundSelector/MapVectorBackgroundSelector.component.tsx @@ -1,24 +1,24 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { mapBackgroundTypeSelector } from '@/redux/map/map.selectors'; +import { mapBackgroundSelector } from '@/redux/map/map.selectors'; import { twMerge } from 'tailwind-merge'; import { MAP_BACKGROUND_TYPES } from '@/redux/map/map.constants'; -import { setMapBackgroundType } from '@/redux/map/map.slice'; +import { setMapBackground } from '@/redux/map/map.slice'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; import { Select } from '@/shared/Select'; export const MapVectorBackgroundSelector = (): JSX.Element => { const dispatch = useAppDispatch(); - const backgroundType = useAppSelector(mapBackgroundTypeSelector); + const backgroundId = useAppSelector(mapBackgroundSelector); - const handleChange = (selectedBackgroundType: string | number): void => { - dispatch(setMapBackgroundType(+selectedBackgroundType)); + const handleChange = (selectedBackgroundId: string | number): void => { + dispatch(setMapBackground(+selectedBackgroundId)); }; return ( <div className={twMerge('absolute right-6 top-[calc(64px+40px+24px)] z-10 flex')}> <Select options={MAP_BACKGROUND_TYPES} - selectedId={backgroundType} + selectedId={backgroundId} onChange={handleChange} width={140} /> diff --git a/src/components/Map/MapViewer/MapViewer.component.test.tsx b/src/components/Map/MapViewer/MapViewer.component.test.tsx index 234854206f6a5310ca22b3009a0ddf11adfcbf92..ea37b540a7f825f0509b76a17cf748448bedb065 100644 --- a/src/components/Map/MapViewer/MapViewer.component.test.tsx +++ b/src/components/Map/MapViewer/MapViewer.component.test.tsx @@ -1,7 +1,6 @@ import { render, screen } from '@testing-library/react'; import { StoreType } from '@/redux/store'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { BACKGROUND_INITIAL_STATE_MOCK } from '@/redux/backgrounds/background.mock'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { MapViewer } from './MapViewer.component'; import { MAP_VIEWER_ROLE } from './MapViewer.constants'; @@ -9,7 +8,6 @@ import { MAP_VIEWER_ROLE } from './MapViewer.constants'; const renderComponent = (): { store: StoreType } => { const { Wrapper, store } = getReduxWrapperWithStore({ map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, }); return ( diff --git a/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts index eba9fde5e0faab891f30e7dd987e3a5a4907b7eb..a23de57b10b819f20a2b24e47c532875662953fc 100644 --- a/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts +++ b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts @@ -3,7 +3,6 @@ import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithSto import { renderHook } from '@testing-library/react'; import VectorLayer from 'ol/layer/Vector'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { BACKGROUND_INITIAL_STATE_MOCK } from '@/redux/backgrounds/background.mock'; import { Map } from 'ol'; import { useOlMapAdditionalLayers } from '@/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers'; @@ -11,7 +10,6 @@ describe('useOlMapAdditionalLayers - util', () => { it('should return VectorLayer', () => { const { Wrapper } = getReduxWrapperWithStore({ map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, }); const dummyElement = document.createElement('div'); diff --git a/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts b/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts index dd9a522058ac4677e9bd8d70767cd4d4edd85879..bec6905d0a4f8a246d3b86af4fd5f2f2828883bc 100644 --- a/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts +++ b/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts @@ -5,7 +5,6 @@ import { renderHook } from '@testing-library/react'; import BaseLayer from 'ol/layer/Base'; import VectorLayer from 'ol/layer/Vector'; import React from 'react'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { useOlMapCardLayer } from './useOlMapCardLayer'; const useRefValue = { @@ -59,7 +58,6 @@ describe('useOlMapCardLayer - util', () => { message: '', }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); diff --git a/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts b/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts index 25aa20784b0fed050637308f74b25987820ecd71..87c6d666e2cc4e11eaf99ab6e365e2227159ff28 100644 --- a/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts @@ -24,7 +24,7 @@ export default function processModelElements( vectorSource: VectorSource, mapInstance: MapInstance, pointToProjection: UsePointToProjectionResult, - mapBackgroundType: number, + backgroundId: number, mapSize: MapSize, ): Array<MapElement | CompartmentCircle | CompartmentSquare | CompartmentPathway | Glyph> { const overlaysVisible = Boolean(overlaysOrder.length); @@ -78,7 +78,7 @@ export default function processModelElements( pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }; if (element.shape === 'OVAL_COMPARTMENT') { @@ -129,7 +129,7 @@ export default function processModelElements( overlaysOrder, overlaysVisible, getOverlayColor, - mapBackgroundType, + backgroundId, mapSize, }), ); diff --git a/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts index c8e961ed2b0f75e12873768570cc1d04a3ed8224..c03a9e9f66f45c1561952ec34431a6d28baf051e 100644 --- a/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts @@ -2,7 +2,6 @@ import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithSto import { renderHook } from '@testing-library/react'; import VectorLayer from 'ol/layer/Vector'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { BACKGROUND_INITIAL_STATE_MOCK } from '@/redux/backgrounds/background.mock'; import { Map } from 'ol'; import { useOlMapProcessLayer } from '@/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer'; @@ -10,7 +9,6 @@ describe('useOlMapReactionsLayer - util', () => { it('should return VectorLayer', () => { const { Wrapper } = getReduxWrapperWithStore({ map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, }); const dummyElement = document.createElement('div'); diff --git a/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts index 09d5b04ef0a64e39c0404ccf2a9a36b99921083f..2837c80bf7199fee4e00a0d09fcc0cdac7b629cd 100644 --- a/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts @@ -35,9 +35,7 @@ import { markersSufraceOfCurrentMapDataSelector } from '@/redux/markers/markers. import { parseSurfaceMarkersToBioEntityRender } from '@/components/Map/MapViewer/utils/config/overlaysLayer/parseSurfaceMarkersToBioEntityRender'; import processModelElements from '@/components/Map/MapViewer/utils/config/processLayer/processModelElements'; import useDebouncedValue from '@/utils/useDebouncedValue'; -import { mapBackgroundTypeSelector, mapDataSizeSelector } from '@/redux/map/map.selectors'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; -import { setMapBackgroundType } from '@/redux/map/map.slice'; +import { mapBackgroundSelector, mapDataSizeSelector } from '@/redux/map/map.selectors'; import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; import { OverlayOrder } from '@/redux/overlayBioEntity/overlayBioEntity.utils'; import MarkerOverlay from '@/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay'; @@ -65,7 +63,7 @@ export const useOlMapProcessLayer = ({ const lineTypes = useSelector(lineTypesSelector); const arrowTypes = useSelector(arrowTypesSelector); const overlaysOrder = useSelector(getOverlayOrderSelector); - const mapBackgroundType = useSelector(mapBackgroundTypeSelector); + const backgroundId = useSelector(mapBackgroundSelector); const currentMarkers = useAppSelector(markersSufraceOfCurrentMapDataSelector); const markersRender = useMemo(() => { return parseSurfaceMarkersToBioEntityRender(currentMarkers); @@ -108,12 +106,6 @@ export const useOlMapProcessLayer = ({ } }, [currentModelId, dispatch, reactionsLoading, modelElementsLoading]); - useEffect(() => { - if (overlaysOrderState.length) { - dispatch(setMapBackgroundType(MapBackgroundsEnum.NETWORK)); - } - }, [dispatch, overlaysOrderState]); - const groupedElementsOverlays = useMemo(() => { const elementsBioEntitesOverlay = debouncedBioEntities.filter( bioEntity => bioEntity.type !== 'line', @@ -219,7 +211,7 @@ export const useOlMapProcessLayer = ({ vectorSource, mapInstance, pointToProjection, - mapBackgroundType, + backgroundId, mapSize, ); }, [ @@ -233,7 +225,7 @@ export const useOlMapProcessLayer = ({ vectorSource, mapInstance, pointToProjection, - mapBackgroundType, + backgroundId, mapSize, ]); diff --git a/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts b/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts index 3fe8e8611d15f028c972e154bd398600067ebd58..4b52f2cdfaa0afb63eee908a751ac43ce7b89d65 100644 --- a/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts +++ b/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts @@ -7,7 +7,6 @@ import VectorLayer from 'ol/layer/Vector'; import React from 'react'; import { useOlMap } from '@/components/Map/MapViewer/utils/useOlMap'; import { useOlMapLayers } from '@/components/Map/MapViewer/utils/config/useOlMapLayers'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; const useRefValue = { current: null, @@ -60,7 +59,6 @@ describe('useOlMapLayers - util', () => { message: '', }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); const dummyElement = document.createElement('div'); diff --git a/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.test.ts b/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.test.ts deleted file mode 100644 index 58e4aaa57dfe5b86e6ae60c1bbd7561cf87303e4..0000000000000000000000000000000000000000 --- a/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.test.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { MAP_DATA_INITIAL_STATE, OPENED_MAPS_INITIAL_STATE } from '@/redux/map/map.constants'; -import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; -import { renderHook } from '@testing-library/react'; -import BaseLayer from 'ol/layer/Base'; -import TileLayer from 'ol/layer/Tile'; -import React from 'react'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; -import { useOlMapTileLayer } from './useOlMapTileLayer'; - -const useRefValue = { - current: null, -}; - -Object.defineProperty(useRefValue, 'current', { - get: jest.fn(() => ({ - innerHTML: '', - appendChild: jest.fn(), - addEventListener: jest.fn(), - getRootNode: jest.fn(), - })), - set: jest.fn(() => ({ - innerHTML: '', - appendChild: jest.fn(), - addEventListener: jest.fn(), - getRootNode: jest.fn(), - })), -}); - -jest.spyOn(React, 'useRef').mockReturnValue(useRefValue); - -describe('useOlMapTileLayer - util', () => { - const getRenderedHookResults = (): BaseLayer => { - const { Wrapper } = getReduxWrapperWithStore({ - map: { - data: { - ...MAP_DATA_INITIAL_STATE, - size: { - width: 256, - height: 256, - tileSize: 256, - minZoom: 1, - maxZoom: 1, - }, - position: { - initial: { - x: 256, - y: 256, - }, - last: { - x: 256, - y: 256, - }, - }, - }, - loading: 'idle', - error: { - name: '', - message: '', - }, - openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, - }, - }); - - const { result } = renderHook(() => useOlMapTileLayer(), { - wrapper: Wrapper, - }); - - return result.current; - }; - - it('should return valid TileLayer instance', () => { - const result = getRenderedHookResults(); - - expect(result).toBeInstanceOf(TileLayer); - expect(result.getSourceState()).toBe('ready'); - }); -}); diff --git a/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.ts b/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.ts deleted file mode 100644 index d98b480fe8c9e2494e841aad28dd37702c1b9c8b..0000000000000000000000000000000000000000 --- a/src/components/Map/MapViewer/utils/config/useOlMapTileLayer.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { OPTIONS } from '@/constants/map'; -import { currentBackgroundImagePathSelector } from '@/redux/backgrounds/background.selectors'; -import { mapDataSizeSelector } from '@/redux/map/map.selectors'; -import { projectDataSelector } from '@/redux/project/project.selectors'; -import { Point } from '@/types/map'; -import { usePointToProjection } from '@/utils/map/usePointToProjection'; -import { Extent, boundingExtent } from 'ol/extent'; -import BaseLayer from 'ol/layer/Base'; -import TileLayer from 'ol/layer/Tile'; -import { XYZ } from 'ol/source'; -import { useMemo } from 'react'; -import { useSelector } from 'react-redux'; -import { getMapTileUrl } from './getMapTileUrl'; - -// useOlMapTileLayer returns visual tile layer of the map -// it makes it possible to view the map, scroll, zoom etc. -export const useOlMapTileLayer = (): BaseLayer => { - const mapSize = useSelector(mapDataSizeSelector); - const currentBackgroundImagePath = useSelector(currentBackgroundImagePathSelector); - const project = useSelector(projectDataSelector); - const pointToProjection = usePointToProjection(); - - const tileExtent = useMemo((): Extent => { - const topLeftPoint: Point = { - x: mapSize.width, - y: mapSize.height, - }; - - const bottomRightPoint: Point = { - x: 0, - y: 0, - }; - - return boundingExtent([topLeftPoint, bottomRightPoint].map(pointToProjection)); - }, [pointToProjection, mapSize]); - - const sourceUrl = useMemo( - () => getMapTileUrl({ projectDirectory: project?.directory, currentBackgroundImagePath }), - [project?.directory, currentBackgroundImagePath], - ); - - const source = useMemo( - () => - new XYZ({ - url: sourceUrl, - maxZoom: mapSize.maxZoom, - minZoom: mapSize.minZoom, - tileSize: Math.max(mapSize.tileSize, 1), - wrapX: OPTIONS.wrapXInTileLayer, - }), - [sourceUrl, mapSize.maxZoom, mapSize.minZoom, mapSize.tileSize], - ); - - const tileLayer = useMemo( - (): TileLayer<XYZ> => - new TileLayer({ - visible: true, - source, - extent: tileExtent, - }), - [source, tileExtent], - ); - - return tileLayer; -}; diff --git a/src/components/Map/MapViewer/utils/config/useOlMapView.test.ts b/src/components/Map/MapViewer/utils/config/useOlMapView.test.ts index d630b12bc4056814dbcf76c16ada0d4e699aa864..0a786468aa112aa2f982c4d1146ca55f744ffa96 100644 --- a/src/components/Map/MapViewer/utils/config/useOlMapView.test.ts +++ b/src/components/Map/MapViewer/utils/config/useOlMapView.test.ts @@ -1,8 +1,4 @@ /* eslint-disable no-magic-numbers */ -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; import { MAP_DATA_INITIAL_STATE, OPENED_MAPS_INITIAL_STATE } from '@/redux/map/map.constants'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; import { setMapPosition } from '@/redux/map/map.slice'; @@ -11,7 +7,6 @@ import { act, renderHook, waitFor } from '@testing-library/react'; import { View } from 'ol'; import Map from 'ol/Map'; import React from 'react'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { useOlMap } from '../useOlMap'; import { useOlMapView } from './useOlMapView'; @@ -40,7 +35,6 @@ describe('useOlMapView - util', () => { it('should modify view of the map instance on INITIAL position config change', async () => { const { Wrapper, store } = getReduxWrapperWithStore({ map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }); const dummyElement = document.createElement('div'); @@ -96,9 +90,7 @@ describe('useOlMapView - util', () => { message: '', }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, }); const dummyElement = document.createElement('div'); const { result: hohResult } = renderHook(() => useOlMap({ target: dummyElement }), { diff --git a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts index 328c827ba3cfceebeb3c7d5b5e71d91443144d30..2b2fabe1f0643264006f43755ca9e048bf457069 100644 --- a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts @@ -3,7 +3,6 @@ import { renderHook } from '@testing-library/react'; import { View } from 'ol'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import * as positionListener from '@/components/Map/MapViewer/utils/listeners/onMapPositionChange'; import { useOlMapListeners } from '@/components/Map/MapViewer/utils/listeners/useOlMapListeners'; import { onMapLeftClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; @@ -32,7 +31,6 @@ describe('useOlMapListeners - util', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); diff --git a/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts b/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts index 2327755136b249486f4d4a24f1c781dc75304d0e..59af80b8ae93f7de39c2c1559c7c5a13eec1297d 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts @@ -49,7 +49,7 @@ export interface BaseMapElementProps { pointToProjection: UsePointToProjectionResult; overlaysVisible: boolean; vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; mapInstance: MapInstance; } @@ -117,7 +117,7 @@ export default abstract class BaseMultiPolygon { vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; @@ -153,7 +153,7 @@ export default abstract class BaseMultiPolygon { pointToProjection, overlaysVisible, vectorSource, - mapBackgroundType, + backgroundId, mapSize, mapInstance, }: BaseMapElementProps) { @@ -181,7 +181,7 @@ export default abstract class BaseMultiPolygon { this.overlaysVisible = overlaysVisible; this.pointToProjection = pointToProjection; this.vectorSource = vectorSource; - this.mapBackgroundType = mapBackgroundType; + this.backgroundId = backgroundId; this.mapSize = mapSize; const maxZoom = mapInstance?.getView().get('originalMaxZoom'); @@ -371,7 +371,7 @@ export default abstract class BaseMultiPolygon { const styles: Array<Style> = []; const scale = this.minResolution / resolution; - if (this.mapBackgroundType === MapBackgroundsEnum.SEMANTIC && scale < TEXT_CUTOFF_SCALE) { + if (this.backgroundId === MapBackgroundsEnum.SEMANTIC && scale < TEXT_CUTOFF_SCALE) { const { hide, coverStyle } = this.processSemanticView(feature, resolution, scale); if (hide) { return undefined; diff --git a/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts b/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts index 10802411741585f4e58b1e926fc5176c7d3609d9..76770a4bec63953d3f36ed140145f2e777b28398 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts @@ -45,7 +45,7 @@ export interface CompartmentProps { pointToProjection: UsePointToProjectionResult; mapInstance: MapInstance; vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; } @@ -90,7 +90,7 @@ export default abstract class Compartment extends BaseMultiPolygon { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }: CompartmentProps) { super({ @@ -118,7 +118,7 @@ export default abstract class Compartment extends BaseMultiPolygon { pointToProjection, overlaysVisible, vectorSource, - mapBackgroundType, + backgroundId, mapSize, mapInstance, }); diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts index eb94b525b31a0e851c95be6f9caf2be967e8be9e..1d5f41d6dedb945ea9299475fb4c18a4bf647f76 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts @@ -67,7 +67,7 @@ describe('CompartmentCircle', () => { pointToProjection: jest.fn(), mapInstance, vectorSource: new VectorSource(), - mapBackgroundType: MapBackgroundsEnum.SEMANTIC, + backgroundId: MapBackgroundsEnum.SEMANTIC, mapSize: { minZoom: 1, maxZoom: 9, diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts index 78915ae4567c4629d0843c24bed61bbb7edff75a..0de0037bb5e440153f67297d22f8c82fc110233d 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts @@ -42,7 +42,7 @@ export type CompartmentCircleProps = { pointToProjection: UsePointToProjectionResult; mapInstance: MapInstance; vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; }; @@ -75,7 +75,7 @@ export default class CompartmentCircle extends Compartment { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }: CompartmentCircleProps) { super({ @@ -106,7 +106,7 @@ export default class CompartmentCircle extends Compartment { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }); } diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts index 05e1801ecdaea7a390812d3dc8e21c3ed4632c2f..0b0da3b41ac5474a087c52112217ec9fc6deacc6 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts @@ -65,7 +65,7 @@ describe('CompartmentPathway', () => { pointToProjection: jest.fn(() => [10, 10]), mapInstance, vectorSource: new VectorSource(), - mapBackgroundType: MapBackgroundsEnum.SEMANTIC, + backgroundId: MapBackgroundsEnum.SEMANTIC, mapSize: { minZoom: 1, maxZoom: 9, diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts index 940346776d9be8ade9372773a211b59de1aaf870..bf6b269e8dc4b8ff4c75d4dd79bd51a3615256dd 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts @@ -45,7 +45,7 @@ export type CompartmentPathwayProps = { pointToProjection: UsePointToProjectionResult; mapInstance: MapInstance; vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; }; @@ -80,7 +80,7 @@ export default class CompartmentPathway extends BaseMultiPolygon { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }: CompartmentPathwayProps) { super({ @@ -108,7 +108,7 @@ export default class CompartmentPathway extends BaseMultiPolygon { pointToProjection, overlaysVisible, vectorSource, - mapBackgroundType, + backgroundId, mapSize, mapInstance, }); diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts index acf2471c9b9fc637a13f1c8035e3c593b374d7de..ebfdcd7a5feb18c639be73daa83b363bb69287dc 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts @@ -65,7 +65,7 @@ describe('CompartmentSquare', () => { pointToProjection: jest.fn(), mapInstance, vectorSource: new VectorSource(), - mapBackgroundType: MapBackgroundsEnum.SEMANTIC, + backgroundId: MapBackgroundsEnum.SEMANTIC, mapSize: { minZoom: 1, maxZoom: 9, diff --git a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts index 34f956932f2c5a9832946a44fd64aad8cbe06018..32bb5a24c5c7e540a0cfe7feac4a103a3bf7d9f2 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts @@ -41,7 +41,7 @@ export type CompartmentSquareProps = { pointToProjection: UsePointToProjectionResult; mapInstance: MapInstance; vectorSource: VectorSource; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; }; @@ -74,7 +74,7 @@ export default class CompartmentSquare extends Compartment { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }: CompartmentSquareProps) { super({ @@ -105,7 +105,7 @@ export default class CompartmentSquare extends Compartment { pointToProjection, mapInstance, vectorSource, - mapBackgroundType, + backgroundId, mapSize, }); } diff --git a/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts index 744c6529dec3cd6eadf85b9895aec59f27a88c52..2137147cf731eed3b05fd99db72228ef33d4ca69 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts @@ -66,7 +66,7 @@ describe('MapElement', () => { overlaysVisible: false, vectorSource: new VectorSource(), getOverlayColor: (): string => '#ffffff', - mapBackgroundType: MapBackgroundsEnum.SEMANTIC, + backgroundId: MapBackgroundsEnum.SEMANTIC, mapSize: { minZoom: 1, maxZoom: 9, diff --git a/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts index ead1dd13ec0bb1750bd696889f45d26deedeedbc..8f5f66d34a833f83b87e295864ebf2f6b9031ea8 100644 --- a/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts @@ -66,7 +66,7 @@ export type MapElementProps = { overlaysOrder?: Array<OverlayOrder>; overlaysVisible: boolean; getOverlayColor: GetOverlayBioEntityColorByAvailableProperties; - mapBackgroundType: number; + backgroundId: number; mapSize: MapSize; }; @@ -131,7 +131,7 @@ export default class MapElement extends BaseMultiPolygon { overlaysOrder = [], overlaysVisible, getOverlayColor, - mapBackgroundType, + backgroundId, mapSize, }: MapElementProps) { super({ @@ -159,7 +159,7 @@ export default class MapElement extends BaseMultiPolygon { pointToProjection, vectorSource, overlaysVisible, - mapBackgroundType, + backgroundId, mapSize, mapInstance, }); diff --git a/src/components/Map/MapViewer/utils/useOlMap.test.ts b/src/components/Map/MapViewer/utils/useOlMap.test.ts index 79bc1ed1bb956a9ad94c51a635a721d6a1a93f3d..5b5fa97bfb941ce2007dea7da7566aba0086f9c1 100644 --- a/src/components/Map/MapViewer/utils/useOlMap.test.ts +++ b/src/components/Map/MapViewer/utils/useOlMap.test.ts @@ -3,7 +3,6 @@ import { Map } from 'ol'; import React from 'react'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { BACKGROUND_INITIAL_STATE_MOCK } from '@/redux/backgrounds/background.mock'; import { useOlMap } from './useOlMap'; const useRefValue = { @@ -30,7 +29,6 @@ jest.spyOn(React, 'useRef').mockReturnValue(useRefValue); describe('useOlMap - util', () => { const { Wrapper } = getReduxWrapperWithStore({ map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, }); describe('when initializing', () => { diff --git a/src/constants/backgrounds.ts b/src/constants/backgrounds.ts deleted file mode 100644 index 1bfb46194f374830b2b9ba89d807cbec4dc658fa..0000000000000000000000000000000000000000 --- a/src/constants/backgrounds.ts +++ /dev/null @@ -1 +0,0 @@ -export const EMPTY_BACKGROUND_NAME = 'Empty'; diff --git a/src/models/fixtures/backgroundsFixture.ts b/src/models/fixtures/backgroundsFixture.ts deleted file mode 100644 index e06e5c15e67fea0ee563e14f80792846f5ed998c..0000000000000000000000000000000000000000 --- a/src/models/fixtures/backgroundsFixture.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ZOD_SEED } from '@/constants'; -import { z } from 'zod'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { createFixture } from 'zod-fixture'; -import { mapBackground } from '../mapBackground'; - -export const backgroundsFixture = createFixture(z.array(mapBackground), { - seed: ZOD_SEED, - array: { min: 2, max: 2 }, -}); diff --git a/src/models/mapBackground.ts b/src/models/mapBackground.ts deleted file mode 100644 index fe6c6e9e1319bad70bd7f627192caea855fd1b6c..0000000000000000000000000000000000000000 --- a/src/models/mapBackground.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { z } from 'zod'; - -export const mapBackground = z.object({ - id: z.number(), - name: z.string(), - defaultOverlay: z.boolean(), - project: z.object({ projectId: z.string() }), - creator: z.object({ login: z.string() }), - status: z.string(), - progress: z.number(), - description: z.string().nullable(), - order: z.number(), - images: z.array( - z.object({ - id: z.number(), - model: z.object({ id: z.number() }), - projectBackground: z.object({ id: z.number() }), - path: z.string(), - }), - ), -}); diff --git a/src/redux/apiPath.ts b/src/redux/apiPath.ts index d20f1a79e61bf3bdcc8955178f1e22b4c5f9ed5c..1e0c81b808574ee25b445dd68a7add92185f5764 100644 --- a/src/redux/apiPath.ts +++ b/src/redux/apiPath.ts @@ -89,8 +89,6 @@ export const apiPath = { projectId: string, { publicOverlay }: { publicOverlay: boolean }, ): string => `projects/${projectId}/overlays/?isPublic=${String(publicOverlay)}`, - getAllBackgroundsByProjectIdQuery: (projectId: string): string => - `projects/${projectId}/backgrounds/`, getProjectById: (projectId: string): string => `projects/${projectId}`, getProjects: (): string => `projects/`, getSessionValid: (): string => `users/isSessionValid`, diff --git a/src/redux/backgrounds/background.mock.ts b/src/redux/backgrounds/background.mock.ts deleted file mode 100644 index 515bb7249c74207a0435d8a220ac24da9ad55b6e..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/background.mock.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { DEFAULT_ERROR } from '@/constants/errors'; -import { MapBackground } from '@/types/models'; -import { BackgroundsState } from './backgrounds.types'; - -export const BACKGROUND_INITIAL_STATE_MOCK: BackgroundsState = { - data: undefined, - loading: 'idle', - error: DEFAULT_ERROR, -}; - -export const BACKGROUNDS_MOCK: MapBackground[] = [ - { - id: 13, - name: 'Pathways and compartments', - defaultOverlay: false, - project: { - projectId: 'pdmap_appu_test', - }, - creator: { - login: 'admin', - }, - status: 'NA', - progress: 0, - description: null, - order: 0, - images: [], - }, - { - id: 14, - name: 'Network', - defaultOverlay: false, - project: { - projectId: 'pdmap_appu_test', - }, - creator: { - login: 'admin', - }, - status: 'NA', - progress: 0, - description: null, - order: 1, - images: [], - }, - { - id: 15, - name: 'Empty', - defaultOverlay: false, - project: { - projectId: 'pdmap_appu_test', - }, - creator: { - login: 'admin', - }, - status: 'NA', - progress: 0, - description: null, - order: 2, - images: [], - }, -]; diff --git a/src/redux/backgrounds/background.selectors.ts b/src/redux/backgrounds/background.selectors.ts deleted file mode 100644 index eda3703446dc38a0ca3aa4997b99296f1e48cba9..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/background.selectors.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { EMPTY_BACKGROUND_NAME } from '@/constants/backgrounds'; -import { createSelector } from '@reduxjs/toolkit'; -import { mapDataSelector } from '../map/map.selectors'; -import { rootSelector } from '../root/root.selectors'; -import { PATHWAYS_AND_COMPARTMENTS_BACKGROUND, SEMANTIC_BACKGROUND } from './backgrounds.constants'; - -export const backgroundsSelector = createSelector(rootSelector, state => state.backgrounds); - -export const backgroundsDataSelector = createSelector(backgroundsSelector, backgrounds => { - return (backgrounds?.data || []).map(background => { - if (background.name === PATHWAYS_AND_COMPARTMENTS_BACKGROUND) { - return { - ...background, - name: SEMANTIC_BACKGROUND, - }; - } - - return background; - }); -}); - -const MAIN_BACKGROUND = 0; -export const mainBackgroundsDataSelector = createSelector( - backgroundsDataSelector, - backgrounds => backgrounds && backgrounds[MAIN_BACKGROUND], -); -export const mainBackgroundIdSelector = createSelector( - backgroundsDataSelector, - backgrounds => backgrounds && backgrounds[MAIN_BACKGROUND]?.id, -); - -export const currentBackgroundSelector = createSelector( - backgroundsDataSelector, - mapDataSelector, - (backgrounds, mapData) => - backgrounds && backgrounds.find(background => background.id === mapData.backgroundId), -); - -export const currentBackgroundImageSelector = createSelector( - mapDataSelector, - currentBackgroundSelector, - (mapData, background) => - background && background.images.find(image => image.model.id === mapData.modelId), -); - -export const currentBackgroundImagePathSelector = createSelector( - currentBackgroundImageSelector, - image => (image ? image.path : ''), -); - -export const emptyBackgroundIdSelector = createSelector(backgroundsDataSelector, backgrounds => { - const emptyBackground = backgrounds?.find( - background => background.name === EMPTY_BACKGROUND_NAME, - ); - return emptyBackground?.id; -}); diff --git a/src/redux/backgrounds/backgrounds.constants.ts b/src/redux/backgrounds/backgrounds.constants.ts deleted file mode 100644 index 49499431e770bfcc5f57a0678931b71475a346eb..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.constants.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const BACKGROUNDS_FETCHING_ERROR_PREFIX = 'Failed to fetch backgrounds'; -export const PATHWAYS_AND_COMPARTMENTS_BACKGROUND = 'Pathways and compartments'; -export const SEMANTIC_BACKGROUND = 'Semantic'; diff --git a/src/redux/backgrounds/backgrounds.reducers.test.ts b/src/redux/backgrounds/backgrounds.reducers.test.ts deleted file mode 100644 index dd13a7711f9d39428ffa0ea0d3b22f90a448a962..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.reducers.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { PROJECT_ID } from '@/constants'; -import { backgroundsFixture } from '@/models/fixtures/backgroundsFixture'; -import { - ToolkitStoreWithSingleSlice, - createStoreInstanceUsingSliceReducer, -} from '@/utils/createStoreInstanceUsingSliceReducer'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { HttpStatusCode } from 'axios'; -import { unwrapResult } from '@reduxjs/toolkit'; -import { apiPath } from '../apiPath'; -import backgroundsReducer from './backgrounds.slice'; -import { getAllBackgroundsByProjectId } from './backgrounds.thunks'; -import { BackgroundsState } from './backgrounds.types'; - -jest.mock('../../utils/showToast'); - -const mockedAxiosClient = mockNetworkResponse(); - -const INITIAL_STATE: BackgroundsState = { - data: [], - loading: 'idle', - error: { name: '', message: '' }, -}; - -describe('backgrounds reducer', () => { - let store = {} as ToolkitStoreWithSingleSlice<BackgroundsState>; - beforeEach(() => { - store = createStoreInstanceUsingSliceReducer('backgrounds', backgroundsReducer); - }); - - it('should match initial state', () => { - const action = { type: 'unknown' }; - - expect(backgroundsReducer(undefined, action)).toEqual(INITIAL_STATE); - }); - it('should update store after succesfull getAllBackgroundsByProjectId query', async () => { - mockedAxiosClient - .onGet(apiPath.getAllBackgroundsByProjectIdQuery(PROJECT_ID)) - .reply(HttpStatusCode.Ok, backgroundsFixture); - - const { type } = await store.dispatch(getAllBackgroundsByProjectId(PROJECT_ID)); - const { data, loading, error } = store.getState().backgrounds; - - expect(type).toBe('backgrounds/getAllBackgroundsByProjectId/fulfilled'); - expect(loading).toEqual('succeeded'); - expect(error).toEqual({ message: '', name: '' }); - expect(data).toEqual(backgroundsFixture); - }); - - it('should update store after failed getAllBackgroundsByProjectId query', async () => { - mockedAxiosClient - .onGet(apiPath.getAllBackgroundsByProjectIdQuery(PROJECT_ID)) - .reply(HttpStatusCode.NotFound, []); - - const action = await store.dispatch(getAllBackgroundsByProjectId(PROJECT_ID)); - const { data, loading, error } = store.getState().backgrounds; - - expect(action.type).toBe('backgrounds/getAllBackgroundsByProjectId/rejected'); - expect(loading).toEqual('failed'); - expect(error).toEqual({ message: '', name: '' }); - expect(data).toEqual([]); - expect(() => unwrapResult(action)).toThrow( - "Failed to fetch backgrounds: The page you're looking for doesn't exist. Please verify the URL and try again.", - ); - }); - - it('should update store on loading getAllBackgroundsByProjectId query', async () => { - mockedAxiosClient - .onGet(apiPath.getAllBackgroundsByProjectIdQuery(PROJECT_ID)) - .reply(HttpStatusCode.Ok, backgroundsFixture); - - const actionPromise = store.dispatch(getAllBackgroundsByProjectId(PROJECT_ID)); - - const { data, loading } = store.getState().backgrounds; - expect(data).toEqual([]); - expect(loading).toEqual('pending'); - - actionPromise.then(() => { - const { data: dataPromiseFulfilled, loading: promiseFulfilled } = - store.getState().backgrounds; - - expect(dataPromiseFulfilled).toEqual(backgroundsFixture); - expect(promiseFulfilled).toEqual('succeeded'); - }); - }); -}); diff --git a/src/redux/backgrounds/backgrounds.reducers.ts b/src/redux/backgrounds/backgrounds.reducers.ts deleted file mode 100644 index 2f0868b4a10d853b4c4d74e5ec913e42b05df9b9..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.reducers.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; -import { getAllBackgroundsByProjectId } from './backgrounds.thunks'; -import { BackgroundsState } from './backgrounds.types'; - -export const getAllBackgroundsByProjectIdReducer = ( - builder: ActionReducerMapBuilder<BackgroundsState>, -): void => { - builder.addCase(getAllBackgroundsByProjectId.pending, state => { - state.loading = 'pending'; - }); - builder.addCase(getAllBackgroundsByProjectId.fulfilled, (state, action) => { - state.data = action.payload || []; - state.loading = 'succeeded'; - }); - builder.addCase(getAllBackgroundsByProjectId.rejected, state => { - state.loading = 'failed'; - // TODO to discuss manage state of failure - }); -}; diff --git a/src/redux/backgrounds/backgrounds.slice.ts b/src/redux/backgrounds/backgrounds.slice.ts deleted file mode 100644 index 491e981d8d91db22a34f03dff1a14559b746d642..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.slice.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; -import { getAllBackgroundsByProjectIdReducer } from './backgrounds.reducers'; -import { BackgroundsState } from './backgrounds.types'; - -const initialState: BackgroundsState = { - data: [], - loading: 'idle', - error: { name: '', message: '' }, -}; - -const backgroundsState = createSlice({ - name: 'backgrounds', - initialState, - reducers: {}, - extraReducers: builder => { - getAllBackgroundsByProjectIdReducer(builder); - }, -}); - -export default backgroundsState.reducer; diff --git a/src/redux/backgrounds/backgrounds.thunks.ts b/src/redux/backgrounds/backgrounds.thunks.ts deleted file mode 100644 index d2ce1949ef25fd4f9768f23e63e556925be48b2b..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.thunks.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { mapBackground } from '@/models/mapBackground'; -import { axiosInstance } from '@/services/api/utils/axiosInstance'; -import { MapBackground } from '@/types/models'; -import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; -import { createAsyncThunk } from '@reduxjs/toolkit'; -import { z } from 'zod'; -import { ThunkConfig } from '@/types/store'; -import { getError } from '@/utils/error-report/getError'; -import { apiPath } from '../apiPath'; -import { BACKGROUNDS_FETCHING_ERROR_PREFIX } from './backgrounds.constants'; - -export const getAllBackgroundsByProjectId = createAsyncThunk<MapBackground[], string, ThunkConfig>( - 'backgrounds/getAllBackgroundsByProjectId', - async (projectId: string) => { - try { - const response = await axiosInstance.get<MapBackground[]>( - apiPath.getAllBackgroundsByProjectIdQuery(projectId), - ); - - const isDataValid = validateDataUsingZodSchema(response.data, z.array(mapBackground)); - - return isDataValid ? response.data : []; - } catch (error) { - return Promise.reject(getError({ error, prefix: BACKGROUNDS_FETCHING_ERROR_PREFIX })); - } - }, -); diff --git a/src/redux/backgrounds/backgrounds.types.ts b/src/redux/backgrounds/backgrounds.types.ts deleted file mode 100644 index 7ce8fcfc7643e9ea526d79895928037fd19d27b8..0000000000000000000000000000000000000000 --- a/src/redux/backgrounds/backgrounds.types.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FetchDataState } from '@/types/fetchDataState'; -import { MapBackground } from '@/types/models'; - -export type BackgroundsState = FetchDataState<MapBackground[]>; diff --git a/src/redux/map/map.constants.ts b/src/redux/map/map.constants.ts index 55b67d50eb035d951828d2d97e23891ebaee4a83..92de423dbafd9a7d61d155f5ff2171dd478bcbb1 100644 --- a/src/redux/map/map.constants.ts +++ b/src/redux/map/map.constants.ts @@ -18,7 +18,7 @@ export const MAP_BACKGROUND_TYPES = [ export const MODEL_ID_DEFAULT: number = 0; -export const BACKGROUND_ID_DEFAULT: number = 0; +export const BACKGROUND_ID_DEFAULT: number = MapBackgroundsEnum.SEMANTIC; export const OVERVIEW_IMAGE_ID_DEFAULT: number = 0; @@ -73,7 +73,6 @@ export const MAP_INITIAL_STATE: MapState = { loading: 'idle', error: { name: '', message: '' }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }; export const INIT_MAP_SIZE_MODEL_ID_ERROR_PREFIX = 'Failed to initialize map size and model ID'; diff --git a/src/redux/map/map.fixtures.ts b/src/redux/map/map.fixtures.ts index 21674c65af5aac7d322980696da5e9acf65c84ed..77d17df669117c8e40c8b81adff2c2f2383d1580 100644 --- a/src/redux/map/map.fixtures.ts +++ b/src/redux/map/map.fixtures.ts @@ -22,7 +22,7 @@ export const initialMapDataFixture: MapData = { projectId: 'pdmap', meshId: '', modelId: 0, - backgroundId: 0, + backgroundId: MapBackgroundsEnum.SEMANTIC, overlaysIds: [], position: { initial: { x: 0, y: 0, z: 5 }, @@ -60,7 +60,6 @@ export const initialMapStateFixture: MapState = { loading: 'idle', error: DEFAULT_ERROR, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }; export const mapStateWithCurrentlySelectedMainMapFixture: MapState = { @@ -78,5 +77,4 @@ export const mapStateWithCurrentlySelectedMainMapFixture: MapState = { loading: 'idle', error: DEFAULT_ERROR, openedMaps: openedMapsInitialValueFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }; diff --git a/src/redux/map/map.reducers.ts b/src/redux/map/map.reducers.ts index 5ae6707d283f8a037a537100d8f99d6dd1e23d62..553ad6174bafe72ad673348b7096bbc2a265a0ab 100644 --- a/src/redux/map/map.reducers.ts +++ b/src/redux/map/map.reducers.ts @@ -1,6 +1,6 @@ import { DEFAULT_ZOOM } from '@/constants/map'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; -import { ActionReducerMapBuilder, PayloadAction } from '@reduxjs/toolkit'; +import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import { getPointMerged } from '@/utils/object/getPointMerged'; import { initMapBackground, @@ -221,11 +221,3 @@ export const initOpenedMapsReducer = (builder: ActionReducerMapBuilder<MapState> state.openedMaps = action.payload; }); }; - -export const setMapBackgroundTypeReducer = ( - state: MapState, - action: PayloadAction<number>, -): void => { - const { payload } = action; - state.backgroundType = payload; -}; diff --git a/src/redux/map/map.selectors.ts b/src/redux/map/map.selectors.ts index 8cb88035a07364e800f227f5361345112ab98e88..92737498e2fbe7f002dfd4b001c319961ca10f28 100644 --- a/src/redux/map/map.selectors.ts +++ b/src/redux/map/map.selectors.ts @@ -35,4 +35,4 @@ export const mapDataLastZoomValue = createSelector( export const mapDataMaxZoomValue = createSelector(mapDataSizeSelector, model => model.maxZoom); -export const mapBackgroundTypeSelector = createSelector(mapSelector, map => map.backgroundType); +export const mapBackgroundSelector = createSelector(mapSelector, map => map.data.backgroundId); diff --git a/src/redux/map/map.slice.ts b/src/redux/map/map.slice.ts index dbfd8bbe316b76183fd1f37884cf2dec618e1b2b..3106a118eaa14cdcc373ea0366b74c53e121dffb 100644 --- a/src/redux/map/map.slice.ts +++ b/src/redux/map/map.slice.ts @@ -12,7 +12,6 @@ import { setActiveMapReducer, setLastPositionZoomReducer, setMapBackgroundReducer, - setMapBackgroundTypeReducer, setMapDataReducer, setMapPositionReducer, updateLastClickReducer, @@ -36,7 +35,6 @@ const mapSlice = createSlice({ setLastPositionZoom: setLastPositionZoomReducer, updateLastClick: updateLastClickReducer, updateLastRightClick: updateLastRightClickReducer, - setMapBackgroundType: setMapBackgroundTypeReducer, }, extraReducers: builder => { initMapPositionReducers(builder); @@ -59,7 +57,6 @@ export const { setLastPositionZoom, updateLastClick, updateLastRightClick, - setMapBackgroundType, } = mapSlice.actions; export default mapSlice.reducer; diff --git a/src/redux/map/map.thunks.test.ts b/src/redux/map/map.thunks.test.ts index b44d0fd824b9540377b335ebefaded9cd727a8b7..81feb7da60b6c941b7d64469fc06c34c743d634c 100644 --- a/src/redux/map/map.thunks.test.ts +++ b/src/redux/map/map.thunks.test.ts @@ -6,7 +6,7 @@ import { Project } from '@/types/models'; import { PROJECT_STATE_INITIAL_MOCK } from '@/redux/project/project.mock'; import { ProjectState } from '@/redux/project/project.types'; import { MAIN_MAP_ID } from '@/constants/mocks'; -import { BACKGROUNDS_MOCK, BACKGROUND_INITIAL_STATE_MOCK } from '../backgrounds/background.mock'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MODELS_INITIAL_STATE_MOCK } from '../models/models.mock'; import { INITIAL_STORE_STATE_MOCK } from '../root/root.fixtures'; import { RootState } from '../store'; @@ -68,33 +68,27 @@ const STATE_WITH_MODELS: RootState = { describe('map thunks - utils', () => { describe('getBackgroundId', () => { - it('should return backgroundId value from queryData', () => { - const backgroundId = getBackgroundId(INITIAL_STORE_STATE_MOCK, QUERY_DATA_WITH_BG); - expect(backgroundId).toBe(21); - }); - it('should return main map background id if query param does not include background id', () => { + it('should return main map background id (2 - semantic) if query param does not include background id', () => { const store: RootState = { ...INITIAL_STORE_STATE_MOCK, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }; const backgroundId = getBackgroundId(store, EMPTY_QUERY_DATA); - expect(backgroundId).toBe(13); + expect(backgroundId).toBe(MapBackgroundsEnum.SEMANTIC); }); - it('should return default value (0) if query data does not include backgroundId and could not find main background in the store', () => { + it('should return default value (2 - semantic) if query data does not include backgroundId and could not find main background in the store', () => { const backgroundId = getBackgroundId(INITIAL_STORE_STATE_MOCK, EMPTY_QUERY_DATA); - expect(backgroundId).toBe(0); + expect(backgroundId).toBe(MapBackgroundsEnum.SEMANTIC); }); - it('should return main map background id if query param background id is invalid', () => { + it('should return semantic map background id if query param background id is invalid', () => { const store: RootState = { ...INITIAL_STORE_STATE_MOCK, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, }; const backgroundId = getBackgroundId(store, QUERY_DATA_WITH_BG); - expect(backgroundId).toBe(13); + expect(backgroundId).toBe(MapBackgroundsEnum.SEMANTIC); }); }); diff --git a/src/redux/map/map.thunks.ts b/src/redux/map/map.thunks.ts index 363b1d9c02c8479a01abf2a8f91078125c52b621..bb1a81d314e93c7fa4b10301825242fa0b6800a5 100644 --- a/src/redux/map/map.thunks.ts +++ b/src/redux/map/map.thunks.ts @@ -7,6 +7,7 @@ import { getPointMerged } from '@/utils/object/getPointMerged'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { ThunkConfig } from '@/types/store'; import { getError } from '@/utils/error-report/getError'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; import type { AppDispatch, RootState } from '../store'; import { InitMapBackgroundActionPayload, @@ -21,10 +22,6 @@ import { OppenedMap, Position, } from './map.types'; -import { - backgroundsDataSelector, - mainBackgroundsDataSelector, -} from '../backgrounds/background.selectors'; import { currentModelSelector, mainMapModelSelector, @@ -43,21 +40,13 @@ import { /** UTILS - in the same file because of dependency cycle */ export const getBackgroundId = (state: RootState, queryData: QueryData): number => { - const mainMapBackground = mainBackgroundsDataSelector(state); - const backgrounds = backgroundsDataSelector(state); - let backgroundId = queryData?.backgroundId || mainMapBackground?.id || ZERO; + let backgroundId = queryData?.backgroundId; - if (backgrounds.length > 0) { - if ( - backgrounds.filter(background => { - return background.id === backgroundId; - }).length === 0 - ) { - backgroundId = backgrounds[ZERO].id; - } + if (!backgroundId || !Object.values(MapBackgroundsEnum).includes(backgroundId)) { + backgroundId = MapBackgroundsEnum.SEMANTIC; } - if (backgroundId !== mainMapBackground?.id) { + if (backgroundId !== MapBackgroundsEnum.SEMANTIC) { PluginsEventBus.dispatchEvent('onBackgroundOverlayChange', backgroundId); } diff --git a/src/redux/map/map.types.ts b/src/redux/map/map.types.ts index dc838aaa4ff842eaed325314c6149c6ab7f5836d..72b600dcf1a42cc08ea329d65d82144db088abaa 100644 --- a/src/redux/map/map.types.ts +++ b/src/redux/map/map.types.ts @@ -44,9 +44,7 @@ export type MapData = { }; }; -export type MapState = FetchDataState<MapData, MapData> & { openedMaps: OppenedMap[] } & { - backgroundType: number; -}; +export type MapState = FetchDataState<MapData, MapData> & { openedMaps: OppenedMap[] }; export type SetMapDataActionPayload = | (Omit<Partial<MapData>, 'position' | 'projectId'> & { diff --git a/src/redux/map/middleware/checkIfIsMapUpdateActionValid.test.ts b/src/redux/map/middleware/checkIfIsMapUpdateActionValid.test.ts index 1509a08944985fd50828be7932f272ba5b4864dd..5580c0242b1e669dddc051a2f0f181a0e0ebe8c4 100644 --- a/src/redux/map/middleware/checkIfIsMapUpdateActionValid.test.ts +++ b/src/redux/map/middleware/checkIfIsMapUpdateActionValid.test.ts @@ -1,6 +1,5 @@ import { RootState } from '@/redux/store'; import { Loading } from '@/types/loadingState'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MAP_DATA_INITIAL_STATE, MIDDLEWARE_ALLOWED_ACTIONS, @@ -18,7 +17,6 @@ const state: Pick<RootState, 'map'> = { loading: 'idle' as Loading, error: { name: '', message: '' }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }; diff --git a/src/redux/map/middleware/map.middleware.test.ts b/src/redux/map/middleware/map.middleware.test.ts index cb928afd24b3272fe030444861946c6c5ceaf95a..b783347eadc765d134bc0692faee79c878cf4d2b 100644 --- a/src/redux/map/middleware/map.middleware.test.ts +++ b/src/redux/map/middleware/map.middleware.test.ts @@ -3,7 +3,6 @@ import { modelsFixture } from '@/models/fixtures/modelsFixture'; import { Loading } from '@/types/loadingState'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { Action } from '@reduxjs/toolkit'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MAP_DATA_INITIAL_STATE, MIDDLEWARE_ALLOWED_ACTIONS, @@ -64,7 +63,6 @@ const { store } = getReduxWrapperWithStore({ modelId: modelsFixture[0].id, }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { ...defaultSliceState, diff --git a/src/redux/map/middleware/map.middleware.ts b/src/redux/map/middleware/map.middleware.ts index bacbb729dd6ff290e3861487912d61f071d9ea32..d4eef340ecc8db9e115197de10794ff2ecc21462 100644 --- a/src/redux/map/middleware/map.middleware.ts +++ b/src/redux/map/middleware/map.middleware.ts @@ -1,8 +1,7 @@ -import { currentBackgroundSelector } from '@/redux/backgrounds/background.selectors'; import type { AppListenerEffectAPI, AppStartListening } from '@/redux/store'; import { getUpdatedMapData } from '@/utils/map/getUpdatedMapData'; import { Action, createListenerMiddleware, isAnyOf } from '@reduxjs/toolkit'; -import { mapOpenedMapPositionByIdSelector } from '../map.selectors'; +import { mapBackgroundSelector, mapOpenedMapPositionByIdSelector } from '../map.selectors'; import { closeMapAndSetMainMapActive, openMapAndOrSetActiveIfSelected, @@ -31,7 +30,7 @@ export const mapDataMiddlewareListener = async ( return; } - const background = currentBackgroundSelector(state); + const background = mapBackgroundSelector(state); const modelId = updatedModel.id; const lastPosition = mapOpenedMapPositionByIdSelector(state, modelId); const updatedMapData = getUpdatedMapData({ diff --git a/src/redux/overlayBioEntity/overlayBioEntity.thunk.ts b/src/redux/overlayBioEntity/overlayBioEntity.thunk.ts index f726bd8fff76200318f7e4f0b40c64bfb985eb3e..c0d3daed0ab35768017fe8024ac11ffae7963d2b 100644 --- a/src/redux/overlayBioEntity/overlayBioEntity.thunk.ts +++ b/src/redux/overlayBioEntity/overlayBioEntity.thunk.ts @@ -12,8 +12,6 @@ import { import { apiPath } from '../apiPath'; import { modelsIdsSelector } from '../models/models.selectors'; import type { RootState } from '../store'; -import { setMapBackground } from '../map/map.slice'; -import { emptyBackgroundIdSelector } from '../backgrounds/background.selectors'; import { overlaySelector, userOverlaySelector } from '../overlays/overlays.selectors'; import { INIT_OVERLAYS_ERROR_PREFIX, @@ -89,11 +87,6 @@ export const getInitOverlays = createAsyncThunk< try { const state = getState(); - const emptyBackgroundId = emptyBackgroundIdSelector(state); - if (emptyBackgroundId) { - dispatch(setMapBackground(emptyBackgroundId)); - } - overlaysId.forEach(id => { const userOverlay = userOverlaySelector(state, id); const overlay = overlaySelector(state, id); diff --git a/src/redux/root/init.selectors.ts b/src/redux/root/init.selectors.ts index 67cdfa08df4a16ab64f183a41c1c741ccc62bb74..5ddcf77a923747da79dcb8030a4ade31828680ec 100644 --- a/src/redux/root/init.selectors.ts +++ b/src/redux/root/init.selectors.ts @@ -1,5 +1,4 @@ import { createSelector } from '@reduxjs/toolkit'; -import { backgroundsSelector } from '../backgrounds/background.selectors'; import { mapSelector } from '../map/map.selectors'; import { modelsSelector } from '../models/models.selectors'; import { overlaysSelector } from '../overlays/overlays.selectors'; @@ -7,7 +6,6 @@ import { projectSelector } from '../project/project.selectors'; export const initDataLoadingInitialized = createSelector( projectSelector, - backgroundsSelector, modelsSelector, overlaysSelector, (...selectors) => selectors.every(selector => selector.loading !== 'idle'), @@ -15,7 +13,6 @@ export const initDataLoadingInitialized = createSelector( export const initDataLoadingFinishedSelector = createSelector( projectSelector, - backgroundsSelector, modelsSelector, overlaysSelector, (...selectors) => selectors.every(selector => selector.loading === 'succeeded'), @@ -23,7 +20,6 @@ export const initDataLoadingFinishedSelector = createSelector( export const initDataAndMapLoadingFinished = createSelector( projectSelector, - backgroundsSelector, modelsSelector, overlaysSelector, mapSelector, diff --git a/src/redux/root/init.thunks.ts b/src/redux/root/init.thunks.ts index ba7f305972bdad744aa4ce396ae86f9a9f9b2cb6..562789dc95102028e759397bbebaf13825dd78b0 100644 --- a/src/redux/root/init.thunks.ts +++ b/src/redux/root/init.thunks.ts @@ -24,7 +24,6 @@ import { } from '@/components/FunctionalArea/CookieBanner/CookieBanner.constants'; import { injectMatomoTracking } from '@/utils/injectMatomoTracking'; import { getGlyphs } from '@/redux/glyphs/glyphs.thunks'; -import { getAllBackgroundsByProjectId } from '../backgrounds/backgrounds.thunks'; import { getConfiguration, getConfigurationOptions } from '../configuration/configuration.thunks'; import { initMapBackground, @@ -64,7 +63,6 @@ export const fetchInitialAppData = createAsyncThunk< dispatch(getConfiguration()), dispatch(getConfigurationOptions()), dispatch(getProjectById(PROJECT_ID)), - dispatch(getAllBackgroundsByProjectId(PROJECT_ID)), dispatch(getAllPublicOverlaysByProjectId(PROJECT_ID)), dispatch(getModels()), dispatch(getShapes()), diff --git a/src/redux/root/root.fixtures.ts b/src/redux/root/root.fixtures.ts index c90d96c3c158bb301cd7533634e652c0e47fec7a..f6d6110c91c93ae6dbc73c2109ac52d30180f3c1 100644 --- a/src/redux/root/root.fixtures.ts +++ b/src/redux/root/root.fixtures.ts @@ -9,7 +9,6 @@ import { LAYERS_STATE_INITIAL_MOCK } from '@/redux/layers/layers.mock'; import { NEW_REACTIONS_INITIAL_STATE_MOCK } from '@/redux/newReactions/newReactions.mock'; import { GLYPHS_STATE_INITIAL_MOCK } from '@/redux/glyphs/glyphs.mock'; import { MAP_EDIT_TOOLS_STATE_INITIAL_MOCK } from '@/redux/mapEditTools/mapEditTools.mock'; -import { BACKGROUND_INITIAL_STATE_MOCK } from '../backgrounds/background.mock'; import { BIOENTITY_INITIAL_STATE_MOCK } from '../bioEntity/bioEntity.mock'; import { CHEMICALS_INITIAL_STATE_MOCK } from '../chemicals/chemicals.mock'; import { COMPARTMENT_PATHWAYS_INITIAL_STATE_MOCK } from '../compartmentPathways/compartmentPathways.mock'; @@ -51,7 +50,6 @@ export const INITIAL_STORE_STATE_MOCK: RootState = { modelElements: MODEL_ELEMENTS_INITIAL_STATE_MOCK, layers: LAYERS_STATE_INITIAL_MOCK, bioEntity: BIOENTITY_INITIAL_STATE_MOCK, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, drawer: drawerInitialStateMock, map: initialMapStateFixture, oauth: OAUTH_INITIAL_STATE_MOCK, diff --git a/src/redux/store.ts b/src/redux/store.ts index 0e3a85b9cf87d116826427e61d973595c2c9fe79..a98370bc8f1c4f26e642fa1b2283c67fa696f381 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -1,4 +1,3 @@ -import backgroundsReducer from '@/redux/backgrounds/backgrounds.slice'; import bioEntityReducer from '@/redux/bioEntity/bioEntity.slice'; import chemicalsReducer from '@/redux/chemicals/chemicals.slice'; import configurationReducer from '@/redux/configuration/configuration.slice'; @@ -62,7 +61,6 @@ export const reducers = { drawer: drawerReducer, modal: modalReducer, map: mapReducer, - backgrounds: backgroundsReducer, overlays: overlaysReducer, models: modelsReducer, shapes: shapesReducer, diff --git a/src/services/pluginsManager/map/data/getBounds.test.ts b/src/services/pluginsManager/map/data/getBounds.test.ts index b824df10325ec77f2569016ec8c813aa32af680a..99f587dab60eacdc703580964f06e5333f4f559c 100644 --- a/src/services/pluginsManager/map/data/getBounds.test.ts +++ b/src/services/pluginsManager/map/data/getBounds.test.ts @@ -2,7 +2,6 @@ import { MAP_DATA_INITIAL_STATE } from '@/redux/map/map.constants'; import { store } from '@/redux/store'; import { Map } from 'ol'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MapManager } from '../mapManager'; import { getBounds } from './getBounds'; @@ -46,7 +45,6 @@ describe('getBounds', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, diff --git a/src/services/pluginsManager/map/fitBounds/fitBounds.test.ts b/src/services/pluginsManager/map/fitBounds/fitBounds.test.ts index de852078e266a7a2342e03011f94dcd0ce6fcd69..1fd5ec32d5a0c87f3327da2042ec443c7f8d7579 100644 --- a/src/services/pluginsManager/map/fitBounds/fitBounds.test.ts +++ b/src/services/pluginsManager/map/fitBounds/fitBounds.test.ts @@ -2,7 +2,6 @@ import { MAP_DATA_INITIAL_STATE } from '@/redux/map/map.constants'; import { Map } from 'ol'; import { store } from '@/redux/store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { fitBounds } from './fitBounds'; import { MapManager } from '../mapManager'; @@ -52,7 +51,6 @@ describe('fitBounds', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, @@ -103,7 +101,6 @@ describe('fitBounds', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, // eslint-disable-next-line @typescript-eslint/no-explicit-any }) as any, diff --git a/src/services/pluginsManager/map/openMap.test.ts b/src/services/pluginsManager/map/openMap.test.ts index 69aca9db5a1a8b97945bbd19f911512c38da782b..ddebdab0eb97cab097541199da442415b0458c0f 100644 --- a/src/services/pluginsManager/map/openMap.test.ts +++ b/src/services/pluginsManager/map/openMap.test.ts @@ -3,7 +3,6 @@ import { openMapAndSetActive, setActiveMap } from '@/redux/map/map.slice'; import { RootState, store } from '@/redux/store'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { MODELS_MOCK, MODELS_MOCK_SHORT } from '@/models/mocks/modelsMock'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks'; import { PluginsEventBus } from '../pluginsEventBus'; import { openMap } from './openMap'; @@ -27,7 +26,6 @@ describe('openMap', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK_SHORT, @@ -53,7 +51,6 @@ describe('openMap', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK, @@ -81,7 +78,6 @@ describe('openMap', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, models: { data: MODELS_MOCK, diff --git a/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.test.ts b/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.test.ts deleted file mode 100644 index 15b32c94cf7c96ce2acb9972717a7e3d412ee20b..0000000000000000000000000000000000000000 --- a/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - BACKGROUNDS_MOCK, - BACKGROUND_INITIAL_STATE_MOCK, -} from '@/redux/backgrounds/background.mock'; -import { initialMapStateFixture } from '@/redux/map/map.fixtures'; -import { RootState, store } from '@/redux/store'; -import { setBackgroundtoEmptyIfAvailable } from './setBackgroundtoEmptyIfAvailable'; - -const DEFAULT_BACKGROUND_ID = 0; -const EMPTY_BACKGROUND_ID = 15; - -describe('setEmptyBackground', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - const getStateSpy = jest.spyOn(store, 'getState'); - const dispatchSpy = jest.spyOn(store, 'dispatch'); - it('should not set background to empty if its not available', () => { - getStateSpy.mockImplementation( - () => - ({ - map: initialMapStateFixture, - backgrounds: BACKGROUND_INITIAL_STATE_MOCK, - }) as RootState, - ); - - expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); - - setBackgroundtoEmptyIfAvailable(); - - expect(dispatchSpy).not.toHaveBeenCalled(); - }); - - it('should set background to empty if its available', () => { - getStateSpy.mockImplementation( - () => - ({ - map: initialMapStateFixture, - backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK }, - }) as RootState, - ); - - expect(store.getState().map.data.backgroundId).toBe(DEFAULT_BACKGROUND_ID); - - setBackgroundtoEmptyIfAvailable(); - - expect(dispatchSpy).toHaveBeenCalledWith({ - payload: EMPTY_BACKGROUND_ID, - type: 'map/setMapBackground', - }); - }); -}); diff --git a/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.ts b/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.ts deleted file mode 100644 index 59c6c06103cdaff3be28cfaaa149e1337f8e39f1..0000000000000000000000000000000000000000 --- a/src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { emptyBackgroundIdSelector } from '@/redux/backgrounds/background.selectors'; -import { setMapBackground } from '@/redux/map/map.slice'; -import { store } from '@/redux/store'; - -export const setBackgroundtoEmptyIfAvailable = (): void => { - const { dispatch, getState } = store; - const emptyBackgroundId = emptyBackgroundIdSelector(getState()); - - if (emptyBackgroundId) { - dispatch(setMapBackground(emptyBackgroundId)); - } -}; diff --git a/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.test.ts b/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.test.ts index da92e7f915ce3c20495cc1ef696fb7b3787cc114..7709f9ec650974834f2503749d90de29d131c67e 100644 --- a/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.test.ts +++ b/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.test.ts @@ -11,11 +11,9 @@ import { import { getOverlayBioEntityForAllModels } from '@/redux/overlayBioEntity/overlayBioEntity.thunk'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { showDataOverlay } from './showDataOverlay'; -import { setBackgroundtoEmptyIfAvailable } from './setBackgroundtoEmptyIfAvailable'; jest.mock('../../../../../redux/overlayBioEntity/overlayBioEntity.thunk'); jest.mock('../../../../../redux/store'); -jest.mock('./setBackgroundtoEmptyIfAvailable'); const OVERLAY_ID = overlaysPageFixture.content[0].idObject; @@ -110,45 +108,4 @@ describe('showDataOverlay function', () => { overlaysPageFixture.content[0], ); }); - - it('should not set empty background when it show overlay', () => { - getStateSpy.mockImplementation( - () => - ({ - overlays: { - ...OVERLAYS_INITIAL_STATE_MOCK, - userOverlays: { - data: overlaysPageFixture.content, - loading: 'idle', - error: DEFAULT_ERROR, - }, - }, - overlayBioEntity: { ...OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK }, - }) as RootState, - ); - - showDataOverlay(OVERLAY_ID); - - expect(setBackgroundtoEmptyIfAvailable).not.toHaveBeenCalled(); - }); - it('should set empty background when it show overlay if setBackgroundEmpty is true', () => { - getStateSpy.mockImplementation( - () => - ({ - overlays: { - ...OVERLAYS_INITIAL_STATE_MOCK, - userOverlays: { - data: overlaysPageFixture.content, - loading: 'idle', - error: DEFAULT_ERROR, - }, - }, - overlayBioEntity: { ...OVERLAY_BIO_ENTITY_INITIAL_STATE_MOCK }, - }) as RootState, - ); - - showDataOverlay(OVERLAY_ID, true); - - expect(setBackgroundtoEmptyIfAvailable).toHaveBeenCalled(); - }); }); diff --git a/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.ts b/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.ts index 8304beed8c8ddf35a0ec97f6f9d4ce90cb76efce..34359036d54d2b13ba498518592773baae5cb709 100644 --- a/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.ts +++ b/src/services/pluginsManager/map/overlays/showDataOverlay/showDataOverlay.ts @@ -7,7 +7,8 @@ import { ERROR_OVERLAY_ID_ALREADY_ACTIVE, ERROR_OVERLAY_ID_NOT_FOUND, } from '@/services/pluginsManager/errorMessages'; -import { setBackgroundtoEmptyIfAvailable } from './setBackgroundtoEmptyIfAvailable'; +import { setMapBackground } from '@/redux/map/map.slice'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; export const showDataOverlay = (overlayId: number, setBackgroundEmpty?: boolean): void => { const { dispatch, getState } = store; @@ -25,7 +26,7 @@ export const showDataOverlay = (overlayId: number, setBackgroundEmpty?: boolean) } if (setBackgroundEmpty) { - setBackgroundtoEmptyIfAvailable(); + dispatch(setMapBackground(MapBackgroundsEnum.SEMANTIC)); } dispatch(getOverlayBioEntityForAllModels({ overlayId })); diff --git a/src/services/pluginsManager/map/position/getCenter.test.ts b/src/services/pluginsManager/map/position/getCenter.test.ts index fe23d527e9cd9e816912430d615bf272c6c5333c..f9d9dd545bda215f262f039e2d9c5f2ae7349ab5 100644 --- a/src/services/pluginsManager/map/position/getCenter.test.ts +++ b/src/services/pluginsManager/map/position/getCenter.test.ts @@ -1,6 +1,5 @@ import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { RootState, store } from '@/redux/store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { getCenter } from './getCenter'; jest.mock('../../../../redux/store'); @@ -26,7 +25,6 @@ describe('getCenter - plugin method', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }) as RootState, ); diff --git a/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts b/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts index 293f9476661069b2c9edaa882a2cdb445b8e0f86..abb470aa4b1fc5e1738a4b2962b0b36b2c168431 100644 --- a/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts +++ b/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts @@ -11,7 +11,6 @@ import { RootState, store } from '@/redux/store'; import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; import { waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { triggerSearch } from './triggerSearch'; import { ERROR_INVALID_MODEL_ID_TYPE } from '../../errorMessages'; @@ -30,7 +29,6 @@ const MOCK_STATE = { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, configuration: CONFIGURATION_INITIAL_STORE_MOCKS, }; diff --git a/src/services/pluginsManager/map/zoom/getZoom.test.ts b/src/services/pluginsManager/map/zoom/getZoom.test.ts index 669d8773b813f557294555dec1f34ea6a81c2cff..b7808d53163d34fa802f14c8e090119590c3c11f 100644 --- a/src/services/pluginsManager/map/zoom/getZoom.test.ts +++ b/src/services/pluginsManager/map/zoom/getZoom.test.ts @@ -1,7 +1,6 @@ /* eslint-disable no-magic-numbers */ import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { RootState, store } from '@/redux/store'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { getZoom } from './getZoom'; jest.mock('../../../../redux/store'); @@ -29,7 +28,6 @@ describe('getZoom - plugin method', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }) as RootState, ); @@ -59,7 +57,6 @@ describe('getZoom - plugin method', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }) as RootState, ); diff --git a/src/services/pluginsManager/map/zoom/setZoom.test.ts b/src/services/pluginsManager/map/zoom/setZoom.test.ts index 2d5f8a3d2de05d808f0c92bbc033d62f25d22c32..55502f302a70e74e6e7b7983e1bc12601e1071d9 100644 --- a/src/services/pluginsManager/map/zoom/setZoom.test.ts +++ b/src/services/pluginsManager/map/zoom/setZoom.test.ts @@ -4,7 +4,6 @@ import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/ma import { setLastPositionZoom } from '@/redux/map/map.slice'; import { RootState, store } from '@/redux/store'; import { ZodError } from 'zod'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { setZoom } from './setZoom'; jest.mock('../../../../redux/store'); @@ -37,7 +36,6 @@ describe('setZoom - plugin method', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }) as RootState, ); diff --git a/src/types/mapLayers.ts b/src/types/mapLayers.ts deleted file mode 100644 index d5b7bb6aaff107991b1aec21a9fd956ec00d3ed1..0000000000000000000000000000000000000000 --- a/src/types/mapLayers.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* excluded from map.ts due to depenceny cycle */ - -import { useOlMapOverlaysLayer } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useOlMapOverlaysLayer'; -import { useOlMapPinsLayer } from '@/components/Map/MapViewer/utils/config/pinsLayer/useOlMapPinsLayer'; -import { useOlMapReactionsLayer } from '@/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer'; -import { useOlMapTileLayer } from '@/components/Map/MapViewer/utils/config/useOlMapTileLayer'; - -export type MapLayers = - | { - tileLayer: ReturnType<typeof useOlMapTileLayer>; - reactionsLayer: ReturnType<typeof useOlMapReactionsLayer>; - pinsLayer: ReturnType<typeof useOlMapPinsLayer>; - overlaysLayer: ReturnType<typeof useOlMapOverlaysLayer>; - } - | undefined; diff --git a/src/types/models.ts b/src/types/models.ts index c70bb0b7c2b737c78090520f96d4faf39845f1f8..168c7fde106887fcb19aae57f79bebf0538b7240 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -16,7 +16,6 @@ import { exportElementsSchema, exportNetworkchema } from '@/models/exportSchema' import { geneVariant } from '@/models/geneVariant'; import { lineSchema } from '@/models/lineSchema'; import { loginSchema } from '@/models/loginSchema'; -import { mapBackground } from '@/models/mapBackground'; import { createdOverlayFileSchema, createdOverlaySchema, @@ -116,7 +115,6 @@ export type ShapeRelAbs = z.infer<typeof shapeRelAbsSchema>; export type ShapeRelAbsBezierPoint = z.infer<typeof shapeRelAbsBezierPointSchema>; export type Modification = z.infer<typeof modelElementModificationSchema>; export type MapOverlay = z.infer<typeof mapOverlay>; -export type MapBackground = z.infer<typeof mapBackground>; export type Organism = z.infer<typeof organism>; export type Disease = z.infer<typeof disease>; export type Drug = z.infer<typeof drugSchema>; diff --git a/src/utils/initialize/useInitializeStore.test.ts b/src/utils/initialize/useInitializeStore.test.ts index 34a1e072e0a64d13b8d47bf18892fbb5fbe4de35..92b5d635da758cbad836baf5286f82531db09836 100644 --- a/src/utils/initialize/useInitializeStore.test.ts +++ b/src/utils/initialize/useInitializeStore.test.ts @@ -1,21 +1,18 @@ import { PROJECT_ID } from '@/constants'; -import { backgroundsFixture } from '@/models/fixtures/backgroundsFixture'; import { modelsFixture, modelsPageFixture } from '@/models/fixtures/modelsFixture'; import { overlaysPageFixture } from '@/models/fixtures/overlaysFixture'; import { projectFixture } from '@/models/fixtures/projectFixture'; import { apiPath } from '@/redux/apiPath'; -import { backgroundsDataSelector } from '@/redux/backgrounds/background.selectors'; import { modelsDataSelector } from '@/redux/models/models.selectors'; import { overlaysDataSelector } from '@/redux/overlays/overlays.selectors'; import { projectDataSelector } from '@/redux/project/project.selectors'; import { initDataLoadingInitialized } from '@/redux/root/init.selectors'; -import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; +import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { renderHook, waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; import * as hook from './useInitializeStore'; -const mockedAxiosClient = mockNetworkResponse(); const mockedAxiosNewClient = mockNetworkNewAPIResponse(); describe('useInitializeStore - hook', () => { @@ -30,9 +27,6 @@ describe('useInitializeStore - hook', () => { mockedAxiosNewClient .onGet(apiPath.getProjectById(PROJECT_ID)) .reply(HttpStatusCode.Ok, projectFixture); - mockedAxiosClient - .onGet(apiPath.getAllBackgroundsByProjectIdQuery(PROJECT_ID)) - .reply(HttpStatusCode.Ok, backgroundsFixture); }); it('should fetch project data in store', async () => { @@ -45,16 +39,6 @@ describe('useInitializeStore - hook', () => { }); }); - it('should fetch backgrounds data in store', async () => { - const { Wrapper, store } = getReduxWrapperWithStore(); - renderHook(() => hook.useInitializeStore(), { wrapper: Wrapper }); - - await waitFor(() => { - const data = backgroundsDataSelector(store.getState()); - expect(data).toEqual(backgroundsFixture); - }); - }); - it('should fetch overlays data in store', async () => { const { Wrapper, store } = getReduxWrapperWithStore(); renderHook(() => hook.useInitializeStore(), { wrapper: Wrapper }); diff --git a/src/utils/initialize/useInitializeStore.ts b/src/utils/initialize/useInitializeStore.ts index c648112775ac249fb74cc4ab3b439f803430297f..3c6ed38940f5055989c97e2c30b87fa263844c05 100644 --- a/src/utils/initialize/useInitializeStore.ts +++ b/src/utils/initialize/useInitializeStore.ts @@ -10,7 +10,7 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { parseQueryToTypes } from '../parseQueryToTypes'; /** - * 1. Initialise all required data before app starts: Project info, available Backgrounds, available Overlays, available Models (maps,submaps) + * 1. Initialise all required data before app starts: Project info, available Overlays, available Models (maps,submaps) * 2. Based on that set required map data to correctly display view. If query params are available -> use them to set map data */ @@ -25,7 +25,6 @@ export const useInitializeStore = (): void => { if (isInitialized || !isQueryReady) { return; } - dispatch(fetchInitialAppData({ queryData: parseQueryToTypes(query) })); }, [dispatch, isInitialized, query, isQueryReady, isInitDataLoadingFinished]); }; diff --git a/src/utils/map/getUpdatedMapData.ts b/src/utils/map/getUpdatedMapData.ts index 1e4fc498ac190f2d3161910b4dd25f36c2112dcf..1d5632f8e43fc31117f9a5f7b7a18f29fa60f6a6 100644 --- a/src/utils/map/getUpdatedMapData.ts +++ b/src/utils/map/getUpdatedMapData.ts @@ -1,14 +1,15 @@ import { DEFAULT_ZOOM } from '@/constants/map'; import { MAP_DATA_INITIAL_STATE } from '@/redux/map/map.constants'; import { GetUpdatedMapDataResult, MapData } from '@/redux/map/map.types'; -import { MapBackground, MapModel } from '@/types/models'; +import { MapModel } from '@/types/models'; import { DeepPartial } from '@reduxjs/toolkit'; +import MapBackgroundsEnum from '@/redux/map/map.enums'; import { getPointMerged } from '../object/getPointMerged'; interface GetUpdatedMapDataArgs { model: MapModel; position?: DeepPartial<MapData['position']>; - background?: MapBackground; + background?: MapBackgroundsEnum; } const HALF = 2; @@ -28,7 +29,7 @@ export const getUpdatedMapData = ({ return { modelId: model.id, - backgroundId: background?.id || MAP_DATA_INITIAL_STATE.backgroundId, + backgroundId: background || MAP_DATA_INITIAL_STATE.backgroundId, size: { width: model.width, height: model.height, diff --git a/src/utils/map/useSetBounds.test.ts b/src/utils/map/useSetBounds.test.ts index fde34efdc5a1e3aade15b00395bc380a5a050843..71ee12602b0c344b7276446cb952b1dbb1d687d9 100644 --- a/src/utils/map/useSetBounds.test.ts +++ b/src/utils/map/useSetBounds.test.ts @@ -4,7 +4,6 @@ import { MAP_DATA_INITIAL_STATE } from '@/redux/map/map.constants'; import { renderHook } from '@testing-library/react'; import { Map } from 'ol'; import { Coordinate } from 'ol/coordinate'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { getReduxWrapperWithStore } from '../testing/getReduxWrapperWithStore'; import { useSetBounds } from './useSetBounds'; @@ -35,7 +34,6 @@ describe('useSetBounds - hook', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, { @@ -81,7 +79,6 @@ describe('useSetBounds - hook', () => { message: '', }, openedMaps: [], - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, { diff --git a/src/utils/query-manager/useReduxBusQueryManager.test.ts b/src/utils/query-manager/useReduxBusQueryManager.test.ts index e71069d63bac0604541af3b4a56007ab400af912..9283e65bb0f280e25038efd5dd8b83cd07de31c4 100644 --- a/src/utils/query-manager/useReduxBusQueryManager.test.ts +++ b/src/utils/query-manager/useReduxBusQueryManager.test.ts @@ -2,7 +2,6 @@ import { MAP_DATA_INITIAL_STATE, OPENED_MAPS_INITIAL_STATE } from '@/redux/map/m import { Loading } from '@/types/loadingState'; import { renderHook, waitFor } from '@testing-library/react'; import mockRouter from 'next-router-mock'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; import { getReduxWrapperWithStore } from '../testing/getReduxWrapperWithStore'; import { useReduxBusQueryManager } from './useReduxBusQueryManager'; @@ -71,9 +70,7 @@ describe('useReduxBusQueryManager - util', () => { }, }, openedMaps: OPENED_MAPS_INITIAL_STATE, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, - backgrounds: loadedDataMock, models: loadedDataMock, overlays: loadedDataMock, });