diff --git a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts index 858b57fb89c8d9ef42c65f70287ed453e718aa50..29056a8fe5467120d207ff2790af3828d3230661 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapRightClick/handleSearchResultForRightClickAction.ts @@ -20,5 +20,5 @@ export const handleSearchResultForRightClickAction = async ({ REACTION: handleReactionResults, }[type]; - await action(dispatch)(closestSearchResult); + await action(dispatch, closestSearchResult)(closestSearchResult); }; diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts index 44ac11c9c8e12c0b7a4d357f7851aae3292ee68d..1d8a0df8ca4d9a6fb8a2084eabceafe62604b4c8 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts @@ -24,7 +24,10 @@ describe('handleAliasResults - util', () => { .reply(HttpStatusCode.Ok, bioEntityResponseFixture); beforeAll(async () => { - handleAliasResults(dispatch)(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); + handleAliasResults( + dispatch, + ELEMENT_SEARCH_RESULT_MOCK_ALIAS, + )(ELEMENT_SEARCH_RESULT_MOCK_ALIAS); }); it('should run openBioEntityDrawerById as first action', async () => { diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts index cd7aefe90caeee8e5270d58052dd2442a7a14672..cd386b1cfd44107bb9ec8499ddfec3d033713954 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts @@ -3,10 +3,11 @@ import { openBioEntityDrawerById } from '@/redux/drawer/drawer.slice'; import { AppDispatch } from '@/redux/store'; import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; import { ElementSearchResult } from '@/types/models'; +import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; /* prettier-ignore */ export const handleAliasResults = - (dispatch: AppDispatch, hasFitBounds?: boolean, fitBoundsZoom?: number) => + (dispatch: AppDispatch, closestSearchResult: ElementSearchResult, hasFitBounds?: boolean, fitBoundsZoom?: number) => async ({ id }: ElementSearchResult): Promise<void> => { dispatch(openBioEntityDrawerById(id)); @@ -16,7 +17,14 @@ export const handleAliasResults = isPerfectMatch: true }), ) - .unwrap().then(() => { + .unwrap().then((bioEntityContents) => { + + PluginsEventBus.dispatchEvent('onSearch', { + type: 'bioEntity', + searchValues: [closestSearchResult], + results: [bioEntityContents], + }); + if (hasFitBounds) { searchFitBounds(fitBoundsZoom); } diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts index b514095b3654a64d101e79df172d841b60abb01d..020f0c6480a1298b8799319fab20ca3e3f9c77b1 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts @@ -33,7 +33,10 @@ describe('handleReactionResults - util', () => { .reply(HttpStatusCode.Ok, reactionsFixture); beforeAll(async () => { - handleReactionResults(dispatch)(ELEMENT_SEARCH_RESULT_MOCK_REACTION); + handleReactionResults( + dispatch, + ELEMENT_SEARCH_RESULT_MOCK_REACTION, + )(ELEMENT_SEARCH_RESULT_MOCK_REACTION); }); it('should run getReactionsByIds as first action', () => { diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts index d82828178e0319f6b6176e2ae6764820f55ff7f4..24332182531f770a76a2372c29e6586a89cf2e33 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.ts @@ -6,10 +6,11 @@ import { AppDispatch } from '@/redux/store'; import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; import { ElementSearchResult, Reaction } from '@/types/models'; import { PayloadAction } from '@reduxjs/toolkit'; +import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; /* prettier-ignore */ export const handleReactionResults = - (dispatch: AppDispatch, hasFitBounds?: boolean, fitBoundsZoom?: number) => + (dispatch: AppDispatch, closestSearchResult: ElementSearchResult, hasFitBounds?: boolean, fitBoundsZoom?: number) => async ({ id }: ElementSearchResult): Promise<void> => { const data = await dispatch(getReactionsByIds([id])) as PayloadAction<Reaction[] | undefined>; const payload = data?.payload; @@ -30,7 +31,13 @@ export const handleReactionResults = searchQueries: bioEntitiesIds, isPerfectMatch: true }, ) - ).unwrap().then(() => { + ).unwrap().then((bioEntityContents) => { + PluginsEventBus.dispatchEvent('onSearch', { + type: 'bioEntity', + searchValues: [closestSearchResult], + results: [bioEntityContents], + }); + if (hasFitBounds) { searchFitBounds(fitBoundsZoom); } diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts index c3663e417a6d055fcaf2f6e8e787c4bcf99fabad..39dea1009c6cbacb44eb5819f49911b801aa7a04 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction.ts @@ -25,7 +25,7 @@ export const handleSearchResultAction = async ({ REACTION: handleReactionResults, }[type]; - await action(dispatch, hasFitBounds, fitBoundsZoom)(closestSearchResult); + await action(dispatch, closestSearchResult, hasFitBounds, fitBoundsZoom)(closestSearchResult); if (type === 'ALIAS') { PluginsEventBus.dispatchEvent('onBioEntityClick', closestSearchResult); diff --git a/src/redux/bioEntity/bioEntity.thunks.test.ts b/src/redux/bioEntity/bioEntity.thunks.test.ts index b45d1941398d5ac6f99c10e30b7b3ab6c4b03587..9757ab4b3dee487935863834a79107d980384fa9 100644 --- a/src/redux/bioEntity/bioEntity.thunks.test.ts +++ b/src/redux/bioEntity/bioEntity.thunks.test.ts @@ -7,7 +7,7 @@ import { import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { HttpStatusCode } from 'axios'; import contentsReducer from './bioEntity.slice'; -import { getBioEntity } from './bioEntity.thunks'; +import { getBioEntity, getMultiBioEntity } from './bioEntity.thunks'; import { BioEntityContentsState } from './bioEntity.types'; const mockedAxiosClient = mockNetworkNewAPIResponse(); @@ -56,4 +56,51 @@ describe('bioEntityContents thunks', () => { expect(payload).toEqual(undefined); }); }); + describe('getMultiBioEntity', () => { + it('should return transformed bioEntityContent array', async () => { + mockedAxiosClient + .onGet( + apiPath.getBioEntityContentsStringWithQuery({ + searchQuery: SEARCH_QUERY, + isPerfectMatch: false, + }), + ) + .reply(HttpStatusCode.Ok, bioEntityResponseFixture); + + const data = await store + .dispatch( + getMultiBioEntity({ + searchQueries: [SEARCH_QUERY], + isPerfectMatch: false, + }), + ) + .unwrap(); + + expect(data).toEqual(bioEntityResponseFixture.content); + }); + it('should combine all returned bioEntityContent arrays and return array with all provided bioEntityContent elements', async () => { + mockedAxiosClient + .onGet( + apiPath.getBioEntityContentsStringWithQuery({ + searchQuery: SEARCH_QUERY, + isPerfectMatch: false, + }), + ) + .reply(HttpStatusCode.Ok, bioEntityResponseFixture); + + const data = await store + .dispatch( + getMultiBioEntity({ + searchQueries: [SEARCH_QUERY, SEARCH_QUERY], + isPerfectMatch: false, + }), + ) + .unwrap(); + + expect(data).toEqual([ + ...bioEntityResponseFixture.content, + ...bioEntityResponseFixture.content, + ]); + }); + }); }); diff --git a/src/redux/bioEntity/bioEntity.thunks.ts b/src/redux/bioEntity/bioEntity.thunks.ts index e1b59d1ed97a7fc4bb77006b7350a8d3e79980d7..32185755ccf261b6aa81edace068e49ba432f872 100644 --- a/src/redux/bioEntity/bioEntity.thunks.ts +++ b/src/redux/bioEntity/bioEntity.thunks.ts @@ -1,5 +1,5 @@ import { PerfectMultiSearchParams, PerfectSearchParams } from '@/types/search'; -import { createAsyncThunk } from '@reduxjs/toolkit'; +import { PayloadAction, createAsyncThunk } from '@reduxjs/toolkit'; import { bioEntityResponseSchema } from '@/models/bioEntityResponseSchema'; import { apiPath } from '@/redux/apiPath'; import { axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; @@ -25,17 +25,26 @@ export const getBioEntity = createAsyncThunk( ); type GetMultiBioEntityProps = PerfectMultiSearchParams; +type GetMultiBioEntityActions = PayloadAction<BioEntityContent[] | undefined>[]; export const getMultiBioEntity = createAsyncThunk( 'project/getMultiBioEntity', async ( { searchQueries, isPerfectMatch }: GetMultiBioEntityProps, { dispatch }, - ): Promise<void> => { + ): Promise<BioEntityContent[]> => { const asyncGetBioEntityFunctions = searchQueries.map(searchQuery => dispatch(getBioEntity({ searchQuery, isPerfectMatch })), ); - await Promise.all(asyncGetBioEntityFunctions); + const bioEntityContentsActions = (await Promise.all( + asyncGetBioEntityFunctions, + )) as GetMultiBioEntityActions; + + const bioEntityContents = bioEntityContentsActions + .map(bioEntityContentsAction => bioEntityContentsAction.payload || []) + .flat(); + + return bioEntityContents; }, ); diff --git a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts index 7679bb0af514be8208c15a0a23c55c3de096aafe..2122a199208061d942f94027b1efba4f97ca811d 100644 --- a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts +++ b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts @@ -1,4 +1,11 @@ -import { BioEntityContent, Chemical, CreatedOverlay, Drug, MapOverlay } from '@/types/models'; +import { + BioEntityContent, + Chemical, + CreatedOverlay, + Drug, + ElementSearchResult, + MapOverlay, +} from '@/types/models'; import { dispatchEvent } from './pluginsEventBus'; export type BackgroundEvents = 'onBackgroundOverlayChange'; @@ -36,7 +43,7 @@ export type ClickedBioEntity = { export type SearchDataBioEntity = { type: 'bioEntity'; - searchValues: string[]; + searchValues: string[] | ElementSearchResult[]; results: BioEntityContent[][]; };