Skip to content
Snippets Groups Projects
Commit 49325847 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

open reaction and bioEntity drawers when clicking on comment

parent bd07fd5a
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...,!201Resolve "[MIN-114] Browse comments on the map"
...@@ -22,12 +22,12 @@ describe('handleFeaturesClick - util', () => { ...@@ -22,12 +22,12 @@ describe('handleFeaturesClick - util', () => {
it('should dispatch event onPinIconClick', () => { it('should dispatch event onPinIconClick', () => {
const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent'); const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent');
handleFeaturesClick(features, dispatch); handleFeaturesClick(features, dispatch, []);
expect(dispatchEventSpy).toHaveBeenCalledWith('onPinIconClick', { id: featureId }); expect(dispatchEventSpy).toHaveBeenCalledWith('onPinIconClick', { id: featureId });
}); });
it('should return shouldBlockCoordSearch=true', () => { it('should return shouldBlockCoordSearch=true', () => {
expect(handleFeaturesClick(features, dispatch)).toStrictEqual({ expect(handleFeaturesClick(features, dispatch, [])).toStrictEqual({
shouldBlockCoordSearch: true, shouldBlockCoordSearch: true,
}); });
}); });
...@@ -46,21 +46,21 @@ describe('handleFeaturesClick - util', () => { ...@@ -46,21 +46,21 @@ describe('handleFeaturesClick - util', () => {
it('should dispatch event onPinIconClick', () => { it('should dispatch event onPinIconClick', () => {
const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent'); const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent');
handleFeaturesClick(features, dispatch); handleFeaturesClick(features, dispatch, []);
expect(dispatchEventSpy).toHaveBeenCalledWith('onPinIconClick', { id: featureId }); expect(dispatchEventSpy).toHaveBeenCalledWith('onPinIconClick', { id: featureId });
}); });
it('should dispatch actions regarding opening entity drawer', () => { it('should dispatch actions regarding opening entity drawer', () => {
const { store: localStore } = getReduxStoreWithActionsListener(); const { store: localStore } = getReduxStoreWithActionsListener();
const { dispatch: localDispatch } = localStore; const { dispatch: localDispatch } = localStore;
handleFeaturesClick(features, localDispatch); handleFeaturesClick(features, localDispatch, []);
expect(store.getActions()).toStrictEqual([ expect(store.getActions()).toStrictEqual([
{ payload: 1234, type: 'drawer/openBioEntityDrawerById' }, { payload: 1234, type: 'drawer/openBioEntityDrawerById' },
]); ]);
}); });
it('should return shouldBlockCoordSearch=true', () => { it('should return shouldBlockCoordSearch=true', () => {
expect(handleFeaturesClick(features, dispatch)).toStrictEqual({ expect(handleFeaturesClick(features, dispatch, [])).toStrictEqual({
shouldBlockCoordSearch: true, shouldBlockCoordSearch: true,
}); });
}); });
...@@ -79,12 +79,12 @@ describe('handleFeaturesClick - util', () => { ...@@ -79,12 +79,12 @@ describe('handleFeaturesClick - util', () => {
it('should dispatch event onSurfaceClick', () => { it('should dispatch event onSurfaceClick', () => {
const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent'); const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent');
handleFeaturesClick(features, dispatch); handleFeaturesClick(features, dispatch, []);
expect(dispatchEventSpy).toHaveBeenCalledWith('onSurfaceClick', { id: featureId }); expect(dispatchEventSpy).toHaveBeenCalledWith('onSurfaceClick', { id: featureId });
}); });
it('should return shouldBlockCoordSearch=false', () => { it('should return shouldBlockCoordSearch=false', () => {
expect(handleFeaturesClick(features, dispatch)).toStrictEqual({ expect(handleFeaturesClick(features, dispatch, [])).toStrictEqual({
shouldBlockCoordSearch: false, shouldBlockCoordSearch: false,
}); });
}); });
...@@ -103,12 +103,12 @@ describe('handleFeaturesClick - util', () => { ...@@ -103,12 +103,12 @@ describe('handleFeaturesClick - util', () => {
it('should dispatch event onSurfaceClick', () => { it('should dispatch event onSurfaceClick', () => {
const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent'); const dispatchEventSpy = jest.spyOn(PluginsEventBus, 'dispatchEvent');
handleFeaturesClick(features, dispatch); handleFeaturesClick(features, dispatch, []);
expect(dispatchEventSpy).toHaveBeenCalledWith('onSurfaceClick', { id: featureId }); expect(dispatchEventSpy).toHaveBeenCalledWith('onSurfaceClick', { id: featureId });
}); });
it('should return shouldBlockCoordSearch=false', () => { it('should return shouldBlockCoordSearch=false', () => {
expect(handleFeaturesClick(features, dispatch)).toStrictEqual({ expect(handleFeaturesClick(features, dispatch, [])).toStrictEqual({
shouldBlockCoordSearch: false, shouldBlockCoordSearch: false,
}); });
}); });
......
import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common';
import { FEATURE_TYPE, PIN_ICON_ANY, SURFACE_ANY } from '@/constants/features'; import { FEATURE_TYPE, PIN_ICON_ANY, SURFACE_ANY } from '@/constants/features';
import { openBioEntityDrawerById } from '@/redux/drawer/drawer.slice'; import { openBioEntityDrawerById, openReactionDrawerById } from '@/redux/drawer/drawer.slice';
import { AppDispatch } from '@/redux/store'; import { AppDispatch } from '@/redux/store';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { FeatureLike } from 'ol/Feature'; import { FeatureLike } from 'ol/Feature';
import { Comment } from '@/types/models';
interface HandleFeaturesClickResult { interface HandleFeaturesClickResult {
shouldBlockCoordSearch: boolean; shouldBlockCoordSearch: boolean;
...@@ -12,6 +13,7 @@ interface HandleFeaturesClickResult { ...@@ -12,6 +13,7 @@ interface HandleFeaturesClickResult {
export const handleFeaturesClick = ( export const handleFeaturesClick = (
features: FeatureLike[], features: FeatureLike[],
dispatch: AppDispatch, dispatch: AppDispatch,
comments: Comment[],
): HandleFeaturesClickResult => { ): HandleFeaturesClickResult => {
const pinFeatures = features.filter(feature => PIN_ICON_ANY.includes(feature.get('type'))); const pinFeatures = features.filter(feature => PIN_ICON_ANY.includes(feature.get('type')));
const surfaceFeatures = features.filter(feature => SURFACE_ANY.includes(feature.get('type'))); const surfaceFeatures = features.filter(feature => SURFACE_ANY.includes(feature.get('type')));
...@@ -24,7 +26,21 @@ export const handleFeaturesClick = ( ...@@ -24,7 +26,21 @@ export const handleFeaturesClick = (
if (pin.get('type') === FEATURE_TYPE.PIN_ICON_BIOENTITY) { if (pin.get('type') === FEATURE_TYPE.PIN_ICON_BIOENTITY) {
dispatch(openBioEntityDrawerById(pinId)); dispatch(openBioEntityDrawerById(pinId));
} else if (pin.get('type') === FEATURE_TYPE.PIN_ICON_COMMENT) { } else if (pin.get('type') === FEATURE_TYPE.PIN_ICON_COMMENT) {
alert(`Show comment: ${pinId}`); const filteredComments = comments.filter(comment => comment.id === pinId);
if (filteredComments.length > ZERO) {
const comment = filteredComments[ZERO];
if (comment.type === 'ALIAS') {
dispatch(openBioEntityDrawerById(Number(comment.elementId)));
} else if (comment.type === 'REACTION') {
dispatch(openReactionDrawerById(Number(comment.elementId)));
} else if (comment.type === 'POINT') {
throw new Error(`Opening point comment is not implemented yet`);
} else {
throw new Error(`Unknown comment type${comment.type}`);
}
} else {
throw new Error(`Cannot find comment with id ${pinId}`);
}
} }
}); });
......
...@@ -67,6 +67,7 @@ describe('onMapSingleClick - util', () => { ...@@ -67,6 +67,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
const coordinate = [90, 90]; const coordinate = [90, 90];
const event = getEvent(coordinate); const event = getEvent(coordinate);
...@@ -100,6 +101,7 @@ describe('onMapSingleClick - util', () => { ...@@ -100,6 +101,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
const coordinate = [90, 90]; const coordinate = [90, 90];
const point = { x: 180.0008084837557, y: 179.99919151624428 }; const point = { x: 180.0008084837557, y: 179.99919151624428 };
...@@ -140,6 +142,7 @@ describe('onMapSingleClick - util', () => { ...@@ -140,6 +142,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
const coordinate = [180, 180]; const coordinate = [180, 180];
const point = { x: 360.0032339350228, y: 359.9967660649771 }; const point = { x: 360.0032339350228, y: 359.9967660649771 };
...@@ -198,6 +201,7 @@ describe('onMapSingleClick - util', () => { ...@@ -198,6 +201,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
await handler(event, mapInstanceMock); await handler(event, mapInstanceMock);
await waitFor(() => expect(handleSearchResultActionSpy).not.toBeCalled()); await waitFor(() => expect(handleSearchResultActionSpy).not.toBeCalled());
...@@ -237,6 +241,7 @@ describe('onMapSingleClick - util', () => { ...@@ -237,6 +241,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
await handler(event, mapInstanceMock); await handler(event, mapInstanceMock);
await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled()); await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled());
...@@ -278,6 +283,7 @@ describe('onMapSingleClick - util', () => { ...@@ -278,6 +283,7 @@ describe('onMapSingleClick - util', () => {
MAX_ZOOM_MOCK_MOCK, MAX_ZOOM_MOCK_MOCK,
ZOOM_MOCK, ZOOM_MOCK,
IS_RESULT_DRAWER_OPEN_MOCK, IS_RESULT_DRAWER_OPEN_MOCK,
[],
); );
await handler(event, mapInstanceMock); await handler(event, mapInstanceMock);
await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled()); await waitFor(() => expect(handleSearchResultActionSpy).toBeCalled());
......
...@@ -3,6 +3,7 @@ import { MapSize } from '@/redux/map/map.types'; ...@@ -3,6 +3,7 @@ import { MapSize } from '@/redux/map/map.types';
import { AppDispatch } from '@/redux/store'; import { AppDispatch } from '@/redux/store';
import { Map, MapBrowserEvent } from 'ol'; import { Map, MapBrowserEvent } from 'ol';
import { FeatureLike } from 'ol/Feature'; import { FeatureLike } from 'ol/Feature';
import { Comment } from '@/types/models';
import { getSearchResults } from './getSearchResults'; import { getSearchResults } from './getSearchResults';
import { handleDataReset } from './handleDataReset'; import { handleDataReset } from './handleDataReset';
import { handleFeaturesClick } from './handleFeaturesClick'; import { handleFeaturesClick } from './handleFeaturesClick';
...@@ -10,11 +11,12 @@ import { handleSearchResultAction } from './handleSearchResultAction'; ...@@ -10,11 +11,12 @@ import { handleSearchResultAction } from './handleSearchResultAction';
/* prettier-ignore */ /* prettier-ignore */
export const onMapSingleClick = export const onMapSingleClick =
(mapSize: MapSize, modelId: number, dispatch: AppDispatch, searchDistance: string | undefined, maxZoom: number, zoom: number, isResultDrawerOpen: boolean) => (mapSize: MapSize, modelId: number, dispatch: AppDispatch, searchDistance: string | undefined, maxZoom: number, zoom: number, isResultDrawerOpen: boolean,
comments: Comment[]) =>
async ({ coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, mapInstance: Map): Promise<void> => { async ({ coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, mapInstance: Map): Promise<void> => {
const featuresAtPixel: FeatureLike[] = []; const featuresAtPixel: FeatureLike[] = [];
mapInstance.forEachFeatureAtPixel(pixel, (feature) => featuresAtPixel.push(feature)); mapInstance.forEachFeatureAtPixel(pixel, (feature) => featuresAtPixel.push(feature));
const { shouldBlockCoordSearch } = handleFeaturesClick(featuresAtPixel, dispatch); const { shouldBlockCoordSearch } = handleFeaturesClick(featuresAtPixel, dispatch, comments);
if (shouldBlockCoordSearch) { if (shouldBlockCoordSearch) {
return; return;
......
...@@ -16,6 +16,7 @@ import { Pixel } from 'ol/pixel'; ...@@ -16,6 +16,7 @@ import { Pixel } from 'ol/pixel';
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useDebouncedCallback } from 'use-debounce'; import { useDebouncedCallback } from 'use-debounce';
import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors';
import { onMapRightClick } from './mapRightClick/onMapRightClick'; import { onMapRightClick } from './mapRightClick/onMapRightClick';
import { onMapSingleClick } from './mapSingleClick/onMapSingleClick'; import { onMapSingleClick } from './mapSingleClick/onMapSingleClick';
import { onMapPositionChange } from './onMapPositionChange'; import { onMapPositionChange } from './onMapPositionChange';
...@@ -38,6 +39,8 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) ...@@ -38,6 +39,8 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput)
const pixel = useRef<Pixel>([]); const pixel = useRef<Pixel>([]);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const comments = useSelector(allCommentsSelectorOfCurrentMap);
useHandlePinIconClick(); useHandlePinIconClick();
const handleRightClick = useDebouncedCallback( const handleRightClick = useDebouncedCallback(
...@@ -63,6 +66,7 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) ...@@ -63,6 +66,7 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput)
maxZoom, maxZoom,
lastZoom || DEFAULT_ZOOM, lastZoom || DEFAULT_ZOOM,
isResultDrawerOpen, isResultDrawerOpen,
comments,
), ),
OPTIONS.clickPersistTime, OPTIONS.clickPersistTime,
{ leading: false }, { leading: false },
......
import { FetchDataState } from '@/types/fetchDataState'; import { FetchDataState } from '@/types/fetchDataState';
import { Comment } from '@/types/models'; import { Comment } from '@/types/models';
import { PayloadAction } from '@reduxjs/toolkit';
export interface CommentsState extends FetchDataState<Comment[], []> { export interface CommentsState extends FetchDataState<Comment[], []> {
isOpen: boolean; isOpen: boolean;
} }
export type OpenCommentByIdPayload = number | string;
export type OpenCommentByIdAction = PayloadAction<OpenCommentByIdPayload>;
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