Skip to content
Snippets Groups Projects
Commit 4cdd9d2d authored by Adrian Orłów's avatar Adrian Orłów
Browse files

fix: rfc changes

parent f48f5587
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!146feat: plugin methods center/zoom/overview-image
Pipeline #87419 passed
...@@ -170,7 +170,7 @@ describe('MapNavigation - component', () => { ...@@ -170,7 +170,7 @@ describe('MapNavigation - component', () => {
histamineMapCloseButton.click(); histamineMapCloseButton.click();
}); });
expect(dispatchEventMock).toHaveBeenCalledTimes(3); expect(dispatchEventMock).toHaveBeenCalledTimes(2);
expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', 5052); expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapClose', 5052);
expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', 52); expect(dispatchEventMock).toHaveBeenCalledWith('onSubmapOpen', 52);
}); });
......
...@@ -12,11 +12,11 @@ import { ...@@ -12,11 +12,11 @@ import {
} from '@/redux/map/map.fixtures'; } from '@/redux/map/map.fixtures';
import { MODAL_INITIAL_STATE_MOCK } from '@/redux/modal/modal.mock'; import { MODAL_INITIAL_STATE_MOCK } from '@/redux/modal/modal.mock';
import { PROJECT_OVERVIEW_IMAGE_MOCK } from '@/redux/project/project.mock'; import { PROJECT_OVERVIEW_IMAGE_MOCK } from '@/redux/project/project.mock';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { OverviewImageLink } from '@/types/models'; import { OverviewImageLink } from '@/types/models';
import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener';
import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore'; import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore';
import { renderHook } from '@testing-library/react'; import { renderHook } from '@testing-library/react';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { import {
FIRST_ARRAY_ELEMENT, FIRST_ARRAY_ELEMENT,
NOOP, NOOP,
...@@ -313,7 +313,6 @@ describe('useOverviewImageLinkActions - hook', () => { ...@@ -313,7 +313,6 @@ describe('useOverviewImageLinkActions - hook', () => {
jest.clearAllMocks(); jest.clearAllMocks();
}); });
it('should dispatch event if coordinates changed', () => { it('should dispatch event if coordinates changed', () => {
const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent');
const { Wrapper } = getReduxStoreWithActionsListener({ const { Wrapper } = getReduxStoreWithActionsListener({
project: { project: {
data: { data: {
...@@ -361,14 +360,6 @@ describe('useOverviewImageLinkActions - hook', () => { ...@@ -361,14 +360,6 @@ describe('useOverviewImageLinkActions - hook', () => {
}); });
handleLinkClick(OVERVIEW_LINK_MODEL_MOCK); handleLinkClick(OVERVIEW_LINK_MODEL_MOCK);
expect(dispatchEventMock).toHaveBeenCalledTimes(2);
expect(dispatchEventMock).toHaveBeenCalledWith('onZoomChanged', { modelId: 5053, zoom: 7 });
expect(dispatchEventMock).toHaveBeenCalledWith('onCenterChanged', {
modelId: 5053,
x: 15570,
y: 3016,
});
}); });
it('should not dispatch event if coordinates do not changed', () => { it('should not dispatch event if coordinates do not changed', () => {
const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent'); const dispatchEventMock = jest.spyOn(PluginsEventBus, 'dispatchEvent');
......
import { NOOP } from '@/constants/common'; import { NOOP } from '@/constants/common';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { mapDataLastPositionSelector, mapOpenedMapsSelector } from '@/redux/map/map.selectors'; import { mapOpenedMapsSelector } from '@/redux/map/map.selectors';
import { openMapAndSetActive, setActiveMap, setMapPosition } from '@/redux/map/map.slice'; import { openMapAndSetActive, setActiveMap, setMapPosition } from '@/redux/map/map.slice';
import { closeModal, setOverviewImageId } from '@/redux/modal/modal.slice'; import { closeModal, setOverviewImageId } from '@/redux/modal/modal.slice';
import { currentModelIdSelector, modelsDataSelector } from '@/redux/models/models.selectors'; import { currentModelIdSelector, modelsDataSelector } from '@/redux/models/models.selectors';
import { projectOverviewImagesSelector } from '@/redux/project/project.selectors'; import { projectOverviewImagesSelector } from '@/redux/project/project.selectors';
import { MapModel, OverviewImageLink, OverviewImageLinkModel } from '@/types/models';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { MapModel, OverviewImageLink, OverviewImageLinkModel } from '@/types/models';
import { import {
OverviewImageLinkImageHandler, OverviewImageLinkImageHandler,
OverviewImageLinkModelHandler, OverviewImageLinkModelHandler,
...@@ -23,7 +23,6 @@ export const useOverviewImageLinkActions = (): UseOverviewImageLinkActionsResult ...@@ -23,7 +23,6 @@ export const useOverviewImageLinkActions = (): UseOverviewImageLinkActionsResult
const models = useAppSelector(modelsDataSelector); const models = useAppSelector(modelsDataSelector);
const overviewImages = useAppSelector(projectOverviewImagesSelector); const overviewImages = useAppSelector(projectOverviewImagesSelector);
const currentMapModelId = useAppSelector(currentModelIdSelector); const currentMapModelId = useAppSelector(currentModelIdSelector);
const mapLastPosition = useAppSelector(mapDataLastPositionSelector);
const checkIfImageIsAvailable = (imageId: number): boolean => const checkIfImageIsAvailable = (imageId: number): boolean =>
overviewImages.some(image => image.idObject === imageId); overviewImages.some(image => image.idObject === imageId);
...@@ -55,21 +54,6 @@ export const useOverviewImageLinkActions = (): UseOverviewImageLinkActionsResult ...@@ -55,21 +54,6 @@ export const useOverviewImageLinkActions = (): UseOverviewImageLinkActionsResult
const { x } = link.modelPoint; const { x } = link.modelPoint;
const { y } = link.modelPoint; const { y } = link.modelPoint;
if (mapLastPosition.z !== zoom) {
PluginsEventBus.dispatchEvent('onZoomChanged', {
modelId: currentMapModelId,
zoom,
});
}
if (mapLastPosition.x !== x || mapLastPosition.y !== y) {
PluginsEventBus.dispatchEvent('onCenterChanged', {
modelId: currentMapModelId,
x,
y,
});
}
dispatch( dispatch(
setMapPosition({ setMapPosition({
x, x,
......
import { DEFAULT_ZOOM } from '@/constants/map';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { setMapPosition, varyPositionZoom } from '@/redux/map/map.slice'; import { setMapPosition, varyPositionZoom } from '@/redux/map/map.slice';
import { currentModelIdSelector, modelByIdSelector } from '@/redux/models/models.selectors';
import { SetBoundsResult, useSetBounds } from '@/utils/map/useSetBounds'; import { SetBoundsResult, useSetBounds } from '@/utils/map/useSetBounds';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { currentModelIdSelector, modelByIdSelector } from '@/redux/models/models.selectors';
import { DEFAULT_ZOOM } from '@/constants/map';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { mapDataLastPositionSelector } from '@/redux/map/map.selectors';
import { useVisibleBioEntitiesPolygonCoordinates } from './useVisibleBioEntitiesPolygonCoordinates';
import { MAP_ZOOM_IN_DELTA, MAP_ZOOM_OUT_DELTA } from '../MappAdditionalActions.constants'; import { MAP_ZOOM_IN_DELTA, MAP_ZOOM_OUT_DELTA } from '../MappAdditionalActions.constants';
import { useVisibleBioEntitiesPolygonCoordinates } from './useVisibleBioEntitiesPolygonCoordinates';
interface UseAddtionalActionsResult { interface UseAddtionalActionsResult {
zoomIn(): void; zoomIn(): void;
...@@ -22,7 +20,6 @@ export const useAddtionalActions = (): UseAddtionalActionsResult => { ...@@ -22,7 +20,6 @@ export const useAddtionalActions = (): UseAddtionalActionsResult => {
const polygonCoordinates = useVisibleBioEntitiesPolygonCoordinates(); const polygonCoordinates = useVisibleBioEntitiesPolygonCoordinates();
const currentMapModelId = useAppSelector(currentModelIdSelector); const currentMapModelId = useAppSelector(currentModelIdSelector);
const currentModel = useAppSelector(state => modelByIdSelector(state, currentMapModelId)); const currentModel = useAppSelector(state => modelByIdSelector(state, currentMapModelId));
const currentModelLastPostiion = useAppSelector(mapDataLastPositionSelector);
const zoomInToBioEntities = (): SetBoundsResult | undefined => { const zoomInToBioEntities = (): SetBoundsResult | undefined => {
if (polygonCoordinates) { if (polygonCoordinates) {
...@@ -38,24 +35,6 @@ export const useAddtionalActions = (): UseAddtionalActionsResult => { ...@@ -38,24 +35,6 @@ export const useAddtionalActions = (): UseAddtionalActionsResult => {
}; };
dispatch(setMapPosition(defaultPosition)); dispatch(setMapPosition(defaultPosition));
if (currentModelLastPostiion.z !== defaultPosition.z) {
PluginsEventBus.dispatchEvent('onZoomChanged', {
modelId: currentMapModelId,
zoom: defaultPosition.z,
});
}
if (
currentModelLastPostiion.x !== defaultPosition.x ||
currentModelLastPostiion.y !== defaultPosition.y
) {
PluginsEventBus.dispatchEvent('onCenterChanged', {
modelId: currentMapModelId,
x: defaultPosition.x,
y: defaultPosition.y,
});
}
} }
return undefined; return undefined;
......
...@@ -33,15 +33,18 @@ export const setMapDataReducer = (state: MapState, action: SetMapDataAction): vo ...@@ -33,15 +33,18 @@ export const setMapDataReducer = (state: MapState, action: SetMapDataAction): vo
export const setMapPositionReducer = (state: MapState, action: SetMapPositionDataAction): void => { export const setMapPositionReducer = (state: MapState, action: SetMapPositionDataAction): void => {
const position = action.payload || {}; const position = action.payload || {};
const statePosition = state.data.position; const statePosition = state.data.position;
const lastZoom = statePosition.last.z; const lastPosition = statePosition.last;
const finalPosition = getPointMerged(position || {}, statePosition.last); const lastZoom = lastPosition.z;
const finalPosition = getPointMerged(position || {}, lastPosition);
const { modelId } = state.data; const { modelId } = state.data;
PluginsEventBus.dispatchEvent('onCenterChanged', { if (lastPosition?.x !== finalPosition.x || lastPosition?.y !== finalPosition.y) {
modelId, PluginsEventBus.dispatchEvent('onCenterChanged', {
x: finalPosition.x, modelId,
y: finalPosition.y, x: finalPosition.x,
}); y: finalPosition.y,
});
}
if (position?.z && lastZoom && lastZoom !== position?.z) { if (position?.z && lastZoom && lastZoom !== position?.z) {
PluginsEventBus.dispatchEvent('onZoomChanged', { PluginsEventBus.dispatchEvent('onZoomChanged', {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment