mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-03 12:16:10 +00:00
fix(ui): fix intermediate white screen after loading asset collection module (#14687)
This commit is contained in:
parent
f458021060
commit
e69a083881
@ -1,5 +1,5 @@
|
||||
import { InfiniteScrollList } from '@components';
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
|
||||
import EmptyContent from '@app/homeV3/module/components/EmptyContent';
|
||||
import EntityItem from '@app/homeV3/module/components/EntityItem';
|
||||
@ -15,6 +15,7 @@ import { DataHubPageModuleType, Entity } from '@types';
|
||||
const DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
const AssetCollectionModule = (props: ModuleProps) => {
|
||||
const [isFirstFetch, setIsFirstFetch] = useState(true);
|
||||
const assetUrns = useMemo(
|
||||
() =>
|
||||
props.module.properties.params.assetCollectionParams?.assetUrns.filter(
|
||||
@ -49,7 +50,7 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
||||
[shouldFetchByDynamicFilter, assetUrns],
|
||||
);
|
||||
|
||||
const { loading, refetch } = useGetSearchResultsForMultipleQuery({
|
||||
const { data, loading, refetch } = useGetSearchResultsForMultipleQuery({
|
||||
variables: {
|
||||
input: {
|
||||
start: 0,
|
||||
@ -63,8 +64,19 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
||||
},
|
||||
},
|
||||
skip: assetUrns.length === 0 && !dynamicOrFilters?.length,
|
||||
onCompleted: () => {
|
||||
setIsFirstFetch(false);
|
||||
},
|
||||
});
|
||||
|
||||
const initialEntities = useMemo(
|
||||
() =>
|
||||
data?.searchAcrossEntities?.searchResults
|
||||
?.map((res) => res.entity)
|
||||
.filter((entity): entity is Entity => !!entity) || [],
|
||||
[data?.searchAcrossEntities?.searchResults],
|
||||
);
|
||||
|
||||
const fetchEntitiesByDynamicFilter = useCallback(
|
||||
async (start: number, count: number): Promise<Entity[]> => {
|
||||
if (!dynamicOrFilters?.length) return [];
|
||||
@ -115,12 +127,21 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
||||
|
||||
const fetchEntities = useCallback(
|
||||
async (start: number, count: number): Promise<Entity[]> => {
|
||||
if (isFirstFetch) {
|
||||
return initialEntities;
|
||||
}
|
||||
if (shouldFetchByDynamicFilter) {
|
||||
return fetchEntitiesByDynamicFilter(start, count);
|
||||
}
|
||||
return fetchEntitiesByAssetUrns(start, count);
|
||||
},
|
||||
[fetchEntitiesByDynamicFilter, fetchEntitiesByAssetUrns, shouldFetchByDynamicFilter],
|
||||
[
|
||||
isFirstFetch,
|
||||
shouldFetchByDynamicFilter,
|
||||
fetchEntitiesByAssetUrns,
|
||||
initialEntities,
|
||||
fetchEntitiesByDynamicFilter,
|
||||
],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user