Skip to content
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

[Bug/Enhancement] Pass PanelHeader props to the onClick handler of action items #1181

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

manassra
Copy link
Collaborator

PanelHeader has a prop called actionItems which contains a list of actions, each with a id, tooltip, iconComponent, dropDownComponent and an onClick handler:
image

In order for the onClick handler to be able to dispatch actions, it needs access to the PanelHeader's prop, which this PR adds.

@manassra manassra requested review from heshan0131 and ibgreen July 10, 2020 00:01
@@ -297,7 +297,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {
if (item.dropdownComponent) {
showExportDropdown(item.id);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ever have an action item that both shows a dropdown and does something on click? If not, then I can update this to return after this statement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents: either-or is a reasonable assumption, weird to do both.

@manassra manassra requested a review from macrigiuseppe July 10, 2020 00:08
@manassra manassra force-pushed the manassra/pass-props-to-action-item branch from 06a5fb0 to 28dddbd Compare July 10, 2020 00:18
Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice short diff! The downside is you get a lot of comments...

@@ -297,7 +297,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {
if (item.dropdownComponent) {
showExportDropdown(item.id);
}
item.onClick();
item.onClick && item.onClick(this.props);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to pass all the props, or can we just pick the one(s) we need? I generally favor more careful approach (eventually with companion types).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we do that? The action can choose to call any action bound prop, which would be hard to predict here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea for that you will need to add a getProp property to the item and have the items decide which prop to pass to onClick. performance wise, it's not going to matter. if just for the purpose of expose less props, maybe...but people would still need to know what are the props to choose from though, and they can just say give me all the props

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. With regards to getProp, they still have to derive it from all props, which would be the same problem as passing this.props to onClick.

@@ -297,7 +297,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {
if (item.dropdownComponent) {
showExportDropdown(item.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents: either-or is a reasonable assumption, weird to do both.

@@ -297,7 +297,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {
if (item.dropdownComponent) {
showExportDropdown(item.id);
}
item.onClick();
item.onClick && item.onClick(this.props);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe init onClick to noop and drop the if?

@@ -297,7 +297,7 @@ function PanelHeaderFactory(SaveExportDropdown, CloudStorageDropdown) {
if (item.dropdownComponent) {
showExportDropdown(item.id);
}
item.onClick();
item.onClick && item.onClick(this.props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea for that you will need to add a getProp property to the item and have the items decide which prop to pass to onClick. performance wise, it's not going to matter. if just for the purpose of expose less props, maybe...but people would still need to know what are the props to choose from though, and they can just say give me all the props

@manassra manassra merged commit 177efd6 into master Jul 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the manassra/pass-props-to-action-item branch July 10, 2020 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants