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

fix: make searchedBioEntitesSelectorOfCurrentMap less complex

parent d3160210
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...,!62feat: add reactions details on map + interactive layer improvements
Pipeline #82067 passed
/* eslint-disable no-magic-numbers */
import { allBioEntitesSelectorOfCurrentMap } from '@/redux/bioEntity/bioEntity.selectors';
import { searchedBioEntitesSelectorOfCurrentMap } from '@/redux/bioEntity/bioEntity.selectors';
import { usePointToProjection } from '@/utils/map/usePointToProjection';
import BaseLayer from 'ol/layer/Base';
import VectorLayer from 'ol/layer/Vector';
......@@ -10,7 +10,7 @@ import { getBioEntitiesFeatures } from './getBioEntitiesFeatures';
export const useOlMapPinsLayer = (): BaseLayer => {
const pointToProjection = usePointToProjection();
const contentBioEntites = useSelector(allBioEntitesSelectorOfCurrentMap);
const contentBioEntites = useSelector(searchedBioEntitesSelectorOfCurrentMap);
const bioEntityFeatures = useMemo(
() =>
......
......@@ -5,7 +5,6 @@ import { BioEntity, BioEntityContent } from '@/types/models';
import { createSelector } from '@reduxjs/toolkit';
import { currentSelectedSearchElement } from '../drawer/drawer.selectors';
import { currentModelIdSelector, modelsDataSelector } from '../models/models.selectors';
import { reduceToJoinedMultiSearchResult } from './bioEntity.utils';
export const bioEntitySelector = createSelector(rootSelector, state => state.bioEntity);
......@@ -23,36 +22,21 @@ export const loadingBioEntityStatusSelector = createSelector(
state => state?.loading,
);
export const bioEntitiesForSelectedSearchElementOrAllFallback = createSelector(
export const searchedBioEntitesSelectorOfCurrentMap = createSelector(
bioEntitySelector,
bioEntitiesForSelectedSearchElement,
currentSelectedSearchElement,
(
bioEntitiesState,
bioEntitiesOfSelected,
currentSearchElement,
): MultiSearchData<BioEntityContent[]> | undefined => {
if (!currentSearchElement) {
const bioEntitiesFiltered = bioEntitiesState.data.filter(d => d !== undefined);
return bioEntitiesFiltered.length === SIZE_OF_EMPTY_ARRAY
? undefined
: bioEntitiesFiltered.reduce(reduceToJoinedMultiSearchResult);
}
return bioEntitiesOfSelected;
},
);
export const allBioEntitesSelectorOfCurrentMap = createSelector(
bioEntitiesForSelectedSearchElementOrAllFallback,
currentModelIdSelector,
(bioEntities, currentModelId): BioEntity[] => {
(bioEntities, currentSearchElement, currentModelId): BioEntity[] => {
if (!bioEntities) {
return [];
}
return (bioEntities?.data || [])
.filter(({ searchQueryElement }) =>
currentSearchElement ? searchQueryElement === currentSearchElement : true,
)
.map(({ data }) => data || [])
.flat()
.filter(({ bioEntity }) => bioEntity.model === currentModelId)
.map(({ bioEntity }) => bioEntity);
},
......
import { MultiSearchData } from '@/types/fetchDataState';
import { BioEntityContent } from '@/types/models';
type MultiSearchBioEntityData = MultiSearchData<BioEntityContent[]>;
type ToJoinedMultiSearchResultFun = (
a: MultiSearchBioEntityData,
b: MultiSearchBioEntityData,
) => MultiSearchBioEntityData;
export const reduceToJoinedMultiSearchResult: ToJoinedMultiSearchResultFun = (a, b) => ({
...b,
searchQueryElement: `${a.searchQueryElement};${b.searchQueryElement}`,
data: (a.data || []).concat(b.data || []),
});
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