Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: Add loading/no results message in grid view #59002

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading