Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Bug Fixes

- DataViews: Fix last column classname in table layout. [#76133](https://github.com/WordPress/gutenberg/pull/76133)
- DataViews: Add spinner in DataViewsLayout in initial load of data. [#76486](https://github.com/WordPress/gutenberg/pull/76486)
- DataForm: Properly handle dates in datetime control. [#76193](https://github.com/WordPress/gutenberg/pull/76193)

### Enhancements
Expand Down
16 changes: 15 additions & 1 deletion packages/dataviews/src/components/dataviews-layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type { ComponentType } from 'react';
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import { Spinner } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import DataViewsContext from '../dataviews-context';
import { VIEW_LAYOUTS } from '../dataviews-layouts';
import { useDelayedLoading } from '../../hooks/use-delayed-loading';
import type { ViewBaseProps } from '../../types';

type DataViewsLayoutProps = {
Expand Down Expand Up @@ -41,8 +43,20 @@ export default function DataViewsLayout( { className }: DataViewsLayoutProps ) {
empty = <p>{ __( 'No results' ) }</p>,
} = useContext( DataViewsContext );

const isDelayedInitialLoading = useDelayedLoading( ! hasInitiallyLoaded, {
delay: 200,
} );
if ( ! hasInitiallyLoaded ) {
return null;
if ( ! isDelayedInitialLoading ) {
return null;
}
return (
<div className="dataviews-loading">
<p>
<Spinner />
</p>
</div>
);
}

const ViewComponent = VIEW_LAYOUTS.find(
Expand Down
Loading