mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-06 04:26:57 +00:00
Fix: Change API calls in mydata page (#1208)
* Fix: Change API calls in mydata page * Fix failing test in mydata component
This commit is contained in:
parent
01f9e54874
commit
1717c82d71
@ -30,10 +30,8 @@ import { MyDataProps } from './MyData.interface';
|
||||
|
||||
const MyData: React.FC<MyDataProps> = ({
|
||||
error,
|
||||
errorHandler,
|
||||
countServices,
|
||||
userDetails,
|
||||
rejectedResult,
|
||||
searchResult,
|
||||
fetchData,
|
||||
entityCounts,
|
||||
@ -122,19 +120,16 @@ const MyData: React.FC<MyDataProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (searchResult) {
|
||||
const formatedData: Array<FormatedTableData> = [];
|
||||
let totalValue = 0;
|
||||
searchResult.forEach((res) => {
|
||||
totalValue = totalValue + res.data.hits.total.value;
|
||||
formatedData.push(...formatDataResponse(res.data.hits.hits));
|
||||
});
|
||||
|
||||
if (formatedData.length === 0 && rejectedResult.length > 0) {
|
||||
errorHandler(rejectedResult[0].response?.data?.responseMessage);
|
||||
const hits = searchResult.data.hits.hits;
|
||||
if (hits.length > 0) {
|
||||
setTotalNumberOfValues(searchResult.data.hits.total.value);
|
||||
setData(formatDataResponse(hits));
|
||||
} else {
|
||||
setData([]);
|
||||
setTotalNumberOfValues(0);
|
||||
}
|
||||
setTotalNumberOfValues(totalValue);
|
||||
setData(formatedData);
|
||||
}
|
||||
|
||||
setIsEntityLoading(false);
|
||||
}, [searchResult]);
|
||||
|
||||
|
||||
@ -5,9 +5,7 @@ export interface MyDataProps {
|
||||
error: string;
|
||||
countServices: number;
|
||||
userDetails: User;
|
||||
rejectedResult: PromiseRejectedResult['reason'][];
|
||||
errorHandler: (error: string) => void;
|
||||
searchResult: SearchResponse[] | undefined;
|
||||
searchResult: SearchResponse | undefined;
|
||||
fetchData: (value: SearchDataFunctionType) => void;
|
||||
entityCounts: EntityCounts;
|
||||
}
|
||||
|
||||
@ -252,7 +252,6 @@ jest.mock('../../utils/ServiceUtils', () => ({
|
||||
}));
|
||||
|
||||
const fetchData = jest.fn();
|
||||
const errorHandler = jest.fn();
|
||||
|
||||
describe('Test MyData page', () => {
|
||||
it('Check if there is an element in the page', async () => {
|
||||
@ -266,10 +265,8 @@ describe('Test MyData page', () => {
|
||||
pipelineCount: 1,
|
||||
}}
|
||||
error=""
|
||||
errorHandler={errorHandler}
|
||||
fetchData={fetchData}
|
||||
rejectedResult={[]}
|
||||
searchResult={[mockData] as unknown as SearchResponse[]}
|
||||
searchResult={mockData as unknown as SearchResponse}
|
||||
userDetails={mockUserDetails as unknown as User}
|
||||
/>,
|
||||
{
|
||||
|
||||
@ -19,6 +19,16 @@ import { FilterObject } from 'Models';
|
||||
import { getCurrentUserId } from '../utils/CommonUtils';
|
||||
import { getFilterString } from '../utils/FilterUtils';
|
||||
|
||||
export const myDataSearchIndex =
|
||||
'dashboard_search_index,topic_search_index,table_search_index,pipeline_search_index';
|
||||
|
||||
export const myDataEntityCounts = {
|
||||
tableCount: 0,
|
||||
topicCount: 0,
|
||||
dashboardCount: 0,
|
||||
pipelineCount: 0,
|
||||
};
|
||||
|
||||
export const myDataFilterType = [
|
||||
{ key: 'Owned', value: 'owner' },
|
||||
{ key: 'Following', value: 'followers' },
|
||||
|
||||
@ -15,20 +15,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AxiosError } from 'axios';
|
||||
import { isUndefined } from 'lodash';
|
||||
import { observer } from 'mobx-react';
|
||||
import {
|
||||
Bucket,
|
||||
EntityCounts,
|
||||
SearchDataFunctionType,
|
||||
SearchResponse,
|
||||
} from 'Models';
|
||||
import { EntityCounts, SearchDataFunctionType, SearchResponse } from 'Models';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import AppState from '../../AppState';
|
||||
import { searchData } from '../../axiosAPIs/miscAPI';
|
||||
import Loader from '../../components/Loader/Loader';
|
||||
import MyData from '../../components/MyData/MyData.component';
|
||||
import { PAGE_SIZE } from '../../constants/constants';
|
||||
import {
|
||||
myDataEntityCounts,
|
||||
myDataSearchIndex,
|
||||
} from '../../constants/Mydata.constants';
|
||||
import {
|
||||
getAllServices,
|
||||
getEntityCountByService,
|
||||
@ -38,62 +38,36 @@ const MyDataPage = () => {
|
||||
const [error, setError] = useState<string>('');
|
||||
const [countServices, setCountServices] = useState<number>();
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||
const [searchResult, setSearchResult] = useState<SearchResponse[]>();
|
||||
const [rejectedResult, setRejectedResult] = useState<
|
||||
PromiseRejectedResult['reason'][]
|
||||
>([]);
|
||||
const [searchResult, setSearchResult] = useState<SearchResponse>();
|
||||
const [entityCounts, setEntityCounts] = useState<EntityCounts>();
|
||||
|
||||
const errorHandler = (error: string) => {
|
||||
setError(error);
|
||||
};
|
||||
|
||||
const fetchData = (value: SearchDataFunctionType, fetchService = false) => {
|
||||
setError('');
|
||||
|
||||
const entityIndexList = [
|
||||
'table_search_index',
|
||||
'topic_search_index',
|
||||
'dashboard_search_index',
|
||||
'pipeline_search_index',
|
||||
];
|
||||
|
||||
const entityResponse = entityIndexList.map((entity) =>
|
||||
searchData(
|
||||
value.queryString,
|
||||
value.from,
|
||||
PAGE_SIZE,
|
||||
value.filters,
|
||||
value.sortField,
|
||||
value.sortOrder,
|
||||
entity
|
||||
)
|
||||
);
|
||||
|
||||
Promise.allSettled(entityResponse).then((response) => {
|
||||
const fulfilledRes: SearchResponse[] = [];
|
||||
const aggregations: Bucket[] = [];
|
||||
const rejectedRes: PromiseRejectedResult['reason'][] = [];
|
||||
|
||||
response.forEach((entity) => {
|
||||
if (entity.status === 'fulfilled') {
|
||||
fulfilledRes.push(entity.value);
|
||||
aggregations.push(
|
||||
...entity.value.data.aggregations?.['sterms#Service']?.buckets
|
||||
searchData(
|
||||
value.queryString,
|
||||
value.from,
|
||||
PAGE_SIZE,
|
||||
value.filters,
|
||||
value.sortField,
|
||||
value.sortOrder,
|
||||
myDataSearchIndex
|
||||
)
|
||||
.then((res: SearchResponse) => {
|
||||
setSearchResult(res);
|
||||
if (isUndefined(entityCounts)) {
|
||||
setEntityCounts(
|
||||
getEntityCountByService(
|
||||
res.data.aggregations?.['sterms#Service']?.buckets
|
||||
)
|
||||
);
|
||||
} else {
|
||||
rejectedRes.push(entity.reason);
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError) => {
|
||||
setError(err.response?.data?.responseMessage);
|
||||
setEntityCounts(myDataEntityCounts);
|
||||
});
|
||||
|
||||
if (fulfilledRes.length === 0 && response[0].status === 'rejected') {
|
||||
setError(response[0].reason.response?.data?.responseMessage);
|
||||
}
|
||||
setRejectedResult(rejectedRes);
|
||||
setEntityCounts(getEntityCountByService(aggregations));
|
||||
setSearchResult(fulfilledRes as unknown as SearchResponse[]);
|
||||
});
|
||||
|
||||
if (fetchService) {
|
||||
getAllServices()
|
||||
.then((res) => setCountServices(res.length))
|
||||
@ -124,9 +98,7 @@ const MyDataPage = () => {
|
||||
countServices={countServices}
|
||||
entityCounts={entityCounts}
|
||||
error={error}
|
||||
errorHandler={errorHandler}
|
||||
fetchData={fetchData}
|
||||
rejectedResult={rejectedResult}
|
||||
searchResult={searchResult}
|
||||
userDetails={AppState.userDetails}
|
||||
/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user