Skip to content

DataViews can render custom empty states with an empty prop #70637

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

Closed
wants to merge 2 commits into from

Conversation

p-jackson
Copy link
Member

@p-jackson p-jackson commented Jul 8, 2025

What?

Related to #61442

Adds an empty prop to the DataViews component. It allows data views to render a custom empty state.

This doesn't fully resolve #61442 because IMO that issue is proposing changes to the design system. This PR is a way of facilitating that, but it doesn't actually do the work of designing a new empty state.

Why?

As is noted in #61442, sometimes it is useful to have more context in the empty state. Here is an example from outside of Gutenberg which is using <DataViews> as a component. In general, providing buttons with "next steps" would be useful. However

  1. we have not settled on a standard design for this, and
  2. we need the ability to pass in context.

By allowing the user of <DataViews> to provide an arbitrary empty state they can use as much context as they like when creating their element. They can also have whatever logic they want to determine whether the view empty because their is no data, or empty because of the filtering.

It also doesn't rule out using a standard design in the future. If we settle on a design then the empty prop would be used like empty={ <DataViews.EmptyState { ... } /> }

An alternative for package users would be to use the <DataView> in "free composition" mode—replacing the inner parts of the data view when there is no data there.

How?

This PR allows the user of a <DataViews> to pass in an arbitrary custom empty state.

I considered using a slot for providing the empty state, but the idea here is that the empty state would be customised on a per-dataview basis. This isn't a way to allow plugins to modify every dataview's empty state. It also matches how the header prop works, which also doesn't use a slot.

I didn't add the empty prop to the DataViewsContext because it doesn't feel like it needs to be drilled down that far. The leaf-most components aren't going to need access to it.

Testing Instructions

In storybook

  • Open the DataViews > Empty story
    • There are no changes, it works as before
  • Open the DataViews > Custom Empty State story
    • See the custom copy

In the site editor

CleanShot 2025-07-11 at 17 17 43@2x

Testing Instructions for Keyboard

No changes to the UI, however custom empty states will need to be accessible.

@p-jackson p-jackson self-assigned this Jul 8, 2025
@p-jackson p-jackson added [Type] Enhancement A suggestion for improvement. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Jul 8, 2025
@@ -335,7 +336,13 @@ function ViewGrid< Item >( {
'dataviews-no-results': ! isLoading,
} ) }
>
<p>{ isLoading ? <Spinner /> : __( 'No results' ) }</p>
{ isLoading ? (
<p>
Copy link
Member Author

Choose a reason for hiding this comment

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

I was careful here to keep the <p> around the <Spinner>. But I'm not sure how useful it actually is. You can see the extra margin the <p> provides in storybook, but that's because the data views in storybook do not stretch vertically.

In practice, the loading states within Gutenberg are centred which makes the margin from the <p> useless.

With <p> Without <p>
before after

onChangeView={ setView }
actions={ actions }
defaultLayouts={ defaultLayouts }
empty={ <p>Nothing found, add some data to your dataview.</p> }
Copy link
Member Author

Choose a reason for hiding this comment

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

Realistic usage will probably look like this

Suggested change
empty={ <p>Nothing found, add some data to your dataview.</p> }
empty={ view.search ? ( <p>Search returned nothing.</p> ) : ( <p>No data.</p> ) }

@p-jackson p-jackson marked this pull request as ready for review July 8, 2025 00:24
Copy link

github-actions bot commented Jul 8, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: p-jackson <[email protected]>
Co-authored-by: arthur791004 <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: keoshi <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jarekmorawski <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@p-jackson p-jackson requested review from ciampo and oandregal July 8, 2025 04:50
@p-jackson p-jackson force-pushed the add/empty-prop-dataviews branch from bfe28f8 to acdfd05 Compare July 11, 2025 05:18
Copy link

Flaky tests detected in acdfd05.
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/16212428780
📝 Reported issues:

@p-jackson
Copy link
Member Author

I'm working on a more fully-featured empty state for dataviews. Rather than allowing a generic slot in which to put anything.

WIP #70867

@p-jackson p-jackson closed this Jul 24, 2025
@oandregal oandregal deleted the add/empty-prop-dataviews branch July 29, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dataviews: Improve the 'No results' view
2 participants