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

Merge branch '279-search-speed' into 'development'

Resolve "Search speed"

Closes #279

See merge request !226
parents 9e7e27bf a40c4803
No related branches found
No related tags found
2 merge requests!231Development,!226Resolve "Search speed"
Pipeline #94119 passed
import { FetchDataState } from '@/types/fetchDataState';
import { BioEntityContent } from '@/types/models';
import { BioEntity } from '@/types/models';
import { BioEntityContentsState } from './bioEntity.types';
export const DEFAULT_BIOENTITY_PARAMS = {
......@@ -9,7 +9,7 @@ export const DEFAULT_BIOENTITY_PARAMS = {
export const BIO_ENTITY_FETCHING_ERROR_PREFIX = 'Failed to fetch bio entity';
export const MULTI_BIO_ENTITY_FETCHING_ERROR_PREFIX = 'Failed to fetch multi bio entity';
export const BIOENTITY_SUBMAP_CONNECTIONS_INITIAL_STATE: FetchDataState<BioEntityContent[]> = {
export const BIOENTITY_SUBMAP_CONNECTIONS_INITIAL_STATE: FetchDataState<BioEntity[]> = {
data: [],
loading: 'idle',
error: { name: '', message: '' },
......
......@@ -51,8 +51,7 @@ export const bioEntityDataListSelector = createSelector(bioEntityDataSelector, b
export const allSubmapConnectionsBioEntitySelector = createSelector(
bioEntitySelector,
(bioEntityData): BioEntity[] =>
(bioEntityData?.submapConnections?.data || []).map(({ bioEntity }) => bioEntity),
(bioEntityData): BioEntity[] => bioEntityData?.submapConnections?.data || [],
);
export const allSubmapConnectionsBioEntityOfCurrentSubmapSelector = createSelector(
......
import { FetchDataState, MultiFetchDataState } from '@/types/fetchDataState';
import { BioEntityContent } from '@/types/models';
import { BioEntity, BioEntityContent } from '@/types/models';
import { PayloadAction } from '@reduxjs/toolkit';
export type BioEntityContentsState = MultiFetchDataState<BioEntityContent[]> & {
submapConnections?: FetchDataState<BioEntityContent[]>;
submapConnections?: FetchDataState<BioEntity[]>;
isContentTabOpened?: boolean;
};
......
import { bioEntityContentSchema } from '@/models/bioEntityContentSchema';
import { submapConnection } from '@/models/submapConnection';
import { apiPath } from '@/redux/apiPath';
import { axiosInstance, axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance';
import { BioEntityContent, BioEntityResponse, SubmapConnection } from '@/types/models';
import { BioEntity, SubmapConnection } from '@/types/models';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { z } from 'zod';
import { getError } from '@/utils/error-report/getError';
import { bioEntitySchema } from '@/models/bioEntitySchema';
import { MULTI_BIO_ENTITY_FETCHING_ERROR_PREFIX } from '../bioEntity.constants';
export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntityContent[]>(
export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntity[]>(
'project/getSubmapConnectionsBioEntity',
async () => {
try {
......@@ -20,21 +20,20 @@ export const getSubmapConnectionsBioEntity = createAsyncThunk<BioEntityContent[]
throw new Error('Submap connections validation error');
}
const searchQueries = response.data.map(({ from }) => `${from.id}`);
const targetElements = response.data.map(({ from }) => from);
const asyncFetchBioEntityFunctions = searchQueries.map(searchQuery =>
axiosInstanceNewAPI.get<BioEntityResponse>(
apiPath.getBioEntityContentsStringWithQuery({ searchQuery, isPerfectMatch: true }),
const asyncFetchBioEntityFunctions = targetElements.map(targetElement =>
axiosInstanceNewAPI.get<BioEntity>(
apiPath.getElementById(targetElement.id, targetElement.modelId),
),
);
const bioEntityContentResponse = await Promise.all(asyncFetchBioEntityFunctions);
const bioEntityContents = bioEntityContentResponse
.map(contentResponse => contentResponse?.data?.content || [])
.map(contentResponse => contentResponse.data)
.flat()
.filter(content => bioEntityContentSchema.safeParse(content).success)
.filter(payload => 'bioEntity' in payload || {});
.filter(content => bioEntitySchema.safeParse(content).success);
return bioEntityContents;
} catch (error) {
......
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