From 7b79d139f3bea2e2d38c7ca43a906418f765e543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Grocholewski?= <m.grocholewski@atcomp.pl> Date: Fri, 17 Jan 2025 08:37:43 +0100 Subject: [PATCH 1/3] feat(map): remove raster rendering --- ...rImageObjectEditFactoryModal.component.tsx | 2 +- .../NavBar/NavBar.component.tsx | 14 -- src/components/Map/Map.component.tsx | 14 +- .../MapDrawEditActions.component.tsx | 4 +- .../MapLoader/MapLoader.component.test.tsx | 25 +-- .../Map/MapLoader/MapLoader.component.tsx | 4 +- .../Map/MapViewer/MapViewer.constants.ts | 202 ++++++++++++++++++ .../Map/MapViewer/MapViewer.types.ts | 15 ++ .../MapViewerVector.constants.ts | 201 ----------------- .../MapViewerVector/MapViewerVector.types.ts | 24 --- .../listeners/useOlMapVectorListeners.test.ts | 50 ----- .../listeners/useOlMapVectorListeners.ts | 100 --------- .../utils/config/useOlMapVectorLayers.test.ts | 85 -------- .../utils/config/useOlMapVectorLayers.ts | 21 -- .../useOlMapAdditionalLayers.test.ts | 2 +- .../useOlMapAdditionalLayers.ts | 24 +-- .../mapCardLayer/useOlMapCardLayer.test.ts | 0 .../config/mapCardLayer/useOlMapCardLayer.ts | 0 .../processLayer}/processModelElements.ts | 15 +- .../useOlMapProcessLayer.test.ts} | 4 +- .../processLayer/useOlMapProcessLayer.ts} | 26 +-- .../utils/config/useOlMapCommonLayers.test.ts | 93 -------- .../utils/config/useOlMapCommonLayers.ts | 16 -- .../utils/config/useOlMapLayers.test.ts | 28 ++- .../MapViewer/utils/config/useOlMapLayers.ts | 35 ++- .../mapSingleClick/handleReactionResults.ts | 2 +- .../mouseClick/clickHandleReaction.test.ts | 2 +- .../mouseClick/clickHandleReaction.ts | 2 +- .../getModelElementsIdsFromReaction.test.ts | 0 .../getModelElementsIdsFromReaction.ts | 0 .../leftClickHandleAlias.test.ts | 2 +- .../mouseLeftClick/leftClickHandleAlias.ts | 0 .../mouseLeftClick/onMapLeftClick.test.ts | 6 +- .../mouseLeftClick/onMapLeftClick.ts | 6 +- .../mouseRightClick/onMapRightClick.test.ts | 4 +- .../mouseRightClick/onMapRightClick.ts | 6 +- .../rightClickHandleAlias.test.ts | 2 +- .../mouseRightClick/rightClickHandleAlias.ts | 0 .../utils/listeners/useOlMapListeners.test.ts | 20 +- .../utils/listeners/useOlMapListeners.ts | 108 ++++------ .../shapes/coords/findLargestExtent.test.ts | 2 +- .../utils/shapes/coords/findLargestExtent.ts | 0 .../shapes/coords/getBezierCurve.test.ts | 0 .../utils/shapes/coords/getBezierCurve.ts | 0 .../coords/getBoundingBoxFromExtent.test.ts | 2 +- .../shapes/coords/getBoundingBoxFromExtent.ts | 2 +- .../utils/shapes/coords/getCenter.test.ts | 2 +- .../utils/shapes/coords/getCenter.ts | 0 .../utils/shapes/coords/getCoordsX.test.ts | 0 .../utils/shapes/coords/getCoordsX.ts | 0 .../utils/shapes/coords/getCoordsY.test.ts | 0 .../utils/shapes/coords/getCoordsY.ts | 0 .../shapes/coords/getCurveCoords.test.ts | 4 +- .../utils/shapes/coords/getCurveCoords.ts | 4 +- .../shapes/coords/getDividedExtents.test.ts | 2 +- .../utils/shapes/coords/getDividedExtents.ts | 0 .../shapes/coords/getEllipseCoords.test.ts | 4 +- .../utils/shapes/coords/getEllipseCoords.ts | 4 +- .../shapes/coords/getLineSegments.test.ts | 2 +- .../utils/shapes/coords/getLineSegments.ts | 0 .../shapes/coords/getPolygonCoords.test.ts | 8 +- .../utils/shapes/coords/getPolygonCoords.ts | 8 +- .../utils/shapes/coords/getRotation.test.ts | 2 +- .../utils/shapes/coords/getRotation.ts | 0 .../utils/shapes/elements/BaseMultiPolygon.ts | 19 +- .../utils/shapes/elements/Compartment.ts | 15 +- .../shapes/elements/CompartmentCircle.test.ts | 25 +-- .../shapes/elements/CompartmentCircle.ts | 11 +- .../elements/CompartmentPathway.test.ts | 25 +-- .../shapes/elements/CompartmentPathway.ts | 17 +- .../shapes/elements/CompartmentSquare.test.ts | 23 +- .../shapes/elements/CompartmentSquare.ts | 11 +- .../utils/shapes/elements/Glyph/Glyph.test.ts | 4 +- .../utils/shapes/elements/Glyph/Glyph.ts | 11 +- .../shapes/elements/Glyph/updateGlyph.ts | 0 .../utils/shapes/elements/MapElement.test.ts | 23 +- .../utils/shapes/elements/MapElement.ts | 23 +- .../shapes/elements/getArrowFeature.test.ts | 8 +- .../utils/shapes/elements/getArrowFeature.ts | 10 +- .../shapes/elements/getShapePolygon.test.ts | 6 +- .../utils/shapes/elements/getShapePolygon.ts | 6 +- .../elements/handleSemanticView.test.ts | 6 +- .../shapes/elements/handleSemanticView.ts | 8 +- .../elements/isFeatureInCompartment.test.ts | 0 .../shapes/elements/isFeatureInCompartment.ts | 0 .../elements/removeElementFromLayer.test.ts | 0 .../shapes/elements/removeElementFromLayer.ts | 0 .../utils/shapes/layer/Layer.test.ts | 17 +- .../utils/shapes/layer/Layer.ts | 21 +- .../layer/getDrawImageInteraction.test.ts | 2 +- .../shapes/layer/getDrawImageInteraction.ts | 2 +- .../getTransformImageInteraction.test.ts | 4 +- .../layer/getTransformImageInteraction.ts | 2 +- .../utils/shapes/overlay/LineOverlay.test.ts | 8 +- .../utils/shapes/overlay/LineOverlay.ts | 2 +- .../shapes/overlay/MarkerOverlay.test.ts | 8 +- .../utils/shapes/overlay/MarkerOverlay.ts | 2 +- .../overlay/areOverlayOrdersNotEqual.ts | 0 .../calculateOverlayDimensions.test.ts | 0 .../overlay/calculateOverlayDimensions.ts | 0 .../findMatchingSubmapLinkRectangle.test.ts | 0 .../findMatchingSubmapLinkRectangle.ts | 0 .../utils/shapes/overlay/getOverlays.test.ts | 0 .../utils/shapes/overlay/getOverlays.ts | 4 +- .../overlay/groupOverlayEntities.test.ts | 0 .../shapes/overlay/groupOverlayEntities.ts | 4 +- .../processOverlayGroupedElements.test.ts | 4 +- .../overlay/processOverlayGroupedElements.ts | 6 +- .../overlay/sortElementOverlayByColor.test.ts | 0 .../overlay/sortElementOverlayByColor.ts | 0 .../utils/shapes/reaction/Reaction.test.ts | 4 +- .../utils/shapes/reaction/Reaction.ts | 20 +- .../utils/shapes/style/getCoverStyles.test.ts | 8 +- .../utils/shapes/style/getCoverStyles.ts | 6 +- .../utils/shapes/style/getFill.test.ts | 0 .../utils/shapes/style/getFill.ts | 0 .../style/getScaledElementStyle.test.ts | 2 +- .../shapes/style/getScaledElementStyle.ts | 2 +- .../shapes/style/getScaledStrokeStyle.test.ts | 0 .../shapes/style/getScaledStrokeStyle.ts | 0 .../utils/shapes/style/getStroke.test.ts | 0 .../utils/shapes/style/getStroke.ts | 0 .../utils/shapes/style/getStyle.test.ts | 2 +- .../utils/shapes/style/getStyle.ts | 11 +- .../utils/shapes/style/rgbToHex.test.ts | 0 .../utils/shapes/style/rgbToHex.ts | 0 .../utils/shapes/text/Text.test.ts | 10 +- .../utils/shapes/text/Text.ts | 13 +- .../utils/shapes/text/getTextCoords.test.ts | 2 +- .../utils/shapes/text/getTextCoords.ts | 5 +- .../utils/shapes/text/getTextStyle.test.ts | 2 +- .../utils/shapes/text/getTextStyle.ts | 2 +- .../text/getWrappedTextWithFontSize.test.ts | 2 +- .../shapes/text/getWrappedTextWithFontSize.ts | 0 .../Map/MapViewer/utils/useOlMap.ts | 47 +--- src/models/mocks/modelsMock.ts | 1 - src/models/modelSchema.ts | 1 - .../fetchReactionsAndGetBioEntitiesIds.ts | 2 +- src/redux/layers/layers.reducers.ts | 3 + src/redux/models/models.reducers.ts | 13 +- src/redux/models/models.selectors.ts | 5 - src/redux/models/models.slice.ts | 8 +- 142 files changed, 592 insertions(+), 1126 deletions(-) delete mode 100644 src/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants.ts delete mode 100644 src/components/Map/MapViewer/MapViewerVector/MapViewerVector.types.ts delete mode 100644 src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.test.ts delete mode 100644 src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.ts delete mode 100644 src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.test.ts delete mode 100644 src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.ts rename src/components/Map/MapViewer/{MapViewerVector => }/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/config/additionalLayers/useOlMapAdditionalLayers.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/config/mapCardLayer/useOlMapCardLayer.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/config/mapCardLayer/useOlMapCardLayer.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector/utils/config/reactionsLayer => utils/config/processLayer}/processModelElements.ts (87%) rename src/components/Map/MapViewer/{MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.test.ts => utils/config/processLayer/useOlMapProcessLayer.test.ts} (79%) rename src/components/Map/MapViewer/{MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.ts => utils/config/processLayer/useOlMapProcessLayer.ts} (87%) delete mode 100644 src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.test.ts delete mode 100644 src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.ts rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/clickHandleReaction.test.ts (97%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/clickHandleReaction.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/getModelElementsIdsFromReaction.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/getModelElementsIdsFromReaction.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts (95%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts (95%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseRightClick/onMapRightClick.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => utils}/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/findLargestExtent.test.ts (76%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/findLargestExtent.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getBezierCurve.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getBezierCurve.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getBoundingBoxFromExtent.test.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getBoundingBoxFromExtent.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCenter.test.ts (81%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCenter.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCoordsX.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCoordsX.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCoordsY.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCoordsY.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCurveCoords.test.ts (90%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getCurveCoords.ts (85%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getDividedExtents.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getDividedExtents.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getEllipseCoords.test.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getEllipseCoords.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getLineSegments.test.ts (97%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getLineSegments.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getPolygonCoords.test.ts (88%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getPolygonCoords.ts (76%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getRotation.test.ts (83%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/coords/getRotation.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/BaseMultiPolygon.ts (91%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/Compartment.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentCircle.test.ts (78%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentCircle.ts (87%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentPathway.test.ts (78%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentPathway.ts (83%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentSquare.test.ts (79%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/CompartmentSquare.ts (87%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/Glyph/Glyph.test.ts (93%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/Glyph/Glyph.ts (95%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/Glyph/updateGlyph.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/MapElement.test.ts (80%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/MapElement.ts (91%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/getArrowFeature.test.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/getArrowFeature.ts (80%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/getShapePolygon.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/getShapePolygon.ts (78%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/handleSemanticView.test.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/handleSemanticView.ts (86%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/isFeatureInCompartment.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/isFeatureInCompartment.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/removeElementFromLayer.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/elements/removeElementFromLayer.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/Layer.test.ts (84%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/Layer.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/getDrawImageInteraction.test.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/getDrawImageInteraction.ts (97%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/getTransformImageInteraction.test.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/layer/getTransformImageInteraction.ts (98%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/LineOverlay.test.ts (78%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/LineOverlay.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/MarkerOverlay.test.ts (79%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/MarkerOverlay.ts (96%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/areOverlayOrdersNotEqual.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/calculateOverlayDimensions.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/calculateOverlayDimensions.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/findMatchingSubmapLinkRectangle.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/findMatchingSubmapLinkRectangle.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/getOverlays.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/getOverlays.ts (83%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/groupOverlayEntities.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/groupOverlayEntities.ts (88%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/processOverlayGroupedElements.test.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/processOverlayGroupedElements.ts (87%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/sortElementOverlayByColor.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/overlay/sortElementOverlayByColor.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/reaction/Reaction.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/reaction/Reaction.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getCoverStyles.test.ts (87%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getCoverStyles.ts (86%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getFill.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getFill.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getScaledElementStyle.test.ts (92%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getScaledElementStyle.ts (76%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getScaledStrokeStyle.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getScaledStrokeStyle.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getStroke.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getStroke.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getStyle.test.ts (94%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/getStyle.ts (65%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/rgbToHex.test.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/style/rgbToHex.ts (100%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/Text.test.ts (80%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/Text.ts (84%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getTextCoords.test.ts (85%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getTextCoords.ts (89%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getTextStyle.test.ts (88%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getTextStyle.ts (95%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getWrappedTextWithFontSize.test.ts (95%) rename src/components/Map/MapViewer/{MapViewerVector => }/utils/shapes/text/getWrappedTextWithFontSize.ts (100%) diff --git a/src/components/FunctionalArea/Modal/LayerImageObjectModal/LayerImageObjectEditFactoryModal.component.tsx b/src/components/FunctionalArea/Modal/LayerImageObjectModal/LayerImageObjectEditFactoryModal.component.tsx index 3e8d27b6..655bb8d9 100644 --- a/src/components/FunctionalArea/Modal/LayerImageObjectModal/LayerImageObjectEditFactoryModal.component.tsx +++ b/src/components/FunctionalArea/Modal/LayerImageObjectModal/LayerImageObjectEditFactoryModal.component.tsx @@ -14,7 +14,7 @@ import { showToast } from '@/utils/showToast'; import { closeModal } from '@/redux/modal/modal.slice'; import { SerializedError } from '@reduxjs/toolkit'; import { useMapInstance } from '@/utils/context/mapInstanceContext'; -import updateGlyph from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/updateGlyph'; +import updateGlyph from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/updateGlyph'; import { mapEditToolsSetLayerObject } from '@/redux/mapEditTools/mapEditTools.slice'; export const LayerImageObjectEditFactoryModal: React.FC = () => { diff --git a/src/components/FunctionalArea/NavBar/NavBar.component.tsx b/src/components/FunctionalArea/NavBar/NavBar.component.tsx index edd14170..eafb96e3 100644 --- a/src/components/FunctionalArea/NavBar/NavBar.component.tsx +++ b/src/components/FunctionalArea/NavBar/NavBar.component.tsx @@ -11,16 +11,11 @@ import { store } from '@/redux/store'; import Image from 'next/image'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { projectIdSelector } from '@/redux/project/project.selectors'; -import { Switch } from '@/shared/Switch'; -import { currentModelIdSelector, vectorRenderingSelector } from '@/redux/models/models.selectors'; -import { setModelVectorRendering } from '@/redux/models/models.slice'; export const NavBar = (): JSX.Element => { const dispatch = useAppDispatch(); const projectId = useAppSelector(projectIdSelector); - const vectorRendering = useAppSelector(vectorRenderingSelector); - const currentModelId = useAppSelector(currentModelIdSelector); const toggleDrawerInfo = (): void => { if (store.getState().drawer.isOpen && store.getState().drawer.drawerName === 'project-info') { @@ -91,15 +86,6 @@ export const NavBar = (): JSX.Element => { <IconButton icon="legend" onClick={toggleDrawerLegend} title="Legend" /> </div> </div> - <div className="flex flex-col items-center gap-[10px] text-center text-[12px]"> - <span>Vector rendering</span> - <Switch - isChecked={vectorRendering} - onToggle={value => - dispatch(setModelVectorRendering({ vectorRendering: value, mapId: currentModelId })) - } - /> - </div> <div className="flex flex-col items-center gap-[20px]" data-testid="nav-logos-and-powered-by"> <a href="https://www.uni.lu/en/" target="_blank"> <Image diff --git a/src/components/Map/Map.component.tsx b/src/components/Map/Map.component.tsx index 0a57b1fb..df0e5eac 100644 --- a/src/components/Map/Map.component.tsx +++ b/src/components/Map/Map.component.tsx @@ -6,16 +6,13 @@ import { MapLoader } from '@/components/Map/MapLoader/MapLoader.component'; import { MapVectorBackgroundSelector } from '@/components/Map/MapVectorBackgroundSelector/MapVectorBackgroundSelector.component'; import { MapActiveLayerSelector } from '@/components/Map/MapActiveLayerSelector/MapActiveLayerSelector.component'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { vectorRenderingSelector } from '@/redux/models/models.selectors'; import { MapAdditionalLogos } from '@/components/Map/MapAdditionalLogos'; import { MapDrawActions } from '@/components/Map/MapDrawActions/MapDrawActions.component'; import { layersActiveLayerSelector } from '@/redux/layers/layers.selectors'; import { MapAdditionalActions } from './MapAdditionalActions'; -import { MapAdditionalOptions } from './MapAdditionalOptions'; import { PluginsDrawer } from './PluginsDrawer'; export const Map = (): JSX.Element => { - const vectorRendering = useAppSelector(vectorRenderingSelector); const activeLayer = useAppSelector(layersActiveLayerSelector); return ( @@ -24,14 +21,9 @@ export const Map = (): JSX.Element => { data-testid="map-container" > <MapViewer /> - {!vectorRendering && <MapAdditionalOptions />} - {vectorRendering && ( - <> - <MapVectorBackgroundSelector /> - <MapActiveLayerSelector /> - {activeLayer && <MapDrawActions />} - </> - )} + <MapVectorBackgroundSelector /> + <MapActiveLayerSelector /> + {activeLayer && <MapDrawActions />} <Drawer /> <PluginsDrawer /> <Legend /> diff --git a/src/components/Map/MapDrawActions/MapDrawEditActions.component.tsx b/src/components/Map/MapDrawActions/MapDrawEditActions.component.tsx index 1782e00e..01ebfff1 100644 --- a/src/components/Map/MapDrawActions/MapDrawEditActions.component.tsx +++ b/src/components/Map/MapDrawActions/MapDrawEditActions.component.tsx @@ -10,12 +10,12 @@ import { layersActiveLayerSelector } from '@/redux/layers/layers.selectors'; import { layerDeleteImage, layerUpdateImage } from '@/redux/layers/layers.slice'; import { useMapInstance } from '@/utils/context/mapInstanceContext'; import { mapEditToolsSetLayerObject } from '@/redux/mapEditTools/mapEditTools.slice'; -import updateGlyph from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/updateGlyph'; +import updateGlyph from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/updateGlyph'; import QuestionModal from '@/components/FunctionalArea/Modal/QuestionModal/QustionModal.component'; import { useState } from 'react'; import { showToast } from '@/utils/showToast'; import { SerializedError } from '@reduxjs/toolkit'; -import removeElementFromLayer from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/removeElementFromLayer'; +import removeElementFromLayer from '@/components/Map/MapViewer/utils/shapes/elements/removeElementFromLayer'; type MapDrawEditActionsComponentProps = { toggleMapEditAction: () => void; diff --git a/src/components/Map/MapLoader/MapLoader.component.test.tsx b/src/components/Map/MapLoader/MapLoader.component.test.tsx index eb35db6b..7f8fb00b 100644 --- a/src/components/Map/MapLoader/MapLoader.component.test.tsx +++ b/src/components/Map/MapLoader/MapLoader.component.test.tsx @@ -9,7 +9,6 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { newReactionsLoadingSelector } from '@/redux/newReactions/newReactions.selectors'; import { modelElementsLoadingSelector } from '@/redux/modelElements/modelElements.selector'; import { isDrawerOpenSelector } from '@/redux/drawer/drawer.selectors'; -import { vectorRenderingSelector } from '@/redux/models/models.selectors'; import { arrowTypesLoadingSelector, bioShapesLoadingSelector, @@ -50,7 +49,6 @@ describe('MapLoader', () => { const selectorMap = new Map<SelectorFunction, string | boolean>([ [newReactionsLoadingSelector, 'succeeded'], [modelElementsLoadingSelector, 'succeeded'], - [vectorRenderingSelector, true], [bioShapesLoadingSelector, 'succeeded'], [lineTypesLoadingSelector, 'succeeded'], [arrowTypesLoadingSelector, 'succeeded'], @@ -65,12 +63,11 @@ describe('MapLoader', () => { expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument(); }); - it('should render the LoadingIndicator when vectorRendering is true and data is loading', () => { + it('should render the LoadingIndicator when data is loading', () => { mockUseAppSelector.mockImplementation(selector => { const selectorMap = new Map<SelectorFunction, string | boolean>([ [newReactionsLoadingSelector, 'pending'], [modelElementsLoadingSelector, 'succeeded'], - [vectorRenderingSelector, true], [bioShapesLoadingSelector, 'succeeded'], [lineTypesLoadingSelector, 'succeeded'], [arrowTypesLoadingSelector, 'succeeded'], @@ -84,24 +81,4 @@ describe('MapLoader', () => { expect(screen.queryByTestId('loading-indicator')).toBeInTheDocument(); }); - - it('should not render the LoadingIndicator when vectorRendering is false even when data is loading', () => { - mockUseAppSelector.mockImplementation(selector => { - const selectorMap = new Map<SelectorFunction, string | boolean>([ - [newReactionsLoadingSelector, 'pending'], - [modelElementsLoadingSelector, 'succeeded'], - [vectorRenderingSelector, false], - [bioShapesLoadingSelector, 'succeeded'], - [lineTypesLoadingSelector, 'succeeded'], - [arrowTypesLoadingSelector, 'succeeded'], - [layersLoadingSelector, 'succeeded'], - [isDrawerOpenSelector, false], - ]); - - return selectorMap.get(selector) ?? false; - }); - renderComponent(); - - expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument(); - }); }); diff --git a/src/components/Map/MapLoader/MapLoader.component.tsx b/src/components/Map/MapLoader/MapLoader.component.tsx index fc457e0b..a521a7f5 100644 --- a/src/components/Map/MapLoader/MapLoader.component.tsx +++ b/src/components/Map/MapLoader/MapLoader.component.tsx @@ -2,7 +2,6 @@ import { LoadingIndicator } from '@/shared/LoadingIndicator'; import { useMemo } from 'react'; import { newReactionsLoadingSelector } from '@/redux/newReactions/newReactions.selectors'; import { modelElementsLoadingSelector } from '@/redux/modelElements/modelElements.selector'; -import { vectorRenderingSelector } from '@/redux/models/models.selectors'; import { arrowTypesLoadingSelector, bioShapesLoadingSelector, @@ -16,7 +15,6 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; export const MapLoader = (): JSX.Element => { const reactionsFetching = useAppSelector(newReactionsLoadingSelector); const modelElementsFetching = useAppSelector(modelElementsLoadingSelector); - const vectorRendering = useAppSelector(vectorRenderingSelector); const bioShapesFetching = useAppSelector(bioShapesLoadingSelector); const lineTypesFetching = useAppSelector(lineTypesLoadingSelector); const arrowTypesFetching = useAppSelector(arrowTypesLoadingSelector); @@ -44,7 +42,7 @@ export const MapLoader = (): JSX.Element => { return ( <div className={`map-loader transition-all duration-500 ${isDrawerOpen ? 'move-right' : ''}`}> - {vectorRendering && showLoader && <LoadingIndicator width={48} height={48} />} + {showLoader && <LoadingIndicator width={48} height={48} />} </div> ); }; diff --git a/src/components/Map/MapViewer/MapViewer.constants.ts b/src/components/Map/MapViewer/MapViewer.constants.ts index 41924be9..2d047265 100644 --- a/src/components/Map/MapViewer/MapViewer.constants.ts +++ b/src/components/Map/MapViewer/MapViewer.constants.ts @@ -1 +1,203 @@ +import { Color, ShapeRelAbs, ShapeRelAbsBezierPoint } from '@/types/models'; + export const MAP_VIEWER_ROLE = 'map-viewer'; + +export const VECTOR_MAP_LAYER_TYPE = 'vectorMapLayer'; + +export const COMPLEX_SBO_TERMS = ['SBO:0000253', 'SBO:0000297', 'SBO:0000289']; + +export const TEXT_CUTOFF_SCALE = 0.34; +export const OUTLINE_CUTOFF_SCALE = 0.18; +export const COMPLEX_CONTENTS_CUTOFF_SCALE = 0.215; +export const REACTION_ELEMENT_CUTOFF_SCALE = 0.125; + +export const WHITE_COLOR: Color = { + alpha: 255, + rgb: 16777215, +}; + +export const BLACK_COLOR: Color = { + alpha: 255, + rgb: -16777216, +}; + +export const TRANSPARENT_COLOR: Color = { + alpha: 0, + rgb: 0, +}; + +export const REACTION_ELEMENT_TYPES = { + OPERATOR: 'OPERATOR', + SQUARE: 'SQUARE', + LINE: 'LINE', + ARROW: 'ARROW', +}; + +export const MAP_ELEMENT_TYPES = { + TEXT: 'TEXT', + MODIFICATION: 'MODIFICATION', + ACTIVITY_BORDER: 'ACTIVITY_BORDER', + ENTITY: 'ENTITY', + OVERLAY: 'OVERLAY', + COMPARTMENT: 'COMPARTMENT', +}; + +export const LAYER_ELEMENT_TYPES = { + TEXT: 'TEXT', + OVAL: 'OVAL', + RECT: 'RECT', + LINE: 'LINE', + ARROW: 'ARROW', +}; + +export const COMPARTMENT_SQUARE_POINTS: Array<ShapeRelAbs | ShapeRelAbsBezierPoint> = [ + { + type: 'REL_ABS_POINT', + absoluteX: 10.0, + absoluteY: 0.0, + relativeX: 0.0, + relativeY: 0.0, + relativeHeightForX: null, + relativeWidthForY: null, + }, + { + type: 'REL_ABS_POINT', + absoluteX: -10.0, + absoluteY: 0.0, + relativeX: 100.0, + relativeY: 0.0, + relativeHeightForX: null, + relativeWidthForY: null, + }, + { + type: 'REL_ABS_BEZIER_POINT', + absoluteX1: 0.0, + absoluteY1: 10.0, + relativeX1: 100.0, + relativeY1: 0.0, + relativeHeightForX1: null, + relativeWidthForY1: null, + absoluteX2: -5.0, + absoluteY2: 0.0, + relativeX2: 100.0, + relativeY2: 0.0, + relativeHeightForX2: null, + relativeWidthForY2: null, + absoluteX3: 0.0, + absoluteY3: 5.0, + relativeX3: 100.0, + relativeY3: 0.0, + relativeHeightForX3: null, + relativeWidthForY3: null, + }, + { + type: 'REL_ABS_POINT', + absoluteX: 0.0, + absoluteY: -10.0, + relativeX: 100.0, + relativeY: 100.0, + relativeHeightForX: null, + relativeWidthForY: null, + }, + { + type: 'REL_ABS_BEZIER_POINT', + absoluteX1: -10.0, + absoluteY1: 0.0, + relativeX1: 100.0, + relativeY1: 100.0, + relativeHeightForX1: null, + relativeWidthForY1: null, + absoluteX2: 0.0, + absoluteY2: -5.0, + relativeX2: 100.0, + relativeY2: 100.0, + relativeHeightForX2: null, + relativeWidthForY2: null, + absoluteX3: -5.0, + absoluteY3: 0.0, + relativeX3: 100.0, + relativeY3: 100.0, + relativeHeightForX3: null, + relativeWidthForY3: null, + }, + { + type: 'REL_ABS_POINT', + absoluteX: 10.0, + absoluteY: 0.0, + relativeX: 0.0, + relativeY: 100.0, + relativeHeightForX: null, + relativeWidthForY: null, + }, + { + type: 'REL_ABS_BEZIER_POINT', + absoluteX1: 0.0, + absoluteY1: -10.0, + relativeX1: 0.0, + relativeY1: 100.0, + relativeHeightForX1: null, + relativeWidthForY1: null, + absoluteX2: 5.0, + absoluteY2: 0.0, + relativeX2: 0.0, + relativeY2: 100.0, + relativeHeightForX2: null, + relativeWidthForY2: null, + absoluteX3: 0.0, + absoluteY3: -5.0, + relativeX3: 0.0, + relativeY3: 100.0, + relativeHeightForX3: null, + relativeWidthForY3: null, + }, + { + type: 'REL_ABS_POINT', + absoluteX: 0.0, + absoluteY: 10.0, + relativeX: 0.0, + relativeY: 0.0, + relativeHeightForX: null, + relativeWidthForY: null, + }, + { + type: 'REL_ABS_BEZIER_POINT', + absoluteX1: 10.0, + absoluteY1: 0.0, + relativeX1: 0.0, + relativeY1: 0.0, + relativeHeightForX1: null, + relativeWidthForY1: null, + absoluteX2: 0.0, + absoluteY2: 5.0, + relativeX2: 0.0, + relativeY2: 0.0, + relativeHeightForX2: null, + relativeWidthForY2: null, + absoluteX3: 5.0, + absoluteY3: 0.0, + relativeX3: 0.0, + relativeY3: 0.0, + relativeHeightForX3: null, + relativeWidthForY3: null, + }, +]; + +export const COMPARTMENT_CIRCLE_CENTER: ShapeRelAbs = { + type: 'REL_ABS_POINT', + absoluteX: 0.0, + absoluteY: 0.0, + relativeX: 50.0, + relativeY: 50.0, + relativeHeightForX: null, + relativeWidthForY: null, +}; + +export const COMPARTMENT_CIRCLE_RADIUS: ShapeRelAbs = { + type: 'REL_ABS_RADIUS', + absoluteX: 0.0, + absoluteY: 0.0, + relativeX: 50.0, + relativeY: 50.0, + relativeHeightForX: null, + relativeWidthForY: null, +}; diff --git a/src/components/Map/MapViewer/MapViewer.types.ts b/src/components/Map/MapViewer/MapViewer.types.ts index f6750e5c..f10c9070 100644 --- a/src/components/Map/MapViewer/MapViewer.types.ts +++ b/src/components/Map/MapViewer/MapViewer.types.ts @@ -1,7 +1,22 @@ import View from 'ol/View'; import BaseLayer from 'ol/layer/Base'; +import { OverlayBioEntityRender } from '@/types/OLrendering'; export type MapConfig = { view: View; layers: BaseLayer[]; }; + +export type VerticalAlign = 'TOP' | 'MIDDLE' | 'BOTTOM'; +export type HorizontalAlign = 'LEFT' | 'RIGHT' | 'CENTER' | 'END' | 'START'; + +export type OverlayBioEntityGroupedElementsType = { + [id: string]: Array<OverlayBioEntityRender & { amount: number }>; +}; + +export type BoundingBox = { + x: number; + y: number; + width: number; + height: number; +}; diff --git a/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants.ts b/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants.ts deleted file mode 100644 index 614d3dcf..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants.ts +++ /dev/null @@ -1,201 +0,0 @@ -import { Color, ShapeRelAbs, ShapeRelAbsBezierPoint } from '@/types/models'; - -export const VECTOR_MAP_LAYER_TYPE = 'vectorMapLayer'; - -export const COMPLEX_SBO_TERMS = ['SBO:0000253', 'SBO:0000297', 'SBO:0000289']; - -export const TEXT_CUTOFF_SCALE = 0.34; -export const OUTLINE_CUTOFF_SCALE = 0.18; -export const COMPLEX_CONTENTS_CUTOFF_SCALE = 0.215; -export const REACTION_ELEMENT_CUTOFF_SCALE = 0.125; - -export const WHITE_COLOR: Color = { - alpha: 255, - rgb: 16777215, -}; - -export const BLACK_COLOR: Color = { - alpha: 255, - rgb: -16777216, -}; - -export const TRANSPARENT_COLOR: Color = { - alpha: 0, - rgb: 0, -}; - -export const REACTION_ELEMENT_TYPES = { - OPERATOR: 'OPERATOR', - SQUARE: 'SQUARE', - LINE: 'LINE', - ARROW: 'ARROW', -}; - -export const MAP_ELEMENT_TYPES = { - TEXT: 'TEXT', - MODIFICATION: 'MODIFICATION', - ACTIVITY_BORDER: 'ACTIVITY_BORDER', - ENTITY: 'ENTITY', - OVERLAY: 'OVERLAY', - COMPARTMENT: 'COMPARTMENT', -}; - -export const LAYER_ELEMENT_TYPES = { - TEXT: 'TEXT', - OVAL: 'OVAL', - RECT: 'RECT', - LINE: 'LINE', - ARROW: 'ARROW', -}; - -export const COMPARTMENT_SQUARE_POINTS: Array<ShapeRelAbs | ShapeRelAbsBezierPoint> = [ - { - type: 'REL_ABS_POINT', - absoluteX: 10.0, - absoluteY: 0.0, - relativeX: 0.0, - relativeY: 0.0, - relativeHeightForX: null, - relativeWidthForY: null, - }, - { - type: 'REL_ABS_POINT', - absoluteX: -10.0, - absoluteY: 0.0, - relativeX: 100.0, - relativeY: 0.0, - relativeHeightForX: null, - relativeWidthForY: null, - }, - { - type: 'REL_ABS_BEZIER_POINT', - absoluteX1: 0.0, - absoluteY1: 10.0, - relativeX1: 100.0, - relativeY1: 0.0, - relativeHeightForX1: null, - relativeWidthForY1: null, - absoluteX2: -5.0, - absoluteY2: 0.0, - relativeX2: 100.0, - relativeY2: 0.0, - relativeHeightForX2: null, - relativeWidthForY2: null, - absoluteX3: 0.0, - absoluteY3: 5.0, - relativeX3: 100.0, - relativeY3: 0.0, - relativeHeightForX3: null, - relativeWidthForY3: null, - }, - { - type: 'REL_ABS_POINT', - absoluteX: 0.0, - absoluteY: -10.0, - relativeX: 100.0, - relativeY: 100.0, - relativeHeightForX: null, - relativeWidthForY: null, - }, - { - type: 'REL_ABS_BEZIER_POINT', - absoluteX1: -10.0, - absoluteY1: 0.0, - relativeX1: 100.0, - relativeY1: 100.0, - relativeHeightForX1: null, - relativeWidthForY1: null, - absoluteX2: 0.0, - absoluteY2: -5.0, - relativeX2: 100.0, - relativeY2: 100.0, - relativeHeightForX2: null, - relativeWidthForY2: null, - absoluteX3: -5.0, - absoluteY3: 0.0, - relativeX3: 100.0, - relativeY3: 100.0, - relativeHeightForX3: null, - relativeWidthForY3: null, - }, - { - type: 'REL_ABS_POINT', - absoluteX: 10.0, - absoluteY: 0.0, - relativeX: 0.0, - relativeY: 100.0, - relativeHeightForX: null, - relativeWidthForY: null, - }, - { - type: 'REL_ABS_BEZIER_POINT', - absoluteX1: 0.0, - absoluteY1: -10.0, - relativeX1: 0.0, - relativeY1: 100.0, - relativeHeightForX1: null, - relativeWidthForY1: null, - absoluteX2: 5.0, - absoluteY2: 0.0, - relativeX2: 0.0, - relativeY2: 100.0, - relativeHeightForX2: null, - relativeWidthForY2: null, - absoluteX3: 0.0, - absoluteY3: -5.0, - relativeX3: 0.0, - relativeY3: 100.0, - relativeHeightForX3: null, - relativeWidthForY3: null, - }, - { - type: 'REL_ABS_POINT', - absoluteX: 0.0, - absoluteY: 10.0, - relativeX: 0.0, - relativeY: 0.0, - relativeHeightForX: null, - relativeWidthForY: null, - }, - { - type: 'REL_ABS_BEZIER_POINT', - absoluteX1: 10.0, - absoluteY1: 0.0, - relativeX1: 0.0, - relativeY1: 0.0, - relativeHeightForX1: null, - relativeWidthForY1: null, - absoluteX2: 0.0, - absoluteY2: 5.0, - relativeX2: 0.0, - relativeY2: 0.0, - relativeHeightForX2: null, - relativeWidthForY2: null, - absoluteX3: 5.0, - absoluteY3: 0.0, - relativeX3: 0.0, - relativeY3: 0.0, - relativeHeightForX3: null, - relativeWidthForY3: null, - }, -]; - -export const COMPARTMENT_CIRCLE_CENTER: ShapeRelAbs = { - type: 'REL_ABS_POINT', - absoluteX: 0.0, - absoluteY: 0.0, - relativeX: 50.0, - relativeY: 50.0, - relativeHeightForX: null, - relativeWidthForY: null, -}; - -export const COMPARTMENT_CIRCLE_RADIUS: ShapeRelAbs = { - type: 'REL_ABS_RADIUS', - absoluteX: 0.0, - absoluteY: 0.0, - relativeX: 50.0, - relativeY: 50.0, - relativeHeightForX: null, - relativeWidthForY: null, -}; diff --git a/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.types.ts b/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.types.ts deleted file mode 100644 index 709336b1..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/MapViewerVector.types.ts +++ /dev/null @@ -1,24 +0,0 @@ -import View from 'ol/View'; -import BaseLayer from 'ol/layer/Base'; -import { OverlayBioEntityRender } from '@/types/OLrendering'; - -export type MapConfig = { - view: View; - layers: BaseLayer[]; -}; - -export type VerticalAlign = 'TOP' | 'MIDDLE' | 'BOTTOM'; -export type HorizontalAlign = 'LEFT' | 'RIGHT' | 'CENTER' | 'END' | 'START'; - -export type ScaleFunction = (resolution: number) => number; - -export type OverlayBioEntityGroupedElementsType = { - [id: string]: Array<OverlayBioEntityRender & { amount: number }>; -}; - -export type BoundingBox = { - x: number; - y: number; - width: number; - height: number; -}; diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.test.ts b/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.test.ts deleted file mode 100644 index 2821fe91..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable @typescript-eslint/explicit-function-return-type */ -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 { useOlMapVectorListeners } from '@/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners'; -import { onMapLeftClick } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; - -jest.mock('./mouseClick/mouseLeftClick/onMapLeftClick', () => ({ - __esModule: true, - onMapLeftClick: jest.fn(), -})); - -jest.mock('use-debounce', () => { - return { - useDebounce: () => {}, - useDebouncedCallback: () => {}, - }; -}); - -describe('useOlMapVectorListeners - util', () => { - const { Wrapper } = getReduxWrapperWithStore({ - map: { - data: { ...initialMapDataFixture }, - loading: 'succeeded', - error: { message: '', name: '' }, - openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, - }, - }); - - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe('on left click event', () => { - it('should run onMapLeftClick event', () => { - const CALLED_ONCE = 1; - const view = new View(); - - renderHook(() => useOlMapVectorListeners({ mapInstance: undefined }), { - wrapper: Wrapper, - }); - view.dispatchEvent('singleclick'); - - expect(onMapLeftClick).toBeCalledTimes(CALLED_ONCE); - }); - }); -}); diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.ts b/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.ts deleted file mode 100644 index 444cf47b..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { OPTIONS } from '@/constants/map'; -import { resultDrawerOpen } from '@/redux/drawer/drawer.selectors'; -import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import { mapDataSizeSelector } from '@/redux/map/map.selectors'; -import { currentModelIdSelector, vectorRenderingSelector } from '@/redux/models/models.selectors'; -import { MapInstance } from '@/types/map'; -import { unByKey } from 'ol/Observable'; -import { useEffect, useRef } from 'react'; -import { useSelector } from 'react-redux'; -import { useDebouncedCallback } from 'use-debounce'; -import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors'; -import { onMapLeftClick } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { Coordinate } from 'ol/coordinate'; -import { Pixel } from 'ol/pixel'; -import { onMapRightClick } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick'; -import { modelElementsForCurrentModelSelector } from '@/redux/modelElements/modelElements.selector'; -import { newReactionsForCurrentModelSelector } from '@/redux/newReactions/newReactions.selectors'; - -interface UseOlMapVectorListenersInput { - mapInstance: MapInstance; -} - -export const useOlMapVectorListeners = ({ mapInstance }: UseOlMapVectorListenersInput): void => { - const mapSize = useSelector(mapDataSizeSelector); - const modelId = useSelector(currentModelIdSelector); - const isResultDrawerOpen = useSelector(resultDrawerOpen); - const modelElementsForCurrentModel = useSelector(modelElementsForCurrentModelSelector); - const newReactionsForCurrentModel = useSelector(newReactionsForCurrentModelSelector); - const dispatch = useAppDispatch(); - const coordinate = useRef<Coordinate>([]); - const pixel = useRef<Pixel>([]); - - const comments = useSelector(allCommentsSelectorOfCurrentMap); - const vectorRendering = useAppSelector(vectorRenderingSelector); - - const handleMapLeftClick = useDebouncedCallback( - onMapLeftClick( - mapSize, - modelId, - dispatch, - isResultDrawerOpen, - comments, - modelElementsForCurrentModel || [], - newReactionsForCurrentModel, - ), - OPTIONS.clickPersistTime, - { leading: false }, - ); - - const handleRightClick = useDebouncedCallback( - onMapRightClick( - mapSize, - modelId, - dispatch, - modelElementsForCurrentModel || [], - newReactionsForCurrentModel, - ), - OPTIONS.clickPersistTime, - { - leading: false, - }, - ); - - useEffect(() => { - if (!mapInstance || !vectorRendering) { - return; - } - - const key = mapInstance.on('singleclick', event => - handleMapLeftClick({ coordinate: event.coordinate, pixel: event.pixel }, mapInstance), - ); - - // eslint-disable-next-line consistent-return - return () => unByKey(key); - }, [mapInstance, handleMapLeftClick, vectorRendering]); - - useEffect(() => { - if (!mapInstance || !vectorRendering) { - return; - } - - const rightClickEvent = (e: MouseEvent): Promise<void> | undefined => { - e.preventDefault(); - - coordinate.current = mapInstance.getEventCoordinate(e); - pixel.current = mapInstance.getEventPixel(e); - - return handleRightClick( - { coordinate: coordinate.current, pixel: pixel.current }, - mapInstance, - ); - }; - - mapInstance.getViewport().addEventListener('contextmenu', rightClickEvent); - - // eslint-disable-next-line consistent-return - return () => mapInstance.getViewport().removeEventListener('contextmenu', rightClickEvent); - }, [mapInstance, handleRightClick, vectorRendering]); -}; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.test.ts b/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.test.ts deleted file mode 100644 index 9ec7e614..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.test.ts +++ /dev/null @@ -1,85 +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 VectorLayer from 'ol/layer/Vector'; -import React from 'react'; -import { useOlMap } from '@/components/Map/MapViewer/utils/useOlMap'; -import { useOlMapVectorLayers } from '@/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; - -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('useOlMapLayers - 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 dummyElement = document.createElement('div'); - const { result: hohResult } = renderHook(() => useOlMap({ target: dummyElement }), { - wrapper: Wrapper, - }); - - const { result } = renderHook( - () => useOlMapVectorLayers({ mapInstance: hohResult.current.mapInstance }), - { - wrapper: Wrapper, - }, - ); - return result.current; - }; - - it('should return valid VectorLayer instance [1]', () => { - const result = getRenderedHookResults(); - expect(result[0]).toBeInstanceOf(VectorLayer); - expect(result[0].getSourceState()).toBe('ready'); - }); -}); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.ts b/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.ts deleted file mode 100644 index 253c3a38..00000000 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { MapInstance } from '@/types/map'; -import { useOlMapAdditionalLayers } from '@/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers'; -import { useMemo } from 'react'; -import { useOlMapCardLayer } from '@/components/Map/MapViewer/MapViewerVector/utils/config/mapCardLayer/useOlMapCardLayer'; -import { useOlMapReactionsLayer } from './reactionsLayer/useOlMapReactionsLayer'; -import { MapConfig } from '../../MapViewerVector.types'; - -interface UseOlMapLayersInput { - mapInstance: MapInstance; -} - -export const useOlMapVectorLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig['layers'] => { - const reactionsLayer = useOlMapReactionsLayer({ mapInstance }); - const additionalLayers = useOlMapAdditionalLayers(mapInstance); - const mapCardLayer = useOlMapCardLayer(); - - return useMemo(() => { - return [mapCardLayer, reactionsLayer, ...additionalLayers]; - }, [mapCardLayer, reactionsLayer, additionalLayers]); -}; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts rename to src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts index 68151ba0..eba9fde5 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts +++ b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.test.ts @@ -5,7 +5,7 @@ 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/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers'; +import { useOlMapAdditionalLayers } from '@/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers'; describe('useOlMapAdditionalLayers - util', () => { it('should return VectorLayer', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.ts b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.ts rename to src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.ts index 01518c93..537df192 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/additionalLayers/useOlMapAdditionalLayers.ts +++ b/src/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers.ts @@ -4,7 +4,7 @@ import VectorLayer from 'ol/layer/Vector'; import VectorSource from 'ol/source/Vector'; import { useEffect, useMemo, useState } from 'react'; import { useSelector } from 'react-redux'; -import { currentModelIdSelector, vectorRenderingSelector } from '@/redux/models/models.selectors'; +import { currentModelIdSelector } from '@/redux/models/models.selectors'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; import { getLayersForModel } from '@/redux/layers/layers.thunks'; import { @@ -17,16 +17,16 @@ import { usePointToProjection } from '@/utils/map/usePointToProjection'; import { MapInstance } from '@/types/map'; import { Geometry, LineString, MultiPolygon, Point } from 'ol/geom'; import Polygon from 'ol/geom/Polygon'; -import Layer from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer'; +import Layer from '@/components/Map/MapViewer/utils/shapes/layer/Layer'; import { arrowTypesSelector, lineTypesSelector } from '@/redux/shapes/shapes.selectors'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { mapDataSizeSelector } from '@/redux/map/map.selectors'; -import getDrawImageInteraction from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction'; +import getDrawImageInteraction from '@/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction'; import { LayerState } from '@/redux/layers/layers.types'; import { mapEditToolsActiveActionSelector } from '@/redux/mapEditTools/mapEditTools.selectors'; import { MAP_EDIT_ACTIONS } from '@/redux/mapEditTools/mapEditTools.constants'; import { Extent } from 'ol/extent'; -import getTransformImageInteraction from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction'; +import getTransformImageInteraction from '@/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction'; import { mapEditToolsSetLayerObject } from '@/redux/mapEditTools/mapEditTools.slice'; export const useOlMapAdditionalLayers = ( @@ -45,7 +45,6 @@ export const useOlMapAdditionalLayers = ( const layersLoading = useAppSelector(layersLoadingSelector); const layersVisibilityForCurrentModel = useAppSelector(layersVisibilityForCurrentModelSelector); const activeLayer = useAppSelector(layersActiveLayerSelector); - const vectorRendering = useAppSelector(vectorRenderingSelector); const [layersState, setLayersState] = useState<Array<LayerState>>([]); const [layersLoadingState, setLayersLoadingState] = useState(false); @@ -164,7 +163,7 @@ export const useOlMapAdditionalLayers = ( if (!transformInteraction) { return () => {}; } - if (!activeLayer || !vectorRendering || activeAction !== MAP_EDIT_ACTIONS.TRANSFORM_IMAGE) { + if (!activeLayer || activeAction !== MAP_EDIT_ACTIONS.TRANSFORM_IMAGE) { return () => {}; } mapInstance?.addInteraction(transformInteraction); @@ -172,25 +171,18 @@ export const useOlMapAdditionalLayers = ( dispatch(mapEditToolsSetLayerObject(null)); mapInstance?.removeInteraction(transformInteraction); }; - }, [activeAction, activeLayer, dispatch, mapInstance, transformInteraction, vectorRendering]); + }, [activeAction, activeLayer, dispatch, mapInstance, transformInteraction]); useEffect(() => { if (!drawImageInteraction) { return; } mapInstance?.removeInteraction(drawImageInteraction); - if (!activeLayer || !vectorRendering || activeAction !== MAP_EDIT_ACTIONS.DRAW_IMAGE) { + if (!activeLayer || activeAction !== MAP_EDIT_ACTIONS.DRAW_IMAGE) { return; } mapInstance?.addInteraction(drawImageInteraction); - }, [ - activeAction, - activeLayer, - currentModelId, - drawImageInteraction, - mapInstance, - vectorRendering, - ]); + }, [activeAction, activeLayer, currentModelId, drawImageInteraction, mapInstance]); return vectorLayers; }; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/mapCardLayer/useOlMapCardLayer.test.ts b/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/mapCardLayer/useOlMapCardLayer.test.ts rename to src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/mapCardLayer/useOlMapCardLayer.ts b/src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/mapCardLayer/useOlMapCardLayer.ts rename to src/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/processModelElements.ts b/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/processModelElements.ts rename to src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts index d832a64b..25aa2078 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/processModelElements.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/processModelElements.ts @@ -1,13 +1,5 @@ import { ModelElement } from '@/types/models'; -import MapElement from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement'; -import CompartmentCircle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle'; -import CompartmentSquare from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare'; -import CompartmentPathway from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway'; -import Glyph from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { MapInstance } from '@/types/map'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { BioShapesDict, LineTypeDict } from '@/redux/shapes/shapes.types'; @@ -16,6 +8,11 @@ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; import VectorSource from 'ol/source/Vector'; import { MapSize } from '@/redux/map/map.types'; +import Glyph from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph'; +import CompartmentPathway from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway'; +import CompartmentSquare from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare'; +import CompartmentCircle from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle'; +import MapElement from '@/components/Map/MapViewer/utils/shapes/elements/MapElement'; export default function processModelElements( modelElements: Array<ModelElement>, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.test.ts b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts similarity index 79% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.test.ts rename to src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts index b54a29b4..c8e961ed 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.test.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.test.ts @@ -4,7 +4,7 @@ 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 { useOlMapReactionsLayer } from '@/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer'; +import { useOlMapProcessLayer } from '@/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer'; describe('useOlMapReactionsLayer - util', () => { it('should return VectorLayer', () => { @@ -15,7 +15,7 @@ describe('useOlMapReactionsLayer - util', () => { const dummyElement = document.createElement('div'); const mapInstance = new Map({ target: dummyElement }); - const { result } = renderHook(() => useOlMapReactionsLayer({ mapInstance }), { + const { result } = renderHook(() => useOlMapProcessLayer({ mapInstance }), { wrapper: Wrapper, }); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.ts b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.ts rename to src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts index fd83ac6f..09d5b04e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/useOlMapReactionsLayer.ts +++ b/src/components/Map/MapViewer/utils/config/processLayer/useOlMapProcessLayer.ts @@ -4,7 +4,6 @@ import VectorLayer from 'ol/layer/Vector'; import VectorSource from 'ol/source/Vector'; import { useEffect, useMemo, useState } from 'react'; import { usePointToProjection } from '@/utils/map/usePointToProjection'; -import MapElement from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement'; import { useSelector } from 'react-redux'; import { arrowTypesSelector, @@ -19,17 +18,12 @@ import { import { currentModelIdSelector } from '@/redux/models/models.selectors'; import { getModelElementsForModel } from '@/redux/modelElements/modelElements.thunks'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import CompartmentSquare from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare'; -import CompartmentCircle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle'; -import Glyph from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph'; -import CompartmentPathway from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway'; -import Reaction from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction'; import { newReactionsForCurrentModelSelector, newReactionsLoadingSelector, } from '@/redux/newReactions/newReactions.selectors'; import { getNewReactionsForModel } from '@/redux/newReactions/newReactions.thunks'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; import { getOverlayOrderSelector, overlayBioEntitiesForCurrentModelSelector, @@ -37,21 +31,27 @@ import { import { groupBy } from '@/utils/array/groupBy'; import { useGetOverlayColor } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import getOverlays from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays'; -import LineOverlay from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay'; import { markersSufraceOfCurrentMapDataSelector } from '@/redux/markers/markers.selectors'; import { parseSurfaceMarkersToBioEntityRender } from '@/components/Map/MapViewer/utils/config/overlaysLayer/parseSurfaceMarkersToBioEntityRender'; -import MarkerOverlay from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay'; -import processModelElements from '@/components/Map/MapViewer/MapViewerVector/utils/config/reactionsLayer/processModelElements'; +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 { ZOOM_RESCALING_FACTOR } from '@/constants/map'; import { OverlayOrder } from '@/redux/overlayBioEntity/overlayBioEntity.utils'; -import areOverlayOrdersNotEqual from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/areOverlayOrdersNotEqual'; +import MarkerOverlay from '@/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay'; +import LineOverlay from '@/components/Map/MapViewer/utils/shapes/overlay/LineOverlay'; +import getOverlays from '@/components/Map/MapViewer/utils/shapes/overlay/getOverlays'; +import Reaction from '@/components/Map/MapViewer/utils/shapes/reaction/Reaction'; +import CompartmentPathway from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway'; +import Glyph from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph'; +import CompartmentCircle from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle'; +import CompartmentSquare from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare'; +import MapElement from '@/components/Map/MapViewer/utils/shapes/elements/MapElement'; +import areOverlayOrdersNotEqual from '@/components/Map/MapViewer/utils/shapes/overlay/areOverlayOrdersNotEqual'; -export const useOlMapReactionsLayer = ({ +export const useOlMapProcessLayer = ({ mapInstance, }: { mapInstance: MapInstance; diff --git a/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.test.ts b/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.test.ts deleted file mode 100644 index b3117b1f..00000000 --- a/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.test.ts +++ /dev/null @@ -1,93 +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 React from 'react'; -import VectorLayer from 'ol/layer/Vector'; -import { useOlMapCommonLayers } from '@/components/Map/MapViewer/utils/config/useOlMapCommonLayers'; -import MapBackgroundsEnum from '@/redux/map/map.enums'; - -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('useOlMapCommonLayers - 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(() => useOlMapCommonLayers(), { - wrapper: Wrapper, - }); - - return result.current; - }; - - it('should return valid VectorLayer instance [1]', () => { - const result = getRenderedHookResults(); - - expect(result[0]).toBeInstanceOf(VectorLayer); - expect(result[0].getSourceState()).toBe('ready'); - }); - - it('should return valid VectorLayer instance [2]', () => { - const result = getRenderedHookResults(); - - expect(result[1]).toBeInstanceOf(VectorLayer); - expect(result[1].getSourceState()).toBe('ready'); - }); - - it('should return valid VectorLayer instance [3]', () => { - const result = getRenderedHookResults(); - - expect(result[2]).toBeInstanceOf(VectorLayer); - expect(result[2].getSourceState()).toBe('ready'); - }); -}); diff --git a/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.ts b/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.ts deleted file mode 100644 index ad70201b..00000000 --- a/src/components/Map/MapViewer/utils/config/useOlMapCommonLayers.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { useOlMapPinsLayer } from '@/components/Map/MapViewer/utils/config/pinsLayer/useOlMapPinsLayer'; -import { useOlMapReactionsLayer } from '@/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer'; -import { useOlMapCommentsLayer } from '@/components/Map/MapViewer/utils/config/commentsLayer/useOlMapCommentsLayer'; -import { useMemo } from 'react'; -import { MapConfig } from '../../MapViewer.types'; - -export const useOlMapCommonLayers = (): MapConfig['layers'] => { - const pinsLayer = useOlMapPinsLayer(); - const reactionsLayer = useOlMapReactionsLayer(); - const commentsLayer = useOlMapCommentsLayer(); - - return useMemo(() => { - return [pinsLayer, reactionsLayer, commentsLayer]; - }, [pinsLayer, reactionsLayer, commentsLayer]); -}; diff --git a/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts b/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts index b4bfec60..3fe8e861 100644 --- a/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts +++ b/src/components/Map/MapViewer/utils/config/useOlMapLayers.test.ts @@ -3,11 +3,11 @@ import { MAP_DATA_INITIAL_STATE, OPENED_MAPS_INITIAL_STATE } from '@/redux/map/m 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 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'; -import { useOlMapLayers } from './useOlMapLayers'; const useRefValue = { current: null, @@ -63,25 +63,23 @@ describe('useOlMapLayers - util', () => { backgroundType: MapBackgroundsEnum.SEMANTIC, }, }); - - const { result } = renderHook(() => useOlMapLayers(), { + const dummyElement = document.createElement('div'); + const { result: hohResult } = renderHook(() => useOlMap({ target: dummyElement }), { wrapper: Wrapper, }); + const { result } = renderHook( + () => useOlMapLayers({ mapInstance: hohResult.current.mapInstance }), + { + wrapper: Wrapper, + }, + ); return result.current; }; - it('should return valid TileLayer instance [1]', () => { + it('should return valid VectorLayer instance [1]', () => { const result = getRenderedHookResults(); - - expect(result[0]).toBeInstanceOf(TileLayer); + expect(result[0]).toBeInstanceOf(VectorLayer); expect(result[0].getSourceState()).toBe('ready'); }); - - it('should return valid VectorLayer instance [2]', () => { - const result = getRenderedHookResults(); - - expect(result[1]).toBeInstanceOf(VectorLayer); - expect(result[1].getSourceState()).toBe('ready'); - }); }); diff --git a/src/components/Map/MapViewer/utils/config/useOlMapLayers.ts b/src/components/Map/MapViewer/utils/config/useOlMapLayers.ts index 10169c98..ed7dc2ff 100644 --- a/src/components/Map/MapViewer/utils/config/useOlMapLayers.ts +++ b/src/components/Map/MapViewer/utils/config/useOlMapLayers.ts @@ -1,11 +1,34 @@ /* eslint-disable no-magic-numbers */ -import { useOlMapOverlaysLayer } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useOlMapOverlaysLayer'; +import { MapInstance } from '@/types/map'; +import { useOlMapAdditionalLayers } from '@/components/Map/MapViewer/utils/config/additionalLayers/useOlMapAdditionalLayers'; +import { useMemo } from 'react'; +import { useOlMapCardLayer } from '@/components/Map/MapViewer/utils/config/mapCardLayer/useOlMapCardLayer'; +import { useOlMapPinsLayer } from '@/components/Map/MapViewer/utils/config/pinsLayer/useOlMapPinsLayer'; +import { useOlMapReactionsLayer } from '@/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer'; +import { useOlMapCommentsLayer } from '@/components/Map/MapViewer/utils/config/commentsLayer/useOlMapCommentsLayer'; import { MapConfig } from '../../MapViewer.types'; -import { useOlMapTileLayer } from './useOlMapTileLayer'; +import { useOlMapProcessLayer } from './processLayer/useOlMapProcessLayer'; -export const useOlMapLayers = (): MapConfig['layers'] => { - const overlaysLayer = useOlMapOverlaysLayer(); - const tileLayer = useOlMapTileLayer(); +interface UseOlMapLayersInput { + mapInstance: MapInstance; +} - return [tileLayer, overlaysLayer]; +export const useOlMapLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig['layers'] => { + const processLayer = useOlMapProcessLayer({ mapInstance }); + const additionalLayers = useOlMapAdditionalLayers(mapInstance); + const mapCardLayer = useOlMapCardLayer(); + const pinsLayer = useOlMapPinsLayer(); + const reactionsLayer = useOlMapReactionsLayer(); + const commentsLayer = useOlMapCommentsLayer(); + + return useMemo(() => { + return [ + mapCardLayer, + processLayer, + pinsLayer, + reactionsLayer, + commentsLayer, + ...additionalLayers, + ]; + }, [mapCardLayer, processLayer, pinsLayer, reactionsLayer, commentsLayer, additionalLayers]); }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts index 963fc428..5631573e 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts @@ -11,7 +11,7 @@ import { apiPath } from '@/redux/apiPath'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { getMultiBioEntityByIds } from '@/redux/bioEntity/thunks/getMultiBioEntity'; import { newReactionSchema } from '@/models/newReactionSchema'; -import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction'; +import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction'; import { handleReactionSearchClickFailure } from './handleReactionSearchClickFailure'; import { findClosestReactionPoint } from './findClosestReactionPoint'; diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.test.ts similarity index 97% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.test.ts index 47b21acd..d809149e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.test.ts @@ -6,7 +6,7 @@ import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { apiPath } from '@/redux/apiPath'; import { HttpStatusCode } from 'axios'; import { bioEntityFixture } from '@/models/fixtures/bioEntityFixture'; -import { clickHandleReaction } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction'; +import { clickHandleReaction } from '@/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction'; import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; const mockedAxiosClient = mockNetworkNewAPIResponse(); diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.ts index f9cbc6ac..2cd86bfa 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction.ts @@ -8,7 +8,7 @@ import { setMultipleBioEntityContents } from '@/redux/bioEntity/bioEntity.slice' import { addNumbersToEntityNumberData } from '@/redux/entityNumber/entityNumber.slice'; import { setReactions } from '@/redux/reactions/reactions.slice'; import { mapReactionToBioEntity } from '@/utils/bioEntity/mapReactionToBioEntity'; -import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction'; +import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction'; import { mapModelElementToBioEntity } from '@/utils/bioEntity/mapModelElementToBioEntity'; /* prettier-ignore */ diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts index 46ca1e40..df86f0a2 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import { leftClickHandleAlias } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; +import { leftClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; import { openBioEntityDrawerById, selectTab } from '@/redux/drawer/drawer.slice'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts index 11211b8b..2ef85495 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts @@ -5,17 +5,17 @@ import { resetReactionsData } from '@/redux/reactions/reactions.slice'; import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick'; import Map from 'ol/Map'; -import { onMapLeftClick } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; +import { onMapLeftClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; import { Comment } from '@/types/models'; import SimpleGeometry from 'ol/geom/SimpleGeometry'; import { Feature } from 'ol'; import { FEATURE_TYPE } from '@/constants/features'; import VectorLayer from 'ol/layer/Vector'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; import * as leftClickHandleAlias from './leftClickHandleAlias'; import * as clickHandleReaction from '../clickHandleReaction'; -jest.mock('../../../../utils/listeners/mapSingleClick/handleFeaturesClick', () => ({ +jest.mock('../../mapSingleClick/handleFeaturesClick', () => ({ handleFeaturesClick: jest.fn(), })); jest.mock('./leftClickHandleAlias', () => ({ diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts similarity index 95% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts index d9a8031c..fdca7e96 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts @@ -9,13 +9,13 @@ import { latLngToPoint } from '@/utils/map/latLngToPoint'; import { FeatureLike } from 'ol/Feature'; import { closeDrawer } from '@/redux/drawer/drawer.slice'; import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; -import { leftClickHandleAlias } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; +import { leftClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick'; import { resetReactionsData } from '@/redux/reactions/reactions.slice'; import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset'; import { FEATURE_TYPE } from '@/constants/features'; -import { clickHandleReaction } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { clickHandleReaction } from '@/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; function isFeatureFilledCompartment(feature: FeatureLike): boolean { return feature.get('type') === FEATURE_TYPE.COMPARTMENT && feature.get('filled'); diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts similarity index 95% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts index 4f9a3ade..fa6a3f17 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-magic-numbers */ import { updateLastRightClick } from '@/redux/map/map.slice'; import Map from 'ol/Map'; -import { onMapRightClick } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick'; +import { onMapRightClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick'; import { Layer } from 'ol/layer'; import { openContextMenu } from '@/redux/contextMenu/contextMenu.slice'; import { Source } from 'ol/source'; @@ -11,7 +11,7 @@ import { Feature } from 'ol'; import { FEATURE_TYPE } from '@/constants/features'; import { modelElementFixture } from '@/models/fixtures/modelElementFixture'; import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; import * as rightClickHandleAlias from './rightClickHandleAlias'; import * as clickHandleReaction from '../clickHandleReaction'; diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts index 74e10fc2..9773b48e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/onMapRightClick.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts @@ -11,9 +11,9 @@ import VectorLayer from 'ol/layer/Vector'; import VectorSource from 'ol/source/Vector'; import { openContextMenu } from '@/redux/contextMenu/contextMenu.slice'; import { ModelElement, NewReaction } from '@/types/models'; -import { rightClickHandleAlias } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias'; -import { clickHandleReaction } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { rightClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias'; +import { clickHandleReaction } from '@/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; /* prettier-ignore */ export const onMapRightClick = diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts index 2b936519..ae53b95c 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import { rightClickHandleAlias } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias'; +import { rightClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias'; import { modelElementFixture } from '@/models/fixtures/modelElementFixture'; import { setBioEntityContents } from '@/redux/bioEntity/bioEntity.slice'; import { addNumbersToEntityNumberData } from '@/redux/entityNumber/entityNumber.slice'; diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/rightClickHandleAlias.ts diff --git a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts index 94a53559..328c827b 100644 --- a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.test.ts @@ -4,18 +4,18 @@ 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 singleClickListener from './mapSingleClick/onMapSingleClick'; -import * as positionListener from './onMapPositionChange'; -import { useOlMapListeners } from './useOlMapListeners'; +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'; jest.mock('./onMapPositionChange', () => ({ __esModule: true, onMapPositionChange: jest.fn(), })); -jest.mock('./mapSingleClick/onMapSingleClick', () => ({ +jest.mock('./mouseClick/mouseLeftClick/onMapLeftClick', () => ({ __esModule: true, - onMapSingleClick: jest.fn(), + onMapLeftClick: jest.fn(), })); jest.mock('use-debounce', () => { @@ -52,15 +52,17 @@ describe('useOlMapListeners - util', () => { }); }); - describe('on singleclick view event', () => { - it('should run onMapPositionChange event', () => { + describe('on left click event', () => { + it('should run onMapLeftClick event', () => { const CALLED_ONCE = 1; const view = new View(); - renderHook(() => useOlMapListeners({ view, mapInstance: undefined }), { wrapper: Wrapper }); + renderHook(() => useOlMapListeners({ view, mapInstance: undefined }), { + wrapper: Wrapper, + }); view.dispatchEvent('singleclick'); - expect(singleClickListener.onMapSingleClick).toBeCalledTimes(CALLED_ONCE); + expect(onMapLeftClick).toBeCalledTimes(CALLED_ONCE); }); }); }); diff --git a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.ts b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.ts index e7df6b03..f2952ea6 100644 --- a/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.ts +++ b/src/components/Map/MapViewer/utils/listeners/useOlMapListeners.ts @@ -1,38 +1,24 @@ -import { DEFAULT_ZOOM, OPTIONS } from '@/constants/map'; -import { searchDistanceValSelector } from '@/redux/configuration/configuration.selectors'; +import { OPTIONS } from '@/constants/map'; import { resultDrawerOpen } from '@/redux/drawer/drawer.selectors'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import { - mapDataLastZoomValue, - mapDataMaxZoomValue, - mapDataSizeSelector, -} from '@/redux/map/map.selectors'; -import { - currentModelSelector, - currentModelIdSelector, - vectorRenderingSelector, -} from '@/redux/models/models.selectors'; +import { mapDataSizeSelector } from '@/redux/map/map.selectors'; +import { currentModelIdSelector } from '@/redux/models/models.selectors'; import { MapInstance } from '@/types/map'; -import { View } from 'ol'; import { unByKey } from 'ol/Observable'; -import { Coordinate } from 'ol/coordinate'; -import { Pixel } from 'ol/pixel'; import { useEffect, useRef } from 'react'; import { useSelector } from 'react-redux'; import { useDebouncedCallback } from 'use-debounce'; import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors'; -import { currentBackgroundSelector } from '@/redux/backgrounds/background.selectors'; -import { - PATHWAYS_AND_COMPARTMENTS_BACKGROUND, - SEMANTIC_BACKGROUND, -} from '@/redux/backgrounds/backgrounds.constants'; -import { TWO } from '@/constants/common'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { onMapRightClick } from './mapRightClick/onMapRightClick'; -import { onMapSingleClick } from './mapSingleClick/onMapSingleClick'; -import { onMapPositionChange } from './onMapPositionChange'; -import { onPointerMove } from './onPointerMove'; -import { useHandlePinIconClick } from './pinIconClick/useHandlePinIconClick'; +import { onMapLeftClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; +import { Coordinate } from 'ol/coordinate'; +import { Pixel } from 'ol/pixel'; +import { onMapRightClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick'; +import { modelElementsForCurrentModelSelector } from '@/redux/modelElements/modelElements.selector'; +import { newReactionsForCurrentModelSelector } from '@/redux/newReactions/newReactions.selectors'; +import { useHandlePinIconClick } from '@/components/Map/MapViewer/utils/listeners/pinIconClick/useHandlePinIconClick'; +import { onMapPositionChange } from '@/components/Map/MapViewer/utils/listeners/onMapPositionChange'; +import { onPointerMove } from '@/components/Map/MapViewer/utils/listeners/onPointerMove'; +import { View } from 'ol'; interface UseOlMapListenersInput { view: View; @@ -41,36 +27,17 @@ interface UseOlMapListenersInput { export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput): void => { const mapSize = useSelector(mapDataSizeSelector); - const model = useSelector(currentModelSelector); const modelId = useSelector(currentModelIdSelector); - const modelMinZoom = model?.minZoom || TWO; - const lastZoom = useSelector(mapDataLastZoomValue) || TWO; - const background = useSelector(currentBackgroundSelector); - const searchDistance = useSelector(searchDistanceValSelector); - const maxZoom = useSelector(mapDataMaxZoomValue); const isResultDrawerOpen = useSelector(resultDrawerOpen); + const modelElementsForCurrentModel = useSelector(modelElementsForCurrentModelSelector); + const newReactionsForCurrentModel = useSelector(newReactionsForCurrentModelSelector); + const dispatch = useAppDispatch(); const coordinate = useRef<Coordinate>([]); const pixel = useRef<Pixel>([]); - const dispatch = useAppDispatch(); const comments = useSelector(allCommentsSelectorOfCurrentMap); - const vectorRendering = useAppSelector(vectorRenderingSelector); - useHandlePinIconClick(); - const handleRightClick = useDebouncedCallback( - onMapRightClick( - mapSize, - modelId, - dispatch, - background?.name === SEMANTIC_BACKGROUND || - background?.name === PATHWAYS_AND_COMPARTMENTS_BACKGROUND, - lastZoom - modelMinZoom, - ), - OPTIONS.clickPersistTime, - { - leading: false, - }, - ); + useHandlePinIconClick(); const handleChangeCenter = useDebouncedCallback( onMapPositionChange(mapSize, dispatch), @@ -78,24 +45,34 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) { leading: false }, ); - const handleMapSingleClick = useDebouncedCallback( - onMapSingleClick( + const handleMapLeftClick = useDebouncedCallback( + onMapLeftClick( mapSize, modelId, dispatch, - searchDistance, - maxZoom, - lastZoom || DEFAULT_ZOOM, isResultDrawerOpen, comments, - background?.name === SEMANTIC_BACKGROUND || - background?.name === PATHWAYS_AND_COMPARTMENTS_BACKGROUND, - lastZoom - modelMinZoom, + modelElementsForCurrentModel || [], + newReactionsForCurrentModel, ), OPTIONS.clickPersistTime, { leading: false }, ); + const handleRightClick = useDebouncedCallback( + onMapRightClick( + mapSize, + modelId, + dispatch, + modelElementsForCurrentModel || [], + newReactionsForCurrentModel, + ), + OPTIONS.clickPersistTime, + { + leading: false, + }, + ); + useEffect(() => { const key = view.on('change:center', handleChangeCenter); return () => unByKey(key); @@ -113,20 +90,20 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) }, [mapInstance]); useEffect(() => { - if (!mapInstance || vectorRendering) { + if (!mapInstance) { return; } const key = mapInstance.on('singleclick', event => - handleMapSingleClick({ coordinate: event.coordinate, pixel: event.pixel }, mapInstance), + handleMapLeftClick({ coordinate: event.coordinate, pixel: event.pixel }, mapInstance), ); // eslint-disable-next-line consistent-return return () => unByKey(key); - }, [mapInstance, handleMapSingleClick, vectorRendering]); + }, [mapInstance, handleMapLeftClick]); useEffect(() => { - if (!mapInstance || vectorRendering) { + if (!mapInstance) { return; } @@ -136,12 +113,15 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) coordinate.current = mapInstance.getEventCoordinate(e); pixel.current = mapInstance.getEventPixel(e); - return handleRightClick(coordinate.current, pixel.current); + return handleRightClick( + { coordinate: coordinate.current, pixel: pixel.current }, + mapInstance, + ); }; mapInstance.getViewport().addEventListener('contextmenu', rightClickEvent); // eslint-disable-next-line consistent-return return () => mapInstance.getViewport().removeEventListener('contextmenu', rightClickEvent); - }, [mapInstance, handleRightClick, vectorRendering]); + }, [mapInstance, handleRightClick]); }; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/findLargestExtent.test.ts similarity index 76% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/findLargestExtent.test.ts index 2a41ebad..2bd23b66 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/findLargestExtent.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ -import findLargestExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent'; +import findLargestExtent from '@/components/Map/MapViewer/utils/shapes/coords/findLargestExtent'; import { Extent } from 'ol/extent'; describe('findLargestExtent', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent.ts b/src/components/Map/MapViewer/utils/shapes/coords/findLargestExtent.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent.ts rename to src/components/Map/MapViewer/utils/shapes/coords/findLargestExtent.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getBezierCurve.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getBezierCurve.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve.ts b/src/components/Map/MapViewer/utils/shapes/coords/getBezierCurve.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getBezierCurve.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.test.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.test.ts index 532c485d..7c44ef3e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ import { Extent } from 'ol/extent'; -import getBoundingBoxFromExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent'; +import getBoundingBoxFromExtent from '@/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent'; describe('getBoundingBoxFromExtent', () => { it('should return a bounding box for extent', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.ts b/src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.ts index efab1e2d..7201ee00 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent.ts @@ -3,7 +3,7 @@ import { MapSize } from '@/redux/map/map.types'; import { toLonLat } from 'ol/proj'; import { latLngToPoint } from '@/utils/map/latLngToPoint'; import { Extent } from 'ol/extent'; -import { BoundingBox } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { BoundingBox } from '@/components/Map/MapViewer/MapViewer.types'; export default function getBoundingBoxFromExtent(extent: Extent, mapSize: MapSize): BoundingBox { const [startLng, startLat] = toLonLat([extent[0], extent[3]]); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCenter.test.ts similarity index 81% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCenter.test.ts index 6373f63b..83defeab 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getCenter.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ import { Coordinate } from 'ol/coordinate'; -import getCenter from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter'; +import getCenter from '@/components/Map/MapViewer/utils/shapes/coords/getCenter'; describe('getCenter', () => { it('should return a center for coordinates', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCenter.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCenter.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCoordsX.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCoordsX.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCoordsX.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCoordsX.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCoordsY.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCoordsY.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCoordsY.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCoordsY.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.test.ts similarity index 90% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.test.ts index adf5685f..1c824de0 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { ShapeRelAbsBezierPoint } from '@/types/models'; import getCurveCoords from './getCurveCoords'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.ts b/src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.ts similarity index 85% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.ts index 8cd0f0ec..e75d72f2 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getCurveCoords.ts @@ -1,7 +1,7 @@ import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { Coordinate } from 'ol/coordinate'; -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; import { ShapeRelAbsBezierPoint } from '@/types/models'; export default function getCurveCoords({ diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getDividedExtents.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getDividedExtents.test.ts index ea4a9f89..302b8f11 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getDividedExtents.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ import { Extent } from 'ol/extent'; -import getDividedExtents from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents'; +import getDividedExtents from '@/components/Map/MapViewer/utils/shapes/coords/getDividedExtents'; describe('getDividedExtents', () => { it('should return original extents if there is no intersection with dividingExtent', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents.ts b/src/components/Map/MapViewer/utils/shapes/coords/getDividedExtents.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getDividedExtents.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.test.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.test.ts index 515eabf4..8c4fd4dc 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { ShapeRelAbs } from '@/types/models'; import getEllipseCoords from './getEllipseCoords'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.ts b/src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.ts index c617ffaf..bd72dd21 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; import { Coordinate } from 'ol/coordinate'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { ShapeRelAbs } from '@/types/models'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getLineSegments.test.ts similarity index 97% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getLineSegments.test.ts index ec6d5a70..9ce67a91 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getLineSegments.test.ts @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers */ import { Line } from '@/types/models'; -import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import getLineSegments from './getLineSegments'; describe('getLineSegments', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments.ts b/src/components/Map/MapViewer/utils/shapes/coords/getLineSegments.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getLineSegments.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.test.ts similarity index 88% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.test.ts index ed84c661..6060feff 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-magic-numbers */ -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; -import getCurveCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords'; -import getBezierCurve from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; +import getCurveCoords from '@/components/Map/MapViewer/utils/shapes/coords/getCurveCoords'; +import getBezierCurve from '@/components/Map/MapViewer/utils/shapes/coords/getBezierCurve'; import { ShapeRelAbs, ShapeRelAbsBezierPoint } from '@/types/models'; import getPolygonCoords from './getPolygonCoords'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.ts b/src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.ts similarity index 76% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.ts index d00816b5..db3f1b7c 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords.ts @@ -1,10 +1,10 @@ /* eslint-disable no-magic-numbers */ import { Coordinate } from 'ol/coordinate'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import getBezierCurve from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBezierCurve'; -import getCoordsX from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsX'; -import getCoordsY from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCoordsY'; -import getCurveCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCurveCoords'; +import getBezierCurve from '@/components/Map/MapViewer/utils/shapes/coords/getBezierCurve'; +import getCoordsX from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsX'; +import getCoordsY from '@/components/Map/MapViewer/utils/shapes/coords/getCoordsY'; +import getCurveCoords from '@/components/Map/MapViewer/utils/shapes/coords/getCurveCoords'; import { ShapeRelAbs, ShapeRelAbsBezierPoint } from '@/types/models'; export default function getPolygonCoords({ diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation.test.ts b/src/components/Map/MapViewer/utils/shapes/coords/getRotation.test.ts similarity index 83% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation.test.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getRotation.test.ts index 363add1a..0e26ba92 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/coords/getRotation.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import getRotation from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation'; +import getRotation from '@/components/Map/MapViewer/utils/shapes/coords/getRotation'; import { Coordinate } from 'ol/coordinate'; const testCases: Array<[Coordinate, Coordinate, number]> = [ diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation.ts b/src/components/Map/MapViewer/utils/shapes/coords/getRotation.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation.ts rename to src/components/Map/MapViewer/utils/shapes/coords/getRotation.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts b/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts similarity index 91% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts rename to src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts index dd541d11..23277551 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon.ts @@ -4,14 +4,8 @@ import { Stroke, Style } from 'ol/style'; import Feature, { FeatureLike } from 'ol/Feature'; import { MultiPolygon } from 'ol/geom'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { MapInstance } from '@/types/map'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; import { Color } from '@/types/models'; import { COMPLEX_CONTENTS_CUTOFF_SCALE, @@ -19,13 +13,16 @@ import { MAP_ELEMENT_TYPES, OUTLINE_CUTOFF_SCALE, TEXT_CUTOFF_SCALE, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import MapBackgroundsEnum from '@/redux/map/map.enums'; import { MapSize } from '@/redux/map/map.types'; -import getCoverStyles from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles'; -import handleSemanticView from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView'; -import getScaledStrokeStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getCoverStyles from '@/components/Map/MapViewer/utils/shapes/style/getCoverStyles'; +import handleSemanticView from '@/components/Map/MapViewer/utils/shapes/elements/handleSemanticView'; +import getScaledStrokeStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle'; export interface BaseMapElementProps { type: string; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Compartment.ts b/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Compartment.ts rename to src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts index 75c519ef..10802411 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Compartment.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/Compartment.ts @@ -1,24 +1,21 @@ /* eslint-disable no-magic-numbers */ import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; -import BaseMultiPolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { Coordinate } from 'ol/coordinate'; import Polygon from 'ol/geom/Polygon'; import { Stroke, Style } from 'ol/style'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; import { MapInstance } from '@/types/map'; import { Color } from '@/types/models'; import { MAP_ELEMENT_TYPES, TRANSPARENT_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import { MapSize } from '@/redux/map/map.types'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import BaseMultiPolygon from '@/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon'; export interface CompartmentProps { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts similarity index 78% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts index 7c5956c6..eb94b525 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.test.ts @@ -2,24 +2,21 @@ import { Feature, Map } from 'ol'; import { Fill, Stroke, Style, Text } from 'ol/style'; import { Polygon, MultiPolygon } from 'ol/geom'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import View from 'ol/View'; -import { - WHITE_COLOR, - BLACK_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import CompartmentCircle, { - CompartmentCircleProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import { WHITE_COLOR, BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import MapBackgroundsEnum from '@/redux/map/map.enums'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import CompartmentCircle, { + CompartmentCircleProps, +} from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; jest.mock('../text/getTextStyle'); jest.mock('../text/getTextCoords'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts index 94a65df8..78915ae4 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentCircle.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentCircle.ts @@ -1,21 +1,18 @@ /* eslint-disable no-magic-numbers */ import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { MapInstance } from '@/types/map'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { BLACK_COLOR, COMPARTMENT_CIRCLE_CENTER, COMPARTMENT_CIRCLE_RADIUS, WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; -import Compartment from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Compartment'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import { Color } from '@/types/models'; import VectorSource from 'ol/source/Vector'; import { MapSize } from '@/redux/map/map.types'; +import Compartment from '@/components/Map/MapViewer/utils/shapes/elements/Compartment'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; export type CompartmentCircleProps = { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts similarity index 78% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts index 00c1931b..05e1801e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.test.ts @@ -2,24 +2,21 @@ import { Feature, Map } from 'ol'; import { Fill, Stroke, Style, Text } from 'ol/style'; import { Polygon, MultiPolygon } from 'ol/geom'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import View from 'ol/View'; -import { - WHITE_COLOR, - BLACK_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import CompartmentPathway, { - CompartmentPathwayProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import { WHITE_COLOR, BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import MapBackgroundsEnum from '@/redux/map/map.enums'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import CompartmentPathway, { + CompartmentPathwayProps, +} from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; jest.mock('../text/getTextStyle'); jest.mock('../text/getTextCoords'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts similarity index 83% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts index eef5c0f7..94034677 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentPathway.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentPathway.ts @@ -1,26 +1,23 @@ /* eslint-disable no-magic-numbers */ import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { MapInstance } from '@/types/map'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { BLACK_COLOR, MAP_ELEMENT_TYPES, TRANSPARENT_COLOR, WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import Polygon from 'ol/geom/Polygon'; -import BaseMultiPolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; import { Color } from '@/types/models'; import VectorSource from 'ol/source/Vector'; import { Style } from 'ol/style'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import { MapSize } from '@/redux/map/map.types'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; +import BaseMultiPolygon from '@/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; export type CompartmentPathwayProps = { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts similarity index 79% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts index 53fff2ff..acf2471c 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.test.ts @@ -2,23 +2,20 @@ import { Feature, Map } from 'ol'; import { Fill, Stroke, Style, Text } from 'ol/style'; import { MultiPolygon } from 'ol/geom'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import View from 'ol/View'; -import { - WHITE_COLOR, - BLACK_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import CompartmentSquare, { - CompartmentSquareProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare'; -import getPolygonCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import { WHITE_COLOR, BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import MapBackgroundsEnum from '@/redux/map/map.enums'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import CompartmentSquare, { + CompartmentSquareProps, +} from '@/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare'; +import getPolygonCoords from '@/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; jest.mock('../text/getTextStyle'); jest.mock('../text/getTextCoords'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.ts b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.ts rename to src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts index 8f033df3..34f95693 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/CompartmentSquare.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/CompartmentSquare.ts @@ -1,20 +1,17 @@ /* eslint-disable no-magic-numbers */ import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { MapInstance } from '@/types/map'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { BLACK_COLOR, COMPARTMENT_SQUARE_POINTS, WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getPolygonCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords'; -import Compartment from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Compartment'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import { Color } from '@/types/models'; import VectorSource from 'ol/source/Vector'; import { MapSize } from '@/redux/map/map.types'; +import Compartment from '@/components/Map/MapViewer/utils/shapes/elements/Compartment'; +import getPolygonCoords from '@/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords'; export type CompartmentSquareProps = { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.test.ts similarity index 93% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.test.ts index ff2a0ac2..2680f7ef 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.test.ts @@ -2,9 +2,7 @@ import { Feature, Map, View } from 'ol'; import { Style } from 'ol/style'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import Glyph, { - GlyphProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph'; +import Glyph, { GlyphProps } from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph'; import { MapInstance } from '@/types/map'; import Polygon from 'ol/geom/Polygon'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.ts b/src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.ts similarity index 95% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.ts rename to src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.ts index a0676acd..1da2b4fb 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph.ts @@ -11,13 +11,13 @@ import Polygon from 'ol/geom/Polygon'; import { Point } from 'ol/geom'; import { Coordinate } from 'ol/coordinate'; import { FEATURE_TYPE } from '@/constants/features'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; -import { WHITE_COLOR } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import getScaledElementStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle'; -import getBoundingBoxFromExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent'; +import { WHITE_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import { MapSize } from '@/redux/map/map.types'; import { LayerImage } from '@/types/models'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import getScaledElementStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle'; +import getBoundingBoxFromExtent from '@/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent'; export type GlyphProps = { elementId: number; @@ -249,6 +249,7 @@ export default class Glyph { }), zIndex: this.zIndex, }); + this.feature.changed(); }; img.src = `${BASE_NEW_API_URL}${apiPath.getGlyphImage(this.glyphId)}`; } diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/updateGlyph.ts b/src/components/Map/MapViewer/utils/shapes/elements/Glyph/updateGlyph.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/updateGlyph.ts rename to src/components/Map/MapViewer/utils/shapes/elements/Glyph/updateGlyph.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts similarity index 80% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts index 9dbf5336..744c6529 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.test.ts @@ -2,24 +2,21 @@ import { Feature, Map } from 'ol'; import { Fill, Stroke, Style, Text } from 'ol/style'; import { Polygon, MultiPolygon } from 'ol/geom'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; -import MapElement, { - MapElementProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement'; import View from 'ol/View'; -import { - WHITE_COLOR, - BLACK_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import { WHITE_COLOR, BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import { shapesFixture } from '@/models/fixtures/shapesFixture'; import VectorSource from 'ol/source/Vector'; import MapBackgroundsEnum from '@/redux/map/map.enums'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import MapElement, { + MapElementProps, +} from '@/components/Map/MapViewer/utils/shapes/elements/MapElement'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; jest.mock('../text/getTextStyle'); jest.mock('../text/getTextCoords'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.ts b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts similarity index 91% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.ts rename to src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts index 38b6b16d..ead1dd13 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/MapElement.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/MapElement.ts @@ -1,28 +1,17 @@ /* eslint-disable no-magic-numbers */ import { Style } from 'ol/style'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; import Polygon from 'ol/geom/Polygon'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import { Color, Modification, Shape } from '@/types/models'; import { MapInstance } from '@/types/map'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { BLACK_COLOR, COMPLEX_SBO_TERMS, MAP_ELEMENT_TYPES, TRANSPARENT_COLOR, WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import BaseMultiPolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/BaseMultiPolygon'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import { BioShapesDict, LineTypeDict } from '@/redux/shapes/shapes.types'; import { FEATURE_TYPE } from '@/constants/features'; import { OverlayBioEntityRender } from '@/types/OLrendering'; @@ -32,6 +21,14 @@ import { OverlayOrder } from '@/redux/overlayBioEntity/overlayBioEntity.utils'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; import VectorSource from 'ol/source/Vector'; import { MapSize } from '@/redux/map/map.types'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import BaseMultiPolygon from '@/components/Map/MapViewer/utils/shapes/elements/BaseMultiPolygon'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; export type MapElementProps = { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.test.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.test.ts index 71a6ce39..970241b9 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.test.ts @@ -2,11 +2,11 @@ import { Feature } from 'ol'; import { Fill, Stroke, Style } from 'ol/style'; import { Polygon, MultiPolygon } from 'ol/geom'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; -import getArrowFeature from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature'; -import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import { ArrowTypeDict } from '@/redux/shapes/shapes.types'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getArrowFeature from '@/components/Map/MapViewer/utils/shapes/elements/getArrowFeature'; jest.mock('../style/getStyle'); jest.mock('./getShapePolygon'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.ts b/src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.ts similarity index 80% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.ts rename to src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.ts index c8f46d9d..0ccc40a2 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/getArrowFeature.ts @@ -1,16 +1,16 @@ /* eslint-disable no-magic-numbers */ import Style from 'ol/style/Style'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; import { Feature } from 'ol'; import { MultiPolygon } from 'ol/geom'; import { Arrow, Color } from '@/types/models'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; import Polygon from 'ol/geom/Polygon'; -import { WHITE_COLOR } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { WHITE_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import { ArrowTypeDict } from '@/redux/shapes/shapes.types'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; export default function getArrowFeature({ arrowTypes, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.test.ts index 0074f57b..5254b54e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.test.ts @@ -1,9 +1,9 @@ /* eslint-disable no-magic-numbers */ -import getPolygonCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; +import getPolygonCoords from '@/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; import Polygon from 'ol/geom/Polygon'; import { Shape } from '@/types/models'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; jest.mock('../coords/getPolygonCoords'); jest.mock('../coords/getEllipseCoords'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.ts b/src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.ts similarity index 78% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.ts rename to src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.ts index 7e2f7a59..a2082fe3 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/getShapePolygon.ts @@ -1,11 +1,11 @@ /* eslint-disable no-magic-numbers */ import Polygon from 'ol/geom/Polygon'; import { Coordinate } from 'ol/coordinate'; -import getPolygonCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getPolygonCoords'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; +import getPolygonCoords from '@/components/Map/MapViewer/utils/shapes/coords/getPolygonCoords'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; import { Shape } from '@/types/models'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import getCenter from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getCenter'; +import getCenter from '@/components/Map/MapViewer/utils/shapes/coords/getCenter'; export default function getShapePolygon({ shape, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.test.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.test.ts index f6360b51..c2d9e620 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.test.ts @@ -1,9 +1,9 @@ /* eslint-disable no-magic-numbers */ import Feature from 'ol/Feature'; import VectorSource from 'ol/source/Vector'; -import getDividedExtents from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents'; -import findLargestExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent'; -import handleSemanticView from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView'; +import getDividedExtents from '@/components/Map/MapViewer/utils/shapes/coords/getDividedExtents'; +import findLargestExtent from '@/components/Map/MapViewer/utils/shapes/coords/findLargestExtent'; +import handleSemanticView from '@/components/Map/MapViewer/utils/shapes/elements/handleSemanticView'; import Geometry from 'ol/geom/Geometry'; import { fromExtent } from 'ol/geom/Polygon'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.ts b/src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.ts similarity index 86% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.ts rename to src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.ts index 71c32e6f..cd5aa1f4 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/handleSemanticView.ts +++ b/src/components/Map/MapViewer/utils/shapes/elements/handleSemanticView.ts @@ -1,14 +1,14 @@ /* eslint-disable no-magic-numbers */ -import getDividedExtents from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getDividedExtents'; -import findLargestExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/findLargestExtent'; import Feature from 'ol/Feature'; import VectorSource from 'ol/source/Vector'; import { Extent } from 'ol/extent'; import { COMPLEX_SBO_TERMS, MAP_ELEMENT_TYPES, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import isFeatureInCompartment from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/isFeatureInCompartment'; +} from '@/components/Map/MapViewer/MapViewer.constants'; +import findLargestExtent from '@/components/Map/MapViewer/utils/shapes/coords/findLargestExtent'; +import getDividedExtents from '@/components/Map/MapViewer/utils/shapes/coords/getDividedExtents'; +import isFeatureInCompartment from '@/components/Map/MapViewer/utils/shapes/elements/isFeatureInCompartment'; export default function handleSemanticView({ vectorSource, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/isFeatureInCompartment.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/isFeatureInCompartment.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/isFeatureInCompartment.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/isFeatureInCompartment.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/isFeatureInCompartment.ts b/src/components/Map/MapViewer/utils/shapes/elements/isFeatureInCompartment.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/isFeatureInCompartment.ts rename to src/components/Map/MapViewer/utils/shapes/elements/isFeatureInCompartment.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/removeElementFromLayer.test.ts b/src/components/Map/MapViewer/utils/shapes/elements/removeElementFromLayer.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/removeElementFromLayer.test.ts rename to src/components/Map/MapViewer/utils/shapes/elements/removeElementFromLayer.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/removeElementFromLayer.ts b/src/components/Map/MapViewer/utils/shapes/elements/removeElementFromLayer.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/removeElementFromLayer.ts rename to src/components/Map/MapViewer/utils/shapes/elements/removeElementFromLayer.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.test.ts b/src/components/Map/MapViewer/utils/shapes/layer/Layer.test.ts similarity index 84% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.test.ts rename to src/components/Map/MapViewer/utils/shapes/layer/Layer.test.ts index 9da93414..d9f3c022 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/Layer.test.ts @@ -1,20 +1,15 @@ /* eslint-disable no-magic-numbers */ import { Map } from 'ol'; import { Stroke, Style, Text } from 'ol/style'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import View from 'ol/View'; -import { - WHITE_COLOR, - BLACK_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; -import Layer, { - LayerProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer'; +import { WHITE_COLOR, BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import VectorSource from 'ol/source/Vector'; import VectorLayer from 'ol/layer/Vector'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; +import Layer, { LayerProps } from '@/components/Map/MapViewer/utils/shapes/layer/Layer'; jest.mock('../text/getTextCoords'); jest.mock('../text/getTextStyle'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts b/src/components/Map/MapViewer/utils/shapes/layer/Layer.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts rename to src/components/Map/MapViewer/utils/shapes/layer/Layer.ts index 84c3f317..282e25e4 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/Layer.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/Layer.ts @@ -4,18 +4,10 @@ import { MapInstance } from '@/types/map'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { Feature } from 'ol'; import { LineString, MultiPolygon, Point } from 'ol/geom'; -import Text from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text'; import Polygon from 'ol/geom/Polygon'; import VectorSource from 'ol/source/Vector'; import VectorLayer from 'ol/layer/Vector'; -import getEllipseCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getEllipseCoords'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; -import getRotation from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation'; -import getArrowFeature from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { FeatureLike } from 'ol/Feature'; import Style from 'ol/style/Style'; import { ArrowTypeDict, LineTypeDict } from '@/redux/shapes/shapes.types'; @@ -23,11 +15,16 @@ import { LAYER_ELEMENT_TYPES, REACTION_ELEMENT_CUTOFF_SCALE, TRANSPARENT_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getScaledElementStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import { Stroke } from 'ol/style'; -import Glyph from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/Glyph/Glyph'; import { MapSize } from '@/redux/map/map.types'; +import getScaledElementStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle'; +import Glyph from '@/components/Map/MapViewer/utils/shapes/elements/Glyph/Glyph'; +import getArrowFeature from '@/components/Map/MapViewer/utils/shapes/elements/getArrowFeature'; +import getRotation from '@/components/Map/MapViewer/utils/shapes/coords/getRotation'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getEllipseCoords from '@/components/Map/MapViewer/utils/shapes/coords/getEllipseCoords'; +import Text from '@/components/Map/MapViewer/utils/shapes/text/Text'; export interface LayerProps { texts: Array<LayerText>; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.test.ts b/src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.test.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.test.ts rename to src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.test.ts index e0c9fb44..2e9e3f88 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.test.ts @@ -12,7 +12,7 @@ import { DEFAULT_TILE_SIZE } from '@/constants/map'; import { Map } from 'ol'; import getDrawImageInteraction from './getDrawImageInteraction'; -jest.mock('../../../../../../../utils/map/latLngToPoint', () => ({ +jest.mock('../../../../../../utils/map/latLngToPoint', () => ({ latLngToPoint: jest.fn(latLng => ({ x: latLng[0], y: latLng[1] })), })); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.ts b/src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.ts similarity index 97% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.ts rename to src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.ts index 35bd90a5..8c37bf36 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getDrawImageInteraction.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/getDrawImageInteraction.ts @@ -7,7 +7,7 @@ import { AppDispatch } from '@/redux/store'; import { Coordinate } from 'ol/coordinate'; import { openLayerImageObjectFactoryModal } from '@/redux/modal/modal.slice'; import { Extent } from 'ol/extent'; -import getBoundingBoxFromExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent'; +import getBoundingBoxFromExtent from '@/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent'; export default function getDrawImageInteraction( mapSize: MapSize, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.test.ts b/src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.test.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.test.ts rename to src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.test.ts index 92a891c8..718037ff 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.test.ts @@ -8,11 +8,11 @@ import { import { ModalState } from '@/redux/modal/modal.types'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; import { Collection, Feature } from 'ol'; -import getTransformImageInteraction from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction'; +import getTransformImageInteraction from '@/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction'; import Transform from 'ol-ext/interaction/Transform'; import { Geometry } from 'ol/geom'; -jest.mock('../../../../../../../utils/map/latLngToPoint', () => ({ +jest.mock('../../../../../../utils/map/latLngToPoint', () => ({ latLngToPoint: jest.fn(latLng => ({ x: latLng[0], y: latLng[1] })), })); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.ts b/src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.ts similarity index 98% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.ts rename to src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.ts index eecc3665..596205e6 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/layer/getTransformImageInteraction.ts +++ b/src/components/Map/MapViewer/utils/shapes/layer/getTransformImageInteraction.ts @@ -7,7 +7,7 @@ import { Collection, Feature } from 'ol'; import BaseEvent from 'ol/events/Event'; import { updateLayerImageObject } from '@/redux/layers/layers.thunks'; import { layerUpdateImage } from '@/redux/layers/layers.slice'; -import getBoundingBoxFromExtent from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getBoundingBoxFromExtent'; +import getBoundingBoxFromExtent from '@/components/Map/MapViewer/utils/shapes/coords/getBoundingBoxFromExtent'; import { MapSize } from '@/redux/map/map.types'; import { Extent } from 'ol/extent'; import { mapEditToolsSetLayerObject } from '@/redux/mapEditTools/mapEditTools.slice'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.test.ts similarity index 78% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.test.ts index 4efbc9d6..0888de5c 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.test.ts @@ -1,13 +1,13 @@ /* eslint-disable no-magic-numbers */ import { Feature, Map } from 'ol'; import { Stroke, Style } from 'ol/style'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; import View from 'ol/View'; import LineOverlay, { LineOverlayProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay'; +} from '@/components/Map/MapViewer/utils/shapes/overlay/LineOverlay'; import { Coordinate } from 'ol/coordinate'; jest.mock('../style/getStroke'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.ts b/src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.ts index b6d8eecb..adf9beb8 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/LineOverlay.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/LineOverlay.ts @@ -2,7 +2,7 @@ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { LineString } from 'ol/geom'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; import { Feature } from 'ol'; import { FeatureLike } from 'ol/Feature'; import Style from 'ol/style/Style'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.test.ts similarity index 79% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.test.ts index 4fe3c4aa..19bc84b6 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.test.ts @@ -1,14 +1,14 @@ /* eslint-disable no-magic-numbers */ import { Feature, Map } from 'ol'; import { Stroke, Style } from 'ol/style'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; import View from 'ol/View'; import { Coordinate } from 'ol/coordinate'; import MarkerOverlay, { MarkerOverlayProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay'; +} from '@/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay'; jest.mock('../style/getStroke'); jest.mock('../style/getFill'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.ts b/src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.ts similarity index 96% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.ts index a0336335..e963d768 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/MarkerOverlay.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/MarkerOverlay.ts @@ -1,7 +1,7 @@ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; import { Feature } from 'ol'; import { FeatureLike } from 'ol/Feature'; import Style from 'ol/style/Style'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/areOverlayOrdersNotEqual.ts b/src/components/Map/MapViewer/utils/shapes/overlay/areOverlayOrdersNotEqual.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/areOverlayOrdersNotEqual.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/areOverlayOrdersNotEqual.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/calculateOverlayDimensions.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/calculateOverlayDimensions.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/calculateOverlayDimensions.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/calculateOverlayDimensions.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/calculateOverlayDimensions.ts b/src/components/Map/MapViewer/utils/shapes/overlay/calculateOverlayDimensions.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/calculateOverlayDimensions.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/calculateOverlayDimensions.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/findMatchingSubmapLinkRectangle.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/findMatchingSubmapLinkRectangle.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/findMatchingSubmapLinkRectangle.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/findMatchingSubmapLinkRectangle.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/findMatchingSubmapLinkRectangle.ts b/src/components/Map/MapViewer/utils/shapes/overlay/findMatchingSubmapLinkRectangle.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/findMatchingSubmapLinkRectangle.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/findMatchingSubmapLinkRectangle.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/getOverlays.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/getOverlays.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays.ts b/src/components/Map/MapViewer/utils/shapes/overlay/getOverlays.ts similarity index 83% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/getOverlays.ts index 8cc7c004..687e2e67 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/getOverlays.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/getOverlays.ts @@ -1,7 +1,7 @@ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; -import groupOverlayEntities from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities'; -import processOverlayGroupedElements from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements'; +import groupOverlayEntities from '@/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities'; +import processOverlayGroupedElements from '@/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements'; export default function getOverlays( groupedOverlays: Record<string, Array<OverlayBioEntityRender>>, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities.ts b/src/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities.ts similarity index 88% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities.ts index 984574cf..f9a63e9e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/groupOverlayEntities.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/groupOverlayEntities.ts @@ -1,6 +1,6 @@ import { OverlayBioEntityRender } from '@/types/OLrendering'; -import findMatchingSubmapLinkRectangle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/findMatchingSubmapLinkRectangle'; -import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewer.types'; +import findMatchingSubmapLinkRectangle from '@/components/Map/MapViewer/utils/shapes/overlay/findMatchingSubmapLinkRectangle'; export default function groupOverlayEntities( overlayBioEntities: Array<OverlayBioEntityRender>, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.test.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.test.ts index 680002ea..c3a094e2 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-magic-numbers */ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; -import processOverlayGroupedElements from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements'; -import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewer.types'; +import processOverlayGroupedElements from '@/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements'; describe('processOverlayGroupedElements', () => { it('should correctly process overlay grouped elements and add to entityOverlays', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.ts b/src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.ts index 7e2a9b43..48ecc167 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/processOverlayGroupedElements.ts +++ b/src/components/Map/MapViewer/utils/shapes/overlay/processOverlayGroupedElements.ts @@ -1,9 +1,9 @@ /* eslint-disable no-magic-numbers */ import { OverlayBioEntityRender } from '@/types/OLrendering'; import { GetOverlayBioEntityColorByAvailableProperties } from '@/components/Map/MapViewer/utils/config/overlaysLayer/useGetOverlayColor'; -import sortElementOverlayByColor from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/sortElementOverlayByColor'; -import calculateOverlayDimensions from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/calculateOverlayDimensions'; -import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { OverlayBioEntityGroupedElementsType } from '@/components/Map/MapViewer/MapViewer.types'; +import sortElementOverlayByColor from '@/components/Map/MapViewer/utils/shapes/overlay/sortElementOverlayByColor'; +import calculateOverlayDimensions from '@/components/Map/MapViewer/utils/shapes/overlay/calculateOverlayDimensions'; export default function processOverlayGroupedElements( groupedElements: OverlayBioEntityGroupedElementsType, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/sortElementOverlayByColor.test.ts b/src/components/Map/MapViewer/utils/shapes/overlay/sortElementOverlayByColor.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/sortElementOverlayByColor.test.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/sortElementOverlayByColor.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/sortElementOverlayByColor.ts b/src/components/Map/MapViewer/utils/shapes/overlay/sortElementOverlayByColor.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/overlay/sortElementOverlayByColor.ts rename to src/components/Map/MapViewer/utils/shapes/overlay/sortElementOverlayByColor.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.test.ts b/src/components/Map/MapViewer/utils/shapes/reaction/Reaction.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.test.ts rename to src/components/Map/MapViewer/utils/shapes/reaction/Reaction.test.ts index 0e6dce24..4125a801 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/reaction/Reaction.test.ts @@ -1,8 +1,6 @@ /* eslint-disable no-magic-numbers */ import { Feature, Map } from 'ol'; -import Reaction, { - ReactionProps, -} from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction'; +import Reaction, { ReactionProps } from '@/components/Map/MapViewer/utils/shapes/reaction/Reaction'; import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; import { lineTypesFixture } from '@/models/fixtures/lineTypesFixture'; import { arrowTypesFixture } from '@/models/fixtures/arrowTypesFixture'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts b/src/components/Map/MapViewer/utils/shapes/reaction/Reaction.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts rename to src/components/Map/MapViewer/utils/shapes/reaction/Reaction.ts index ccefcd64..a2e786fc 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/reaction/Reaction.ts +++ b/src/components/Map/MapViewer/utils/shapes/reaction/Reaction.ts @@ -3,7 +3,6 @@ import { Line, Operator, ReactionProduct, Shape } from '@/types/models'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { Feature } from 'ol'; import { Circle, LineString, MultiLineString, MultiPolygon } from 'ol/geom'; -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; import Polygon from 'ol/geom/Polygon'; import Style from 'ol/style/Style'; import { @@ -11,21 +10,22 @@ import { REACTION_ELEMENT_TYPES, TEXT_CUTOFF_SCALE, WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +} from '@/components/Map/MapViewer/MapViewer.constants'; import { FeatureLike } from 'ol/Feature'; import { MapInstance } from '@/types/map'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import { ArrowTypeDict, LineTypeDict } from '@/redux/shapes/shapes.types'; import { FEATURE_TYPE } from '@/constants/features'; -import getScaledElementStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle'; import VectorSource from 'ol/source/Vector'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; import { Stroke } from 'ol/style'; -import getLineSegments from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getLineSegments'; -import getRotation from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/coords/getRotation'; -import getArrowFeature from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getArrowFeature'; -import getShapePolygon from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/elements/getShapePolygon'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; +import getScaledElementStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; +import getLineSegments from '@/components/Map/MapViewer/utils/shapes/coords/getLineSegments'; +import getRotation from '@/components/Map/MapViewer/utils/shapes/coords/getRotation'; +import getArrowFeature from '@/components/Map/MapViewer/utils/shapes/elements/getArrowFeature'; +import getShapePolygon from '@/components/Map/MapViewer/utils/shapes/elements/getShapePolygon'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; export interface ReactionProps { id: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.test.ts similarity index 87% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.test.ts index 8178ab4a..a8ea5c82 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.test.ts @@ -1,15 +1,15 @@ /* eslint-disable no-magic-numbers */ import Style from 'ol/style/Style'; import { Extent } from 'ol/extent'; -import getWrappedTextWithFontSize from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; +import getWrappedTextWithFontSize from '@/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import getCoverStyles from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles'; +import getCoverStyles from '@/components/Map/MapViewer/utils/shapes/style/getCoverStyles'; import { DEFAULT_TILE_SIZE } from '@/constants/map'; jest.mock('../text/getWrappedTextWithFontSize'); jest.mock('../text/getTextStyle'); -jest.mock('../../../../../../../utils/map/latLngToPoint'); +jest.mock('../../../../../../utils/map/latLngToPoint'); describe('getCoverStyles', () => { it('should return cover and text styles based on the provided parameters', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.ts b/src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.ts similarity index 86% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.ts rename to src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.ts index 78f2ef6b..83ad9a71 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getCoverStyles.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getCoverStyles.ts @@ -3,12 +3,12 @@ import Style from 'ol/style/Style'; import { Extent, getCenter } from 'ol/extent'; import { toLonLat } from 'ol/proj'; import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import getWrappedTextWithFontSize from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize'; +import getWrappedTextWithFontSize from '@/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize'; import { Point } from 'ol/geom'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; import { MapSize } from '@/redux/map/map.types'; import { Stroke } from 'ol/style'; -import getScaledStrokeStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle'; +import getScaledStrokeStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle'; export default function getCoverStyles({ coverStyle, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getFill.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getFill.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill.ts b/src/components/Map/MapViewer/utils/shapes/style/getFill.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill.ts rename to src/components/Map/MapViewer/utils/shapes/style/getFill.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.test.ts similarity index 92% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.test.ts index 5c22d994..bd36a7d8 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-magic-numbers */ import Style from 'ol/style/Style'; import { Stroke, Text } from 'ol/style'; -import getScaledStrokeStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle'; +import getScaledStrokeStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle'; import getScaledElementStyle from './getScaledElementStyle'; jest.mock('./getScaledStrokeStyle'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.ts b/src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.ts similarity index 76% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.ts rename to src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.ts index a91c0309..5f2eaa40 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledElementStyle.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getScaledElementStyle.ts @@ -1,7 +1,7 @@ /* eslint-disable no-magic-numbers */ import Style from 'ol/style/Style'; import { Stroke } from 'ol/style'; -import getScaledStrokeStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle'; +import getScaledStrokeStyle from '@/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle'; export default function getScaledElementStyle( style: Style, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle.ts b/src/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getScaledStrokeStyle.ts rename to src/components/Map/MapViewer/utils/shapes/style/getScaledStrokeStyle.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getStroke.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getStroke.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke.ts b/src/components/Map/MapViewer/utils/shapes/style/getStroke.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke.ts rename to src/components/Map/MapViewer/utils/shapes/style/getStroke.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.test.ts b/src/components/Map/MapViewer/utils/shapes/style/getStyle.test.ts similarity index 94% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/getStyle.test.ts index e46f9ef0..974b9272 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getStyle.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import getStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle'; +import getStyle from '@/components/Map/MapViewer/utils/shapes/style/getStyle'; import Style from 'ol/style/Style'; import Polygon from 'ol/geom/Polygon'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.ts b/src/components/Map/MapViewer/utils/shapes/style/getStyle.ts similarity index 65% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.ts rename to src/components/Map/MapViewer/utils/shapes/style/getStyle.ts index 96083434..9e121e1a 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStyle.ts +++ b/src/components/Map/MapViewer/utils/shapes/style/getStyle.ts @@ -1,14 +1,11 @@ /* eslint-disable no-magic-numbers */ import Style from 'ol/style/Style'; import { Geometry } from 'ol/geom'; -import getStroke from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getStroke'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; -import { - BLACK_COLOR, - WHITE_COLOR, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getFill from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/getFill'; +import { BLACK_COLOR, WHITE_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; import { Color } from '@/types/models'; +import getStroke from '@/components/Map/MapViewer/utils/shapes/style/getStroke'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getFill from '@/components/Map/MapViewer/utils/shapes/style/getFill'; export default function getStyle({ geometry, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex.test.ts b/src/components/Map/MapViewer/utils/shapes/style/rgbToHex.test.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex.test.ts rename to src/components/Map/MapViewer/utils/shapes/style/rgbToHex.test.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex.ts b/src/components/Map/MapViewer/utils/shapes/style/rgbToHex.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex.ts rename to src/components/Map/MapViewer/utils/shapes/style/rgbToHex.ts diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.test.ts b/src/components/Map/MapViewer/utils/shapes/text/Text.test.ts similarity index 80% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.test.ts rename to src/components/Map/MapViewer/utils/shapes/text/Text.test.ts index 68b8d9f8..d40cf459 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/Text.test.ts @@ -1,12 +1,12 @@ /* eslint-disable no-magic-numbers */ import { Map } from 'ol'; import { Style } from 'ol/style'; -import Text, { TextProps } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import View from 'ol/View'; -import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import { BLACK_COLOR } from '@/components/Map/MapViewer/MapViewer.constants'; +import Text, { TextProps } from '@/components/Map/MapViewer/utils/shapes/text/Text'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; jest.mock('./getTextCoords'); jest.mock('./getTextStyle'); diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts b/src/components/Map/MapViewer/utils/shapes/text/Text.ts similarity index 84% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts rename to src/components/Map/MapViewer/utils/shapes/text/Text.ts index 27b8ec6f..c853b369 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/Text.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/Text.ts @@ -1,19 +1,16 @@ /* eslint-disable no-magic-numbers */ -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; -import { rgbToHex } from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/style/rgbToHex'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import Style from 'ol/style/Style'; import { Point } from 'ol/geom'; import { Feature } from 'ol'; import { FeatureLike } from 'ol/Feature'; import { MapInstance } from '@/types/map'; -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; import { Color } from '@/types/models'; -import { TEXT_CUTOFF_SCALE } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.constants'; +import { TEXT_CUTOFF_SCALE } from '@/components/Map/MapViewer/MapViewer.constants'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; +import { rgbToHex } from '@/components/Map/MapViewer/utils/shapes/style/rgbToHex'; export interface TextProps { x: number; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.test.ts b/src/components/Map/MapViewer/utils/shapes/text/getTextCoords.test.ts similarity index 85% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.test.ts rename to src/components/Map/MapViewer/utils/shapes/text/getTextCoords.test.ts index 6121a92d..a48c180a 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/getTextCoords.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import getTextCoords from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords'; +import getTextCoords from '@/components/Map/MapViewer/utils/shapes/text/getTextCoords'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; describe('getTextCoords', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.ts b/src/components/Map/MapViewer/utils/shapes/text/getTextCoords.ts similarity index 89% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.ts rename to src/components/Map/MapViewer/utils/shapes/text/getTextCoords.ts index 3dcbb8fa..e3224fc9 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextCoords.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/getTextCoords.ts @@ -1,8 +1,5 @@ /* eslint-disable no-magic-numbers */ -import { - HorizontalAlign, - VerticalAlign, -} from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign, VerticalAlign } from '@/components/Map/MapViewer/MapViewer.types'; import { UsePointToProjectionResult } from '@/utils/map/usePointToProjection'; import { Coordinate } from 'ol/coordinate'; diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.test.ts b/src/components/Map/MapViewer/utils/shapes/text/getTextStyle.test.ts similarity index 88% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.test.ts rename to src/components/Map/MapViewer/utils/shapes/text/getTextStyle.test.ts index d16623b5..3d6fc5f4 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/getTextStyle.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import getTextStyle from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle'; +import getTextStyle from '@/components/Map/MapViewer/utils/shapes/text/getTextStyle'; import Style from 'ol/style/Style'; describe('getTextStyle', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.ts b/src/components/Map/MapViewer/utils/shapes/text/getTextStyle.ts similarity index 95% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.ts rename to src/components/Map/MapViewer/utils/shapes/text/getTextStyle.ts index 4858fb21..6558ab9a 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getTextStyle.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/getTextStyle.ts @@ -1,6 +1,6 @@ import { Fill, Text } from 'ol/style'; import Style from 'ol/style/Style'; -import { HorizontalAlign } from '@/components/Map/MapViewer/MapViewerVector/MapViewerVector.types'; +import { HorizontalAlign } from '@/components/Map/MapViewer/MapViewer.types'; export default function getTextStyle({ text, diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize.test.ts b/src/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize.test.ts similarity index 95% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize.test.ts rename to src/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize.test.ts index 2cfaa243..eba60616 100644 --- a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize.test.ts +++ b/src/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import getWrappedTextWithFontSize from '@/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize'; +import getWrappedTextWithFontSize from '@/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize'; describe('getWrappedTextWithFontSize', () => { it('should return a wrapped text and font size for this text when maxWidth is limited and maxHeight is unlimited', () => { diff --git a/src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize.ts b/src/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize.ts similarity index 100% rename from src/components/Map/MapViewer/MapViewerVector/utils/shapes/text/getWrappedTextWithFontSize.ts rename to src/components/Map/MapViewer/utils/shapes/text/getWrappedTextWithFontSize.ts diff --git a/src/components/Map/MapViewer/utils/useOlMap.ts b/src/components/Map/MapViewer/utils/useOlMap.ts index 68ec65bd..6e372dc3 100644 --- a/src/components/Map/MapViewer/utils/useOlMap.ts +++ b/src/components/Map/MapViewer/utils/useOlMap.ts @@ -2,15 +2,9 @@ import { MapInstance } from '@/types/map'; import { useMapInstance } from '@/utils/context/mapInstanceContext'; import Map from 'ol/Map'; import { Zoom } from 'ol/control'; -import React, { MutableRefObject, useEffect, useMemo } from 'react'; -import { useOlMapVectorLayers } from '@/components/Map/MapViewer/MapViewerVector/utils/config/useOlMapVectorLayers'; -import LayerGroup from 'ol/layer/Group'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { vectorRenderingSelector } from '@/redux/models/models.selectors'; +import React, { MutableRefObject, useEffect } from 'react'; +import { useOlMapLayers } from '@/components/Map/MapViewer/utils/config/useOlMapLayers'; import { defaults, MouseWheelZoom } from 'ol/interaction'; -import { useOlMapVectorListeners } from '@/components/Map/MapViewer/MapViewerVector/listeners/useOlMapVectorListeners'; -import { useOlMapCommonLayers } from '@/components/Map/MapViewer/utils/config/useOlMapCommonLayers'; -import { useOlMapLayers } from './config/useOlMapLayers'; import { useOlMapView } from './config/useOlMapView'; import { useOlMapListeners } from './listeners/useOlMapListeners'; @@ -25,34 +19,13 @@ interface UseOlMapOutput { type UseOlMap = (input?: UseOlMapInput) => UseOlMapOutput; export const useOlMap: UseOlMap = ({ target } = {}) => { - const vectorRendering = useAppSelector(vectorRenderingSelector); const mapRef = React.useRef<null | HTMLDivElement>(null); const { mapInstance, handleSetMapInstance } = useMapInstance(); const view = useOlMapView({ mapInstance }); - const rasterLayers = useOlMapLayers(); - const rasterLayersGroup = useMemo(() => { - return new LayerGroup({ - layers: rasterLayers, - }); - }, [rasterLayers]); - - const vectorLayers = useOlMapVectorLayers({ mapInstance }); - const vectorLayersGroup = useMemo(() => { - return new LayerGroup({ - layers: vectorLayers, - }); - }, [vectorLayers]); - - const commonLayers = useOlMapCommonLayers(); - const commonLayersGroup = useMemo(() => { - return new LayerGroup({ - layers: commonLayers, - }); - }, [commonLayers]); + const mapLayers = useOlMapLayers({ mapInstance }); useOlMapListeners({ view, mapInstance }); - useOlMapVectorListeners({ mapInstance }); useEffect(() => { // checking if innerHTML is empty due to possibility of target element cloning by OpenLayers map instance @@ -86,18 +59,8 @@ export const useOlMap: UseOlMap = ({ target } = {}) => { if (!mapInstance) { return; } - mapInstance.setLayers([vectorLayersGroup, rasterLayersGroup, commonLayersGroup]); - }, [mapInstance, rasterLayersGroup, vectorLayersGroup, commonLayersGroup]); - - useEffect(() => { - if (vectorRendering) { - rasterLayersGroup.setVisible(false); - vectorLayersGroup.setVisible(true); - } else { - vectorLayersGroup.setVisible(false); - rasterLayersGroup.setVisible(true); - } - }, [rasterLayersGroup, vectorLayersGroup, vectorRendering]); + mapInstance.setLayers(mapLayers); + }, [mapInstance, mapLayers]); return { mapRef, diff --git a/src/models/mocks/modelsMock.ts b/src/models/mocks/modelsMock.ts index 85e29299..5c14d13a 100644 --- a/src/models/mocks/modelsMock.ts +++ b/src/models/mocks/modelsMock.ts @@ -475,7 +475,6 @@ export const CORE_PD_MODEL_MOCK: MapModel = { modificationDates: [], minZoom: 2, maxZoom: 9, - vectorRendering: true, }; export const MODEL_WITH_DESCRIPTION: MapModel = { diff --git a/src/models/modelSchema.ts b/src/models/modelSchema.ts index feb8817b..392cda85 100644 --- a/src/models/modelSchema.ts +++ b/src/models/modelSchema.ts @@ -29,7 +29,6 @@ export const mapModelSchema = z.object({ references: z.array(referenceSchema), creationDate: z.string().nullable(), modificationDates: z.array(z.string()), - vectorRendering: z.boolean().optional(), }); export const mapModelsSchema = pageableSchema(mapModelSchema); diff --git a/src/redux/bioEntity/thunks/utils/fetchReactionsAndGetBioEntitiesIds.ts b/src/redux/bioEntity/thunks/utils/fetchReactionsAndGetBioEntitiesIds.ts index cae4025d..a29317ed 100644 --- a/src/redux/bioEntity/thunks/utils/fetchReactionsAndGetBioEntitiesIds.ts +++ b/src/redux/bioEntity/thunks/utils/fetchReactionsAndGetBioEntitiesIds.ts @@ -5,7 +5,7 @@ import { modelsNameMapSelector } from '@/redux/models/models.selectors'; import { getReactionsByIds } from '@/redux/reactions/reactions.thunks'; import type { AppDispatch, store } from '@/redux/store'; import type { BioEntityContent, NewReaction } from '@/types/models'; -import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction'; +import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction'; interface Args { bioEntityContents: BioEntityContent[]; diff --git a/src/redux/layers/layers.reducers.ts b/src/redux/layers/layers.reducers.ts index 715611f1..58aa3a23 100644 --- a/src/redux/layers/layers.reducers.ts +++ b/src/redux/layers/layers.reducers.ts @@ -57,6 +57,9 @@ export const setActiveLayerReducer = ( action: PayloadAction<{ modelId: number; layerId: number | null }>, ): void => { const { modelId, layerId } = action.payload; + if (!state[modelId]) { + return; + } const { data } = state[modelId]; if (!data) { return; diff --git a/src/redux/models/models.reducers.ts b/src/redux/models/models.reducers.ts index 054b4c0b..eb653786 100644 --- a/src/redux/models/models.reducers.ts +++ b/src/redux/models/models.reducers.ts @@ -1,5 +1,5 @@ /* eslint-disable no-magic-numbers */ -import { ActionReducerMapBuilder, PayloadAction } from '@reduxjs/toolkit'; +import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import { getModels } from './models.thunks'; import { ModelsState } from './models.types'; @@ -16,14 +16,3 @@ export const getModelsReducer = (builder: ActionReducerMapBuilder<ModelsState>): // TODO to discuss manage state of failure }); }; - -export const setModelVectorRenderingReducer = ( - state: ModelsState, - action: PayloadAction<{ vectorRendering: boolean; mapId: number }>, -): void => { - const { payload } = action; - 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 606aa70e..a26e8e94 100644 --- a/src/redux/models/models.selectors.ts +++ b/src/redux/models/models.selectors.ts @@ -63,8 +63,3 @@ export const mainMapModelDescriptionSelector = createSelector( mainMapModelSelector, model => model?.description, ); - -export const vectorRenderingSelector = createSelector( - currentModelSelector, - model => model?.vectorRendering || false, -); diff --git a/src/redux/models/models.slice.ts b/src/redux/models/models.slice.ts index 48cf8654..5c969f3e 100644 --- a/src/redux/models/models.slice.ts +++ b/src/redux/models/models.slice.ts @@ -1,6 +1,6 @@ import { ModelsState } from '@/redux/models/models.types'; import { createSlice } from '@reduxjs/toolkit'; -import { getModelsReducer, setModelVectorRenderingReducer } from './models.reducers'; +import { getModelsReducer } from './models.reducers'; const initialState: ModelsState = { data: [], @@ -11,14 +11,10 @@ const initialState: ModelsState = { export const modelsSlice = createSlice({ name: 'models', initialState, - reducers: { - setModelVectorRendering: setModelVectorRenderingReducer, - }, + reducers: {}, extraReducers: builder => { getModelsReducer(builder); }, }); -export const { setModelVectorRendering } = modelsSlice.actions; - export default modelsSlice.reducer; -- GitLab From 8d1cbb00fa002e86c0d77ef767b42b44df4bc657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Grocholewski?= <m.grocholewski@atcomp.pl> Date: Mon, 20 Jan 2025 11:09:40 +0100 Subject: [PATCH 2/3] feat(vector-map): remove communication with backend about backgrounds --- .../MapNavigation.component.test.tsx | 8 -- .../utils/useOverviewImageLinkActions.test.ts | 9 -- .../ElementLink.component.test.tsx | 2 - .../TopBar/TopBar.component.test.tsx | 7 -- .../AssociatedSubmap.component.test.tsx | 3 - .../ExportCompound.component.tsx | 12 +- .../OverlayListItem.component.test.tsx | 19 +--- .../hooks/useEmptyBackground.test.ts | 43 -------- .../hooks/useEmptyBackground.ts | 22 ---- .../Drawer/OverlaysDrawer/hooks/useOverlay.ts | 6 +- .../BioEntitiesSubmapItem.component.test.tsx | 3 - .../PinsListItem.component.test.tsx | 4 - .../DownloadSubmap.component.test.tsx | 10 -- .../utils/useGetSubmapDownloadUrl.test.ts | 10 -- .../utils/useGetSubmapDownloadUrl.ts | 9 +- .../SubmapsDrawer/SubmapsDrawer.test.tsx | 3 - .../MapAdditionalActions.component.test.tsx | 2 - .../utils/useAdditionalActions.test.ts | 2 - .../BackgroundsSelector.component.test.tsx | 104 ------------------ .../BackgroundsSelector.component.tsx | 86 --------------- .../BackgroundsSelector/index.ts | 1 - .../MapAdditionalOptions.component.test.tsx | 29 ----- .../MapAdditionalOptions.component.tsx | 10 -- .../Map/MapAdditionalOptions/index.ts | 1 - .../MapVectorBackgroundSelector.component.tsx | 12 +- .../MapViewer/MapViewer.component.test.tsx | 2 - .../useOlMapAdditionalLayers.test.ts | 2 - .../mapCardLayer/useOlMapCardLayer.test.ts | 2 - .../processLayer/processModelElements.ts | 6 +- .../processLayer/useOlMapProcessLayer.test.ts | 2 - .../processLayer/useOlMapProcessLayer.ts | 16 +-- .../utils/config/useOlMapLayers.test.ts | 2 - .../utils/config/useOlMapTileLayer.test.ts | 79 ------------- .../utils/config/useOlMapTileLayer.ts | 66 ----------- .../utils/config/useOlMapView.test.ts | 8 -- .../utils/listeners/useOlMapListeners.test.ts | 2 - .../utils/shapes/elements/BaseMultiPolygon.ts | 10 +- .../utils/shapes/elements/Compartment.ts | 6 +- .../shapes/elements/CompartmentCircle.test.ts | 2 +- .../shapes/elements/CompartmentCircle.ts | 6 +- .../elements/CompartmentPathway.test.ts | 2 +- .../shapes/elements/CompartmentPathway.ts | 6 +- .../shapes/elements/CompartmentSquare.test.ts | 2 +- .../shapes/elements/CompartmentSquare.ts | 6 +- .../utils/shapes/elements/MapElement.test.ts | 2 +- .../utils/shapes/elements/MapElement.ts | 6 +- .../Map/MapViewer/utils/useOlMap.test.ts | 2 - src/constants/backgrounds.ts | 1 - src/models/fixtures/backgroundsFixture.ts | 10 -- src/models/mapBackground.ts | 21 ---- src/redux/apiPath.ts | 2 - src/redux/backgrounds/background.mock.ts | 60 ---------- src/redux/backgrounds/background.selectors.ts | 56 ---------- .../backgrounds/backgrounds.constants.ts | 3 - .../backgrounds/backgrounds.reducers.test.ts | 86 --------------- src/redux/backgrounds/backgrounds.reducers.ts | 19 ---- src/redux/backgrounds/backgrounds.slice.ts | 20 ---- src/redux/backgrounds/backgrounds.thunks.ts | 27 ----- src/redux/backgrounds/backgrounds.types.ts | 4 - src/redux/map/map.constants.ts | 3 +- src/redux/map/map.fixtures.ts | 4 +- src/redux/map/map.reducers.ts | 10 +- src/redux/map/map.selectors.ts | 2 +- src/redux/map/map.slice.ts | 3 - src/redux/map/map.thunks.test.ts | 20 ++-- src/redux/map/map.thunks.ts | 21 +--- src/redux/map/map.types.ts | 4 +- .../checkIfIsMapUpdateActionValid.test.ts | 2 - .../map/middleware/map.middleware.test.ts | 2 - src/redux/map/middleware/map.middleware.ts | 5 +- .../overlayBioEntity.thunk.ts | 7 -- src/redux/root/init.selectors.ts | 4 - src/redux/root/init.thunks.ts | 2 - src/redux/root/root.fixtures.ts | 2 - src/redux/store.ts | 2 - .../pluginsManager/map/data/getBounds.test.ts | 2 - .../map/fitBounds/fitBounds.test.ts | 3 - .../pluginsManager/map/openMap.test.ts | 4 - .../setBackgroundtoEmptyIfAvailable.test.ts | 52 --------- .../setBackgroundtoEmptyIfAvailable.ts | 12 -- .../showDataOverlay/showDataOverlay.test.ts | 43 -------- .../showDataOverlay/showDataOverlay.ts | 5 +- .../map/position/getCenter.test.ts | 2 - .../map/triggerSearch/triggerSearch.test.ts | 2 - .../pluginsManager/map/zoom/getZoom.test.ts | 3 - .../pluginsManager/map/zoom/setZoom.test.ts | 2 - src/types/mapLayers.ts | 15 --- src/types/models.ts | 2 - .../initialize/useInitializeStore.test.ts | 18 +-- src/utils/initialize/useInitializeStore.ts | 3 +- src/utils/map/getUpdatedMapData.ts | 7 +- src/utils/map/useSetBounds.test.ts | 3 - .../useReduxBusQueryManager.test.ts | 3 - 93 files changed, 84 insertions(+), 1153 deletions(-) delete mode 100644 src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.test.ts delete mode 100644 src/components/Map/Drawer/OverlaysDrawer/hooks/useEmptyBackground.ts delete mode 100644 src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.test.tsx delete mode 100644 src/components/Map/MapAdditionalOptions/BackgroundsSelector/BackgroundsSelector.component.tsx delete mode 100644 src/components/Map/MapAdditionalOptions/BackgroundsSelector/index.ts delete mode 100644 src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.test.tsx delete mode 100644 src/components/Map/MapAdditionalOptions/MapAdditionalOptions.component.tsx delete mode 100644 src/components/Map/MapAdditionalOptions/index.ts delete mode 100644 src/components/Map/MapViewer/utils/config/useOlMapTileLayer.test.ts delete mode 100644 src/components/Map/MapViewer/utils/config/useOlMapTileLayer.ts delete mode 100644 src/constants/backgrounds.ts delete mode 100644 src/models/fixtures/backgroundsFixture.ts delete mode 100644 src/models/mapBackground.ts delete mode 100644 src/redux/backgrounds/background.mock.ts delete mode 100644 src/redux/backgrounds/background.selectors.ts delete mode 100644 src/redux/backgrounds/backgrounds.constants.ts delete mode 100644 src/redux/backgrounds/backgrounds.reducers.test.ts delete mode 100644 src/redux/backgrounds/backgrounds.reducers.ts delete mode 100644 src/redux/backgrounds/backgrounds.slice.ts delete mode 100644 src/redux/backgrounds/backgrounds.thunks.ts delete mode 100644 src/redux/backgrounds/backgrounds.types.ts delete mode 100644 src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.test.ts delete mode 100644 src/services/pluginsManager/map/overlays/showDataOverlay/setBackgroundtoEmptyIfAvailable.ts delete mode 100644 src/types/mapLayers.ts diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx index e1839e66..22c43bc9 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 33e0afd0..4cf7330e 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 cdd2e42f..ea4fe1f6 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 f87cc56c..3f7463f3 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 267ad439..84ff3087 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 906dd9ee..1a60d63d 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 d1080df9..83ac53a3 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 9c58dfc3..00000000 --- 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 2536fa84..00000000 --- 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 084877fd..bca5b9ad 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 62654f69..a93282db 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 23c0490f..0b9a5de5 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'; @@ -39,7 +38,6 @@ const INITIAL_STORE_STATE: InitialStoreState = { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }; @@ -172,7 +170,6 @@ describe('PinsListItem - component ', () => { loading: 'succeeded', error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, - backgroundType: MapBackgroundsEnum.SEMANTIC, }, }, ); @@ -206,7 +203,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 4789c9c5..b753634e 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 8bb6e92d..8c078809 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 397f7aad..5d05f263 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 { currentModelSelector } from '@/redux/models/models.selectors'; import { useSelector } from 'react-redux'; @@ -8,11 +7,11 @@ export type GetSubmapDownloadUrl = ({ handler }: { handler: string }) => string; export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { const model = useSelector(currentModelSelector); - const background = useSelector(currentBackgroundSelector); + const background = useSelector(mapBackgroundSelector); const mapSize = useSelector(mapDataSizeSelector); const getSubmapDownloadUrl: GetSubmapDownloadUrl = ({ handler }) => { - const allParamsValid = [model?.id, background?.id, mapSize.maxZoom, handler].reduce( + const allParamsValid = [model?.id, background, mapSize.maxZoom, handler].reduce( (a, b) => Boolean(a) && Boolean(b), true, ); @@ -20,7 +19,7 @@ export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { return ''; } - return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${model?.id}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; + return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${model?.id}: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 492be6cb..d4a6e092 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 5fe7353f..06bd09fe 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 a65473f7..de9d56f1 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 8aaf2bd1..00000000 --- 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 610cb371..00000000 --- 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 0b379515..00000000 --- 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 5b877e38..00000000 --- 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 ce96a907..00000000 --- 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 ff61a27a..00000000 --- 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 97463f27..caea44b9 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 23485420..ea37b540 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 eba9fde5..a23de57b 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 dd9a5220..bec6905d 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 25aa2078..87c6d666 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 c8e961ed..c03a9e9f 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 09d5b04e..2837c80b 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 3fe8e861..4b52f2cd 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 58e4aaa5..00000000 --- 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 d98b480f..00000000 --- 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 d630b12b..0a786468 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 328c827b..2b2fabe1 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 23277551..59af80b8 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 10802411..76770a4b 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 eb94b525..1d5f41d6 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 78915ae4..0de0037b 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 05e1801e..0b0da3b4 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 94034677..bf6b269e 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 acf2471c..ebfdcd7a 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 34f95693..32bb5a24 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 744c6529..2137147c 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 ead1dd13..8f5f66d3 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 79bc1ed1..5b5fa97b 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 1bfb4619..00000000 --- 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 e06e5c15..00000000 --- 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 fe6c6e9e..00000000 --- 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 d20f1a79..1e0c81b8 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 515bb724..00000000 --- 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 eda37034..00000000 --- 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 49499431..00000000 --- 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 dd13a771..00000000 --- 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 2f0868b4..00000000 --- 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 491e981d..00000000 --- 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 d2ce1949..00000000 --- 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 7ce8fcfc..00000000 --- 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 55b67d50..92de423d 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 21674c65..77d17df6 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 5ae6707d..553ad617 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 8cb88035..92737498 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 dbfd8bbe..3106a118 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 b44d0fd8..81feb7da 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 363b1d9c..bb1a81d3 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 dc838aaa..72b600dc 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 1509a089..5580c024 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 cb928afd..b783347e 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 bacbb729..d4eef340 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 f726bd8f..c0d3daed 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 67cdfa08..5ddcf77a 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 ba7f3059..562789dc 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 c90d96c3..f6d6110c 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 0e3a85b9..a98370bc 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 b824df10..99f587da 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 de852078..1fd5ec32 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 69aca9db..ddebdab0 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 15b32c94..00000000 --- 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 59c6c061..00000000 --- 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 da92e7f9..7709f9ec 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 8304beed..34359036 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 fe23d527..f9d9dd54 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 293f9476..abb470aa 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 669d8773..b7808d53 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 2d5f8a3d..55502f30 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 d5b7bb6a..00000000 --- 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 c70bb0b7..168c7fde 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 34a1e072..92b5d635 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 c6481127..3c6ed389 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 1e4fc498..1d5632f8 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 fde34efd..71ee1260 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 e71069d6..9283e65b 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, }); -- GitLab From 9d4a063dfa1373b06e03a3917e36eb370f1ce32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Grocholewski?= <m.grocholewski@atcomp.pl> Date: Tue, 21 Jan 2025 16:18:35 +0100 Subject: [PATCH 3/3] feat(clean-up): remove communication with backend about search by coordinates --- docs/plugins/search.md | 4 +- .../getReactionLineSegments.test.ts | 51 +++ .../reactionsLayer/getReactionLineSegments.ts | 19 ++ .../reactionsLayer/useOlMapReactionsLayer.ts | 2 +- .../handleBioEntityResults.test.ts | 47 --- .../mapRightClick/handleBioEntityResults.ts | 18 - ...dleSearchResultForRightClickAction.test.ts | 45 --- .../handleSearchResultForRightClickAction.ts | 24 -- .../mapRightClick/onMapRightClick.test.ts | 148 -------- .../mapRightClick/onMapRightClick.ts | 32 -- .../findClosestBioEntityPoint.test.ts | 54 --- .../findClosestBioEntityPoint.ts | 29 -- .../findClosestReactionPoint.test.ts | 49 --- .../findClosestReactionPoint.ts | 62 ---- .../getMaxClickDistance.test.ts | 26 -- .../mapSingleClick/getMaxClickDistance.ts | 21 -- .../mapSingleClick/getSearchResults.test.ts | 114 ------- .../mapSingleClick/getSearchResults.ts | 40 --- .../mapSingleClick/handleAliasResults.test.ts | 266 --------------- .../mapSingleClick/handleAliasResults.ts | 58 ---- .../handleReactionResults.test.ts | 323 ------------------ .../mapSingleClick/handleReactionResults.ts | 89 ----- .../handleReactionSearchClickFailure.ts | 15 - .../handleSearchResultAction.test.ts | 67 ---- .../handleSearchResultAction.ts | 49 --- .../mapSingleClick/onMapSingleClick.test.ts | 299 ---------------- .../mapSingleClick/onMapSingleClick.ts | 47 --- .../mouseClick/getFeatureAtCoordinate.test.ts | 85 +++++ .../mouseClick/getFeatureAtCoordinate.ts | 52 +++ .../handleDataReset.test.ts | 0 .../handleDataReset.ts | 0 .../handleFeaturesClick.test.ts | 0 .../mouseLeftClick}/handleFeaturesClick.ts | 0 .../mouseLeftClick/leftClickHandleAlias.ts | 5 +- .../mouseLeftClick/onMapLeftClick.test.ts | 4 +- .../mouseLeftClick/onMapLeftClick.ts | 51 +-- .../mouseRightClick/onMapRightClick.ts | 2 +- src/redux/apiPath.ts | 8 - .../configuration/configuration.selectors.ts | 11 - .../modelElements/modelElements.selector.ts | 5 + .../newReactions/newReactions.selectors.ts | 5 + .../map/triggerSearch/searchByCoordinates.ts | 68 ++-- .../map/triggerSearch/triggerSearch.test.ts | 112 +++--- .../map/triggerSearch/triggerSearch.ts | 10 +- .../map/triggerSearch/triggerSearch.types.ts | 1 - .../search/getElementsByCoordinates.test.ts | 54 --- src/utils/search/getElementsByCoordinates.ts | 101 ------ 47 files changed, 349 insertions(+), 2223 deletions(-) create mode 100644 src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.test.ts create mode 100644 src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionSearchClickFailure.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.test.ts delete mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.ts create mode 100644 src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.test.ts create mode 100644 src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.ts rename src/components/Map/MapViewer/utils/listeners/{mapSingleClick => mouseClick}/handleDataReset.test.ts (100%) rename src/components/Map/MapViewer/utils/listeners/{mapSingleClick => mouseClick}/handleDataReset.ts (100%) rename src/components/Map/MapViewer/utils/listeners/{mapSingleClick => mouseClick/mouseLeftClick}/handleFeaturesClick.test.ts (100%) rename src/components/Map/MapViewer/utils/listeners/{mapSingleClick => mouseClick/mouseLeftClick}/handleFeaturesClick.ts (100%) delete mode 100644 src/utils/search/getElementsByCoordinates.test.ts delete mode 100644 src/utils/search/getElementsByCoordinates.ts diff --git a/docs/plugins/search.md b/docs/plugins/search.md index 05856f17..9401f1f6 100644 --- a/docs/plugins/search.md +++ b/docs/plugins/search.md @@ -24,7 +24,6 @@ If we want to search using coordinates, we need to provide an object with the fo - coordinates: this property should indicate the x and y coordinates on the map. Its value should be an object type with x and y properties - modelId: this property should indicate submap identifier. Its value should be a number type -- zoom: this property should indicate zoom level at which we want to trigger search. Its value should be a number type - fitBounds: should the map be resized to the rectangle fitting all results. Its value should be a boolean type. This property is optional, and by default, its value is `false`. ##### Example of search by query: @@ -38,12 +37,11 @@ window.minerva.map.triggerSearch({ fitBounds: true, }); -window.minerva.map.triggerSearch({ coordinates: { x: 1947, y: 5203 }, modelId: 60, zoom: 5 }); +window.minerva.map.triggerSearch({ coordinates: { x: 1947, y: 5203 }, modelId: 60 }); window.minerva.map.triggerSearch({ coordinates: { x: 1947, y: 5203 }, modelId: 51, fitBounds: true, - zoom: 6, }); ``` diff --git a/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.test.ts b/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.test.ts new file mode 100644 index 00000000..692f274d --- /dev/null +++ b/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.test.ts @@ -0,0 +1,51 @@ +/* eslint-disable no-magic-numbers */ +import { NewReaction } from '@/types/models'; +import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; +import { getReactionLineSegments } from '@/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments'; + +describe('getReactionLineSegments', () => { + it('should return all segments from reaction line and associated entities', () => { + const mockSegments1 = [ + { x1: 0, y1: 0, x2: 1, y2: 1 }, + { x1: 1, y1: 1, x2: 2, y2: 2 }, + ]; + const mockSegments2 = [ + { x1: 2, y1: 2, x2: 3, y2: 3 }, + { x1: 4, y1: 4, x2: 5, y2: 5 }, + ]; + const mockSegments3 = [ + { x1: 6, y1: 6, x2: 7, y2: 7 }, + { x1: 8, y1: 8, x2: 9, y2: 9 }, + ]; + const mockSegments4 = [ + { x1: 10, y1: 10, x2: 11, y2: 11 }, + { x1: 12, y1: 12, x2: 13, y2: 13 }, + ]; + const mockSegments5 = [ + { x1: 14, y1: 14, x2: 15, y2: 15 }, + { x1: 16, y1: 16, x2: 17, y2: 17 }, + ]; + + const mockReaction: NewReaction = newReactionFixture; + mockReaction.operators = [mockReaction.operators[0]]; + mockReaction.reactants = [mockReaction.reactants[0]]; + mockReaction.modifiers = [mockReaction.modifiers[0]]; + mockReaction.products = [mockReaction.products[0]]; + + mockReaction.line.segments = mockSegments1; + mockReaction.reactants[0].line.segments = mockSegments2; + mockReaction.products[0].line.segments = mockSegments3; + mockReaction.modifiers[0].line.segments = mockSegments4; + mockReaction.operators[0].line.segments = mockSegments5; + + const result = getReactionLineSegments(mockReaction); + + expect(result).toEqual([ + ...mockSegments1, + ...mockSegments2, + ...mockSegments3, + ...mockSegments4, + ...mockSegments5, + ]); + }); +}); diff --git a/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.ts b/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.ts new file mode 100644 index 00000000..eed454db --- /dev/null +++ b/src/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments.ts @@ -0,0 +1,19 @@ +import { NewReaction, Segment } from '@/types/models'; + +export function getReactionLineSegments(reaction: NewReaction): Segment[] { + const result: Segment[] = []; + result.push(...reaction.line.segments); + reaction.reactants.forEach(reactant => { + result.push(...reactant.line.segments); + }); + reaction.products.forEach(product => { + result.push(...product.line.segments); + }); + reaction.modifiers.forEach(modifier => { + result.push(...modifier.line.segments); + }); + reaction.operators.forEach(operator => { + result.push(...operator.line.segments); + }); + return result; +} diff --git a/src/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer.ts b/src/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer.ts index fa7c4196..cf4416f3 100644 --- a/src/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer.ts +++ b/src/components/Map/MapViewer/utils/config/reactionsLayer/useOlMapReactionsLayer.ts @@ -15,7 +15,7 @@ import { useEffect, useMemo } from 'react'; import { useSelector } from 'react-redux'; import { createOverlayLineFeature } from '@/components/Map/MapViewer/utils/config/overlaysLayer/createOverlayLineFeature'; import { Geometry } from 'ol/geom'; -import { getReactionLineSegments } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint'; +import { getReactionLineSegments } from '@/components/Map/MapViewer/utils/config/reactionsLayer/getReactionLineSegments'; import { getLineFeature } from './getLineFeature'; const getReactionsLines = (reactions: NewReaction[]): LinePoint[] => diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.test.ts deleted file mode 100644 index 04a81b69..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture'; -import { ELEMENT_SEARCH_RESULT_MOCK_ALIAS } from '@/models/mocks/elementSearchResultMock'; -import { apiPath } from '@/redux/apiPath'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; -import { HttpStatusCode } from 'axios'; -import { waitFor } from '@testing-library/react'; -import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { handleBioEntityResults } from './handleBioEntityResults'; - -const mockedAxiosOldClient = mockNetworkResponse(); - -describe('handleBioEntityResults - util', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - mockedAxiosOldClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); - - beforeAll(async () => { - handleBioEntityResults(dispatch)(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - }); - - it('should run setCurrentSelectedBioEntityId as first action', async () => { - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[FIRST_ARRAY_ELEMENT].type).toEqual( - 'contextMenu/setCurrentSelectedBioEntityId', - ); - }); - }); - - it('should run getMultiBioEntity as second action', async () => { - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[SECOND_ARRAY_ELEMENT].type).toEqual('project/getMultiBioEntity/pending'); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.ts deleted file mode 100644 index be06232a..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleBioEntityResults.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { getMultiBioEntity } from '@/redux/bioEntity/bioEntity.thunks'; -import { setCurrentSelectedBioEntityId } from '@/redux/contextMenu/contextMenu.slice'; -import { AppDispatch } from '@/redux/store'; -import { ElementSearchResult } from '@/types/models'; - -/* prettier-ignore */ -export const handleBioEntityResults = - (dispatch: AppDispatch) => - async ({ id }: ElementSearchResult): Promise<void> => { - - dispatch(setCurrentSelectedBioEntityId(id)); - dispatch( - getMultiBioEntity({ - searchQueries: [id.toString()], - isPerfectMatch: true - }), - ); - }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.test.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.test.ts deleted file mode 100644 index 161d96b5..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import * as handleReactionResults from '../mapSingleClick/handleReactionResults'; -import { handleSearchResultForRightClickAction } from './handleSearchResultForRightClickAction'; -import * as handleBioEntityResults from './handleBioEntityResults'; - -jest.mock('./handleBioEntityResults', () => ({ - __esModule: true, - handleBioEntityResults: jest.fn().mockImplementation(() => (): null => null), -})); -jest.mock('../mapSingleClick/handleReactionResults', () => ({ - __esModule: true, - handleReactionResults: jest.fn().mockImplementation(() => (): null => null), -})); - -const handleBioEntityResultsSpy = jest.spyOn(handleBioEntityResults, 'handleBioEntityResults'); -const handleReactionResultsSpy = jest.spyOn(handleReactionResults, 'handleReactionResults'); - -describe('handleSearchResultForRightClickAction - util', () => { - const dispatch = jest.fn(); - - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe('on ALIAS search results', () => { - const searchResults = [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]; - - it('should fire handleBioEntityResults', async () => { - await handleSearchResultForRightClickAction({ searchResults, dispatch }); - expect(handleBioEntityResultsSpy).toBeCalled(); - }); - }); - - describe('on REACTION search results', () => { - const searchResults = [ELEMENT_SEARCH_RESULT_MOCK_REACTION]; - - it('should fire handleReactionResults', async () => { - await handleSearchResultForRightClickAction({ searchResults, dispatch }); - expect(handleReactionResultsSpy).toBeCalled(); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts deleted file mode 100644 index 29056a8f..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { AppDispatch } from '@/redux/store'; -import { ElementSearchResult } from '@/types/models'; -import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; -import { handleBioEntityResults } from './handleBioEntityResults'; -import { handleReactionResults } from '../mapSingleClick/handleReactionResults'; - -interface HandleSearchResultActionInput { - searchResults: ElementSearchResult[]; - dispatch: AppDispatch; -} - -export const handleSearchResultForRightClickAction = async ({ - searchResults, - dispatch, -}: HandleSearchResultActionInput): Promise<void> => { - const closestSearchResult = searchResults[FIRST_ARRAY_ELEMENT]; - const { type } = closestSearchResult; - const action = { - ALIAS: handleBioEntityResults, - REACTION: handleReactionResults, - }[type]; - - await action(dispatch, closestSearchResult)(closestSearchResult); -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.test.ts deleted file mode 100644 index 33216241..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.test.ts +++ /dev/null @@ -1,148 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { apiPath } from '@/redux/apiPath'; -import { HttpStatusCode } from 'axios'; -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import { waitFor } from '@testing-library/react'; -import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { onMapRightClick } from './onMapRightClick'; -import * as handleDataReset from '../mapSingleClick/handleDataReset'; -import * as handleSearchResultForRightClickAction from './handleSearchResultForRightClickAction'; - -jest.mock('./handleSearchResultForRightClickAction', () => ({ - __esModule: true, - ...jest.requireActual('./handleSearchResultForRightClickAction'), -})); -jest.mock('../mapSingleClick/handleDataReset', () => ({ - __esModule: true, - ...jest.requireActual('../mapSingleClick/handleDataReset'), -})); - -const mockedAxiosOldClient = mockNetworkResponse(); - -const handleSearchResultForRightClickActionSpy = jest.spyOn( - handleSearchResultForRightClickAction, - 'handleSearchResultForRightClickAction', -); -const handleDataResetSpy = jest.spyOn(handleDataReset, 'handleDataReset'); - -describe('onMapRightClick - util', () => { - beforeEach(() => { - jest.clearAllMocks(); - jest.resetAllMocks(); - }); - - describe('when always', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const modelId = 1000; - const mapSize = { - width: 90, - height: 90, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const handler = onMapRightClick(mapSize, modelId, dispatch, false); - const coordinate = [90, 90]; - const pixel = [250, 250]; - - it('should fire data reset handler', async () => { - await handler(coordinate, pixel); - expect(handleDataResetSpy).toBeCalled(); - }); - it('should fire open context menu handler', async () => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[FIRST_ARRAY_ELEMENT].type).toEqual('map/updateLastRightClick'); - expect(actions[SECOND_ARRAY_ELEMENT].type).toEqual('contextMenu/openContextMenu'); - }); - }); - - describe('when searchResults are undefined', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const modelId = 1000; - const mapSize = { - width: 90, - height: 90, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const handler = onMapRightClick(mapSize, modelId, dispatch, false); - const coordinate = [90, 90]; - const point = { x: 180.0008084837557, y: 179.99919151624428 }; - const pixel = [250, 250]; - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, undefined); - - it('does not fire search result action', async () => { - await handler(coordinate, pixel); - expect(handleSearchResultForRightClickActionSpy).not.toBeCalled(); - }); - }); - - describe('when searchResults are valid', () => { - describe('when results type is ALIAS', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - const pixel = [250, 250]; - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]); - - it('does fire search result for right click action handler', async () => { - const handler = onMapRightClick(mapSize, modelId, dispatch, false); - await handler(coordinate, pixel); - await waitFor(() => expect(handleSearchResultForRightClickActionSpy).toBeCalled()); - }); - }); - - describe('when results type is REACTION', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_REACTION; - const mapSize = { - width: 0, - height: 0, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [0, 0]; - const point = { - x: 0, - y: 0, - }; - const pixel = [0, 0]; - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_REACTION]); - - it('does fire search result for right click action - handle reaction', async () => { - const handler = onMapRightClick(mapSize, modelId, dispatch, false); - await handler(coordinate, pixel); - await waitFor(() => expect(handleSearchResultForRightClickActionSpy).toBeCalled()); - }); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.ts deleted file mode 100644 index a52cd458..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/onMapRightClick.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { openContextMenu } from '@/redux/contextMenu/contextMenu.slice'; -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { MapSize } from '@/redux/map/map.types'; -import { AppDispatch } from '@/redux/store'; -import { Coordinate } from 'ol/coordinate'; -import { Pixel } from 'ol/pixel'; -import { updateLastRightClick } from '@/redux/map/map.slice'; -import { toLonLat } from 'ol/proj'; -import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import { getSearchResults } from '../mapSingleClick/getSearchResults'; -import { handleDataReset } from '../mapSingleClick/handleDataReset'; -import { handleSearchResultForRightClickAction } from './handleSearchResultForRightClickAction'; - -/* prettier-ignore */ -export const onMapRightClick = - (mapSize: MapSize, modelId: number,dispatch: AppDispatch, shouldConsiderZoomLevel:boolean, - considerZoomLevel?:number, ) => async (coordinate: Coordinate, pixel: Pixel): Promise<void> => { - const [lng, lat] = toLonLat(coordinate); - const point = latLngToPoint([lat, lng], mapSize); - - dispatch(updateLastRightClick({coordinates:point, modelId})); - - dispatch(handleDataReset); - dispatch(openContextMenu(pixel)); - - const { searchResults } = await getSearchResults({ coordinate, mapSize, modelId, shouldConsiderZoomLevel, considerZoomLevel }); - if (!searchResults || searchResults.length === SIZE_OF_EMPTY_ARRAY) { - return; - } - - handleSearchResultForRightClickAction({ searchResults, dispatch }); - }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.test.ts deleted file mode 100644 index 44b10f68..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { bioEntityFixture } from '@/models/fixtures/bioEntityFixture'; -import { findClosestBioEntityPoint } from './findClosestBioEntityPoint'; - -describe('findClosestBioEntityPoint', () => { - const bioEntityContents = [ - { - ...bioEntityFixture, - x: 10, - y: 10, - width: 20, - height: 20, - }, - { - ...bioEntityFixture, - x: 50, - y: 50, - width: 30, - height: 30, - }, - ]; - - const validPoint = { x: 15, y: 15 }; - const invalidPoint = { - x: 500, - y: 300, - }; - - const searchDistance = '10'; - const maxZoom = 5; - const zoom = 2; - - it('should return the closest bioEntity within the search distance', () => { - const result = findClosestBioEntityPoint( - bioEntityContents, - searchDistance, - maxZoom, - zoom, - validPoint, - ); - expect(result).toEqual(bioEntityContents[0]); - }); - - it('should return undefined if no matching bioEntity is found within the search distance', () => { - const result = findClosestBioEntityPoint( - bioEntityContents, - searchDistance, - maxZoom, - zoom, - invalidPoint, - ); - expect(result).toBeUndefined(); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.ts deleted file mode 100644 index 329f8452..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestBioEntityPoint.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Point as PointType } from '@/types/map'; -import { BioEntity } from '@/types/models'; -import { getMaxClickDistance } from './getMaxClickDistance'; - -export const findClosestBioEntityPoint = ( - bioEntityContents: BioEntity[], - searchDistance: string, - maxZoom: number, - zoom: number, - point: PointType, -): BioEntity | undefined => { - const maxDistance = getMaxClickDistance(maxZoom, zoom, searchDistance); - - const matchingBioEntityFound = bioEntityContents.find(bio => { - const { x, y, width, height } = bio; - - const minX = x - maxDistance; - const maxX = x + width + maxDistance; - const minY = y - maxDistance; - const maxY = y + height + maxDistance; - - const withinXRange = point.x >= minX && point.x <= maxX; - const withinYRange = point.y >= minY && point.y <= maxY; - - return withinXRange && withinYRange; - }); - - return matchingBioEntityFound; -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.test.ts deleted file mode 100644 index 94369919..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; -import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; -import { findClosestReactionPoint, getReactionLineSegments } from './findClosestReactionPoint'; - -describe('findClosestReactionPoint', () => { - const reaction = { - ...newReactionFixture, - }; - - const validPoint = { x: reaction.line.segments[0].x1, y: reaction.line.segments[0].y1 }; - - let x = reaction.line.segments[0].x1; - let y = reaction.line.segments[0].y1; - getReactionLineSegments(reaction).forEach(lineSegment => { - x = Math.min(x, lineSegment.x1); - x = Math.min(x, lineSegment.x2); - y = Math.min(y, lineSegment.y1); - y = Math.min(y, lineSegment.y2); - }); - const invalidPoint = { x: x - 1000, y: y - 1000 }; - const searchDistance = '10'; - const maxZoom = 10; - const zoom = ZOOM_RESCALING_FACTOR * 5; - - it('should return the matching line segment if a point within the search distance is found', () => { - const result = findClosestReactionPoint({ - reaction, - searchDistance, - maxZoom, - zoom, - point: validPoint, - }); - - expect(result).toEqual(reaction.line.segments[0]); - }); - - it('should return undefined if no point within the search distance is found', () => { - const result = findClosestReactionPoint({ - reaction, - searchDistance, - maxZoom, - zoom, - point: invalidPoint, - }); - - expect(result).toBeUndefined(); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.ts deleted file mode 100644 index 33fbd42f..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/findClosestReactionPoint.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { Point as PointType } from '@/types/map'; -import { NewReaction, Segment } from '@/types/models'; -import { distance } from 'ol/coordinate'; -import { LineString, Point } from 'ol/geom'; -import { getMaxClickDistance } from './getMaxClickDistance'; - -type ReactionLine = Segment; - -type FindClosestReactionArgs = { - reaction: NewReaction; - searchDistance: string; - maxZoom: number; - zoom: number; - point: PointType; -}; - -export function getReactionLineSegments(reaction: NewReaction): Segment[] { - const result: Segment[] = []; - result.push(...reaction.line.segments); - reaction.reactants.forEach(reactant => { - result.push(...reactant.line.segments); - }); - reaction.products.forEach(product => { - result.push(...product.line.segments); - }); - reaction.modifiers.forEach(modifier => { - result.push(...modifier.line.segments); - }); - reaction.operators.forEach(operator => { - result.push(...operator.line.segments); - }); - return result; -} - -export const findClosestReactionPoint = ({ - reaction, - searchDistance, - maxZoom, - zoom, - point, -}: FindClosestReactionArgs): ReactionLine | undefined => { - const maxDistance = getMaxClickDistance(maxZoom, zoom, searchDistance); - - const clickedPoint = new Point([point.x, point.y]); - - const lines = getReactionLineSegments(reaction); - - const closestLine = lines.find(line => { - const lineString = new LineString([ - [line.x1, line.y1], - [line.x2, line.y2], - ]); - - const closestPointOnLine = lineString.getClosestPoint(clickedPoint.getCoordinates()); - const distanceToLine = distance(closestPointOnLine, clickedPoint.getCoordinates()); - - return distanceToLine <= maxDistance; - }); - - return closestLine; -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.test.ts deleted file mode 100644 index 3425b442..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; -import { getMaxClickDistance } from './getMaxClickDistance'; - -describe('getMaxClickDistance', () => { - it.each([ - [10, ZOOM_RESCALING_FACTOR * 5, '10', 320], - [10, ZOOM_RESCALING_FACTOR * 5, '20', 640], - [10, ZOOM_RESCALING_FACTOR * 2, '10', 2560], - [10, ZOOM_RESCALING_FACTOR * 3, '18', 2304], - ])( - 'should calculate the maximum click distance correctly', - (maxZoom, zoom, searchDistance, expected) => { - expect(getMaxClickDistance(maxZoom, zoom, searchDistance)).toBe(expected); - }, - ); - - it.each([['invalid'], [''], [' ']])( - 'should throw an error if the search distance "%s" is not a valid number', - invalidDistance => { - expect(() => getMaxClickDistance(10, 5, invalidDistance)).toThrow( - 'Invalid search distance. Please provide a valid number.', - ); - }, - ); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.ts deleted file mode 100644 index 42317465..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getMaxClickDistance.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* eslint-disable no-magic-numbers */ - -import { ZOOM_FACTOR } from '@/constants/common'; -import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; - -export const getMaxClickDistance = ( - maxZoom: number, - zoom: number, - searchDistance: string, -): number => { - const distance = parseFloat(searchDistance); - - if (typeof distance !== 'number' || Number.isNaN(distance)) { - throw new Error('Invalid search distance. Please provide a valid number.'); - } - - const zoomDiff = (ZOOM_RESCALING_FACTOR * maxZoom - zoom) / ZOOM_RESCALING_FACTOR; - const maxDistance = distance * ZOOM_FACTOR ** zoomDiff; - - return maxDistance; -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.test.ts deleted file mode 100644 index 0fa4d06f..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.test.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import { apiPath } from '@/redux/apiPath'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { HttpStatusCode } from 'axios'; -import { getSearchResults } from './getSearchResults'; - -const mockedAxiosOldClient = mockNetworkResponse(); - -describe('getSearchResults - util', () => { - describe('when results type is ALIAS', () => { - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - - beforeAll(() => { - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]); - }); - - it('returns valid array of objects', async () => { - const result = await getSearchResults({ - coordinate, - mapSize, - modelId, - shouldConsiderZoomLevel: false, - }); - - expect(result).toEqual({ - point, - searchResults: [ELEMENT_SEARCH_RESULT_MOCK_ALIAS], - }); - }); - }); - - describe('when results type is REACTION', () => { - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_REACTION; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - - beforeAll(() => { - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_REACTION]); - }); - - it('returns valid array of objects', async () => { - const result = await getSearchResults({ - coordinate, - mapSize, - modelId, - shouldConsiderZoomLevel: false, - }); - - expect(result).toEqual({ - point, - searchResults: [ELEMENT_SEARCH_RESULT_MOCK_REACTION], - }); - }); - }); - - describe('when results type is invalid', () => { - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - - beforeAll(() => { - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, { - invalidObject: true, - }); - }); - - it('should return undefined', async () => { - const result = await getSearchResults({ - coordinate, - mapSize, - modelId, - shouldConsiderZoomLevel: false, - }); - - expect(result).toEqual({ - point, - searchResults: undefined, - }); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.ts deleted file mode 100644 index f86ee0fe..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/getSearchResults.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { MapSize } from '@/redux/map/map.types'; -import { Point } from '@/types/map'; -import { ElementSearchResult } from '@/types/models'; -import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import { getElementsByPoint } from '@/utils/search/getElementsByCoordinates'; -import { Coordinate } from 'ol/coordinate'; -import { toLonLat } from 'ol/proj'; - -interface GetSearchResultsInput { - coordinate: Coordinate; - mapSize: MapSize; - modelId: number; - shouldConsiderZoomLevel: boolean; - considerZoomLevel?: number; -} - -export const getSearchResults = async ({ - coordinate, - mapSize, - modelId, - shouldConsiderZoomLevel, - considerZoomLevel, -}: GetSearchResultsInput): Promise<{ - searchResults: ElementSearchResult[] | undefined; - point: Point; -}> => { - const [lng, lat] = toLonLat(coordinate); - const point = latLngToPoint([lat, lng], mapSize); - const searchResults = await getElementsByPoint({ - point, - currentModelId: modelId, - shouldConsiderZoomLevel, - considerZoomLevel, - }); - - return { - searchResults, - point, - }; -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts deleted file mode 100644 index a1dacb26..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts +++ /dev/null @@ -1,266 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common'; -import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture'; -import { ELEMENT_SEARCH_RESULT_MOCK_ALIAS } from '@/models/mocks/elementSearchResultMock'; -import { apiPath } from '@/redux/apiPath'; -import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; -import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; -import { waitFor } from '@testing-library/react'; -import { HttpStatusCode } from 'axios'; -import { bioEntityFixture } from '@/models/fixtures/bioEntityFixture'; -import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; -import { isReactionBioEntity } from '@/redux/reactions/isReactionBioentity'; -import { handleAliasResults } from './handleAliasResults'; - -jest.mock('../../../../../../services/pluginsManager/map/triggerSearch/searchFitBounds'); - -const mockedAxiosClient = mockNetworkNewAPIResponse(); -const mockedAxiosOldClient = mockNetworkResponse(); - -const SEARCH_CONFIG_MOCK = { - point: { - x: 500, - y: 700, - }, - maxZoom: 9, - zoom: ZOOM_RESCALING_FACTOR * 5, - isResultDrawerOpen: false, -}; - -describe('handleAliasResults - util', () => { - beforeEach(() => { - jest.clearAllMocks(); - - const bioEntityWithIdReaction = bioEntityResponseFixture.content - .filter(c => isReactionBioEntity(c.bioEntity)) - ?.map(b => b.bioEntity || { id: ZERO }); - - mockedAxiosOldClient - .onGet( - apiPath.getReactionsWithIds( - bioEntityWithIdReaction.map(bioEntity => Number(`${bioEntity.id}`)), - ), - ) - .reply(HttpStatusCode.Ok, []); - }); - describe('when matching bioEntity not found', () => { - it('should clear bio entities and do not close drawer if result drawer is not open', async () => { - mockedAxiosClient - .onGet( - apiPath.getElementById( - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.modelId, - ), - ) - .reply(HttpStatusCode.Ok, { - ...bioEntityFixture, - idReaction: undefined, - }); - - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - await handleAliasResults(dispatch, ELEMENT_SEARCH_RESULT_MOCK_ALIAS, { - ...SEARCH_CONFIG_MOCK, - searchDistance: '10', - })(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toEqual([ - 'project/getMultiBioEntity/pending', - 'project/getBioEntityById/pending', - 'project/getCommentElement/pending', - 'project/getCommentElement/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getBioEntityById/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getMultiBioEntity/fulfilled', - 'bioEntityContents/clearBioEntities', - ]); - }); - }); - it('should clear bio entities and close drawer if result drawer is already open', async () => { - mockedAxiosClient - .onGet( - apiPath.getElementById( - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.modelId, - ), - ) - .reply(HttpStatusCode.Ok, { - ...bioEntityFixture, - idReaction: undefined, - }); - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - await handleAliasResults(dispatch, ELEMENT_SEARCH_RESULT_MOCK_ALIAS, { - ...SEARCH_CONFIG_MOCK, - searchDistance: '10', - isResultDrawerOpen: true, - })(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toEqual([ - 'project/getMultiBioEntity/pending', - 'project/getBioEntityById/pending', - 'project/getCommentElement/pending', - 'project/getCommentElement/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getBioEntityById/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getMultiBioEntity/fulfilled', - 'drawer/closeDrawer', - 'bioEntityContents/clearBioEntities', - ]); - }); - }); - }); - describe('when matching bioEntity found', () => { - it('should select tab and open bio entity drawer', async () => { - mockedAxiosClient - .onGet( - apiPath.getElementById( - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.modelId, - ), - ) - .reply(HttpStatusCode.Ok, { - ...bioEntityFixture, - x: 500, - y: 700, - width: 50, - height: 50, - idReaction: undefined, - }); - - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - await handleAliasResults( - dispatch, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - SEARCH_CONFIG_MOCK, - )(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toEqual([ - 'project/getMultiBioEntity/pending', - 'project/getBioEntityById/pending', - 'project/getCommentElement/pending', - 'project/getCommentElement/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getBioEntityById/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getMultiBioEntity/fulfilled', - 'drawer/selectTab', - 'drawer/openBioEntityDrawerById', - ]); - }); - }); - }); - - describe('when searchDistance is not provided', () => { - it('should select tab and open drawer without clearing bio entities', async () => { - mockedAxiosClient - .onGet( - apiPath.getElementById( - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.modelId, - ), - ) - .reply(HttpStatusCode.Ok, bioEntityFixture); - mockedAxiosOldClient - .onGet(apiPath.getReactionsWithIds([Number(bioEntityFixture.id)])) - .reply(HttpStatusCode.Ok, bioEntityFixture); - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - await handleAliasResults(dispatch, ELEMENT_SEARCH_RESULT_MOCK_ALIAS, { - ...SEARCH_CONFIG_MOCK, - isResultDrawerOpen: true, - })(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toEqual([ - 'project/getMultiBioEntity/pending', - 'project/getBioEntityById/pending', - 'project/getCommentElement/pending', - 'project/getCommentElement/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getBioEntityById/fulfilled', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getMultiBioEntity/fulfilled', - 'drawer/selectTab', - 'drawer/openBioEntityDrawerById', - ]); - }); - }); - - describe('fitBounds after search', () => { - it('should fit bounds after search when hasFitBounds is true', async () => { - mockedAxiosClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - await handleAliasResults(dispatch, ELEMENT_SEARCH_RESULT_MOCK_ALIAS, { - ...SEARCH_CONFIG_MOCK, - hasFitBounds: true, - })(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - expect(searchFitBounds).toHaveBeenCalled(); - }); - }); - - it('should not fit bounds after search when hasFitBounds is false', async () => { - mockedAxiosClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - await handleAliasResults(dispatch, ELEMENT_SEARCH_RESULT_MOCK_ALIAS, { - ...SEARCH_CONFIG_MOCK, - hasFitBounds: false, - })(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); - - await waitFor(() => { - expect(searchFitBounds).not.toHaveBeenCalled(); - }); - }); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts deleted file mode 100644 index c3d05aba..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { closeDrawer, openBioEntityDrawerById, selectTab } from '@/redux/drawer/drawer.slice'; -import { AppDispatch } from '@/redux/store'; -import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; -import { ElementSearchResult } from '@/types/models'; -import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; -import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; -import { Point } from '@/types/map'; -import { getMultiBioEntityByIds } from '@/redux/bioEntity/thunks/getMultiBioEntity'; -import { findClosestBioEntityPoint } from './findClosestBioEntityPoint'; - -type SearchConfig = { - point: Point; - searchDistance?: string; - maxZoom: number; - zoom: number; - hasFitBounds?: boolean; - isResultDrawerOpen?: boolean; -}; -/* prettier-ignore */ - -/* prettier-ignore */ -export const handleAliasResults = - (dispatch: AppDispatch, closestSearchResult: ElementSearchResult, { hasFitBounds, maxZoom, point, searchDistance, zoom, isResultDrawerOpen }: SearchConfig) => - async ({ id, modelId, type }: ElementSearchResult): Promise<void> => { - const bioEntities = await dispatch( - getMultiBioEntityByIds({ - elementsToFetch: [{elementId: id, type, modelId, addNumbersToEntityNumber: true}] - }), - ).unwrap(); - - if (searchDistance) { - - const matchingBioEntityFound = findClosestBioEntityPoint(bioEntities, searchDistance, maxZoom, zoom, point); - - if (!matchingBioEntityFound) { - if (isResultDrawerOpen) { - dispatch(closeDrawer()); - } - - dispatch(clearBioEntities()); - return; - } - } - - dispatch(selectTab(`${id}`)); - dispatch(openBioEntityDrawerById(id)); - - - PluginsEventBus.dispatchEvent('onSearch', { - type: 'bioEntity', - searchValues: [closestSearchResult], - results: [bioEntities.map((bioEntity)=>{return {perfect: true, bioEntity};})], - }); - - if (hasFitBounds) { - searchFitBounds(); - } - }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts deleted file mode 100644 index b39bdca0..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts +++ /dev/null @@ -1,323 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture'; -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import { apiPath } from '@/redux/apiPath'; -import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures'; -import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; -import { HttpStatusCode } from 'axios'; -import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; -import { bioEntityFixture } from '@/models/fixtures/bioEntityFixture'; -import { newReactionFixture } from '@/models/fixtures/newReactionFixture'; -import { ZOOM_RESCALING_FACTOR } from '@/constants/map'; -import * as findClosestReactionPoint from './findClosestReactionPoint'; -import { handleReactionResults } from './handleReactionResults'; - -const mockedAxiosOldClient = mockNetworkResponse(); -const mockedAxiosNewClient = mockNetworkNewAPIResponse(); - -jest.mock('../../../../../../services/pluginsManager/pluginsEventBus'); - -jest.mock('./findClosestReactionPoint', () => ({ - __esModule: true, - ...jest.requireActual('./findClosestReactionPoint'), -})); - -const findClosestReactionPointSpy = jest.spyOn( - findClosestReactionPoint, - 'findClosestReactionPoint', -); - -const SEARCH_CONFIG_MOCK = { - point: { - x: 200, - y: 3012, - }, - maxZoom: 9, - zoom: ZOOM_RESCALING_FACTOR * 3, - isResultDrawerOpen: false, -}; - -const reaction = { - ...newReactionFixture, - id: ELEMENT_SEARCH_RESULT_MOCK_REACTION.id, - model: ELEMENT_SEARCH_RESULT_MOCK_REACTION.modelId, - products: [], - reactants: [], - modifiers: [], -}; - -describe('handleReactionResults - util', () => { - const searchDistance = '10'; - - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe('actions', () => { - const { store } = getReduxStoreWithActionsListener({ - ...INITIAL_STORE_STATE_MOCK, - }); - const { dispatch } = store; - - mockedAxiosNewClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); - - mockedAxiosNewClient - .onGet( - apiPath.getElementById( - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - ELEMENT_SEARCH_RESULT_MOCK_ALIAS.modelId, - ), - ) - .reply(HttpStatusCode.Ok, bioEntityFixture); - - mockedAxiosNewClient - .onGet( - apiPath.getNewReaction( - ELEMENT_SEARCH_RESULT_MOCK_REACTION.modelId, - ELEMENT_SEARCH_RESULT_MOCK_REACTION.id, - ), - ) - .reply(HttpStatusCode.Ok, { - ...reaction, - reactants: [], - products: [], - modifiers: [ - { - ...newReactionFixture.modifiers[0], - element: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - }, - ], - }); - - beforeEach(async () => { - await handleReactionResults( - dispatch, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, - )(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - }); - - it('should run getReactionsByIds as first action', () => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[0].type).toEqual('reactions/getByIds/pending'); - expect(actions[1].type).toEqual('reactions/getByIds/fulfilled'); - }); - - it('should run openReactionDrawerById to empty array as third action', () => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[2].type).toEqual('drawer/openReactionDrawerById'); - expect(actions[2].payload).toEqual(reaction.id); - }); - - it('should run select tab as fourth action', () => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[3].type).toEqual('drawer/selectTab'); - }); - - it('should run getMultiBioEntity to empty array as fifth action', () => { - const actions = store.getActions(); - expect(actions.length).toBeGreaterThan(SIZE_OF_EMPTY_ARRAY); - expect(actions[4].type).toEqual('project/getMultiBioEntity/pending'); - }); - }); - describe('when search config provided but search distance is not provided', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - it('should not find closest reaction', async () => { - await handleReactionResults( - dispatch, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, - SEARCH_CONFIG_MOCK, - )(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - - expect(findClosestReactionPointSpy).not.toHaveBeenCalled(); - }); - }); - - describe('when search config provided and matching reaction not found', () => { - mockedAxiosNewClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); - - mockedAxiosNewClient - .onGet( - apiPath.getNewReaction( - ELEMENT_SEARCH_RESULT_MOCK_REACTION.modelId, - ELEMENT_SEARCH_RESULT_MOCK_REACTION.id, - ), - ) - .reply(HttpStatusCode.Ok, reaction); - - mockedAxiosOldClient - .onGet(apiPath.getReactionsWithIds([ELEMENT_SEARCH_RESULT_MOCK_REACTION.id])) - .reply(HttpStatusCode.Ok, [ - { - ...reaction, - reactants: [], - products: [], - modifiers: [ - { - ...newReactionFixture.modifiers[0], - element: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, - }, - ], - }, - ]); - - const invalidPoint = { - x: 991, - y: 612, - }; - it('should close drawer and reset data if result drawer open', async () => { - const { store } = getReduxStoreWithActionsListener(); - - await handleReactionResults(store.dispatch, ELEMENT_SEARCH_RESULT_MOCK_REACTION, { - ...SEARCH_CONFIG_MOCK, - searchDistance, - point: invalidPoint, - isResultDrawerOpen: true, - })(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - - const actions = store.getActions(); - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toStrictEqual([ - 'reactions/getByIds/pending', - 'reactions/getByIds/fulfilled', - 'drawer/closeDrawer', - 'reactions/resetReactionsData', - 'bioEntityContents/clearBioEntities', - ]); - }); - - it('should only reset data if result drawer is closed', async () => { - const { store } = getReduxStoreWithActionsListener(); - - const dispatchSpy = jest.spyOn(store, 'dispatch'); - - await handleReactionResults(store.dispatch, ELEMENT_SEARCH_RESULT_MOCK_REACTION, { - ...SEARCH_CONFIG_MOCK, - searchDistance, - point: invalidPoint, - isResultDrawerOpen: false, - })(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - - expect(dispatchSpy).toHaveBeenCalledWith({ - payload: undefined, - type: 'reactions/resetReactionsData', - }); - - expect(dispatchSpy).toHaveBeenCalledWith({ - payload: undefined, - type: 'bioEntityContents/clearBioEntities', - }); - }); - }); - describe('when search config provided and matching reaction found', () => { - const point = { x: 1, y: 1 }; - const maxZoom = 10; - const zoom = ZOOM_RESCALING_FACTOR * 5; - - it('should open reaction drawer and fetch bio entities', async () => { - const { store } = getReduxStoreWithActionsListener(); - mockedAxiosNewClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, []); - - mockedAxiosNewClient - .onGet( - apiPath.getNewReaction( - ELEMENT_SEARCH_RESULT_MOCK_REACTION.modelId, - ELEMENT_SEARCH_RESULT_MOCK_REACTION.id, - ), - ) - .reply(HttpStatusCode.Ok, reaction); - - await handleReactionResults(store.dispatch, ELEMENT_SEARCH_RESULT_MOCK_REACTION, { - searchDistance, - maxZoom, - zoom, - point, - isResultDrawerOpen: false, - })(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - - const actions = store.getActions(); - const actionTypes = actions.map(action => action.type); - - expect(actionTypes).toStrictEqual([ - 'reactions/getByIds/pending', - 'reactions/getByIds/fulfilled', - 'drawer/openReactionDrawerById', - 'drawer/selectTab', - 'project/getMultiBioEntity/pending', - 'entityNumber/addNumbersToEntityNumberData', - 'project/getMultiBioEntity/fulfilled', - ]); - }); - }); - describe('when matching reaction found', () => { - const point = { x: reaction.line.segments[0].x1, y: reaction.line.segments[0].y1 }; - const maxZoom = 10; - const zoom = ZOOM_RESCALING_FACTOR * 5; - - it('should dispatch onSearch event with reaction data', async () => { - const { store } = getReduxStoreWithActionsListener(); - mockedAxiosNewClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, []); - - mockedAxiosNewClient - .onGet( - apiPath.getNewReaction( - ELEMENT_SEARCH_RESULT_MOCK_REACTION.modelId, - ELEMENT_SEARCH_RESULT_MOCK_REACTION.id, - ), - ) - .reply(HttpStatusCode.Ok, reaction); - - await handleReactionResults(store.dispatch, ELEMENT_SEARCH_RESULT_MOCK_REACTION, { - searchDistance, - maxZoom, - zoom, - point, - isResultDrawerOpen: false, - })(ELEMENT_SEARCH_RESULT_MOCK_REACTION); - - expect(PluginsEventBus.dispatchEvent).toHaveBeenCalledWith('onSearch', { - results: [[{ bioEntity: reaction, perfect: true }]], - searchValues: [ELEMENT_SEARCH_RESULT_MOCK_REACTION], - type: 'reaction', - }); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts deleted file mode 100644 index 5631573e..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { FIRST_ARRAY_ELEMENT, SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { openReactionDrawerById, selectTab } from '@/redux/drawer/drawer.slice'; -import { getReactionsByIds } from '@/redux/reactions/reactions.thunks'; -import { AppDispatch } from '@/redux/store'; -import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; -import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; -import { Point } from '@/types/map'; -import { BioEntity, ElementSearchResult } from '@/types/models'; -import { axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; -import { apiPath } from '@/redux/apiPath'; -import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; -import { getMultiBioEntityByIds } from '@/redux/bioEntity/thunks/getMultiBioEntity'; -import { newReactionSchema } from '@/models/newReactionSchema'; -import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/utils/listeners/mouseClick/getModelElementsIdsFromReaction'; -import { handleReactionSearchClickFailure } from './handleReactionSearchClickFailure'; -import { findClosestReactionPoint } from './findClosestReactionPoint'; - -type SearchConfig = { - point: Point; - searchDistance?: string; - maxZoom: number; - zoom: number; - hasFitBounds?: boolean; - isResultDrawerOpen: boolean; -}; - -/* prettier-ignore */ -export const handleReactionResults = - (dispatch: AppDispatch, closestSearchResult: ElementSearchResult, searchConfig?: SearchConfig) => - async ({ id, modelId }: ElementSearchResult): Promise<void> => { - const data = await dispatch(getReactionsByIds({ ids: [{ id, modelId }] })); - const payload = data?.payload; - if (!data || !payload || typeof payload === 'string' || payload.data.length === SIZE_OF_EMPTY_ARRAY) { - return; - } - - const reaction = payload.data[FIRST_ARRAY_ELEMENT]; - const bioEntitiesIds = getModelElementsIdsFromReaction(reaction); - - if (searchConfig && searchConfig.searchDistance) { - const { maxZoom, point, searchDistance, zoom, isResultDrawerOpen } = searchConfig; - const matchingReactionFound = findClosestReactionPoint({ - reaction, searchDistance, maxZoom, zoom, point - }); - - if (!matchingReactionFound) { - handleReactionSearchClickFailure(dispatch, isResultDrawerOpen); - - return; - } - } - - dispatch(openReactionDrawerById(reaction.id)); - - dispatch(selectTab('')); - - const response = await axiosInstanceNewAPI.get<BioEntity>(apiPath.getNewReaction(reaction.model, reaction.id)); - const isDataValid = validateDataUsingZodSchema(response.data, newReactionSchema); - - if (isDataValid) { - const reactionNewApi = response.data; - - const bioEntities = await dispatch( - getMultiBioEntityByIds({ - elementsToFetch: bioEntitiesIds.map((bioEntityId) => { - return { - elementId: bioEntityId, - modelId, - type: 'ALIAS' - }; - }) - }) - ).unwrap(); - - if (bioEntities) { - const result = bioEntities.map((bioEntity) => {return { bioEntity, perfect: true };}); - result.push({ bioEntity: reactionNewApi, perfect: true }); - PluginsEventBus.dispatchEvent('onSearch', { - type: 'reaction', - searchValues: [closestSearchResult], - results: [result] - }); - - if (searchConfig && searchConfig.hasFitBounds) { - searchFitBounds(); - } - } - } - }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionSearchClickFailure.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionSearchClickFailure.ts deleted file mode 100644 index 30c6178f..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionSearchClickFailure.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { AppDispatch } from '@/redux/store'; -import { closeDrawer } from '@/redux/drawer/drawer.slice'; -import { resetReactionsData } from '@/redux/reactions/reactions.slice'; -import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; - -export const handleReactionSearchClickFailure = ( - dispatch: AppDispatch, - isResultDrawerOpen: boolean, -): void => { - if (isResultDrawerOpen) { - dispatch(closeDrawer()); - } - dispatch(resetReactionsData()); - dispatch(clearBioEntities()); -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.test.ts deleted file mode 100644 index d07fe1be..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import * as handleAliasResults from './handleAliasResults'; -import * as handleReactionResults from './handleReactionResults'; -import { handleSearchResultAction } from './handleSearchResultAction'; - -jest.mock('./handleAliasResults', () => ({ - __esModule: true, - handleAliasResults: jest.fn().mockImplementation(() => (): null => null), -})); - -jest.mock('./handleReactionResults', () => ({ - __esModule: true, - handleReactionResults: jest.fn().mockImplementation(() => (): null => null), -})); - -const handleAliasResultsSpy = jest.spyOn(handleAliasResults, 'handleAliasResults'); -const handleReactionResultsSpy = jest.spyOn(handleReactionResults, 'handleReactionResults'); - -const POINT_MOCK = { - x: 1323, - y: 2000, -}; -const ZOOM_MOCK = 3; -const MAX_ZOOM_MOCK = 9; - -describe('handleSearchResultAction - util', () => { - const dispatch = jest.fn(); - - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe('on ALIAS search results', () => { - const searchResults = [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]; - - it('should fire handleAliasResults', async () => { - await handleSearchResultAction({ - searchResults, - dispatch, - maxZoom: MAX_ZOOM_MOCK, - isResultDrawerOpen: false, - point: POINT_MOCK, - zoom: ZOOM_MOCK, - }); - expect(handleAliasResultsSpy).toBeCalled(); - }); - }); - - describe('on REACTION search results', () => { - const searchResults = [ELEMENT_SEARCH_RESULT_MOCK_REACTION]; - - it('should fire handleReactionResults', async () => { - await handleSearchResultAction({ - searchResults, - dispatch, - maxZoom: MAX_ZOOM_MOCK, - isResultDrawerOpen: false, - point: POINT_MOCK, - zoom: ZOOM_MOCK, - }); - expect(handleReactionResultsSpy).toBeCalled(); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts deleted file mode 100644 index f85813b1..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; -import { AppDispatch } from '@/redux/store'; -import { ElementSearchResult } from '@/types/models'; -import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; -import { Point } from '@/types/map'; -import { handleAliasResults } from './handleAliasResults'; -import { handleReactionResults } from './handleReactionResults'; - -interface HandleSearchResultActionInput { - searchResults: ElementSearchResult[]; - dispatch: AppDispatch; - point: Point; - searchDistance?: string; - maxZoom: number; - zoom: number; - hasFitBounds?: boolean; - isResultDrawerOpen: boolean; -} - -export const handleSearchResultAction = async ({ - searchResults, - dispatch, - point, - searchDistance, - maxZoom, - zoom, - hasFitBounds, - isResultDrawerOpen, -}: HandleSearchResultActionInput): Promise<void> => { - const closestSearchResult = searchResults[FIRST_ARRAY_ELEMENT]; - const { type } = closestSearchResult; - const action = { - ALIAS: handleAliasResults, - REACTION: handleReactionResults, - }[type]; - - await action(dispatch, closestSearchResult, { - point, - searchDistance, - maxZoom, - zoom, - hasFitBounds, - isResultDrawerOpen, - })(closestSearchResult); - - if (type === 'ALIAS') { - PluginsEventBus.dispatchEvent('onBioEntityClick', closestSearchResult); - } -}; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.test.ts deleted file mode 100644 index b91b2b33..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.test.ts +++ /dev/null @@ -1,299 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable no-magic-numbers */ -import { FEATURE_TYPE } from '@/constants/features'; -import { - ELEMENT_SEARCH_RESULT_MOCK_ALIAS, - ELEMENT_SEARCH_RESULT_MOCK_REACTION, -} from '@/models/mocks/elementSearchResultMock'; -import { apiPath } from '@/redux/apiPath'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; -import { waitFor } from '@testing-library/react'; -import { HttpStatusCode } from 'axios'; -import { Feature, Map, MapBrowserEvent } from 'ol'; -import * as handleDataReset from './handleDataReset'; -import * as handleSearchResultAction from './handleSearchResultAction'; -import { onMapSingleClick } from './onMapSingleClick'; - -jest.mock('./handleSearchResultAction', () => ({ - __esModule: true, - ...jest.requireActual('./handleSearchResultAction'), -})); -jest.mock('./handleDataReset', () => ({ - __esModule: true, - ...jest.requireActual('./handleDataReset'), -})); - -const mockedAxiosOldClient = mockNetworkResponse(); - -const handleSearchResultActionSpy = jest.spyOn( - handleSearchResultAction, - 'handleSearchResultAction', -); -const handleDataResetSpy = jest.spyOn(handleDataReset, 'handleDataReset'); - -const getEvent = (coordinate: MapBrowserEvent<UIEvent>['coordinate']): MapBrowserEvent<UIEvent> => - ({ - coordinate, - }) as unknown as MapBrowserEvent<UIEvent>; - -const MAX_ZOOM_MOCK_MOCK = 9; -const ZOOM_MOCK = 3; -const SEARCH_DISTANCE_MOCK = '10'; -const IS_RESULT_DRAWER_OPEN_MOCK = true; - -describe('onMapSingleClick - util', () => { - beforeEach(() => { - jest.clearAllMocks(); - jest.resetAllMocks(); - }); - - describe('when always', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const modelId = 1000; - const mapSize = { - width: 90, - height: 90, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - const coordinate = [90, 90]; - const event = getEvent(coordinate); - - const mapInstanceMock = { - forEachFeatureAtPixel: (): void => {}, - } as unknown as Map; - - it('should fire data reset handler', async () => { - await handler(event, mapInstanceMock); - expect(handleDataResetSpy).toBeCalled(); - }); - }); - - describe('when searchResults are undefined', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const modelId = 1000; - const mapSize = { - width: 90, - height: 90, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - const coordinate = [90, 90]; - const point = { x: 180.0008084837557, y: 179.99919151624428 }; - const event = getEvent(coordinate); - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, undefined); - - const mapInstanceMock = { - forEachFeatureAtPixel: (): void => {}, - } as unknown as Map; - - it('does not fire search result action', async () => { - await handler(event, mapInstanceMock); - expect(handleSearchResultActionSpy).not.toBeCalled(); - }); - }); - - describe('when searchResults are empty', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - - const modelId = 1000; - const mapSize = { - width: 180, - height: 180, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - const coordinate = [180, 180]; - const point = { x: 360.0032339350228, y: 359.9967660649771 }; - const event = getEvent(coordinate); - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, []); - - const mapInstanceMock = { - forEachFeatureAtPixel: (): void => {}, - } as unknown as Map; - - it('does not fire search result action', async () => { - await handler(event, mapInstanceMock); - expect(handleSearchResultActionSpy).not.toBeCalled(); - }); - }); - - describe('when clicked on feature type = pin icon bioentity', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - const event = getEvent(coordinate); - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]); - - const mapInstanceMock = { - forEachFeatureAtPixel: (pixel: any, mappingFunction: (feature: Feature) => void): void => { - [ - new Feature({ - id: 1000, - type: FEATURE_TYPE.PIN_ICON_BIOENTITY, - }), - ].forEach(mappingFunction); - }, - } as unknown as Map; - - it('does NOT fire search result action handler', async () => { - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - await handler(event, mapInstanceMock); - await waitFor(() => expect(handleSearchResultActionSpy).not.toBeCalled()); - }); - }); - - describe('when searchResults are valid', () => { - describe('when results type is ALIAS', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; - const mapSize = { - width: 270, - height: 270, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [270, 270]; - const point = { x: 540.0072763538013, y: 539.9927236461986 }; - const event = getEvent(coordinate); - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]); - - const mapInstanceMock = { - forEachFeatureAtPixel: (): void => {}, - } as unknown as Map; - - it('does fire search result action handler', async () => { - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - await handler(event, mapInstanceMock); - await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled()); - }); - }); - - describe('when results type is REACTION', () => { - const { store } = getReduxStoreWithActionsListener(); - const { dispatch } = store; - const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_REACTION; - const mapSize = { - width: 0, - height: 0, - tileSize: 256, - minZoom: 2, - maxZoom: 9, - }; - const coordinate = [0, 0]; - const point = { - x: 0, - y: 0, - }; - const event = getEvent(coordinate); - - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_REACTION]); - - const mapInstanceMock = { - forEachFeatureAtPixel: (): void => {}, - } as unknown as Map; - - it('does fire search result action - handle reaction', async () => { - const handler = onMapSingleClick( - mapSize, - modelId, - dispatch, - SEARCH_DISTANCE_MOCK, - MAX_ZOOM_MOCK_MOCK, - ZOOM_MOCK, - IS_RESULT_DRAWER_OPEN_MOCK, - [], - false, - ); - await handler(event, mapInstanceMock); - await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled()); - }); - }); - }); -}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.ts deleted file mode 100644 index 44e9d10b..00000000 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/onMapSingleClick.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { MapSize } from '@/redux/map/map.types'; -import { AppDispatch } from '@/redux/store'; -import { Map, MapBrowserEvent } from 'ol'; -import { FeatureLike } from 'ol/Feature'; -import { Comment } from '@/types/models'; -import { updateLastClick } from '@/redux/map/map.slice'; -import { toLonLat } from 'ol/proj'; -import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import { getSearchResults } from './getSearchResults'; -import { handleDataReset } from './handleDataReset'; -import { handleFeaturesClick } from './handleFeaturesClick'; -import { handleSearchResultAction } from './handleSearchResultAction'; - -/* prettier-ignore */ -export const onMapSingleClick = - (mapSize: MapSize, modelId: number, dispatch: AppDispatch, searchDistance: string | undefined, maxZoom: number, zoom: number, isResultDrawerOpen: boolean, - comments: Comment[], shouldConsiderZoomLevel:boolean, - considerZoomLevel?:number, - ) => - async ({ coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, mapInstance: Map): Promise<void> => { - const [lng, lat] = toLonLat(coordinate); - const point = latLngToPoint([lat, lng], mapSize); - - dispatch(updateLastClick({coordinates:point, modelId})); - - const featuresAtPixel: FeatureLike[] = []; - mapInstance.forEachFeatureAtPixel(pixel, (feature) => featuresAtPixel.push(feature)); - - const { shouldBlockCoordSearch } = handleFeaturesClick(featuresAtPixel, dispatch, comments); - - if (shouldBlockCoordSearch) { - return; - } - - // side-effect below is to prevent complications with data update - old data may conflict with new data - // so we need to reset all the data before updating - dispatch(handleDataReset); - - const {searchResults} = await getSearchResults({ coordinate, mapSize, modelId, shouldConsiderZoomLevel, - considerZoomLevel, - }); - if (!searchResults || searchResults.length === SIZE_OF_EMPTY_ARRAY) { - return; - } - handleSearchResultAction({ searchResults, dispatch, point, searchDistance, maxZoom, zoom, isResultDrawerOpen }); - }; diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.test.ts new file mode 100644 index 00000000..edc575be --- /dev/null +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.test.ts @@ -0,0 +1,85 @@ +/* eslint-disable no-magic-numbers */ +import { Feature } from 'ol'; +import VectorLayer from 'ol/layer/Vector'; +import Map from 'ol/Map'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; +import { FEATURE_TYPE } from '@/constants/features'; +import getFeatureAtCoordinate from '@/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate'; +import SimpleGeometry from 'ol/geom/SimpleGeometry'; + +describe('getFeatureAtCoordinate', () => { + let mapInstance: Map; + const coordinate = [100, 50]; + const vectorLayer = new VectorLayer({}); + vectorLayer.set('type', VECTOR_MAP_LAYER_TYPE); + + beforeEach(() => { + const dummyElement = document.createElement('div'); + mapInstance = new Map({ target: dummyElement }); + jest.clearAllMocks(); + }); + + it('returns undefined if mapInstance is not provided', () => { + const result = getFeatureAtCoordinate({ + mapInstance: undefined, + coordinate, + }); + expect(result).toBeUndefined(); + }); + + it('returns undefined if no feature is found at the pixel', () => { + jest.spyOn(mapInstance, 'getPixelFromCoordinate').mockReturnValue([200, 100]); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation(() => {}); + + const result = getFeatureAtCoordinate({ + mapInstance, + coordinate, + }); + expect(result).toBeUndefined(); + }); + + it('returns the feature if a filled compartment feature is found', () => { + const feature = new Feature({ type: FEATURE_TYPE.COMPARTMENT, filled: true, zIndex: 1 }); + + jest.spyOn(mapInstance, 'getPixelFromCoordinate').mockReturnValue([200, 100]); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { + callback(feature, vectorLayer, new SimpleGeometry()); + }); + + const result = getFeatureAtCoordinate({ + mapInstance, + coordinate, + }); + expect(result).toBe(feature); + }); + + it('returns the feature if a non-compartment feature is found', () => { + const feature = new Feature({ type: FEATURE_TYPE.ALIAS, zIndex: 1 }); + + jest.spyOn(mapInstance, 'getPixelFromCoordinate').mockReturnValue([200, 100]); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { + callback(feature, vectorLayer, new SimpleGeometry()); + }); + + const result = getFeatureAtCoordinate({ + mapInstance, + coordinate, + }); + expect(result).toBe(feature); + }); + + it('ignores features with invalid zIndex', () => { + const feature = new Feature({ type: FEATURE_TYPE.ALIAS, zIndex: -1 }); + + jest.spyOn(mapInstance, 'getPixelFromCoordinate').mockReturnValue([200, 100]); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { + callback(feature, vectorLayer, new SimpleGeometry()); + }); + + const result = getFeatureAtCoordinate({ + mapInstance, + coordinate, + }); + expect(result).toBeUndefined(); + }); +}); diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.ts new file mode 100644 index 00000000..5c1fc99e --- /dev/null +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate.ts @@ -0,0 +1,52 @@ +/* eslint-disable no-magic-numbers */ +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; +import { MapInstance } from '@/types/map'; +import { Coordinate } from 'ol/coordinate'; +import { FeatureLike } from 'ol/Feature'; +import { FEATURE_TYPE } from '@/constants/features'; + +function isFeatureFilledCompartment(feature: FeatureLike): boolean { + return feature.get('type') === FEATURE_TYPE.COMPARTMENT && feature.get('filled'); +} + +function isFeatureNotCompartment(feature: FeatureLike): boolean { + return ( + [...Object.values(FEATURE_TYPE)].includes(feature.get('type')) && + feature.get('type') !== FEATURE_TYPE.COMPARTMENT + ); +} + +export default function getFeatureAtCoordinate({ + mapInstance, + coordinate, + hitTolerance = 10, +}: { + mapInstance: MapInstance; + coordinate: Coordinate; + multiple?: boolean; + hitTolerance?: number; +}): FeatureLike | undefined { + let featureAtPixel: FeatureLike | undefined; + if (!mapInstance) { + return featureAtPixel; + } + const pixel = mapInstance.getPixelFromCoordinate(coordinate); + mapInstance.forEachFeatureAtPixel( + pixel, + (feature, layer) => { + const featureZIndex = feature.get('zIndex'); + if ( + layer && + layer.get('type') === VECTOR_MAP_LAYER_TYPE && + (isFeatureFilledCompartment(feature) || isFeatureNotCompartment(feature)) && + (featureZIndex === undefined || featureZIndex >= 0) + ) { + featureAtPixel = feature; + return true; + } + return false; + }, + { hitTolerance }, + ); + return featureAtPixel; +} diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset.test.ts similarity index 100% rename from src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset.test.ts diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset.ts similarity index 100% rename from src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset.ts diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick.test.ts similarity index 100% rename from src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick.test.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick.test.ts diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick.ts similarity index 100% rename from src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick.ts rename to src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick.ts diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts index f5d678d9..06a4e4d1 100644 --- a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias.ts @@ -19,15 +19,18 @@ export const leftClickHandleAlias = dispatch(selectTab(`${id}`)); dispatch(openBioEntityDrawerById(id)); + const searchValue = { id, modelId, type: FEATURE_TYPE.ALIAS }; PluginsEventBus.dispatchEvent('onSearch', { type: 'bioEntity', - searchValues: [{ id, modelId, type: FEATURE_TYPE.ALIAS }], + searchValues: [searchValue], results: [ bioEntities.map(bioEntity => { return { perfect: true, bioEntity }; }), ], }); + PluginsEventBus.dispatchEvent('onBioEntityClick', searchValue); + if (hasFitBounds) { searchFitBounds(); diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts index 2ef85495..deb19107 100644 --- a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.test.ts @@ -3,7 +3,7 @@ import { updateLastClick } from '@/redux/map/map.slice'; import { closeDrawer } from '@/redux/drawer/drawer.slice'; import { resetReactionsData } from '@/redux/reactions/reactions.slice'; import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; -import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick'; +import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick'; import Map from 'ol/Map'; import { onMapLeftClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick'; import { Comment } from '@/types/models'; @@ -15,7 +15,7 @@ import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.cons import * as leftClickHandleAlias from './leftClickHandleAlias'; import * as clickHandleReaction from '../clickHandleReaction'; -jest.mock('../../mapSingleClick/handleFeaturesClick', () => ({ +jest.mock('./handleFeaturesClick', () => ({ handleFeaturesClick: jest.fn(), })); jest.mock('./leftClickHandleAlias', () => ({ diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts index fdca7e96..0c01e4a2 100644 --- a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/onMapLeftClick.ts @@ -6,27 +6,15 @@ import { Comment, ModelElement, NewReaction } from '@/types/models'; import { updateLastClick } from '@/redux/map/map.slice'; import { toLonLat } from 'ol/proj'; import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import { FeatureLike } from 'ol/Feature'; import { closeDrawer } from '@/redux/drawer/drawer.slice'; import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; import { leftClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; -import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleFeaturesClick'; +import { handleFeaturesClick } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick'; import { resetReactionsData } from '@/redux/reactions/reactions.slice'; -import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset'; +import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset'; import { FEATURE_TYPE } from '@/constants/features'; import { clickHandleReaction } from '@/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction'; -import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; - -function isFeatureFilledCompartment(feature: FeatureLike): boolean { - return feature.get('type') === FEATURE_TYPE.COMPARTMENT && feature.get('filled'); -} - -function isFeatureNotCompartment(feature: FeatureLike): boolean { - return ( - [...Object.values(FEATURE_TYPE)].includes(feature.get('type')) && - feature.get('type') !== FEATURE_TYPE.COMPARTMENT - ); -} +import getFeatureAtCoordinate from '@/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate'; /* prettier-ignore */ export const onMapLeftClick = @@ -40,34 +28,17 @@ export const onMapLeftClick = reactions: Array<NewReaction>, ) => async ( - { coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, + { coordinate }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, mapInstance: Map, ): Promise<void> => { const [lng, lat] = toLonLat(coordinate); const point = latLngToPoint([lat, lng], mapSize); dispatch(updateLastClick({ coordinates: point, modelId })); + const featureAtCoordinate = getFeatureAtCoordinate({mapInstance, coordinate, multiple: false}); - let featureAtPixel: FeatureLike | undefined; - mapInstance.forEachFeatureAtPixel( - pixel, - (feature, layer) => { - const featureZIndex = feature.get('zIndex'); - if ( - layer && layer.get('type') === VECTOR_MAP_LAYER_TYPE && - (isFeatureFilledCompartment(feature) || isFeatureNotCompartment(feature)) && - (featureZIndex === undefined || featureZIndex >= 0) - ) { - featureAtPixel = feature; - return true; - } - return false; - }, - { hitTolerance: 10 }, - ); - - if (featureAtPixel) { - const { shouldBlockCoordSearch } = handleFeaturesClick([featureAtPixel], dispatch, comments); + if (featureAtCoordinate) { + const { shouldBlockCoordSearch } = handleFeaturesClick([featureAtCoordinate], dispatch, comments); if (shouldBlockCoordSearch) { return; } @@ -75,7 +46,7 @@ export const onMapLeftClick = dispatch(handleDataReset); - if (!featureAtPixel) { + if (!featureAtCoordinate) { if (isResultDrawerOpen) { dispatch(closeDrawer()); } @@ -85,10 +56,10 @@ export const onMapLeftClick = return; } - const type = featureAtPixel.get('type'); - const id = featureAtPixel.get('id'); + const type = featureAtCoordinate.get('type'); + const id = featureAtCoordinate.get('id'); if ([FEATURE_TYPE.ALIAS, FEATURE_TYPE.GLYPH, FEATURE_TYPE.COMPARTMENT].includes(type)) { - await leftClickHandleAlias(dispatch)(featureAtPixel, modelId); + await leftClickHandleAlias(dispatch)(featureAtCoordinate, modelId); } else if (type === FEATURE_TYPE.REACTION) { clickHandleReaction(dispatch)(modelElements, reactions, id, modelId); } diff --git a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts index 9773b48e..0daefedd 100644 --- a/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts +++ b/src/components/Map/MapViewer/utils/listeners/mouseClick/mouseRightClick/onMapRightClick.ts @@ -5,7 +5,7 @@ import { Feature, Map, MapBrowserEvent } from 'ol'; import { updateLastRightClick } from '@/redux/map/map.slice'; import { toLonLat } from 'ol/proj'; import { latLngToPoint } from '@/utils/map/latLngToPoint'; -import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset'; +import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset'; import { FEATURE_TYPE } from '@/constants/features'; import VectorLayer from 'ol/layer/Vector'; import VectorSource from 'ol/source/Vector'; diff --git a/src/redux/apiPath.ts b/src/redux/apiPath.ts index 1e0c81b8..9f81dab4 100644 --- a/src/redux/apiPath.ts +++ b/src/redux/apiPath.ts @@ -1,5 +1,4 @@ import { PROJECT_ID } from '@/constants'; -import { Point } from '@/types/map'; import { PerfectSearchParams } from '@/types/search'; import { GetPublicationsParams, PublicationsQueryParams } from './publications/publications.types'; @@ -28,13 +27,6 @@ export const apiPath = { isPerfectMatch, }: PerfectSearchParams): string => `projects/${PROJECT_ID}/models/*/bioEntities/:search?query=${searchQuery}&size=1000&perfectMatch=${isPerfectMatch}`, - getSingleBioEntityContentsStringWithCoordinates: ( - { x, y }: Point, - currentModelId: number, - ): string => { - const coordinates = [x, y].join(); - return `projects/${PROJECT_ID}/models/${currentModelId}/bioEntities:search/?coordinates=${coordinates}&count=1`; - }, getReactionsWithIds: (ids: number[]): string => `projects/${PROJECT_ID}/models/*/bioEntities/reactions/?id=${ids.join(',')}&size=1000`, getDrugsStringWithQuery: (searchQuery: string): string => diff --git a/src/redux/configuration/configuration.selectors.ts b/src/redux/configuration/configuration.selectors.ts index 158ac404..7a8009e4 100644 --- a/src/redux/configuration/configuration.selectors.ts +++ b/src/redux/configuration/configuration.selectors.ts @@ -16,7 +16,6 @@ import { SBML_HANDLER_NAME_ID, SIMPLE_COLOR_VAL_NAME_ID, SVG_IMAGE_HANDLER_NAME_ID, - SEARCH_DISTANCE_NAME_ID, REQUEST_ACCOUNT_EMAIL, TERMS_OF_SERVICE_ID, COOKIE_POLICY_URL, @@ -62,11 +61,6 @@ export const simpleColorValSelector = createSelector( state => configurationAdapterSelectors.selectById(state, SIMPLE_COLOR_VAL_NAME_ID)?.value, ); -export const searchDistanceValSelector = createSelector( - configurationOptionsSelector, - state => configurationAdapterSelectors.selectById(state, SEARCH_DISTANCE_NAME_ID)?.value, -); - export const matomoUrlSelector = createSelector( configurationOptionsSelector, state => configurationAdapterSelectors.selectById(state, MATOMO_URL)?.value, @@ -93,11 +87,6 @@ export const defaultLegendImagesSelector = createSelector(configurationOptionsSe ).filter(legendImage => Boolean(legendImage)), ); -export const elementTypesSelector = createSelector( - configurationMainSelector, - state => state?.elementTypes, -); - export const modelFormatsSelector = createSelector( configurationMainSelector, state => state?.modelFormats, diff --git a/src/redux/modelElements/modelElements.selector.ts b/src/redux/modelElements/modelElements.selector.ts index 4be70ab4..b31fd45f 100644 --- a/src/redux/modelElements/modelElements.selector.ts +++ b/src/redux/modelElements/modelElements.selector.ts @@ -10,6 +10,11 @@ export const modelElementsStateForCurrentModelSelector = createSelector( (state, currentModelId) => state[currentModelId], ); +export const modelElementsByModelIdSelector = createSelector( + [modelElementsSelector, (_state, modelId: number): number => modelId], + (state, modelId) => state[modelId]?.data || [], +); + export const modelElementsLoadingSelector = createSelector( modelElementsStateForCurrentModelSelector, state => state?.loading, diff --git a/src/redux/newReactions/newReactions.selectors.ts b/src/redux/newReactions/newReactions.selectors.ts index 6bf11f0e..a17245b4 100644 --- a/src/redux/newReactions/newReactions.selectors.ts +++ b/src/redux/newReactions/newReactions.selectors.ts @@ -19,3 +19,8 @@ export const newReactionsForCurrentModelSelector = createSelector( newReactionsStateForCurrentModelSelector, state => state?.data || [], ); + +export const newReactionsByModelIdSelector = createSelector( + [newReactionsSelector, (_state, modelId: number): number => modelId], + (state, modelId) => state[modelId]?.data || [], +); diff --git a/src/services/pluginsManager/map/triggerSearch/searchByCoordinates.ts b/src/services/pluginsManager/map/triggerSearch/searchByCoordinates.ts index 6b7a9b9d..235bf0f5 100644 --- a/src/services/pluginsManager/map/triggerSearch/searchByCoordinates.ts +++ b/src/services/pluginsManager/map/triggerSearch/searchByCoordinates.ts @@ -1,51 +1,59 @@ -import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset'; -import { handleSearchResultAction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction'; -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; +import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mouseClick/handleDataReset'; import { store } from '@/redux/store'; -import { getElementsByPoint } from '@/utils/search/getElementsByCoordinates'; -import { mapDataLastZoomValue, mapDataMaxZoomValue } from '@/redux/map/map.selectors'; -import { searchDistanceValSelector } from '@/redux/configuration/configuration.selectors'; -import { DEFAULT_ZOOM } from '@/constants/map'; +import { mapDataSizeSelector } from '@/redux/map/map.selectors'; import { resultDrawerOpen } from '@/redux/drawer/drawer.selectors'; +import { MapInstance } from '@/types/map'; +import getFeatureAtCoordinate from '@/components/Map/MapViewer/utils/listeners/mouseClick/getFeatureAtCoordinate'; +import { pointToLngLat } from '@/utils/map/pointToLatLng'; +import { fromLonLat } from 'ol/proj'; +import { FEATURE_TYPE } from '@/constants/features'; +import { leftClickHandleAlias } from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; +import { clickHandleReaction } from '@/components/Map/MapViewer/utils/listeners/mouseClick/clickHandleReaction'; +import { modelElementsByModelIdSelector } from '@/redux/modelElements/modelElements.selector'; +import { newReactionsByModelIdSelector } from '@/redux/newReactions/newReactions.selectors'; +import { closeDrawer } from '@/redux/drawer/drawer.slice'; +import { resetReactionsData } from '@/redux/reactions/reactions.slice'; +import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; import { Coordinates } from './triggerSearch.types'; export const searchByCoordinates = async ( + mapInstance: MapInstance, coordinates: Coordinates, modelId: number, - shouldConsiderZoomLevel: boolean, hasFitBounds?: boolean, - fitBoundsZoom?: number, - considerZoomLevel?: number, ): Promise<void> => { const { dispatch, getState } = store; // side-effect below is to prevent complications with data update - old data may conflict with new data // so we need to reset all the data before updating dispatch(handleDataReset); - const maxZoom = mapDataMaxZoomValue(getState()); - const lastZoom = mapDataLastZoomValue(getState()); - const searchDistance = searchDistanceValSelector(getState()); + const mapSize = mapDataSizeSelector(getState()); const isResultDrawerOpen = resultDrawerOpen(getState()); - - const searchResults = await getElementsByPoint({ - point: coordinates, - currentModelId: modelId, - shouldConsiderZoomLevel, - considerZoomLevel, + const newReactions = newReactionsByModelIdSelector(getState(), modelId); + const modelElements = modelElementsByModelIdSelector(getState(), modelId); + const [lng, lat] = pointToLngLat(coordinates, mapSize); + const projection = fromLonLat([lng, lat]); + const coordinate = projection.map(v => Math.round(v)); + const searchResultVector = getFeatureAtCoordinate({ + mapInstance, + coordinate, }); - if (!searchResults || searchResults?.length === SIZE_OF_EMPTY_ARRAY) { + if (!searchResultVector) { + if (isResultDrawerOpen) { + dispatch(closeDrawer()); + } + + dispatch(resetReactionsData()); + dispatch(clearBioEntities()); return; } - handleSearchResultAction({ - searchResults, - dispatch, - hasFitBounds, - zoom: fitBoundsZoom || lastZoom || DEFAULT_ZOOM, - maxZoom, - point: coordinates, - searchDistance, - isResultDrawerOpen, - }); + const type = searchResultVector.get('type'); + const id = searchResultVector.get('id'); + if ([FEATURE_TYPE.ALIAS, FEATURE_TYPE.GLYPH, FEATURE_TYPE.COMPARTMENT].includes(type)) { + await leftClickHandleAlias(dispatch, hasFitBounds)(searchResultVector, modelId); + } else if (type === FEATURE_TYPE.REACTION) { + clickHandleReaction(dispatch)(modelElements, newReactions, id, modelId); + } }; diff --git a/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts b/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts index abb470aa..adba6dd6 100644 --- a/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts +++ b/src/services/pluginsManager/map/triggerSearch/triggerSearch.test.ts @@ -1,21 +1,27 @@ /* eslint-disable no-magic-numbers */ -import { handleSearchResultAction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction'; import { initialMapDataFixture, openedMapsThreeSubmapsFixture } from '@/redux/map/map.fixtures'; import { CONFIGURATION_INITIAL_STORE_MOCKS } from '@/redux/configuration/configuration.mock'; import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture'; import { chemicalsFixture } from '@/models/fixtures/chemicalsFixture'; import { drugsFixture } from '@/models/fixtures/drugFixtures'; -import { ELEMENT_SEARCH_RESULT_MOCK_ALIAS } from '@/models/mocks/elementSearchResultMock'; import { apiPath } from '@/redux/apiPath'; import { RootState, store } from '@/redux/store'; -import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; +import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; -import { triggerSearch } from './triggerSearch'; +import { Feature, Map } from 'ol'; +import SimpleGeometry from 'ol/geom/SimpleGeometry'; +import VectorLayer from 'ol/layer/Vector'; +import { VECTOR_MAP_LAYER_TYPE } from '@/components/Map/MapViewer/MapViewer.constants'; +import { FEATURE_TYPE } from '@/constants/features'; +import * as leftClickHandleAlias from '@/components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias'; +import { MapManager } from '@/services/pluginsManager/map/mapManager'; +import { ModelElementsState } from '@/redux/modelElements/modelElements.types'; +import { NewReactionsState } from '@/redux/newReactions/newReactions.types'; import { ERROR_INVALID_MODEL_ID_TYPE } from '../../errorMessages'; +import { triggerSearch } from './triggerSearch'; const mockedAxiosClient = mockNetworkNewAPIResponse(); -const mockedAxiosOldClient = mockNetworkResponse(); const SEARCH_QUERY = 'park7'; const point = { x: 545.8013, y: 500.9926 }; const modelId = 1000; @@ -30,18 +36,54 @@ const MOCK_STATE = { error: { message: '', name: '' }, openedMaps: openedMapsThreeSubmapsFixture, }, + modelElements: { + 0: { + data: [], + loading: 'succeeded', + error: { message: '', name: '' }, + }, + } as ModelElementsState, + newReactions: { + 0: { + data: [], + loading: 'succeeded', + error: { message: '', name: '' }, + }, + } as NewReactionsState, configuration: CONFIGURATION_INITIAL_STORE_MOCKS, }; jest.mock('../../../../redux/store'); jest.mock( - '../../../../components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction', + '../../../../components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias', + () => ({ + __esModule: true, + ...jest.requireActual( + '../../../../components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/leftClickHandleAlias', + ), + }), +); +const leftClickHandleAliasSpy = jest.spyOn(leftClickHandleAlias, 'leftClickHandleAlias'); + +jest.mock( + '../../../../components/Map/MapViewer/utils/listeners/mouseClick/mouseLeftClick/handleFeaturesClick', + () => ({ + handleFeaturesClick: jest.fn(), + }), ); describe('triggerSearch', () => { + let mapInstance: Map; + const vectorLayer = new VectorLayer({}); + vectorLayer.set('type', VECTOR_MAP_LAYER_TYPE); + beforeEach(() => { + const dummyElement = document.createElement('div'); + mapInstance = new Map({ target: dummyElement }); + MapManager.setMapInstance(mapInstance); jest.clearAllMocks(); }); + describe('search by query', () => { it('should throw error if query param is wrong type', async () => { jest.spyOn(store, 'getState').mockImplementation(() => MOCK_STATE as RootState); @@ -142,7 +184,8 @@ describe('triggerSearch', () => { getState.mockRestore(); }); }); - describe('search by coordinations', () => { + + describe('search by coordinates', () => { it('should throw error if coordinates param is wrong type', async () => { jest.spyOn(store, 'getState').mockImplementation(() => MOCK_STATE as RootState); const invalidParams = { @@ -155,6 +198,7 @@ describe('triggerSearch', () => { 'Invalid coordinates type or values', ); }); + it('should throw error if model id param is wrong type', async () => { jest.spyOn(store, 'getState').mockImplementation(() => MOCK_STATE as RootState); const invalidParams = { @@ -165,20 +209,20 @@ describe('triggerSearch', () => { await expect(triggerSearch(invalidParams)).rejects.toThrowError(ERROR_INVALID_MODEL_ID_TYPE); }); + it('should search result with proper data', async () => { + const mockBioEntities = [{ id: 1, name: 'BioEntity 1' }]; jest.spyOn(store, 'getState').mockImplementation(() => MOCK_STATE as RootState); - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, [ELEMENT_SEARCH_RESULT_MOCK_ALIAS]); + jest.spyOn(store, 'dispatch').mockImplementation( + jest.fn(() => ({ + unwrap: jest.fn().mockResolvedValue(mockBioEntities), + })), + ); + const feature = new Feature({ id: 1, type: FEATURE_TYPE.ALIAS, zIndex: 1 }); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { + callback(feature, vectorLayer, null as unknown as SimpleGeometry); + }); - mockedAxiosClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); const params = { coordinates: point, modelId, @@ -187,35 +231,15 @@ describe('triggerSearch', () => { await expect(triggerSearch(params)).resolves.toBe(undefined); await waitFor(() => { - expect(handleSearchResultAction).toHaveBeenCalledWith({ - searchResults: [ELEMENT_SEARCH_RESULT_MOCK_ALIAS], - dispatch: store.dispatch, - hasFitBounds: undefined, - isResultDrawerOpen: false, - maxZoom: 9, - point: { - x: 545.8013, - y: 500.9926, - }, - searchDistance: '10', - zoom: 5, - }); + expect(leftClickHandleAliasSpy).toHaveBeenCalledWith(store.dispatch, undefined); }); }); + it('should not search result if there is no bio entity with specific coordinates', async () => { jest.spyOn(store, 'getState').mockImplementation(() => MOCK_STATE as RootState); - mockedAxiosOldClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, modelId)) - .reply(HttpStatusCode.Ok, []); - - mockedAxiosClient - .onGet( - apiPath.getBioEntityContentsStringWithQuery({ - searchQuery: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id.toString(), - isPerfectMatch: true, - }), - ) - .reply(HttpStatusCode.Ok, bioEntityResponseFixture); + jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { + callback(new Feature({ zIndex: 1 }), vectorLayer, null as unknown as SimpleGeometry); + }); const params = { coordinates: point, modelId, @@ -223,7 +247,7 @@ describe('triggerSearch', () => { await expect(triggerSearch(params)).resolves.toBe(undefined); - expect(handleSearchResultAction).not.toHaveBeenCalled(); + expect(leftClickHandleAliasSpy).not.toHaveBeenCalled(); }); }); }); diff --git a/src/services/pluginsManager/map/triggerSearch/triggerSearch.ts b/src/services/pluginsManager/map/triggerSearch/triggerSearch.ts index 363a0155..01b1cdad 100644 --- a/src/services/pluginsManager/map/triggerSearch/triggerSearch.ts +++ b/src/services/pluginsManager/map/triggerSearch/triggerSearch.ts @@ -1,3 +1,4 @@ +import { MapManager } from '@/services/pluginsManager/map/mapManager'; import { SearchParams } from './triggerSearch.types'; import { searchByQuery } from './searchByQuery'; import { searchByCoordinates } from './searchByCoordinates'; @@ -8,6 +9,10 @@ import { } from '../../errorMessages'; export async function triggerSearch(params: SearchParams): Promise<void> { + const mapInstance = MapManager.getMapInstance(); + if (!mapInstance) { + return; + } if ('query' in params) { if (typeof params.query !== 'string') { throw new Error(ERROR_INVALID_QUERY_TYPE); @@ -19,15 +24,12 @@ export async function triggerSearch(params: SearchParams): Promise<void> { const areCoordinatesMissingKeys = !('x' in params.coordinates) || !('y' in params.coordinates); const areCoordinatesValuesInvalid = typeof params.coordinates.x !== 'number' || typeof params.coordinates.y !== 'number'; - if (areCoordinatesInvalidType || areCoordinatesMissingKeys || areCoordinatesValuesInvalid) { throw new Error(ERROR_INVALID_COORDINATES); } - if (typeof params.modelId !== 'number') { throw new Error(ERROR_INVALID_MODEL_ID_TYPE); } - - searchByCoordinates(params.coordinates, params.modelId, false, params.fitBounds, params.zoom); + await searchByCoordinates(mapInstance, params.coordinates, params.modelId, params.fitBounds); } } diff --git a/src/services/pluginsManager/map/triggerSearch/triggerSearch.types.ts b/src/services/pluginsManager/map/triggerSearch/triggerSearch.types.ts index fa6cd67a..c4302364 100644 --- a/src/services/pluginsManager/map/triggerSearch/triggerSearch.types.ts +++ b/src/services/pluginsManager/map/triggerSearch/triggerSearch.types.ts @@ -13,7 +13,6 @@ export type SearchByCoordinatesParams = { coordinates: Coordinates; modelId: number; fitBounds?: boolean; - zoom?: number; }; export type SearchParams = SearchByCoordinatesParams | SearchByQueryParams; diff --git a/src/utils/search/getElementsByCoordinates.test.ts b/src/utils/search/getElementsByCoordinates.test.ts deleted file mode 100644 index d24ece7c..00000000 --- a/src/utils/search/getElementsByCoordinates.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { elementSearchResultFixture } from '@/models/fixtures/elementSearchResultFixture'; -import { apiPath } from '@/redux/apiPath'; -import { HttpStatusCode } from 'axios'; -import { mockNetworkResponse } from '../mockNetworkResponse'; -import { getElementsByPoint } from './getElementsByCoordinates'; - -const mockedAxiosClient = mockNetworkResponse(); - -describe('getElementsByPoint - utils', () => { - const point = { - x: 0, - y: 0, - }; - const currentModelId = 1000; - - it('should return data when data response from API is valid', async () => { - mockedAxiosClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, currentModelId)) - .reply(HttpStatusCode.Ok, elementSearchResultFixture); - - const response = await getElementsByPoint({ - point, - currentModelId, - shouldConsiderZoomLevel: false, - }); - expect(response).toEqual(elementSearchResultFixture); - }); - - it('should return undefined when data response from API is not valid ', async () => { - mockedAxiosClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, currentModelId)) - .reply(HttpStatusCode.Ok, { randomProperty: 'randomValue' }); - - const response = await getElementsByPoint({ - point, - currentModelId, - shouldConsiderZoomLevel: false, - }); - expect(response).toEqual(undefined); - }); - - it('should return empty array when data response from API is empty', async () => { - mockedAxiosClient - .onGet(apiPath.getSingleBioEntityContentsStringWithCoordinates(point, currentModelId)) - .reply(HttpStatusCode.Ok, []); - - const response = await getElementsByPoint({ - point, - currentModelId, - shouldConsiderZoomLevel: false, - }); - expect(response).toEqual([]); - }); -}); diff --git a/src/utils/search/getElementsByCoordinates.ts b/src/utils/search/getElementsByCoordinates.ts deleted file mode 100644 index fa54f1de..00000000 --- a/src/utils/search/getElementsByCoordinates.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { elementSearchResult } from '@/models/elementSearchResult'; -import { apiPath } from '@/redux/apiPath'; -import { axiosInstance, axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; -import { Point } from '@/types/map'; -import { BioEntity, ElementSearchResult } from '@/types/models'; -import { z } from 'zod'; -import { ONE, ZERO } from '@/constants/common'; -import { validateDataUsingZodSchema } from '../validateDataUsingZodSchema'; - -interface FirstVisibleParentArgs { - bioEntity: BioEntity; - considerZoomLevel: number; -} - -export const getFirstVisibleParent = async ({ - bioEntity, - considerZoomLevel, -}: FirstVisibleParentArgs): Promise<BioEntity> => { - let parentId = bioEntity.complex; - if (!parentId) { - parentId = bioEntity.compartment; - } - if (parentId) { - const parentResponse = await axiosInstanceNewAPI.get<BioEntity>( - apiPath.getElementById(parentId, bioEntity.model), - ); - const parent = parentResponse.data; - if ( - parent.visibilityLevel !== null && - parseInt(parent.visibilityLevel, 10) > Math.ceil(considerZoomLevel) - ) { - return getFirstVisibleParent({ - bioEntity: parent, - considerZoomLevel, - }); - } - return parent; - } - // eslint-disable-next-line no-console - console.log(`Cannot find visible parent for object. (zoomLevel=${considerZoomLevel})`, bioEntity); - return bioEntity; -}; - -interface Args { - point: Point; - currentModelId: number; - shouldConsiderZoomLevel: boolean; - considerZoomLevel?: number; -} - -const FRACTIONAL_ZOOM_AT_WHICH_IMAGE_LAYER_CHANGE = 0.415; - -export const getElementsByPoint = async ({ - point, - currentModelId, - shouldConsiderZoomLevel, - considerZoomLevel, -}: Args): Promise<ElementSearchResult[] | undefined> => { - let result: ElementSearchResult[]; - const response = await axiosInstance.get<ElementSearchResult[]>( - apiPath.getSingleBioEntityContentsStringWithCoordinates(point, currentModelId), - ); - const isDataValid = validateDataUsingZodSchema(response.data, z.array(elementSearchResult)); - - if (!isDataValid) { - return undefined; - } - result = response.data; - - if (shouldConsiderZoomLevel && result.length > ZERO && result[ZERO].type === 'ALIAS') { - const elementResponse = await axiosInstanceNewAPI.get<BioEntity>( - apiPath.getElementById(result[ZERO].id, result[ZERO].modelId), - ); - const element = elementResponse.data; - if ( - element.visibilityLevel != null && - parseInt(element.visibilityLevel, 10) - (ONE - FRACTIONAL_ZOOM_AT_WHICH_IMAGE_LAYER_CHANGE) > - (considerZoomLevel || Number.MAX_SAFE_INTEGER) - ) { - const visibleParent = await getFirstVisibleParent({ - bioEntity: element, - considerZoomLevel: considerZoomLevel || Number.MAX_SAFE_INTEGER, - }); - let id: number; - if (typeof visibleParent.id === 'string') { - id = parseInt(visibleParent.id, 10); - } else { - id = visibleParent.id; - } - result = [ - { - id, - type: 'ALIAS', - modelId: visibleParent.model, - }, - ]; - } - } - - return result; -}; -- GitLab