Skip to content

Commit

Permalink
DataViews: Add loading/no results message in grid view (#59002)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
5 people authored Feb 14, 2024
1 parent c35d6ff commit ec329cd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
64 changes: 41 additions & 23 deletions packages/dataviews/src/view-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
__experimentalVStack as VStack,
Tooltip,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';
import { useState } from '@wordpress/element';

Expand Down Expand Up @@ -128,6 +129,7 @@ export default function ViewGrid( {
fields,
view,
actions,
isLoading,
getItemId,
deferredRendering,
selection,
Expand All @@ -148,29 +150,45 @@ export default function ViewGrid( {
);
const shownData = useAsyncList( data, { step: 3 } );
const usedData = deferredRendering ? shownData : data;
const hasData = !! usedData?.length;
return (
<Grid
gap={ 6 }
columns={ 2 }
alignment="top"
className="dataviews-view-grid"
>
{ usedData.map( ( item ) => {
return (
<GridItem
key={ getItemId( item ) }
selection={ selection }
data={ data }
onSelectionChange={ onSelectionChange }
getItemId={ getItemId }
item={ item }
actions={ actions }
mediaField={ mediaField }
primaryField={ primaryField }
visibleFields={ visibleFields }
/>
);
} ) }
</Grid>
<>
{ hasData && (
<Grid
gap={ 6 }
columns={ 2 }
alignment="top"
className="dataviews-view-grid"
aria-busy={ isLoading }
>
{ usedData.map( ( item ) => {
return (
<GridItem
key={ getItemId( item ) }
selection={ selection }
data={ data }
onSelectionChange={ onSelectionChange }
getItemId={ getItemId }
item={ item }
actions={ actions }
mediaField={ mediaField }
primaryField={ primaryField }
visibleFields={ visibleFields }
/>
);
} ) }
</Grid>
) }
{ ! hasData && (
<div
className={ classnames( {
'dataviews-loading': isLoading,
'dataviews-no-results': ! isLoading,
} ) }
>
<p>{ isLoading ? __( 'Loading…' ) : __( 'No results' ) }</p>
</div>
) }
</>
);
}
18 changes: 13 additions & 5 deletions packages/edit-site/src/components/page-patterns/use-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const selectTemplatePartsAsPatterns = createSelector(
const selectThemePatterns = createSelector(
( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
const { getIsResolving } = select( coreStore );
const settings = getSettings();
const blockPatterns =
settings.__experimentalAdditionalBlockPatterns ??
Expand All @@ -136,19 +137,23 @@ const selectThemePatterns = createSelector(
__unstableSkipMigrationLogs: true,
} ),
} ) );

return { patterns, isResolving: false };
return { patterns, isResolving: getIsResolving( 'getBlockPatterns' ) };
},
( select ) => [
select( coreStore ).getBlockPatterns(),
select( coreStore ).getIsResolving( 'getBlockPatterns' ),
unlock( select( editSiteStore ) ).getSettings(),
]
);

const selectPatterns = createSelector(
( select, categoryId, syncStatus, search = '' ) => {
const { patterns: themePatterns } = selectThemePatterns( select );
const { patterns: userPatterns } = selectUserPatterns( select );
const {
patterns: themePatterns,
isResolving: isResolvingThemePatterns,
} = selectThemePatterns( select );
const { patterns: userPatterns, isResolving: isResolvingUserPatterns } =
selectUserPatterns( select );

let patterns = [
...( themePatterns || [] ),
Expand Down Expand Up @@ -176,7 +181,10 @@ const selectPatterns = createSelector(
hasCategory: ( item ) => ! item.hasOwnProperty( 'categories' ),
} );
}
return { patterns, isResolving: false };
return {
patterns,
isResolving: isResolvingThemePatterns || isResolvingUserPatterns,
};
},
( select ) => [
selectThemePatterns( select ),
Expand Down

1 comment on commit ec329cd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in ec329cd.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7900672020
📝 Reported issues:

Please sign in to comment.