-
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: iterate on filter's API #55440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. So this is the global filter and yet we apply it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm trying to run with the idea we talked about: <DataViews
fields={fields}
view={view}
filters={filters}
actions={actions}
...
/> Though, right now, I'm trying to stretch a bit the idea of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I'd extract |
||
{ id: 'search', type: 'search', name: __( 'Search' ) }, | ||
], | ||
maxWidth: 400, | ||
sortingFn: 'alphanumeric', | ||
enableHiding: false, | ||
|
@@ -150,27 +152,27 @@ export default function PagePages() { | |
</a> | ||
); | ||
}, | ||
filters: [ { id: 'author', type: 'enumeration' } ], | ||
elements: [ | ||
{ | ||
value: '', | ||
label: __( 'All' ), | ||
}, | ||
...( authors?.map( ( { id, name } ) => ( { | ||
filters: [ 'enumeration' ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a filter is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rationale is that the |
||
elements: | ||
authors?.map( ( { id, name } ) => ( { | ||
value: id, | ||
label: name, | ||
} ) ) || [] ), | ||
], | ||
} ) ) || [], | ||
}, | ||
{ | ||
header: __( 'Status' ), | ||
id: 'status', | ||
getValue: ( { item } ) => | ||
postStatuses[ item.status ] ?? item.status, | ||
filters: [ { type: 'enumeration', id: 'status' } ], | ||
elements: [ | ||
{ label: __( 'All' ), value: 'publish,draft' }, | ||
...( ( postStatuses && | ||
filters: [ | ||
{ | ||
type: 'enumeration', | ||
id: 'status', | ||
resetValue: 'publish,draft', | ||
}, | ||
], | ||
elements: | ||
( postStatuses && | ||
Object.entries( postStatuses ) | ||
.filter( ( [ slug ] ) => | ||
[ 'publish', 'draft' ].includes( slug ) | ||
|
@@ -179,8 +181,7 @@ export default function PagePages() { | |
value: slug, | ||
label: name, | ||
} ) ) ) || | ||
[] ), | ||
], | ||
[], | ||
enableSorting: false, | ||
}, | ||
{ | ||
|
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 thisif
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:
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: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.