-
Notifications
You must be signed in to change notification settings - Fork 667
DetailsPage - pass extra resources to PageHeading Actions #1907
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
DetailsPage - pass extra resources to PageHeading Actions #1907
Conversation
|
@spadgett could you please take a look? |
56888f8 to
7ad788e
Compare
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 resourceKeys prop addition seems to be the only effective change here.
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.
Just curious, is resources expected to be an object? (Instead of an array?)
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 could be literary anything
|
Please see #1907 (comment) - I think we can lower the complexity by augmenting & reusing the existing @spadgett FYI, this PR touches core |
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.
KebabAction is actually the "creator" of KebabOption (single) object, while the proposed KebabOptionsCreator is the "creator" of KebabOption object array, reusing the same argument list.
This adds ambiguity as to which one to use, since it's either a list of functions (KebabAction[]) or a single function (KebabOptionsCreator), each of which have different return types (and therefore different signatures), and therefore need to be handled differently.
We can make this simpler, without introducing an alternative type/signature
export type KebabAction = (kind: K8sKind, obj: K8sResourceKind, resources?: any) => KebabOption | KebabOption[];and in PageHeading component
const hasMenuActions = !_.isEmpty(menuActions); // no change here, contract stays the same
// { hasMenuActions && <ActionsMenu actions={menuActions.map(a => a(kindObj, data))} /> }
{ hasMenuActions && <ActionsMenu actions={menuActions.reduce((items: KebabOption[], action: KebabAction) => [
...items,
...(_.castArray(action(kindObj, data))),
], [])} /> }This way, we use a single KebabAction type while supporting multiple outputs, i.e. KebabOption | KebabOption[].
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.
Yup, that would be nicer but it would not work.
The issue with this approach
- the resources are not the actual resources but are computed from the loaded data, please see for example vm status https://github.com/openshift/console/pull/1906/files#diff-e1ea60ed2e820073acdfd59753ed6636R147
- the resources are first accessible in PageHeading (please see DetailsPage)
- we have to compute something from these resources, hence the need for callback
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.
Both KebabAction and KebabOptionsCreator are functions with same arguments
kind: K8sKind, obj: K8sResourceKind, resources?: any
but different return value types, KebabOption vs. KebabOption[].
The argument semantics when calling one function vs. the other one should be the same, right?
_.isFunction(menuActions)
? menuActions(kindObj, data, extraResources) // case A
: menuActions.map(a => a(kindObj, data, extraResources)) // case B- In case A, we run one function and expect
KebabOption[]. - In case B, we run N functions each returning
KebabOptionand map result toKebabOption[]. - The discriminator is the
menuActionsshape, either a single function (case A) or array of functions (case B).
TL;DR
In both PageHeadingProps and DetailsPageProps:
-menuActions?: any[];
+menuActions?: Function[] | KebabMultiAction; // FIXME: should be "KebabAction[] | KebabMultiAction"At the bottom of headings.tsx (this type is unrelated to kebab.tsx, we need it specifically for PageHeading):
export type KebabMultiAction = (kind: K8sKind, obj: K8sResourceKind, resources?: any) => KebabOption[];2298b6d to
86ab445
Compare
|
fixed the nit |
|
/test e2e-aws-console-olm |
|
/test e2e-aws-console-olm |
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.
Both KebabAction and KebabOptionsCreator are functions with same arguments
kind: K8sKind, obj: K8sResourceKind, resources?: any
but different return value types, KebabOption vs. KebabOption[].
The argument semantics when calling one function vs. the other one should be the same, right?
_.isFunction(menuActions)
? menuActions(kindObj, data, extraResources) // case A
: menuActions.map(a => a(kindObj, data, extraResources)) // case B- In case A, we run one function and expect
KebabOption[]. - In case B, we run N functions each returning
KebabOptionand map result toKebabOption[]. - The discriminator is the
menuActionsshape, either a single function (case A) or array of functions (case B).
TL;DR
In both PageHeadingProps and DetailsPageProps:
-menuActions?: any[];
+menuActions?: Function[] | KebabMultiAction; // FIXME: should be "KebabAction[] | KebabMultiAction"At the bottom of headings.tsx (this type is unrelated to kebab.tsx, we need it specifically for PageHeading):
export type KebabMultiAction = (kind: K8sKind, obj: K8sResourceKind, resources?: any) => KebabOption[];|
One more thing, TypeScript allows you to extract & reuse function parameter list, so you don't have to duplicate it: type KebabAction = (kind: K8sKind, obj: K8sResourceKind, resources?: any) => KebabOption;
type KebabMultiAction = (...args: Parameters<KebabAction>) => KebabOption[]; |
86ab445 to
635501b
Compare
good to know, changed I am not convinced that |
Anyway, I'm not good at naming things, it was just a suggestion. |
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.
As suggested in my other comment, I'd prefer to put this type next to React component that actually uses it, i.e. in public/components/utils/headings.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.
ok, moved to headings.tsx
e9cab5c to
b27622d
Compare
|
/test e2e-aws-console-olm |
b27622d to
4fc2850
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: suomiy, vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@suomiy: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
It allows passing of additional resources to actions or to action creator. Needed for #1906