From 0fb0d1225b6273dd0c2b4a563da6776a55500ae5 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <p.gawron@atcomp.pl> Date: Fri, 22 Nov 2024 12:55:59 +0100 Subject: [PATCH] use new endpoint for obtaining maps --- .../ContextMenu/ContextMenu.component.tsx | 2 +- .../MapNavigation/MapNavigation.component.tsx | 4 +- .../utils/useOverviewImageLinkActions.ts | 4 +- ...PublicationsModalLayout.component.test.tsx | 6 +- .../ElementLink.component.test.tsx | 6 +- .../FilterBySubmapHeader.test.tsx | 2 +- .../AssociatedSubmap.component.tsx | 2 +- .../OverlayData.component.test.tsx | 18 +++--- .../Elements/Elements.component.test.tsx | 2 +- .../ExportCompound.component.tsx | 2 +- .../useExportGraphicsSelectedModel.test.tsx | 2 +- .../utils/useExportGraphicsSelectedModel.ts | 2 +- .../ImageSize/utils/useImageSize.test.ts | 6 +- .../Submap/Submap.component.tsx | 4 +- .../ExportDrawer.component.utils.tsx | 2 +- .../ExportDrawer/ExportDrawer.utils.test.ts | 2 +- .../Network/Network.component.test.tsx | 2 +- .../BioEntitiesSubmapItem.component.test.tsx | 2 +- .../PinsListItem.component.utils.ts | 2 +- .../DownloadSubmap.component.test.tsx | 2 +- .../utils/useGetSubmapDownloadUrl.test.ts | 2 +- .../utils/useGetSubmapDownloadUrl.ts | 4 +- .../Drawer/SubmapsDrawer/SubmapsDrawer.tsx | 12 ++-- .../utils/useAdditionalActions.test.ts | 4 +- ...sibleBioEntitiesPolygonCoordinates.test.ts | 2 +- src/hooks/useOpenSubmaps.ts | 2 +- src/models/fixtures/modelsFixture.ts | 14 ++++- src/models/mocks/modelsMock.ts | 56 +++++++++---------- src/models/modelSchema.ts | 9 ++- src/redux/apiPath.ts | 2 +- src/redux/bioEntity/bioEntity.selectors.ts | 8 +-- .../compartmentPathways.mock.ts | 6 +- .../compartmentPathways.thunks.test.ts | 4 +- src/redux/map/map.thunks.ts | 20 +++---- .../map/middleware/getUpdatedModel.test.ts | 2 +- src/redux/map/middleware/getUpdatedModel.ts | 2 +- .../map/middleware/map.middleware.test.ts | 6 +- src/redux/map/middleware/map.middleware.ts | 2 +- src/redux/models/models.mock.ts | 2 +- src/redux/models/models.reducers.test.ts | 18 +++--- src/redux/models/models.reducers.ts | 2 +- src/redux/models/models.selectors.ts | 15 ++--- src/redux/models/models.thunks.test.ts | 12 ++-- src/redux/models/models.thunks.ts | 13 ++--- src/services/pluginsManager/map/openMap.ts | 12 ++-- src/types/models.ts | 4 +- .../initialize/useInitializeStore.test.ts | 6 +- src/utils/map/getUpdatedMapData.test.ts | 6 +- src/utils/map/getUpdatedMapData.ts | 2 +- 49 files changed, 170 insertions(+), 153 deletions(-) diff --git a/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx b/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx index 973785e6..38a81da8 100644 --- a/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx +++ b/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx @@ -41,7 +41,7 @@ export const ContextMenu = (): React.ReactNode => { dispatch(openAddCommentModal()); }; - const modelId = model ? model.idObject : ZERO; + const modelId = model ? model.id : ZERO; const handleCallback = ( callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void, diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx index e6904890..380918b6 100644 --- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx +++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.tsx @@ -30,13 +30,13 @@ export const MapNavigation = (): JSX.Element => { if (isActive(map.modelId)) { dispatch( closeMapAndSetMainMapActive({ - modelId: mainMapModel.idObject, + modelId: mainMapModel.id, currentModelId: map.modelId, }), ); PluginsEventBus.dispatchEvent('onSubmapClose', map.modelId); - PluginsEventBus.dispatchEvent('onSubmapOpen', mainMapModel.idObject); + PluginsEventBus.dispatchEvent('onSubmapOpen', mainMapModel.id); } else { dispatch(closeMap({ modelId: map.modelId })); } diff --git a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.ts b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.ts index d69596ff..bb5380df 100644 --- a/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.ts +++ b/src/components/FunctionalArea/Modal/OverviewImagesModal/utils/useOverviewImageLinkActions.ts @@ -31,10 +31,10 @@ export const useOverviewImageLinkActions = (): UseOverviewImageLinkActionsResult openedMaps.some(map => map.modelId === modelId); const getModelById = (modelId: number): MapModel | undefined => - models.find(map => map.idObject === modelId); + models.find(map => map.id === modelId); const handleOpenMap = (model: MapModel): void => { - const modelId = model.idObject; + const modelId = model.id; const isMapOpened = checkIfMapAlreadyOpened(modelId); if (currentMapModelId !== modelId) { diff --git a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsModalLayout/PublicationsModalLayout.component.test.tsx b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsModalLayout/PublicationsModalLayout.component.test.tsx index d44c61ba..aa7755b5 100644 --- a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsModalLayout/PublicationsModalLayout.component.test.tsx +++ b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsModalLayout/PublicationsModalLayout.component.test.tsx @@ -18,9 +18,9 @@ import { HttpStatusCode } from 'axios'; import { fetchElementData } from '../utils/fetchElementData'; import { PublicationsModalLayout } from './PublicationsModalLayout.component'; -const FIRST_MODEL_ID = MODELS_MOCK[FIRST_ARRAY_ELEMENT].idObject; -const SECOND_MODEL_ID = MODELS_MOCK[SECOND_ARRAY_ELEMENT].idObject; -const THIRD_MODEL_ID = MODELS_MOCK[THIRD_ARRAY_ELEMENT].idObject; +const FIRST_MODEL_ID = MODELS_MOCK[FIRST_ARRAY_ELEMENT].id; +const SECOND_MODEL_ID = MODELS_MOCK[SECOND_ARRAY_ELEMENT].id; +const THIRD_MODEL_ID = MODELS_MOCK[THIRD_ARRAY_ELEMENT].id; const FIRST_ELEMENT_ID = 100; const SECOND_ELEMENT_ID = 200; 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 bb30b23f..0ab301d5 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 @@ -110,7 +110,7 @@ describe('ElementLink - component', () => { data: [ { ...modelsFixture[FIRST_ARRAY_ELEMENT], - idObject: TARGET_ELEMENT.modelId, + id: TARGET_ELEMENT.modelId, }, ], }, @@ -191,7 +191,7 @@ describe('ElementLink - component', () => { data: [ { ...modelsFixture[FIRST_ARRAY_ELEMENT], - idObject: TARGET_ELEMENT.modelId, + id: TARGET_ELEMENT.modelId, }, ], }, @@ -199,7 +199,7 @@ describe('ElementLink - component', () => { ...INITIAL_STORE_STATE_MOCK.map, data: { ...INITIAL_STORE_STATE_MOCK.map.data, - modelId: modelsFixture[FIRST_ARRAY_ELEMENT].idObject, + modelId: modelsFixture[FIRST_ARRAY_ELEMENT].id, }, openedMaps: [ { diff --git a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/FilterBySubmapHeader/FilterBySubmapHeader.test.tsx b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/FilterBySubmapHeader/FilterBySubmapHeader.test.tsx index 6dfca3c7..f238cef3 100644 --- a/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/FilterBySubmapHeader/FilterBySubmapHeader.test.tsx +++ b/src/components/FunctionalArea/Modal/PublicationsModal/PublicationsTable/FilterBySubmapHeader/FilterBySubmapHeader.test.tsx @@ -131,7 +131,7 @@ describe('FilterBySubmapHeader - component', () => { expect(actions[FIRST_ARRAY_ELEMENT].type).toBe('publications/setSelectedModelId'); const selectedModelId = actions[FIRST_ARRAY_ELEMENT].payload; - expect(selectedModelId).toBe(String(MODELS_MOCK[FIRST_ARRAY_ELEMENT].idObject)); + expect(selectedModelId).toBe(String(MODELS_MOCK[FIRST_ARRAY_ELEMENT].id)); }); it('should dispatch getPublications action', async () => { const mockStore = configureMockStore([thunk]); diff --git a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.tsx b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.tsx index 659ff193..ae421606 100644 --- a/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.tsx +++ b/src/components/Map/Drawer/BioEntityDrawer/AssociatedSubmap/AssociatedSubmap.component.tsx @@ -6,7 +6,7 @@ import { Button } from '@/shared/Button'; export const AssociatedSubmap = (): React.ReactNode => { const relatedSubmap = useAppSelector(currentDrawerBioEntityRelatedSubmapSelector); const { openSubmap } = useOpenSubmap({ - modelId: relatedSubmap?.idObject, + modelId: relatedSubmap?.id, modelName: relatedSubmap?.name, }); diff --git a/src/components/Map/Drawer/BioEntityDrawer/OverlayData/OverlayData.component.test.tsx b/src/components/Map/Drawer/BioEntityDrawer/OverlayData/OverlayData.component.test.tsx index 3704c38f..c03ea142 100644 --- a/src/components/Map/Drawer/BioEntityDrawer/OverlayData/OverlayData.component.test.tsx +++ b/src/components/Map/Drawer/BioEntityDrawer/OverlayData/OverlayData.component.test.tsx @@ -55,7 +55,7 @@ describe('OverlayData - component', () => { ...INITIAL_STORE_STATE_MOCK, map: { ...initialMapStateFixture, - data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.idObject }, + data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.id }, }, overlays: { ...INITIAL_STORE_STATE_MOCK.overlays, @@ -86,11 +86,11 @@ describe('OverlayData - component', () => { overlaysId: [OVERLAY_ID], data: { [OVERLAY_ID]: { - [CORE_PD_MODEL_MOCK.idObject]: [ + [CORE_PD_MODEL_MOCK.id]: [ { ...BIO_ENTITY, geneVariants: GENE_VARIANTS_MOCK, - modelId: CORE_PD_MODEL_MOCK.idObject, + modelId: CORE_PD_MODEL_MOCK.id, overlayId: OVERLAY_ID, }, ], @@ -127,7 +127,7 @@ describe('OverlayData - component', () => { ...INITIAL_STORE_STATE_MOCK, map: { ...initialMapStateFixture, - data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.idObject }, + data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.id }, }, overlays: { ...INITIAL_STORE_STATE_MOCK.overlays, @@ -158,11 +158,11 @@ describe('OverlayData - component', () => { overlaysId: [OVERLAY_ID], data: { [OVERLAY_ID]: { - [CORE_PD_MODEL_MOCK.idObject]: [ + [CORE_PD_MODEL_MOCK.id]: [ { ...BIO_ENTITY, geneVariants: GENE_VARIANTS_MOCK, - modelId: CORE_PD_MODEL_MOCK.idObject, + modelId: CORE_PD_MODEL_MOCK.id, overlayId: OVERLAY_ID, }, ], @@ -203,7 +203,7 @@ describe('OverlayData - component', () => { ...INITIAL_STORE_STATE_MOCK, map: { ...initialMapStateFixture, - data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.idObject }, + data: { ...initialMapStateFixture.data, modelId: CORE_PD_MODEL_MOCK.id }, }, overlays: { ...INITIAL_STORE_STATE_MOCK.overlays, @@ -234,11 +234,11 @@ describe('OverlayData - component', () => { overlaysId: [OVERLAY_ID], data: { [OVERLAY_ID]: { - [CORE_PD_MODEL_MOCK.idObject]: [ + [CORE_PD_MODEL_MOCK.id]: [ { ...BIO_ENTITY, geneVariants: GENE_VARIANTS_MOCK, - modelId: CORE_PD_MODEL_MOCK.idObject, + modelId: CORE_PD_MODEL_MOCK.id, overlayId: OVERLAY_ID, name: 'element name', }, diff --git a/src/components/Map/Drawer/ExportDrawer/Elements/Elements.component.test.tsx b/src/components/Map/Drawer/ExportDrawer/Elements/Elements.component.test.tsx index 9fa8624b..e3307241 100644 --- a/src/components/Map/Drawer/ExportDrawer/Elements/Elements.component.test.tsx +++ b/src/components/Map/Drawer/ExportDrawer/Elements/Elements.component.test.tsx @@ -201,7 +201,7 @@ describe('Elements - component', () => { const firstAction = actions[0]; expect(firstAction.meta.arg).toEqual({ columns: ELEMENTS_COLUMNS, - submaps: modelsFixture.map(item => item.idObject), + submaps: modelsFixture.map(item => item.id), annotations: ['compartment_label'], includedCompartmentIds: [FIRST_COMPARMENT_PATHWAY_ID], excludedCompartmentIds: [SECOND_COMPARMENT_PATHWAY_ID], diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx index f5803c10..55991db9 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ExportCompound.component.tsx @@ -69,7 +69,7 @@ export const Export = ({ children }: ExportProps): JSX.Element => { const handleDownloadGraphics = useCallback(async () => { const modelId = models?.[FIRST_ARRAY_ELEMENT]?.id; - const model = currentModels.find(currentModel => currentModel.idObject === Number(modelId)); + const model = currentModels.find(currentModel => currentModel.id === Number(modelId)); const url = getGraphicsDownloadUrl({ backgroundId: currentBackground?.id, diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.test.tsx b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.test.tsx index 20ac3edf..86b7d602 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.test.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.test.tsx @@ -44,7 +44,7 @@ describe('useExportGraphicsSelectedModel - util', () => { ...EXPORT_CONTEXT_DEFAULT_VALUE.data, models: [ { - id: selectedModel.idObject.toString(), + id: selectedModel.id.toString(), label: selectedModel.name, }, ], diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.ts b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.ts index 5ee35b4c..b2e18ebe 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.ts +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useExportGraphicsSelectedModel.ts @@ -14,5 +14,5 @@ export const useExportGraphicsSelectedModel = (): MapModel | undefined => { return undefined; } - return models.find(model => model.idObject === Number(currentSelectedModelId)); + return models.find(model => model.id === Number(currentSelectedModelId)); }; diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useImageSize.test.ts b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useImageSize.test.ts index a182496e..11e97e36 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useImageSize.test.ts +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/ImageSize/utils/useImageSize.test.ts @@ -49,7 +49,7 @@ describe('useImageSize - hook', () => { ...EXPORT_CONTEXT_DEFAULT_VALUE.data, models: [ { - id: selectedModel.idObject.toString(), + id: selectedModel.id.toString(), label: selectedModel.name, }, ], @@ -90,7 +90,7 @@ describe('useImageSize - hook', () => { ...EXPORT_CONTEXT_DEFAULT_VALUE.data, models: [ { - id: selectedModel.idObject.toString(), + id: selectedModel.id.toString(), label: selectedModel.name, }, ], @@ -166,7 +166,7 @@ describe('useImageSize - hook', () => { ...EXPORT_CONTEXT_DEFAULT_VALUE.data, models: [ { - id: selectedModel.idObject.toString(), + id: selectedModel.id.toString(), label: selectedModel.name, }, ], diff --git a/src/components/Map/Drawer/ExportDrawer/ExportCompound/Submap/Submap.component.tsx b/src/components/Map/Drawer/ExportDrawer/ExportCompound/Submap/Submap.component.tsx index 422c4b73..b2efd28b 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportCompound/Submap/Submap.component.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportCompound/Submap/Submap.component.tsx @@ -14,8 +14,8 @@ export const Submap = (): React.ReactNode => { const loadingModels = useAppSelector(loadingModelsSelector); const isPending = loadingModels === 'pending'; - const mappedElementAnnotations = models.map(({ idObject, name }) => ({ - id: `${idObject}`, + const mappedElementAnnotations = models.map(({ id, name }) => ({ + id: `${id}`, label: name, })); diff --git a/src/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils.tsx b/src/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils.tsx index 20e5e871..4dd9af71 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils.tsx +++ b/src/components/Map/Drawer/ExportDrawer/ExportDrawer.component.utils.tsx @@ -3,5 +3,5 @@ import { MapModel } from '@/types/models'; export const getModelsIds = (models: MapModel[] | undefined): number[] => { if (!models) return []; - return models.map(model => model.idObject); + return models.map(model => model.id); }; diff --git a/src/components/Map/Drawer/ExportDrawer/ExportDrawer.utils.test.ts b/src/components/Map/Drawer/ExportDrawer/ExportDrawer.utils.test.ts index ee1aa52f..576f4040 100644 --- a/src/components/Map/Drawer/ExportDrawer/ExportDrawer.utils.test.ts +++ b/src/components/Map/Drawer/ExportDrawer/ExportDrawer.utils.test.ts @@ -1,7 +1,7 @@ import { modelsFixture } from '@/models/fixtures/modelsFixture'; import { getModelsIds } from './ExportDrawer.component.utils'; -const MODELS_IDS = modelsFixture.map(item => item.idObject); +const MODELS_IDS = modelsFixture.map(item => item.id); describe('getModelsIds', () => { it('should return an empty array if models are not provided', () => { diff --git a/src/components/Map/Drawer/ExportDrawer/Network/Network.component.test.tsx b/src/components/Map/Drawer/ExportDrawer/Network/Network.component.test.tsx index 4bf77ac6..2fddcfed 100644 --- a/src/components/Map/Drawer/ExportDrawer/Network/Network.component.test.tsx +++ b/src/components/Map/Drawer/ExportDrawer/Network/Network.component.test.tsx @@ -204,7 +204,7 @@ describe('Network - component', () => { const firstAction = actions[0]; expect(firstAction.meta.arg).toEqual({ columns: NETWORK_COLUMNS, - submaps: modelsFixture.map(item => item.idObject), + submaps: modelsFixture.map(item => item.id), annotations: ['reaction'], includedCompartmentIds: [FIRST_COMPARMENT_PATHWAY_ID], excludedCompartmentIds: [SECOND_COMPARMENT_PATHWAY_ID], 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 aa753d71..dde94491 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 @@ -27,7 +27,7 @@ const renderComponent = (initialStoreState: InitialStoreState = {}): { store: St <Wrapper> <BioEntitiesSubmapItem mapName={MODELS_MOCK_SHORT[0].name} - mapId={MODELS_MOCK_SHORT[0].idObject} + mapId={MODELS_MOCK_SHORT[0].id} numberOfEntities={21} bioEntities={bioEntitiesContentFixture} /> diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts index bbc87ce8..26f45776 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts @@ -30,7 +30,7 @@ export const getListOfAvailableSubmaps = ( const data: AvailableSubmaps = { id: submap.id, modelId: submap.model, - name: models.find(model => model.idObject === submap.model)?.name || '', + name: models.find(model => model.id === submap.model)?.name || '', }; return data; 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 a30986f5..23e1eef1 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 @@ -39,7 +39,7 @@ const getState = (): RootState => ({ data: [ { ...modelsFixture[FIRST_ARRAY_ELEMENT], - idObject: VALID_MODEL_ID, + id: VALID_MODEL_ID, }, ], }, 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 c8f335bf..704176d2 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 @@ -40,7 +40,7 @@ const getState = ({ data: [ { ...modelsFixture[FIRST_ARRAY_ELEMENT], - idObject: VALID_MODEL_ID, + id: VALID_MODEL_ID, }, ], }, 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 e003af36..397f7aad 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts @@ -12,7 +12,7 @@ export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { const mapSize = useSelector(mapDataSizeSelector); const getSubmapDownloadUrl: GetSubmapDownloadUrl = ({ handler }) => { - const allParamsValid = [model?.idObject, background?.id, mapSize.maxZoom, handler].reduce( + const allParamsValid = [model?.id, background?.id, mapSize.maxZoom, handler].reduce( (a, b) => Boolean(a) && Boolean(b), true, ); @@ -20,7 +20,7 @@ export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { return ''; } - return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${model?.idObject}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; + return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${model?.id}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; }; return getSubmapDownloadUrl; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx index eb15bad6..2532be19 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx @@ -18,14 +18,14 @@ export const SubmapsDrawer = (): JSX.Element => { openedMaps.some(map => map.modelId === modelId); const onSubmapOpenClick = (model: MapModel): void => { - if (isMapAlreadyOpened(model.idObject)) { - dispatch(setActiveMap({ modelId: model.idObject })); + if (isMapAlreadyOpened(model.id)) { + dispatch(setActiveMap({ modelId: model.id })); } else { - dispatch(openMapAndSetActive({ modelId: model.idObject, modelName: model.name })); + dispatch(openMapAndSetActive({ modelId: model.id, modelName: model.name })); } - if (currentModelId !== model.idObject) { + if (currentModelId !== model.id) { PluginsEventBus.dispatchEvent('onSubmapClose', currentModelId); - PluginsEventBus.dispatchEvent('onSubmapOpen', model.idObject); + PluginsEventBus.dispatchEvent('onSubmapOpen', model.id); } }; @@ -35,7 +35,7 @@ export const SubmapsDrawer = (): JSX.Element => { <ul className="h-[calc(100%-93px)] max-h-[calc(100%-93px)] overflow-y-auto px-6"> {models.map(model => ( <SubmpamItem - key={model.idObject} + key={model.id} modelName={model.name} onOpenClick={(): void => onSubmapOpenClick(model)} /> diff --git a/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts b/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts index 898b10e0..de9d56f1 100644 --- a/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts +++ b/src/components/Map/MapAdditionalActions/utils/useAdditionalActions.test.ts @@ -168,7 +168,7 @@ describe('useAddtionalActions - hook', () => { ...MAP_CONFIG.zoom, tileSize: 256, }, - modelId: modelsFixture[0].idObject, + modelId: modelsFixture[0].id, }, }, }); @@ -234,7 +234,7 @@ describe('useAddtionalActions - hook', () => { ...MAP_CONFIG.zoom, tileSize: 256, }, - modelId: modelsFixture[0].idObject, + modelId: modelsFixture[0].id, }, }, }); diff --git a/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts b/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts index 8f84e5d6..331d5e98 100644 --- a/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts +++ b/src/components/Map/MapAdditionalActions/utils/useVisibleBioEntitiesPolygonCoordinates.test.ts @@ -43,7 +43,7 @@ const getInitalState = ( data: [ { ...modelsFixture[0], - idObject: 5052, + id: 5052, }, ], }, diff --git a/src/hooks/useOpenSubmaps.ts b/src/hooks/useOpenSubmaps.ts index 85956836..15b798d3 100644 --- a/src/hooks/useOpenSubmaps.ts +++ b/src/hooks/useOpenSubmaps.ts @@ -26,7 +26,7 @@ export const useOpenSubmap = ({ const currentModelId = useAppSelector(mapModelIdSelector); const isMapAlreadyOpened = openedMaps.some(map => map.modelId === modelId); - const isMapExist = models.some(model => model.idObject === modelId); + const isMapExist = models.some(model => model.id === modelId); const isItPossibleToOpenMap = modelId && modelName && isMapExist; const openSubmap = useCallback(() => { diff --git a/src/models/fixtures/modelsFixture.ts b/src/models/fixtures/modelsFixture.ts index 91bc15d7..619692f2 100644 --- a/src/models/fixtures/modelsFixture.ts +++ b/src/models/fixtures/modelsFixture.ts @@ -1,15 +1,23 @@ import { ZOD_SEED } from '@/constants'; import { mapModelSchema } from '@/models/modelSchema'; -import { z } from 'zod'; // eslint-disable-next-line import/no-extraneous-dependencies import { createFixture } from 'zod-fixture'; +import { pageableSchema } from '@/models/pageableSchema'; +import { z } from 'zod'; -export const modelsFixture = createFixture(z.array(mapModelSchema), { +export const singleModelFixture = createFixture(mapModelSchema, { seed: ZOD_SEED, array: { min: 3, max: 3 }, }); -export const singleModelFixture = createFixture(mapModelSchema, { +export const modelsPageFixture = createFixture(pageableSchema(mapModelSchema), { seed: ZOD_SEED, array: { min: 3, max: 3 }, }); + +export const modelsFixture = createFixture(z.array(mapModelSchema), { + seed: ZOD_SEED, + array: { min: 3, max: 3 }, +}); + +modelsPageFixture.content = modelsFixture; diff --git a/src/models/mocks/modelsMock.ts b/src/models/mocks/modelsMock.ts index 53dac6b9..7166e45f 100644 --- a/src/models/mocks/modelsMock.ts +++ b/src/models/mocks/modelsMock.ts @@ -2,7 +2,7 @@ import { MapModel } from '@/types/models'; export const MODELS_MOCK: MapModel[] = [ { - idObject: 5053, + id: 5053, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -19,7 +19,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 9, }, { - idObject: 5052, + id: 5052, width: 3511.09375, height: 1312.125, defaultCenterX: null, @@ -36,7 +36,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 6, }, { - idObject: 5054, + id: 5054, width: 1652.75, height: 1171.9429798877356, defaultCenterX: null, @@ -53,7 +53,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5055, + id: 5055, width: 2473.8078571428596, height: 1143.0, defaultCenterX: null, @@ -70,7 +70,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 6, }, { - idObject: 5056, + id: 5056, width: 1975.0, height: 1950.0, defaultCenterX: null, @@ -88,7 +88,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5057, + id: 5057, width: 21838.0, height: 10376.0, defaultCenterX: null, @@ -106,7 +106,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 9, }, { - idObject: 5058, + id: 5058, width: 5170.0, height: 1535.1097689075634, defaultCenterX: null, @@ -123,7 +123,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5059, + id: 5059, width: 4556.0, height: 2852.0, defaultCenterX: null, @@ -141,7 +141,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5060, + id: 5060, width: 2500.0, height: 1238.25, defaultCenterX: null, @@ -159,7 +159,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 6, }, { - idObject: 5061, + id: 5061, width: 1289.0, height: 1572.2941176470588, defaultCenterX: null, @@ -177,7 +177,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5062, + id: 5062, width: 1220.0, height: 1395.0, defaultCenterX: null, @@ -195,7 +195,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5063, + id: 5063, width: 9215.0, height: 3880.0, defaultCenterX: null, @@ -212,7 +212,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 8, }, { - idObject: 5064, + id: 5064, width: 9102.0, height: 4544.0, defaultCenterX: null, @@ -229,7 +229,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 8, }, { - idObject: 5065, + id: 5065, width: 1639.0, height: 1814.0, defaultCenterX: null, @@ -247,7 +247,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5066, + id: 5066, width: 2823.0, height: 1695.5, defaultCenterX: null, @@ -265,7 +265,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 6, }, { - idObject: 5067, + id: 5067, width: 1980.0, height: 1740.0, defaultCenterX: null, @@ -282,7 +282,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 5, }, { - idObject: 5068, + id: 5068, width: 10312.75, height: 4172.15625, defaultCenterX: null, @@ -300,7 +300,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 8, }, { - idObject: 5069, + id: 5069, width: 4368.5, height: 1644.0, defaultCenterX: null, @@ -317,7 +317,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5070, + id: 5070, width: 5092.0, height: 2947.0, defaultCenterX: null, @@ -334,7 +334,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5071, + id: 5071, width: 5497.5, height: 3699.25, defaultCenterX: null, @@ -351,7 +351,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5072, + id: 5072, width: 11529.0, height: 6911.0, defaultCenterX: null, @@ -369,7 +369,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 8, }, { - idObject: 5073, + id: 5073, width: 8081.0, height: 5096.0, defaultCenterX: null, @@ -386,7 +386,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 7, }, { - idObject: 5074, + id: 5074, width: 4498.0, height: 2653.0, defaultCenterX: null, @@ -406,7 +406,7 @@ export const MODELS_MOCK: MapModel[] = [ export const MODELS_MOCK_SHORT: MapModel[] = [ { - idObject: 5053, + id: 5053, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -423,7 +423,7 @@ export const MODELS_MOCK_SHORT: MapModel[] = [ maxZoom: 9, }, { - idObject: 5052, + id: 5052, width: 3511.09375, height: 1312.125, defaultCenterX: null, @@ -440,7 +440,7 @@ export const MODELS_MOCK_SHORT: MapModel[] = [ maxZoom: 6, }, { - idObject: 5054, + id: 5054, width: 1652.75, height: 1171.9429798877356, defaultCenterX: null, @@ -459,7 +459,7 @@ export const MODELS_MOCK_SHORT: MapModel[] = [ ]; export const CORE_PD_MODEL_MOCK: MapModel = { - idObject: 5053, + id: 5053, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -478,7 +478,7 @@ export const CORE_PD_MODEL_MOCK: MapModel = { }; export const MODEL_WITH_DESCRIPTION: MapModel = { - idObject: 5056, + id: 5056, width: 1975.0, height: 1950.0, defaultCenterX: null, diff --git a/src/models/modelSchema.ts b/src/models/modelSchema.ts index 107579d0..feb8817b 100644 --- a/src/models/modelSchema.ts +++ b/src/models/modelSchema.ts @@ -1,13 +1,14 @@ import { z } from 'zod'; +import { pageableSchema } from '@/models/pageableSchema'; import { authorSchema } from './authorSchema'; import { referenceSchema } from './referenceSchema'; export const mapModelSchema = z.object({ + /** map id */ + id: z.number(), /** name of the map */ name: z.string(), description: z.string(), - /** map id */ - idObject: z.number(), /** map width */ width: z.number(), /** map height */ @@ -20,7 +21,7 @@ export const mapModelSchema = z.object({ defaultCenterY: z.number().nullable(), /** default zoom level used in frontend visualization */ defaultZoomLevel: z.number().nullable(), - /** minimum zoom level availbale for the map */ + /** minimum zoom level available for the map */ minZoom: z.number(), /** maximum zoom level available for the map */ maxZoom: z.number(), @@ -30,3 +31,5 @@ export const mapModelSchema = z.object({ modificationDates: z.array(z.string()), vectorRendering: z.boolean().optional(), }); + +export const mapModelsSchema = pageableSchema(mapModelSchema); diff --git a/src/redux/apiPath.ts b/src/redux/apiPath.ts index 5346ef4d..3c46cabf 100644 --- a/src/redux/apiPath.ts +++ b/src/redux/apiPath.ts @@ -43,7 +43,7 @@ export const apiPath = { `projects/${PROJECT_ID}/drugs:search?columns=${columns}&target=${target}`, getChemicalsStringWithColumnsTarget: (columns: string, target: string): string => `projects/${PROJECT_ID}/chemicals:search?columns=${columns}&target=${target}`, - getModelsString: (): string => `projects/${PROJECT_ID}/models/`, + getModelsString: (): string => `projects/${PROJECT_ID}/maps/?size=10000`, getModelElements: (modelId: number): string => `projects/${PROJECT_ID}/maps/${modelId}/bioEntities/elements/?size=10000`, getShapes: (): string => `projects/${PROJECT_ID}/shapes/`, diff --git a/src/redux/bioEntity/bioEntity.selectors.ts b/src/redux/bioEntity/bioEntity.selectors.ts index 5ad5c766..eb4e8f21 100644 --- a/src/redux/bioEntity/bioEntity.selectors.ts +++ b/src/redux/bioEntity/bioEntity.selectors.ts @@ -99,7 +99,7 @@ export const searchedFromMapBioEntityElementRelatedSubmapSelector = createSelect searchedFromMapBioEntityElement, modelsDataSelector, (bioEntity, models): MapModel | undefined => - models.find(({ idObject }) => idObject === bioEntity?.submodel?.mapId), + models.find(({ id }) => id === bioEntity?.submodel?.mapId), ); export const loadingBioEntityStatusSelector = createSelector( @@ -176,12 +176,12 @@ export const bioEntitiesPerModelSelector = createSelector( (bioEntities, models) => { const bioEntitiesPerModelPerSearchElement = (models || []).map(model => { const bioEntitiesInGivenModel = (bioEntities?.data || []).filter( - entity => model.idObject === entity.bioEntity.model, + entity => model.id === entity.bioEntity.model, ); return { modelName: model.name, - modelId: model.idObject, + modelId: model.id, numberOfEntities: bioEntitiesInGivenModel.length, bioEntities: bioEntitiesInGivenModel, }; @@ -279,7 +279,7 @@ export const currentDrawerBioEntityRelatedSubmapSelector = createSelector( currentDrawerBioEntitySelector, modelsDataSelector, (bioEntity, models): MapModel | undefined => - models.find(({ idObject }) => idObject === bioEntity?.submodel?.mapId), + models.find(({ id }) => id === bioEntity?.submodel?.mapId), ); export const allSubmapConnectionsBioEntityOfCurrentSubmapWithRealConnectionsSelector = diff --git a/src/redux/compartmentPathways/compartmentPathways.mock.ts b/src/redux/compartmentPathways/compartmentPathways.mock.ts index 6d62817d..a8c7fdb9 100644 --- a/src/redux/compartmentPathways/compartmentPathways.mock.ts +++ b/src/redux/compartmentPathways/compartmentPathways.mock.ts @@ -8,7 +8,7 @@ export const COMPARTMENT_PATHWAYS_INITIAL_STATE_MOCK: CompartmentPathwaysState = }; export const MODELS_MOCK: MapModel[] = [ { - idObject: 5053, + id: 5053, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -25,7 +25,7 @@ export const MODELS_MOCK: MapModel[] = [ maxZoom: 9, }, { - idObject: 5054, + id: 5054, width: 26779.25, height: 13503.0, defaultCenterX: null, @@ -45,7 +45,7 @@ export const MODELS_MOCK: MapModel[] = [ export const MODELS_MOCK_SHORT: MapModel[] = [ { - idObject: 5050, + id: 5050, width: 26779.25, height: 13503.0, defaultCenterX: null, diff --git a/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts b/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts index 407eb70d..517b8fec 100644 --- a/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts +++ b/src/redux/compartmentPathways/compartmentPathways.thunks.test.ts @@ -93,7 +93,7 @@ describe('compartmentPathways thunk', () => { it('should not do a network request sendCompartmentPathwaysIds if it is less than 100 ids', async () => { const ONE_MODEL = MODELS_MOCK_SHORT[0]; - const ID = ONE_MODEL.idObject; + const ID = ONE_MODEL.id; mockedAxiosClient .onGet(apiPath.getCompartmentPathwaysIds(ID)) @@ -107,7 +107,7 @@ describe('compartmentPathways thunk', () => { .onPost(apiPath.sendCompartmentPathwaysIds()) .reply(HttpStatusCode.Ok, compartmentPathwaysDetailsFixture); - const compartmentPathwaysPromise = store.dispatch(getCompartmentPathways([ONE_MODEL.idObject])); + const compartmentPathwaysPromise = store.dispatch(getCompartmentPathways([ONE_MODEL.id])); const { loading, data } = store.getState().compartmentPathways; diff --git a/src/redux/map/map.thunks.ts b/src/redux/map/map.thunks.ts index fb0f3dc6..75fcb092 100644 --- a/src/redux/map/map.thunks.ts +++ b/src/redux/map/map.thunks.ts @@ -67,14 +67,14 @@ export const getBackgroundId = (state: RootState, queryData: QueryData): number export const getModelId = (state: RootState, queryData: QueryData): number => { const mainMapModel = mainMapModelSelector(state); const models = modelsDataSelector(state); - let modelId = queryData?.modelId || mainMapModel?.idObject || ZERO; + let modelId = queryData?.modelId || mainMapModel?.id || ZERO; if (models.length > 0) { if ( models.filter(model => { - return model.idObject === modelId; + return model.id === modelId; }).length === 0 ) { - modelId = models[ZERO].idObject; + modelId = models[ZERO].id; } } return modelId; @@ -103,14 +103,14 @@ export const getInitMapPosition = (state: RootState, queryData: QueryData): Posi if (mergedPosition.z && mergedPosition.z !== defaultPosition.z) { PluginsEventBus.dispatchEvent('onZoomChanged', { - modelId: currentModel.idObject, + modelId: currentModel.id, zoom: mergedPosition.z, }); } if (mergedPosition.x !== defaultPosition.x || mergedPosition.y !== defaultPosition.y) { PluginsEventBus.dispatchEvent('onCenterChanged', { - modelId: currentModel.idObject, + modelId: currentModel.id, x: mergedPosition.x, y: mergedPosition.y, }); @@ -130,12 +130,12 @@ export const getInitMapSizeAndModelId = ( const modelId = getModelId(state, queryData); const currentModel = modelByIdSelector(state, modelId); - if (modelId !== mainMapModel?.idObject) { + if (modelId !== mainMapModel?.id) { PluginsEventBus.dispatchEvent('onSubmapOpen', modelId); } return { - modelId: currentModel?.idObject || ZERO, + modelId: currentModel?.id || ZERO, size: { width: currentModel?.width || ZERO, height: currentModel?.height || ZERO, @@ -150,17 +150,17 @@ export const getOpenedMaps = (state: RootState, queryData: QueryData): OppenedMa const FIRST = 0; const models = modelsDataSelector(state); const currentModel = currentModelSelector(state); - const mainMapId = models?.[FIRST]?.idObject || ZERO; + const mainMapId = models?.[FIRST]?.id || ZERO; const openedMaps: OppenedMap[] = [ { modelId: mainMapId, modelName: MAIN_MAP, lastPosition: DEFAULT_POSITION }, ]; - const isMainMapSetAsCurrentModel = currentModel?.idObject !== mainMapId; + const isMainMapSetAsCurrentModel = currentModel?.id !== mainMapId; if (isMainMapSetAsCurrentModel) { openedMaps.push({ - modelId: currentModel?.idObject || ZERO, + modelId: currentModel?.id || ZERO, modelName: currentModel?.name || '', lastPosition: { ...DEFAULT_POSITION, ...queryData.initialPosition }, }); diff --git a/src/redux/map/middleware/getUpdatedModel.test.ts b/src/redux/map/middleware/getUpdatedModel.test.ts index 65cd7f25..c3d4ca2a 100644 --- a/src/redux/map/middleware/getUpdatedModel.test.ts +++ b/src/redux/map/middleware/getUpdatedModel.test.ts @@ -18,7 +18,7 @@ describe('getUpdatedModel - util', () => { const action = { type: MIDDLEWARE_ALLOWED_ACTIONS[0], payload: { - modelId: model.idObject, + modelId: model.id, }, }; diff --git a/src/redux/map/middleware/getUpdatedModel.ts b/src/redux/map/middleware/getUpdatedModel.ts index 4302c552..a2b25dc7 100644 --- a/src/redux/map/middleware/getUpdatedModel.ts +++ b/src/redux/map/middleware/getUpdatedModel.ts @@ -8,5 +8,5 @@ export const getUpdatedModel = (action: Action, state: RootState): MapModel | un const models = modelsDataSelector(state); const payloadModelId = getModelIdFromAction(action); - return models.find(model => model.idObject === payloadModelId); + return models.find(model => model.id === payloadModelId); }; diff --git a/src/redux/map/middleware/map.middleware.test.ts b/src/redux/map/middleware/map.middleware.test.ts index 11015648..b783347e 100644 --- a/src/redux/map/middleware/map.middleware.test.ts +++ b/src/redux/map/middleware/map.middleware.test.ts @@ -60,7 +60,7 @@ const { store } = getReduxWrapperWithStore({ ...defaultSliceState, data: { ...MAP_DATA_INITIAL_STATE, - modelId: modelsFixture[0].idObject, + modelId: modelsFixture[0].id, }, openedMaps: OPENED_MAPS_INITIAL_STATE, }, @@ -92,7 +92,7 @@ describe('map middleware', () => { const action = { payload: { - modelId: model.idObject, + modelId: model.id, }, type: actionType, }; @@ -110,7 +110,7 @@ describe('map middleware', () => { const model = modelsFixture[0]; const action = { payload: { - modelId: model.idObject, + modelId: model.id, }, type: actionType, }; diff --git a/src/redux/map/middleware/map.middleware.ts b/src/redux/map/middleware/map.middleware.ts index 92fce878..bacbb729 100644 --- a/src/redux/map/middleware/map.middleware.ts +++ b/src/redux/map/middleware/map.middleware.ts @@ -32,7 +32,7 @@ export const mapDataMiddlewareListener = async ( } const background = currentBackgroundSelector(state); - const modelId = updatedModel.idObject; + const modelId = updatedModel.id; const lastPosition = mapOpenedMapPositionByIdSelector(state, modelId); const updatedMapData = getUpdatedMapData({ model: updatedModel, diff --git a/src/redux/models/models.mock.ts b/src/redux/models/models.mock.ts index b7658d38..dd426993 100644 --- a/src/redux/models/models.mock.ts +++ b/src/redux/models/models.mock.ts @@ -10,7 +10,7 @@ export const MODELS_INITIAL_STATE_MOCK: ModelsState = { export const MODELS_DATA_MOCK_WITH_MAIN_MAP: ModelsState = { data: [ { - idObject: 52, + id: 52, width: 26779.25, height: 13503, defaultCenterX: null, diff --git a/src/redux/models/models.reducers.test.ts b/src/redux/models/models.reducers.test.ts index c25cd72d..b4610360 100644 --- a/src/redux/models/models.reducers.test.ts +++ b/src/redux/models/models.reducers.test.ts @@ -1,17 +1,17 @@ -import { modelsFixture } from '@/models/fixtures/modelsFixture'; +import { modelsFixture, modelsPageFixture } from '@/models/fixtures/modelsFixture'; import { apiPath } from '@/redux/apiPath'; import { ToolkitStoreWithSingleSlice, createStoreInstanceUsingSliceReducer, } from '@/utils/createStoreInstanceUsingSliceReducer'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; +import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { HttpStatusCode } from 'axios'; import { unwrapResult } from '@reduxjs/toolkit'; import modelsReducer from './models.slice'; import { getModels } from './models.thunks'; import { ModelsState } from './models.types'; -const mockedAxiosClient = mockNetworkResponse(); +const mockedAxiosNEWApiClient = mockNetworkNewAPIResponse(); const INITIAL_STATE: ModelsState = { data: [], @@ -30,8 +30,10 @@ describe('models reducer', () => { expect(modelsReducer(undefined, action)).toEqual(INITIAL_STATE); }); - it('should update store after succesfull getModels query', async () => { - mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.Ok, modelsFixture); + it('should update store after successfull getModels query', async () => { + mockedAxiosNEWApiClient + .onGet(apiPath.getModelsString()) + .reply(HttpStatusCode.Ok, modelsPageFixture); const { type } = await store.dispatch(getModels()); const { data, loading, error } = store.getState().models; @@ -43,7 +45,7 @@ describe('models reducer', () => { }); it('should update store after failed getModels query', async () => { - mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.NotFound, []); + mockedAxiosNEWApiClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.NotFound, []); const action = await store.dispatch(getModels()); const { data, loading, error } = store.getState().models; @@ -58,7 +60,9 @@ describe('models reducer', () => { }); it('should update store on loading getModels query', async () => { - mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.Ok, modelsFixture); + mockedAxiosNEWApiClient + .onGet(apiPath.getModelsString()) + .reply(HttpStatusCode.Ok, modelsPageFixture); const modelsPromise = store.dispatch(getModels()); diff --git a/src/redux/models/models.reducers.ts b/src/redux/models/models.reducers.ts index ee7b9a63..054b4c0b 100644 --- a/src/redux/models/models.reducers.ts +++ b/src/redux/models/models.reducers.ts @@ -22,7 +22,7 @@ export const setModelVectorRenderingReducer = ( action: PayloadAction<{ vectorRendering: boolean; mapId: number }>, ): void => { const { payload } = action; - const modelIndex = state.data.findIndex(model => model.idObject === payload.mapId); + const modelIndex = state.data.findIndex(model => model.id === payload.mapId); if (modelIndex !== -1) { state.data[modelIndex].vectorRendering = payload.vectorRendering; } diff --git a/src/redux/models/models.selectors.ts b/src/redux/models/models.selectors.ts index 95a3c884..9676601d 100644 --- a/src/redux/models/models.selectors.ts +++ b/src/redux/models/models.selectors.ts @@ -10,27 +10,24 @@ export const modelsDataSelector = createSelector(modelsSelector, models => model export const currentModelSelector = createSelector( modelsDataSelector, mapDataSelector, - (models, mapData) => models.find(model => model.idObject === mapData.modelId), + (models, mapData) => models.find(model => model.id === mapData.modelId), ); export const modelsIdsSelector = createSelector(modelsDataSelector, models => - models.map(model => model.idObject), + models.map(model => model.id), ); export const modelsNameMapSelector = createSelector(modelsDataSelector, models => - models.reduce( - (acc, model) => ({ ...acc, [model.idObject]: model.name }), - {} as Record<number, string>, - ), + models.reduce((acc, model) => ({ ...acc, [model.id]: model.name }), {} as Record<number, string>), ); export const modelsIdsAndNamesSelector = createSelector(modelsDataSelector, models => - models.map(({ idObject, name }) => ({ id: idObject, name })), + models.map(({ id, name }) => ({ id, name })), ); export const currentModelIdSelector = createSelector( currentModelSelector, - model => model?.idObject || MODEL_ID_DEFAULT, + model => model?.id || MODEL_ID_DEFAULT, ); export const lastClickSelector = createSelector(mapDataSelector, mapData => mapData.lastClick); @@ -46,7 +43,7 @@ export const currentModelNameSelector = createSelector( export const modelByIdSelector = createSelector( [modelsSelector, (_state, modelId: number): number => modelId], - (models, modelId) => (models?.data || []).find(({ idObject }) => idObject === modelId), + (models, modelId) => (models?.data || []).find(({ id }) => id === modelId), ); const MAIN_MAP = 0; diff --git a/src/redux/models/models.thunks.test.ts b/src/redux/models/models.thunks.test.ts index a8daf71d..4ad436aa 100644 --- a/src/redux/models/models.thunks.test.ts +++ b/src/redux/models/models.thunks.test.ts @@ -1,16 +1,16 @@ -import { modelsFixture } from '@/models/fixtures/modelsFixture'; +import { modelsFixture, modelsPageFixture } from '@/models/fixtures/modelsFixture'; import { apiPath } from '@/redux/apiPath'; import { ModelsState } from '@/redux/models/models.types'; import { ToolkitStoreWithSingleSlice, createStoreInstanceUsingSliceReducer, } from '@/utils/createStoreInstanceUsingSliceReducer'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; +import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { HttpStatusCode } from 'axios'; import modelsReducer from './models.slice'; import { getModels } from './models.thunks'; -const mockedAxiosClient = mockNetworkResponse(); +const mockedAxiosNEWApiClient = mockNetworkNewAPIResponse(); describe('models thunks', () => { let store = {} as ToolkitStoreWithSingleSlice<ModelsState>; @@ -19,13 +19,15 @@ describe('models thunks', () => { }); describe('getModels', () => { it('should return data when data response from API is valid', async () => { - mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.Ok, modelsFixture); + mockedAxiosNEWApiClient + .onGet(apiPath.getModelsString()) + .reply(HttpStatusCode.Ok, modelsPageFixture); const { payload } = await store.dispatch(getModels()); expect(payload).toEqual(modelsFixture); }); it('should return undefined when data response from API is not valid ', async () => { - mockedAxiosClient + mockedAxiosNEWApiClient .onGet(apiPath.getModelsString()) .reply(HttpStatusCode.Ok, { randomProperty: 'randomValue' }); diff --git a/src/redux/models/models.thunks.ts b/src/redux/models/models.thunks.ts index d81096c9..6447728e 100644 --- a/src/redux/models/models.thunks.ts +++ b/src/redux/models/models.thunks.ts @@ -1,23 +1,22 @@ -import { mapModelSchema } from '@/models/modelSchema'; import { apiPath } from '@/redux/apiPath'; -import { axiosInstance } from '@/services/api/utils/axiosInstance'; -import { MapModel } from '@/types/models'; +import { axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; +import { MapModel, MapModels } 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 { mapModelsSchema } from '@/models/modelSchema'; import { MODELS_FETCHING_ERROR_PREFIX } from './models.constants'; export const getModels = createAsyncThunk<MapModel[] | undefined, void, ThunkConfig>( 'project/getModels', async () => { try { - const response = await axiosInstance.get<MapModel[]>(apiPath.getModelsString()); + const response = await axiosInstanceNewAPI.get<MapModels>(apiPath.getModelsString()); - const isDataValid = validateDataUsingZodSchema(response.data, z.array(mapModelSchema)); + const isDataValid = validateDataUsingZodSchema(response.data, mapModelsSchema); - return isDataValid ? response.data : undefined; + return isDataValid ? response.data.content : undefined; } catch (error) { return Promise.reject(getError({ error, prefix: MODELS_FETCHING_ERROR_PREFIX })); } diff --git a/src/services/pluginsManager/map/openMap.ts b/src/services/pluginsManager/map/openMap.ts index ec6a9149..eeb1eed7 100644 --- a/src/services/pluginsManager/map/openMap.ts +++ b/src/services/pluginsManager/map/openMap.ts @@ -13,21 +13,21 @@ export const openMap = ({ id }: OpenMapArgs): void => { const { getState, dispatch } = store; const models = modelsDataSelector(getState()); const openedMaps = mapOpenedMapsSelector(getState()); - const mapToOpen = models.find(model => model.idObject === id); + const mapToOpen = models.find(model => model.id === id); const currentModelId = mapModelIdSelector(getState()); if (!mapToOpen) throw new Error(ERROR_MAP_NOT_FOUND); - const isMapAlreadyOpened = openedMaps.some(map => map.modelId === mapToOpen.idObject); + const isMapAlreadyOpened = openedMaps.some(map => map.modelId === mapToOpen.id); if (isMapAlreadyOpened) { - dispatch(setActiveMap({ modelId: mapToOpen.idObject })); + dispatch(setActiveMap({ modelId: mapToOpen.id })); } else { - dispatch(openMapAndSetActive({ modelId: mapToOpen.idObject, modelName: mapToOpen.name })); + dispatch(openMapAndSetActive({ modelId: mapToOpen.id, modelName: mapToOpen.name })); } - if (currentModelId !== mapToOpen.idObject) { + if (currentModelId !== mapToOpen.id) { PluginsEventBus.dispatchEvent('onSubmapClose', currentModelId); - PluginsEventBus.dispatchEvent('onSubmapOpen', mapToOpen.idObject); + PluginsEventBus.dispatchEvent('onSubmapOpen', mapToOpen.id); } }; diff --git a/src/types/models.ts b/src/types/models.ts index 4821833d..99add0a5 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -31,7 +31,7 @@ import { markerTypeSchema, markerWithPositionSchema, } from '@/models/markerSchema'; -import { mapModelSchema } from '@/models/modelSchema'; +import { mapModelSchema, mapModelsSchema } from '@/models/modelSchema'; import { organism } from '@/models/organism'; import { overlayBioEntitySchema, @@ -89,6 +89,8 @@ export type OverviewImageView = z.infer<typeof overviewImageView>; export type OverviewImageLink = z.infer<typeof overviewImageLink>; export type OverviewImageLinkImage = z.infer<typeof overviewImageLinkImage>; export type OverviewImageLinkModel = z.infer<typeof overviewImageLinkModel>; + +export type MapModels = z.infer<typeof mapModelsSchema>; export type MapModel = z.infer<typeof mapModelSchema>; export type BioShape = z.infer<typeof bioShapeSchema>; export type LineType = z.infer<typeof lineTypeSchema>; diff --git a/src/utils/initialize/useInitializeStore.test.ts b/src/utils/initialize/useInitializeStore.test.ts index 1a99f715..94780641 100644 --- a/src/utils/initialize/useInitializeStore.test.ts +++ b/src/utils/initialize/useInitializeStore.test.ts @@ -1,6 +1,6 @@ import { PROJECT_ID } from '@/constants'; import { backgroundsFixture } from '@/models/fixtures/backgroundsFixture'; -import { modelsFixture } from '@/models/fixtures/modelsFixture'; +import { modelsFixture, modelsPageFixture } from '@/models/fixtures/modelsFixture'; import { overlaysFixture } from '@/models/fixtures/overlaysFixture'; import { projectFixture } from '@/models/fixtures/projectFixture'; import { apiPath } from '@/redux/apiPath'; @@ -21,7 +21,9 @@ const mockedAxiosNEWApiClient = mockNetworkNewAPIResponse(); describe('useInitializeStore - hook', () => { describe('when fired', () => { beforeAll(() => { - mockedAxiosClient.onGet(apiPath.getModelsString()).reply(HttpStatusCode.Ok, modelsFixture); + mockedAxiosNEWApiClient + .onGet(apiPath.getModelsString()) + .reply(HttpStatusCode.Ok, modelsPageFixture); mockedAxiosClient .onGet(apiPath.getAllOverlaysByProjectIdQuery(PROJECT_ID, { publicOverlay: true })) .reply(HttpStatusCode.Ok, overlaysFixture); diff --git a/src/utils/map/getUpdatedMapData.test.ts b/src/utils/map/getUpdatedMapData.test.ts index 4e4b2852..6f381977 100644 --- a/src/utils/map/getUpdatedMapData.test.ts +++ b/src/utils/map/getUpdatedMapData.test.ts @@ -15,7 +15,7 @@ describe('getUpdatedMapData - util', () => { it('should return correct value', () => { const result = { - modelId: model.idObject, + modelId: model.id, size: { width: model.width, height: model.height, @@ -51,7 +51,7 @@ describe('getUpdatedMapData - util', () => { it('should return correct value', () => { const result = { - modelId: model.idObject, + modelId: model.id, size: { width: model.width, height: model.height, @@ -87,7 +87,7 @@ describe('getUpdatedMapData - util', () => { it('should return correct value', () => { const result = { - modelId: model.idObject, + modelId: model.id, size: { width: model.width, height: model.height, diff --git a/src/utils/map/getUpdatedMapData.ts b/src/utils/map/getUpdatedMapData.ts index 6baeeae0..1e4fc498 100644 --- a/src/utils/map/getUpdatedMapData.ts +++ b/src/utils/map/getUpdatedMapData.ts @@ -27,7 +27,7 @@ export const getUpdatedMapData = ({ const mergedPosition = getPointMerged(position?.initial || {}, defaultPosition); return { - modelId: model.idObject, + modelId: model.id, backgroundId: background?.id || MAP_DATA_INITIAL_STATE.backgroundId, size: { width: model.width, -- GitLab