-
Notifications
You must be signed in to change notification settings - Fork 667
Add extension for list-page filters #1693
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
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mareklibra The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @mareklibra. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
This will need to be updated for #1465 |
| }>; | ||
| }> & { | ||
| /** Function. If "true" is returned then particular item is included in the list. */ | ||
| filter?: (filterGroups: ResourceListFilterGroups, obj: K8sResourceKind) => boolean; |
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.
@mareklibra If I understand correctly, this PR is effectively about extending the listFilters object declared in public/components/factory/list.tsx, which is used to filter List component's rendered data.
The ResourceListPage extension makes Console aware of additional list pages, mapping model to page component to handle listing for that model. The implementation of the entire list page component is provided by the plugin.
Therefore, I think a better approach is to make the List component itself extensible in terms of list filters used.
ListInnerProps already includes filters, this value is used to lookup the corresponding filter impl. within the listFilters object. So I'd suggest doing the following:
Step 1, improve typing of list filters. In the List component:
- add
ListFilterGroupstype (theResourceprefix is not needed) - add type:
type ListFilter = (groups: ListFilterGroups, obj: K8sResourceKind) => boolean; - update
listFiltersobject to useListFiltertype consistently, for example:'name': (filter, obj): ListFilter => fuzzyCaseInsensitive(filter, obj.metadata.name),
- adapt
ListFilterGroupstype if necessary (add properties likevaluesetc.)
Step 2, allow extension of built-in list filters. In the List component:
- in
ListInnerProps, addcustomFilterFuncs?: {[name: string]: ListFilter}; - in
stateToProps- add
customFilterFuncs = {}topropsobject destructuring assignment - change
getFilteredRows(allFilters, data);togetFilteredRows(allFilters, data, customFilterFuncs);
- add
- in
getFilteredRowsconst filter = listFilters[name] || customFilterFuncs[name];
- in
filterPropTypeif (key in listFilters || key in customFilterFuncs || key === 'loadTest') { continue; }
Step 3, use the newly introduced customFilterFuncs prop of List component in VirtualMachinesPage.
This way, we have a List component that supports using custom filters in addition to ones that are built-in.
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.
Note that the List component is deprecated and soon to be removed! We should be making these changes to table.tsx.
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.
Agreed, I'll look into this.
What we actually need here is adding new prop to Table component (successor of List) that allows us to extend the built-in tableFilters.
(This is unrelated to resource list page mapping extension point.)
|
/hold |
| .forEach(rlp => { | ||
| if (listFilters[rlp.properties.model.kind]) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(`List filter for ${rlp.properties.model.kind} already defined, skipping.`); |
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.
Move this check to a unit test.
fyi @vojtechszocs
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, this is exactly the purpose of #1708 - run extension checks as part of yarn test while keeping the runtime browser console log cleaner.
| }); | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.info(`${Object.keys(listFilters).length - baseListCount} new list filters added by plugins.`); |
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.
Is this really necessary?
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 in-line with a former convention to inform users about extensions being applied & any potential conflicts.
With #1708 we no longer need this because
- conflicts are detected via extension checks (test phase)
- reporting on various extensions is meant to be done via
plugin-stats(printed as part of the Console webpack build)
| }>; | ||
| }> & { | ||
| /** Function. If "true" is returned then particular item is included in the list. */ | ||
| filter?: (filterGroups: ResourceListFilterGroups, obj: K8sResourceKind) => boolean; |
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.
Shouldn't the filter be named and allow more than one?
filters?: { [key: string]: (filterGroups: ResourceListFilterGroups, obj: K8sResourceKind) => boolean };
|
Dev console needs a solution here as well in order. I added something very similar as part of this PR: #1721 |
|
@mareklibra are you still working on this? |
|
After talking with @christianvogt I wrote a separate PR #1735. @mareklibra, please have a look at that one. |
|
Replaced by #1735 /close |
|
@spadgett: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
A plug-in can newly register custom list-page filters.
First consumer of this feature is kubevirt for listing virtual machines (#1689).