Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions src/containers/Tenant/Schema/SchemaViewer/SchemaViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';

import {skipToken} from '@reduxjs/toolkit/query';

import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
import {TableSkeleton} from '../../../../components/TableSkeleton/TableSkeleton';
import {overviewApi} from '../../../../store/reducers/overview/overview';
Expand Down Expand Up @@ -42,27 +40,28 @@ export const SchemaViewer = ({type, path, tenantName, extended = false}: SchemaV
// Refresh table only in Diagnostics
const pollingInterval = extended ? autoRefreshInterval : undefined;

const {currentData: schemaData, isFetching} = overviewApi.useGetOverviewQuery(
{path, database: tenantName},
{pollingInterval},
);

// useGetOverviewQuery is called in Tenant, so isLoading will be always false in this component
// to show loader properly, we need to check isFetching and currentData
const loading = isFetching && schemaData === undefined;

const viewSchemaRequestParams = isViewType(type) ? {path, database: tenantName} : skipToken;

const {currentData: viewColumnsData, isLoading: isViewSchemaLoading} =
viewSchemaApi.useGetViewSchemaQuery(viewSchemaRequestParams, {pollingInterval});
const {currentData: tableSchemaData, isFetching: isTableSchemaFetching} =
overviewApi.useGetOverviewQuery(
{path, database: tenantName},
{pollingInterval, skip: isViewType(type)},
);
const {currentData: viewColumnsData, isFetching: isViewSchemaFetching} =
viewSchemaApi.useGetViewSchemaQuery(
{path, database: tenantName},
{pollingInterval, skip: !isViewType(type)},
);

const loading =
(isViewSchemaFetching && viewColumnsData === undefined) ||
(isTableSchemaFetching && tableSchemaData === undefined);
Comment on lines +54 to +56
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoading isn't set to true when path changes, so we don't see loader on schema object change


const tableData = React.useMemo(() => {
if (isViewType(type)) {
return prepareViewSchema(viewColumnsData);
}

return prepareSchemaData(type, schemaData);
}, [schemaData, type, viewColumnsData]);
return prepareSchemaData(type, tableSchemaData);
}, [tableSchemaData, type, viewColumnsData]);

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

if (loading || isViewSchemaLoading) {
if (loading) {
return <TableSkeleton />;
}

Expand Down
Loading