Skip to content

Commit

Permalink
Use genomes endpoint for species search (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
imransl authored Sep 29, 2023
1 parent 0f7b0b0 commit 29f35b5
Showing 1 changed file with 21 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* limitations under the License.
*/

import upperFirst from 'lodash/upperFirst';

import restApiSlice from 'src/shared/state/api-slices/restSlice';

import config from 'config';

import type { PopularSpecies } from 'src/content/app/new-species-selector/types/popularSpecies';
import type { SpeciesSearchMatch } from 'src/content/app/new-species-selector/types/speciesSearchMatch';

Expand Down Expand Up @@ -60,49 +64,32 @@ const speciesSelectorApiSlice = restApiSlice.injectEndpoints({
SpeciesSearchResponse,
SpeciesSearchRequestParams
>({
queryFn: async () => {
// TODO: change this function when BE exposes an endpoint
const { humanSearchMatches, createHumanPangenomeSearchMatches } =
await import('./speciesSelectorSampleData');

const combinedHumanSearchMatches = [
...humanSearchMatches,
...createHumanPangenomeSearchMatches()
];

return {
data: {
matches: combinedHumanSearchMatches,
meta: { total_count: combinedHumanSearchMatches.length }
}
};
}
query: ({ query }) => ({
url: `${config.searchApiBaseUrl}/genomes?query=${query}`
}),
transformResponse: transformGenomesSearchResponse
}),
getGenomesBySpeciesTaxonomyId: builder.query<
SpeciesSearchResponse,
GenomesSearchBySpeciesTaxonomyIdRequestParams
>({
queryFn: async () => {
// TODO: change this function when BE exposes an endpoint
const { humanSearchMatches, createHumanPangenomeSearchMatches } =
await import('./speciesSelectorSampleData');

const combinedHumanSearchMatches = [
...humanSearchMatches,
...createHumanPangenomeSearchMatches()
];

return {
data: {
matches: combinedHumanSearchMatches,
meta: { total_count: combinedHumanSearchMatches.length }
}
};
}
query: ({ speciesTaxonomyId }) => ({
url: `${config.searchApiBaseUrl}/genomes?species_taxonomy_id=${speciesTaxonomyId}`
}),
transformResponse: transformGenomesSearchResponse
})
})
});

const transformGenomesSearchResponse = (response: SpeciesSearchResponse) => {
response.matches.forEach((match) => {
match.common_name = match.common_name
? upperFirst(match.common_name)
: match.common_name;
});
return response;
};

export const {
useGetPopularSpeciesQuery,
useLazyGetSpeciesSearchResultsQuery,
Expand Down

0 comments on commit 29f35b5

Please sign in to comment.