-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: iterate on filter's API #55440
Conversation
Size Change: +72 B (0%) Total Size: 1.66 MB
ℹ️ View Unchanged
|
@@ -133,7 +133,9 @@ export default function PagePages() { | |||
</VStack> | |||
); | |||
}, | |||
filters: [ { id: 'search', type: 'search' } ], | |||
filters: [ |
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 this is the global filter and yet we apply it in title
. This should work in any field right? Maybe it's better to have flag for that and add it in the main component?
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.
Yeah, search
is weird. See related conversation #55270 (comment)
I'm trying to run with the idea we talked about: filters
are part of the fields
API. Though, the more I think about it, the more it makes sense that filters are an independent property of the DataViews
component:
<DataViews
fields={fields}
view={view}
filters={filters}
actions={actions}
...
/>
Though, right now, I'm trying to stretch a bit the idea of filters
as part of the fields
API before giving up on it. One use case that will help clarify this is implementing column filters.
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.
Yeah, I guess will see how the API will evolve. In general a global filter could be part of the API by just having an interface, consumers can abide to. So they would have to map keys(like search
) with their own respective param.
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 thought I'd extract search
from the fields and pass it directly as a prop, as you suggested #55475
label: __( 'All' ), | ||
}, | ||
...( authors?.map( ( { id, name } ) => ( { | ||
filters: [ 'enumeration' ], |
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.
If a filter is enumeration
it requires the elements
prop, right? Why we have them disconnected in the declaration?
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.
The rationale is that the elements
of a field will be used in a few scenarios: filters, when editing the cells, etc.
filters[ f.id ] = { type: f.type }; | ||
field.filters.forEach( ( filter ) => { | ||
let id = field.id; | ||
if ( 'string' === typeof 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.
The logic confuses me a bit and I think it's because of trying to introduce some short hand versions for declaring the filters. For example enumeration
(for author), get's in this if
block and the one below. Why not have a single way of declaring filters for now?
I might be missing something though.
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.
(sorry: hit enter before the comment was ready)
We need to support the following use case: a field can have different filters. For example:
id: 'author',
filters: [
{ id: 'author', type: 'enumeration' }, // This is the IN filter.
{ id: 'author_exclude', type: 'enumeration' }, // This is the NOT IN filter.
]
However, at the moment, we don't have any NOT IN
filter, so the feedback I've got is that providing a filter id that is the same as the field id is repetitive:
id: 'author',
filters: [
{ id: 'author', type: 'enumeration' }
]
That's why it's worth adding it now: most of the fields won't have multiple filters or filters whose id is different from then field id.
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.
Thank you @oandregal!
Not in this PR, but since it's filters related, we could also add the has_published_posts
flag when getting the users.
@ntsekouras nice one. I've prepared #55455 |
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.
Thanks for the PR! Still I'm a bit sceptical with some details like the existence of enumeration
which can be inferred by the presence of elements
, etc.., but the API will be iterated many times again. So let's ship.
Good feedback! What I'm thinking is that the same field can have many types of filters. That's why |
Part of #55083
Follow-up to #55270
What?
Introduces a few changes to the filters:
Before: the
field.elements
property held all values, including the "reset value". After: thefield.elements
property only holds the set of elements and the filter provides the "reset value" by default. The filter can also change it.Testing Instructions
Verify that the filters in the "Site editor > Pages > Manage all pages" experiment work as before.