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

feat: partial fix dependency cycle

parent 17f09e86
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...,!156feat: publications modal elements links + reaction search (MIN-241, MIN-229)
Pipeline #87849 failed
import { getBioEntitiesIdsFromReaction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/getBioEntitiesIdsFromReaction';
import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common';
import { selectTab } from '@/redux/drawer/drawer.slice';
import { getReactionsByIds } from '@/redux/reactions/reactions.thunks';
import { BioEntityContent } from '@/types/models'; import { BioEntityContent } from '@/types/models';
import { PerfectMultiSearchParams } from '@/types/search'; import { PerfectMultiSearchParams } from '@/types/search';
import { ThunkConfig } from '@/types/store'; import { ThunkConfig } from '@/types/store';
...@@ -9,7 +5,8 @@ import { getErrorMessage } from '@/utils/getErrorMessage'; ...@@ -9,7 +5,8 @@ import { getErrorMessage } from '@/utils/getErrorMessage';
import { PayloadAction, createAsyncThunk } from '@reduxjs/toolkit'; import { PayloadAction, createAsyncThunk } from '@reduxjs/toolkit';
import { addNumbersToEntityNumberData } from '../../entityNumber/entityNumber.slice'; import { addNumbersToEntityNumberData } from '../../entityNumber/entityNumber.slice';
import { MULTI_BIO_ENTITY_FETCHING_ERROR_PREFIX } from '../bioEntity.constants'; import { MULTI_BIO_ENTITY_FETCHING_ERROR_PREFIX } from '../bioEntity.constants';
import { getBioEntity } from '../bioEntity.thunks'; import { getBioEntity } from './getBioEntity';
import { fetchReactionsAndGetBioEntitiesIds } from './utils/fetchReactionsAndGetBioEntitiesIds';
type GetMultiBioEntityProps = PerfectMultiSearchParams; type GetMultiBioEntityProps = PerfectMultiSearchParams;
type GetMultiBioEntityActions = PayloadAction<BioEntityContent[] | undefined | string>[]; // if error thrown, string containing error message is returned type GetMultiBioEntityActions = PayloadAction<BioEntityContent[] | undefined | string>[]; // if error thrown, string containing error message is returned
...@@ -40,37 +37,11 @@ export const getMultiBioEntity = createAsyncThunk< ...@@ -40,37 +37,11 @@ export const getMultiBioEntity = createAsyncThunk<
const bioEntityIds = bioEntityContents.map(b => b.bioEntity.elementId); const bioEntityIds = bioEntityContents.map(b => b.bioEntity.elementId);
dispatch(addNumbersToEntityNumberData(bioEntityIds)); dispatch(addNumbersToEntityNumberData(bioEntityIds));
const bioEntityReactionsIds = (bioEntityContents || []) const bioEntitiesIds = await fetchReactionsAndGetBioEntitiesIds({
.filter(c => c?.bioEntity?.idReaction) bioEntityContents,
.map(c => c?.bioEntity?.id) dispatch,
.filter((id): id is number => typeof id === 'number'); });
getMultiBioEntity({ searchQueries: bioEntitiesIds, isPerfectMatch: true });
if (bioEntityReactionsIds.length > ZERO) {
dispatch(
getReactionsByIds({
ids: bioEntityReactionsIds,
shouldConcat: true,
}),
).then(async result => {
if (typeof result.payload === 'string') return;
const reactions = result.payload?.data;
if (!reactions || reactions.length === SIZE_OF_EMPTY_ARRAY) return;
const bioEntitiesIds = reactions
.map(reaction => getBioEntitiesIdsFromReaction(reaction))
.flat();
// dispatch(openReactionDrawerById(reactions[FIRST_ARRAY_ELEMENT].id));
dispatch(selectTab(''));
await dispatch(
getMultiBioEntity({
searchQueries: bioEntitiesIds,
isPerfectMatch: true,
}),
);
});
}
return bioEntityContents; return bioEntityContents;
} catch (error) { } catch (error) {
......
import { getBioEntitiesIdsFromReaction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/getBioEntitiesIdsFromReaction';
import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common';
import { selectTab } from '@/redux/drawer/drawer.slice';
import { getReactionsByIds } from '@/redux/reactions/reactions.thunks';
import type { AppDispatch } from '@/redux/store';
import type { BioEntityContent } from '@/types/models';
interface Args {
bioEntityContents: BioEntityContent[];
dispatch: AppDispatch;
}
export const fetchReactionsAndGetBioEntitiesIds = async ({
dispatch,
bioEntityContents,
}: Args): Promise<string[]> => {
const bioEntityReactionsIds = (bioEntityContents || [])
.filter(c => c?.bioEntity?.idReaction)
.map(c => c?.bioEntity?.id)
.filter((id): id is number => typeof id === 'number');
if (bioEntityReactionsIds.length === ZERO) {
return [];
}
const result = await dispatch(
getReactionsByIds({
ids: bioEntityReactionsIds,
shouldConcat: true,
}),
);
if (typeof result.payload === 'string') {
return [];
}
const reactions = result.payload?.data;
if (!reactions || reactions.length === SIZE_OF_EMPTY_ARRAY) {
return [];
}
const bioEntitiesIds = reactions.map(reaction => getBioEntitiesIdsFromReaction(reaction)).flat();
// dispatch(openReactionDrawerById(reactions[FIRST_ARRAY_ELEMENT].id));
dispatch(selectTab(''));
return bioEntitiesIds;
};
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