chore: Improves D2D loading indicator (#21908)

This commit is contained in:
Michael S. Molina 2022-10-21 13:24:57 -03:00 committed by GitHub
parent 04b017e006
commit 3da9687328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -122,11 +122,11 @@ test('should render', async () => {
expect(container).toBeInTheDocument();
});
test('should render metadata and table loading indicators', async () => {
test('should render loading indicator', async () => {
fetchWithData();
setup();
await waitFor(() =>
expect(screen.getAllByLabelText('Loading').length).toBe(2),
expect(screen.getByLabelText('Loading')).toBeInTheDocument(),
);
});

View File

@ -194,6 +194,12 @@ export default function DrillDetailPane({
resultsPages,
]);
// Get datasource metadata
const response = useApiV1Resource<Dataset>(`/api/v1/dataset/${datasourceId}`);
const bootstrapping =
(!responseError && !resultsPages.size) || response.status === 'loading';
let tableContent = null;
if (responseError) {
// Render error if page download failed
@ -206,7 +212,7 @@ export default function DrillDetailPane({
{responseError}
</pre>
);
} else if (!resultsPages.size) {
} else if (bootstrapping) {
// Render loading if first page hasn't loaded
tableContent = <Loading />;
} else if (resultsPage?.total === 0) {
@ -241,9 +247,6 @@ export default function DrillDetailPane({
);
}
// Get datasource metadata
const response = useApiV1Resource<Dataset>(`/api/v1/dataset/${datasourceId}`);
const metadata = useMemo(() => {
const { status, result } = response;
const items: ContentType[] = [];
@ -298,7 +301,6 @@ export default function DrillDetailPane({
margin-bottom: ${theme.gridUnit * 4}px;
`}
>
{status === 'loading' && <Loading position="inline-centered" />}
{status === 'complete' && <MetadataBar items={items} />}
{status === 'error' && (
<Alert
@ -312,14 +314,16 @@ export default function DrillDetailPane({
return (
<>
{metadata}
<TableControls
filters={filters}
setFilters={setFilters}
totalCount={resultsPage?.total}
loading={isLoading}
onReload={handleReload}
/>
{!bootstrapping && metadata}
{!bootstrapping && (
<TableControls
filters={filters}
setFilters={setFilters}
totalCount={resultsPage?.total}
loading={isLoading}
onReload={handleReload}
/>
)}
{tableContent}
</>
);