Show a status-aware empty state on My Patterns - #758
Open
ekamran wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #745.
Problem
On the My Patterns page, the empty state always uses first-time-user copy. If you filter by a status and have nothing in that status, the page says "Create your first pattern" even when you already have patterns in other statuses.
This happens because the
wp:query-no-resultsblock in_grid-mine.phpfires whenever the current query returns nothing. It has no way to know that the result is empty only because a status filter is applied.Solution
Check whether a status filter is active, and show different copy when it is.
The check reads
$wp_query->query['status'], which is the same query var thatmodify_query_loop_block_query_vars()infunctions.phpuses to filter the list. Reading the same source keeps the message in sync with whatever caused the empty result.Behaviour after the change:
The button points to
get_permalink(), which is where the existing "All" status link already points.Testing
Tested locally with wp-env, using a user with 2 published patterns, 1 pending, and 0 drafts.
Before the change,
status=draftshowed "Create your first pattern".After the change, it shows the new message. With no filter the output is unchanged.
Also checked:
statusvalues of empty, pending, publish, and an array all behave correctly.$wp_queryis not set up, for example in REST or CLI contexts. It falls back to the original copy.php -landcomposer run lintare both clean.Notes
I could not load
/my-patterns/over HTTP locally, because that page and its template come from WordPress.org rather than this repo. So the visual result is not verified. I did confirm the original behaviour on the live site when reporting #745. A visual check during review would be helpful.Separately, line 51 of the same file has a
wp:buttonblock that is closed with<!-- /wp:paragraph -->. It is pre-existing and I have left it alone to keep this change focused. Happy to open a separate issue for it.