-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 sync filter in patterns page #57532
Conversation
Size Change: +316 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
_fields.push( { | ||
header: __( 'Sync Status' ), | ||
id: 'sync-status', | ||
isVirtual: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should this be a virtual filter. For me it's actually a valid field that can show Sync or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could definitely delay this virtual
concept for now, and by not providing a render
prop and adjusting the views to check for that, we could not display the field. My exploration was based on thoughts I had for other cases too, as I describe in the PR's description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I can't think of a case where a filter doesn't make sense as a regular field personally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good other than the fact that I'm not sure there's any valid reason to make this a "virtual" field.
41af9ae
to
b86cbd2
Compare
packages/edit-site/src/components/page-patterns/dataviews-patterns.js
Outdated
Show resolved
Hide resolved
[ view.type, categoryId ] | ||
); | ||
]; | ||
if ( type === PATTERN_TYPES.theme ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I trigger a situation in which the category type is PATTERN_TYPES.user
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test
- I went to the "manage my patterns" screen
- edited one of my patterns by adding a new "howdy" category
I see this new category is listed in the patterns page, though it works as any other:
Gravacao.do.ecra.2024-01-04.as.14.27.03.mov
Should I do anything differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for later, but making sync
visible and changing the listing hide the field (this is: the sidebar is not using the views yet, like the pages page).
Gravacao.do.ecra.2024-01-04.as.14.32.12.mov
Though, this makes me think that I wouldn't want the sync
field to be removed from the view. Consider the following case: a user is navigating through the categories to see what patterns are available, though they are only interested in "not synced" patterns:
sync
field is shown in the layoutsync
filter is also shown
What happens when the user visits a user-provided category and then a theme provided category?
The consequences are that 1) visual jumps in the layout and 2) the user preferences (hiddenFields and filter statuses) are cleared once they visit a user-provided category.
It sounds it's to always render the sync
field and its filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I trigger a situation in which the category type is PATTERN_TYPES.user?
Did you encountered something unexpected that is different from the old patterns page?
I'm not really sure but that param contains the value wp_block
. Maybe @talldan or @aaronrobertshaw can shed some light here?
This is for later, but making sync visible and changing the listing hide the field (this is: the sidebar is not using the views yet, like the pages page).
We discussed this a bit with Riad here and for now we reset the whole view. It does resemble the custom
views we have in pages list. We can revisit later if we need to..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you encountered something unexpected that is different from the old patterns page?
I don't know, because I don't know how to trigger a situation where type is not PATTERN_TYPES.thems
:)
From what I gathered, my suggestion here is to always render the sync-status
field and its filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a look. What's confusing is there are two PATTERN_TYPES
consts that seem to have different values.
One is used in the inserter for inserter items:
gutenberg/packages/block-editor/src/components/inserter/block-patterns-tab/utils.js
Lines 7 to 14 in 6f61d8b
export const PATTERN_TYPES = { | |
all: 'all', | |
synced: 'synced', | |
unsynced: 'unsynced', | |
user: 'user', | |
theme: 'theme', | |
directory: 'directory', | |
}; |
One is used by most of the other patterns code:
gutenberg/packages/patterns/src/constants.js
Lines 6 to 9 in 6f61d8b
export const PATTERN_TYPES = { | |
theme: 'pattern', | |
user: 'wp_block', | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the majority of the codebase uses the first variable, where PATTERN_TYPES.user === 'user'
.
It seems you're using the second variable where PATTERN_TYPES.user === 'wp_block'
, it doesn't seem to be used much in the codebase.
I think the first variable is the one you'll want to use, though I think it's still not great as the one object seems to mix and match lots of different concepts (syncing, pattern source, and I'm not sure what 'all' is).
Ignore that, my assumption was wrong.
This definitely needs some improvement!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think sometimes we're working with one kind of pattern item (where type is user
) and other times a different type of item (where type is wp_block
).
I've started looking into improving the code quality. First PR here - Rename patternBlock to patternPost
I've made another PR that renames the inserter constants to better indicate that they're for inserter items - Code Quality: Improve inserter pattern constants.
I think the goal should be to have a single normalized pattern item data structure (even if the data is sourced from different places) with consistent values, then hopefully we'll be able to tidy up the constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have a full understanding of what the code is doing now.
There's a categoryType
sprinkled across the codebase, but this is purely for routing and can be one of two values, pattern
(for any time of pattern) or wp_template_part
(for template parts). It's confusing that PATTERN_TYPES
is often used to check this in addition to being used to check the pattern item types. The category type values are also unusual with one being a post type and the other not.
I'll follow up with another PR that improves this, but it'll be next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for looking into this, Dan.
What?
This PR adds a
sync status
filter in patterns page.This PR does a couple of more small things:
enumeration
to provide a helping descriptionDesign wise
The old patterns page adds an extra header when we apply one of the
sync status
filter. For now I just added that description in the filter menu item, as a helper text.Testing Instructions
sync status
filters works as expectedsync status
field is not visible in sorting and hideable fields menusScreenshots or screencast
Screen.Recording.2024-01-04.at.8.49.35.AM.mov