-
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: update filters in view config #55735
Conversation
Size Change: +102 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
author: 2, | ||
status: 'publish, draft' | ||
author: { in: 2 }, | ||
status: { in: 'publish, draft' } |
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 feel a better representation of the filter is something like { operator: 'in', values: 2 }
because in a lot of cases you should be able to switch the operator without switching the values.
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 we need to support multiple operators per field and being ready for logical operators and/or (hierarchicial filters). This is how it looks like in the current approach:
{
filters: {
or: {
date: { before: "20231001", after: "20230101" }, // date published
modified: { before: "20231001", after: "20230101" }, // date modified
}
}
}
It's inspired by linear. It sounds easy enough to do anything we want, even switching values/operators.
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 actually prefer something like
filters: {
operator: 'or',
children: [
{ 'field': 'author', operator: 'startsWith', value: "something" ],
{ 'field': 'author', operator: 'contain', value: "ok" ],
{ 'field2': 'author', operator: 'in', values: ["blabla" ] },
]
}
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.
which could also support this:
filters: {
operator: 'or',
children: [
{ 'field': 'author', operator: 'startsWith', value: "something" ],
{ 'field': 'author', operator: 'contain', value: "ok" ],
{ 'field2': 'author', operator: 'in', values: ["blabla" ] },
{ operator: 'and', children: [
{ 'field': 'status', operator: 'in', values: [ 'draft', 'publish' ] }
] }
]
}
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.
Do you feel strongly about that filters shape? I don't see it being easier to work with for changing operators or anything else (update the value of an existing filter). It's also a lot more verbose. Example:
{
filters: [
{ field: 'author', operator: 'in', value: 2 },
{ field: 'status', operator: 'in', value: 'draft' }
]
}
vs
{
filters: {
author: { in: 'draft' },
status: { in: 2 }
}
}
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 don't feel strongly but I think it's actually easier to work with compared to what you propose:
- A filter object is self sufficient, it contains all the information it needs (the field id, the operator and the values), it's not on multiple levels.
- Filter objets can be combined.
So basically you can pass a filter object to a component and renders it entirely.
In your proposal, it's not clear to me, how you handle: multiple operators for the same field and nested logical operators. Can you translate the example I have here in your format to get more clarity #55735 (comment) ?
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.
In your proposal, it's not clear to me, how you handle: multiple operators for the same field and nested logical operators. Can you translate the example I have here in your format to get more clarity #55735 (comment) ?
I already did right at the beginning of this thread and in the PR description :)
I went ahead and implemented your proposal at 379fae1 Also updated the PR description with the new shape.
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 already did right at the beginning of this thread and in the PR description :)
I see the multiple operators but not the "and" nested within the "or"
a97ba29
to
c813994
Compare
9d92ffc
to
d0a33fb
Compare
Is anything left to address here? Can it be merged? I'm working on some related PRs and would be beneficial to merge this one, so I can publish the others based on |
Part of #55083
What?
This PR updates how filters are stored in the view config.
Before:
After:
Why?
This provides a general syntax that consumers can use to query their datasets.
Testing Instructions
You may need to clear any previously stored dataview entity/CPT. One way to do it is to set
show_ui
totrue
indataviews.php
so they are listed in wp-admin. Then, delete it.