mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-11 00:42:29 +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 { 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 EmptyContent from '@app/homeV3/module/components/EmptyContent';
|
||||||
import EntityItem from '@app/homeV3/module/components/EntityItem';
|
import EntityItem from '@app/homeV3/module/components/EntityItem';
|
||||||
@ -15,6 +15,7 @@ import { DataHubPageModuleType, Entity } from '@types';
|
|||||||
const DEFAULT_PAGE_SIZE = 10;
|
const DEFAULT_PAGE_SIZE = 10;
|
||||||
|
|
||||||
const AssetCollectionModule = (props: ModuleProps) => {
|
const AssetCollectionModule = (props: ModuleProps) => {
|
||||||
|
const [isFirstFetch, setIsFirstFetch] = useState(true);
|
||||||
const assetUrns = useMemo(
|
const assetUrns = useMemo(
|
||||||
() =>
|
() =>
|
||||||
props.module.properties.params.assetCollectionParams?.assetUrns.filter(
|
props.module.properties.params.assetCollectionParams?.assetUrns.filter(
|
||||||
@ -49,7 +50,7 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
|||||||
[shouldFetchByDynamicFilter, assetUrns],
|
[shouldFetchByDynamicFilter, assetUrns],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { loading, refetch } = useGetSearchResultsForMultipleQuery({
|
const { data, loading, refetch } = useGetSearchResultsForMultipleQuery({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
start: 0,
|
start: 0,
|
||||||
@ -63,8 +64,19 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
skip: assetUrns.length === 0 && !dynamicOrFilters?.length,
|
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(
|
const fetchEntitiesByDynamicFilter = useCallback(
|
||||||
async (start: number, count: number): Promise<Entity[]> => {
|
async (start: number, count: number): Promise<Entity[]> => {
|
||||||
if (!dynamicOrFilters?.length) return [];
|
if (!dynamicOrFilters?.length) return [];
|
||||||
@ -115,12 +127,21 @@ const AssetCollectionModule = (props: ModuleProps) => {
|
|||||||
|
|
||||||
const fetchEntities = useCallback(
|
const fetchEntities = useCallback(
|
||||||
async (start: number, count: number): Promise<Entity[]> => {
|
async (start: number, count: number): Promise<Entity[]> => {
|
||||||
|
if (isFirstFetch) {
|
||||||
|
return initialEntities;
|
||||||
|
}
|
||||||
if (shouldFetchByDynamicFilter) {
|
if (shouldFetchByDynamicFilter) {
|
||||||
return fetchEntitiesByDynamicFilter(start, count);
|
return fetchEntitiesByDynamicFilter(start, count);
|
||||||
}
|
}
|
||||||
return fetchEntitiesByAssetUrns(start, count);
|
return fetchEntitiesByAssetUrns(start, count);
|
||||||
},
|
},
|
||||||
[fetchEntitiesByDynamicFilter, fetchEntitiesByAssetUrns, shouldFetchByDynamicFilter],
|
[
|
||||||
|
isFirstFetch,
|
||||||
|
shouldFetchByDynamicFilter,
|
||||||
|
fetchEntitiesByAssetUrns,
|
||||||
|
initialEntities,
|
||||||
|
fetchEntitiesByDynamicFilter,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user