Skip to content
Snippets Groups Projects
Commit 90b79ac3 authored by Miłosz Grocholewski's avatar Miłosz Grocholewski
Browse files

Merge branch 'feat/MIN-107-avoid-multiple-load-overlays' into 'development'

feat(vector-map): avoid multiple loading overlays

Closes MIN-107

See merge request !320
parents 60837f99 dc687db1
No related branches found
No related tags found
1 merge request!320feat(vector-map): avoid multiple loading overlays
Pipeline #98640 passed
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 { import {
areOverlayBioEntitiesLoadedSelector,
isOverlayActiveSelector, isOverlayActiveSelector,
isOverlayLoadingSelector, isOverlayLoadingSelector,
} from '@/redux/overlayBioEntity/overlayBioEntity.selector'; } from '@/redux/overlayBioEntity/overlayBioEntity.selector';
import { removeOverlayBioEntityForGivenOverlay } from '@/redux/overlayBioEntity/overlayBioEntity.slice';
import { getOverlayBioEntityForAllModels } from '@/redux/overlayBioEntity/overlayBioEntity.thunk'; import { getOverlayBioEntityForAllModels } from '@/redux/overlayBioEntity/overlayBioEntity.thunk';
import { BASE_API_URL } from '@/constants'; import { BASE_API_URL } from '@/constants';
import { apiPath } from '@/redux/apiPath'; import { apiPath } from '@/redux/apiPath';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { overlaySelector, userOverlaySelector } from '@/redux/overlays/overlays.selectors'; import { overlaySelector, userOverlaySelector } from '@/redux/overlays/overlays.selectors';
import {
addOverlayToOverlaysId,
removeOverlayFromOverlaysId,
} from '@/redux/overlayBioEntity/overlayBioEntity.slice';
import { useEmptyBackground } from './useEmptyBackground'; import { useEmptyBackground } from './useEmptyBackground';
type UseOverlay = { type UseOverlay = {
...@@ -25,6 +29,9 @@ export const useOverlay = (overlayId: number): UseOverlay => { ...@@ -25,6 +29,9 @@ export const useOverlay = (overlayId: number): UseOverlay => {
const isOverlayLoading = useAppSelector(state => isOverlayLoadingSelector(state, overlayId)); const isOverlayLoading = useAppSelector(state => isOverlayLoadingSelector(state, overlayId));
const { setBackgroundtoEmptyIfAvailable } = useEmptyBackground(); const { setBackgroundtoEmptyIfAvailable } = useEmptyBackground();
const overlay = useAppSelector(state => overlaySelector(state, overlayId)); const overlay = useAppSelector(state => overlaySelector(state, overlayId));
const areOverlayBioEntitiesLoaded = useAppSelector(state =>
areOverlayBioEntitiesLoadedSelector(state, overlayId),
);
const userOverlay = useAppSelector(state => userOverlaySelector(state, overlayId)); const userOverlay = useAppSelector(state => userOverlaySelector(state, overlayId));
const dispatchPluginEvents = (): void => { const dispatchPluginEvents = (): void => {
...@@ -41,9 +48,13 @@ export const useOverlay = (overlayId: number): UseOverlay => { ...@@ -41,9 +48,13 @@ export const useOverlay = (overlayId: number): UseOverlay => {
const toggleOverlay = async (): Promise<void> => { const toggleOverlay = async (): Promise<void> => {
if (isOverlayActive) { if (isOverlayActive) {
dispatch(removeOverlayBioEntityForGivenOverlay({ overlayId })); dispatch(removeOverlayFromOverlaysId(overlayId));
} else { } else {
await dispatch(getOverlayBioEntityForAllModels({ overlayId })); if (areOverlayBioEntitiesLoaded) {
dispatch(addOverlayToOverlaysId(overlayId));
} else {
await dispatch(getOverlayBioEntityForAllModels({ overlayId }));
}
setBackgroundtoEmptyIfAvailable(); setBackgroundtoEmptyIfAvailable();
} }
......
...@@ -59,8 +59,7 @@ export const useOlMapReactionsLayer = ({ ...@@ -59,8 +59,7 @@ export const useOlMapReactionsLayer = ({
const currentMarkers = useAppSelector(markersSufraceOfCurrentMapDataSelector); const currentMarkers = useAppSelector(markersSufraceOfCurrentMapDataSelector);
const markersRender = parseSurfaceMarkersToBioEntityRender(currentMarkers); const markersRender = parseSurfaceMarkersToBioEntityRender(currentMarkers);
const bioEntities = useAppSelector(overlayBioEntitiesForCurrentModelSelector); const bioEntities = useAppSelector(overlayBioEntitiesForCurrentModelSelector);
const debouncedBioEntities = useDebouncedValue(bioEntities, 2000); const debouncedBioEntities = useDebouncedValue(bioEntities, 1000);
const { getOverlayBioEntityColorByAvailableProperties } = useGetOverlayColor(); const { getOverlayBioEntityColorByAvailableProperties } = useGetOverlayColor();
const pointToProjection = usePointToProjection(); const pointToProjection = usePointToProjection();
......
import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import { ActionReducerMapBuilder, PayloadAction } from '@reduxjs/toolkit';
import { getOverlayBioEntity, getOverlayBioEntityForAllModels } from './overlayBioEntity.thunk'; import { getOverlayBioEntity, getOverlayBioEntityForAllModels } from './overlayBioEntity.thunk';
import { import {
OverlaysBioEntityState, OverlaysBioEntityState,
...@@ -41,3 +41,21 @@ export const removeOverlayBioEntityForGivenOverlayReducer = ( ...@@ -41,3 +41,21 @@ export const removeOverlayBioEntityForGivenOverlayReducer = (
state.overlaysId = state.overlaysId.filter(id => id !== overlayId); state.overlaysId = state.overlaysId.filter(id => id !== overlayId);
delete state.data[overlayId]; delete state.data[overlayId];
}; };
export const removeOverlayFromOverlaysIdReducer = (
state: OverlaysBioEntityState,
action: PayloadAction<number>,
): void => {
const overlayId = action.payload;
state.overlaysId = state.overlaysId.filter(id => id !== overlayId);
};
export const addOverlayToOverlaysIdReducer = (
state: OverlaysBioEntityState,
action: PayloadAction<number>,
): void => {
const overlayId = action.payload;
if (!state.overlaysId.includes(overlayId)) {
state.overlaysId.push(overlayId);
}
};
...@@ -86,6 +86,11 @@ export const isOverlayActiveSelector = createSelector( ...@@ -86,6 +86,11 @@ export const isOverlayActiveSelector = createSelector(
(overlaysId, overlayId) => overlaysId.includes(overlayId), (overlaysId, overlayId) => overlaysId.includes(overlayId),
); );
export const areOverlayBioEntitiesLoadedSelector = createSelector(
[overlayBioEntityDataSelector, (_, overlayId: number): number => overlayId],
(bioEntities, overlayId) => Boolean(bioEntities[overlayId]),
);
export const isOverlayLoadingSelector = createSelector( export const isOverlayLoadingSelector = createSelector(
[overlayBioEntitySelector, mapModelIdSelector, (_, overlayId: number): number => overlayId], [overlayBioEntitySelector, mapModelIdSelector, (_, overlayId: number): number => overlayId],
({ overlaysId, data }, mapId, overlayId) => { ({ overlaysId, data }, mapId, overlayId) => {
......
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import { import {
addOverlayToOverlaysIdReducer,
getOverlayBioEntityForAllModelsReducer, getOverlayBioEntityForAllModelsReducer,
getOverlayBioEntityReducer, getOverlayBioEntityReducer,
removeOverlayBioEntityForGivenOverlayReducer, removeOverlayBioEntityForGivenOverlayReducer,
removeOverlayFromOverlaysIdReducer,
} from './overlayBioEntity.reducers'; } from './overlayBioEntity.reducers';
import { OverlaysBioEntityState } from './overlayBioEntity.types'; import { OverlaysBioEntityState } from './overlayBioEntity.types';
...@@ -16,6 +18,8 @@ export const overlayBioEntitySlice = createSlice({ ...@@ -16,6 +18,8 @@ export const overlayBioEntitySlice = createSlice({
initialState, initialState,
reducers: { reducers: {
removeOverlayBioEntityForGivenOverlay: removeOverlayBioEntityForGivenOverlayReducer, removeOverlayBioEntityForGivenOverlay: removeOverlayBioEntityForGivenOverlayReducer,
removeOverlayFromOverlaysId: removeOverlayFromOverlaysIdReducer,
addOverlayToOverlaysId: addOverlayToOverlaysIdReducer,
}, },
extraReducers: builder => { extraReducers: builder => {
getOverlayBioEntityReducer(builder); getOverlayBioEntityReducer(builder);
...@@ -23,5 +27,9 @@ export const overlayBioEntitySlice = createSlice({ ...@@ -23,5 +27,9 @@ export const overlayBioEntitySlice = createSlice({
}, },
}); });
export const { removeOverlayBioEntityForGivenOverlay } = overlayBioEntitySlice.actions; export const {
removeOverlayBioEntityForGivenOverlay,
removeOverlayFromOverlaysId,
addOverlayToOverlaysId,
} = overlayBioEntitySlice.actions;
export default overlayBioEntitySlice.reducer; export default overlayBioEntitySlice.reducer;
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