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

remove getBioEntitiesIdsFromReaction in favor of getModelElementsIdsFromReaction

parent 2818e12f
No related branches found
No related tags found
1 merge request!311Resolve "remove usage of old reaction endpoint"
Pipeline #98248 passed
import { NewReaction } from '@/types/models';
export const getBioEntitiesIdsFromReaction = (reaction: NewReaction): string[] => {
const { products, reactants, modifiers } = reaction;
const productsIds = products.map(p => p.element);
const reactantsIds = reactants.map(r => r.element);
const modifiersIds = modifiers.map(m => m.element);
return [...productsIds, ...reactantsIds, ...modifiersIds].map(identifier => String(identifier));
};
......@@ -11,8 +11,8 @@ import { apiPath } from '@/redux/apiPath';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { getMultiBioEntityByIds } from '@/redux/bioEntity/thunks/getMultiBioEntity';
import { newReactionSchema } from '@/models/newReactionSchema';
import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction';
import { handleReactionSearchClickFailure } from './handleReactionSearchClickFailure';
import { getBioEntitiesIdsFromReaction } from './getBioEntitiesIdsFromReaction';
import { findClosestReactionPoint } from './findClosestReactionPoint';
type SearchConfig = {
......@@ -35,7 +35,7 @@ export const handleReactionResults =
}
const reaction = payload.data[FIRST_ARRAY_ELEMENT];
const bioEntitiesIds = getBioEntitiesIdsFromReaction(reaction);
const bioEntitiesIds = getModelElementsIdsFromReaction(reaction);
if (searchConfig && searchConfig.searchDistance) {
const { maxZoom, point, searchDistance, zoom, isResultDrawerOpen } = searchConfig;
......@@ -64,7 +64,7 @@ export const handleReactionResults =
getMultiBioEntityByIds({
elementsToFetch: bioEntitiesIds.map((bioEntityId) => {
return {
elementId: parseInt(bioEntityId, 10),
elementId: bioEntityId,
modelId,
type: 'ALIAS'
};
......
......@@ -44,8 +44,11 @@ export const getMultiBioEntity = createAsyncThunk<
dispatch: dispatch as AppDispatch,
getState: getState as typeof store.getState,
});
const bioEntitiesStringIds = bioEntitiesIds.map(id => String(id));
if (bioEntitiesIds.length > ZERO) {
await dispatch(getMultiBioEntity({ searchQueries: bioEntitiesIds, isPerfectMatch: true }));
await dispatch(
getMultiBioEntity({ searchQueries: bioEntitiesStringIds, isPerfectMatch: true }),
);
}
return bioEntityContents;
......@@ -90,7 +93,8 @@ export const getMultiBioEntityByIds = createAsyncThunk<
getState: getState as typeof store.getState,
});
if (bioEntitiesIds.length > ZERO) {
await dispatch(getMultiBioEntity({ searchQueries: bioEntitiesIds, isPerfectMatch: true }));
const searchQueries = bioEntitiesIds.map(id => String(id));
await dispatch(getMultiBioEntity({ searchQueries, isPerfectMatch: true }));
}
return bioEntities;
......
import { getBioEntitiesIdsFromReaction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/getBioEntitiesIdsFromReaction';
import { FIRST_ARRAY_ELEMENT, SIZE_OF_EMPTY_ARRAY } from '@/constants/common';
import { openReactionDrawerById, selectTab } from '@/redux/drawer/drawer.slice';
import { openMapAndOrSetActiveIfSelected } from '@/redux/map/map.slice';
......@@ -6,6 +5,7 @@ import { modelsNameMapSelector } from '@/redux/models/models.selectors';
import { getReactionsByIds } from '@/redux/reactions/reactions.thunks';
import type { AppDispatch, store } from '@/redux/store';
import type { BioEntityContent, NewReaction } from '@/types/models';
import getModelElementsIdsFromReaction from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/getModelElementsIdsFromReaction';
interface Args {
bioEntityContents: BioEntityContent[];
......@@ -73,7 +73,7 @@ const handleReactionShowInfoAndOpenMap = async (
);
};
export const fetchReactionsAndGetBioEntitiesIds = async (args: Args): Promise<string[]> => {
export const fetchReactionsAndGetBioEntitiesIds = async (args: Args): Promise<number[]> => {
const { dispatch, bioEntityContents } = args;
const bioEntityReactionsIds = getReactionsIdsFromBioEntities(bioEntityContents || []);
......@@ -86,7 +86,9 @@ export const fetchReactionsAndGetBioEntitiesIds = async (args: Args): Promise<st
return [];
}
const bioEntitiesIds = reactions.map(reaction => getBioEntitiesIdsFromReaction(reaction)).flat();
const bioEntitiesIds = reactions
.map(reaction => getModelElementsIdsFromReaction(reaction))
.flat();
const firstReaction = reactions[FIRST_ARRAY_ELEMENT];
if (firstReaction) {
handleReactionShowInfoAndOpenMap(args, firstReaction);
......
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