Skip to content

Commit 5b6fecb

Browse files
fix loader for view
1 parent 764a2ff commit 5b6fecb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/containers/Tenant/Schema/SchemaViewer/SchemaViewer.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from 'react';
22

3-
import {skipToken} from '@reduxjs/toolkit/query';
4-
53
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
64
import {TableSkeleton} from '../../../../components/TableSkeleton/TableSkeleton';
75
import {overviewApi} from '../../../../store/reducers/overview/overview';
@@ -42,27 +40,28 @@ export const SchemaViewer = ({type, path, tenantName, extended = false}: SchemaV
4240
// Refresh table only in Diagnostics
4341
const pollingInterval = extended ? autoRefreshInterval : undefined;
4442

45-
const {currentData: schemaData, isFetching} = overviewApi.useGetOverviewQuery(
46-
{path, database: tenantName},
47-
{pollingInterval},
48-
);
49-
50-
// useGetOverviewQuery is called in Tenant, so isLoading will be always false in this component
51-
// to show loader properly, we need to check isFetching and currentData
52-
const loading = isFetching && schemaData === undefined;
53-
54-
const viewSchemaRequestParams = isViewType(type) ? {path, database: tenantName} : skipToken;
55-
56-
const {currentData: viewColumnsData, isLoading: isViewSchemaLoading} =
57-
viewSchemaApi.useGetViewSchemaQuery(viewSchemaRequestParams, {pollingInterval});
43+
const {currentData: tableSchemaData, isFetching: isTableSchemaFetching} =
44+
overviewApi.useGetOverviewQuery(
45+
{path, database: tenantName},
46+
{pollingInterval, skip: isViewType(type)},
47+
);
48+
const {currentData: viewColumnsData, isFetching: isViewSchemaFetching} =
49+
viewSchemaApi.useGetViewSchemaQuery(
50+
{path, database: tenantName},
51+
{pollingInterval, skip: !isViewType(type)},
52+
);
53+
54+
const loading =
55+
(isViewSchemaFetching && viewColumnsData === undefined) ||
56+
(isTableSchemaFetching && tableSchemaData === undefined);
5857

5958
const tableData = React.useMemo(() => {
6059
if (isViewType(type)) {
6160
return prepareViewSchema(viewColumnsData);
6261
}
6362

64-
return prepareSchemaData(type, schemaData);
65-
}, [schemaData, type, viewColumnsData]);
63+
return prepareSchemaData(type, tableSchemaData);
64+
}, [tableSchemaData, type, viewColumnsData]);
6665

6766
const hasAutoIncrement = React.useMemo(() => {
6867
return tableData.some((i) => i.autoIncrement);
@@ -89,7 +88,7 @@ export const SchemaViewer = ({type, path, tenantName, extended = false}: SchemaV
8988
return [];
9089
}, [type, extended, hasAutoIncrement, hasDefaultValue, tableData]);
9190

92-
if (loading || isViewSchemaLoading) {
91+
if (loading) {
9392
return <TableSkeleton />;
9493
}
9594

0 commit comments

Comments
 (0)