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