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

fix: optimize mapStateToProps for chart controls #10264

Merged
merged 4 commits into from Jul 9, 2020

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Jul 9, 2020

SUMMARY

This is a bug fix for "EXPLORE" button in SQL query results.

The query mode control for table chart relies on controls prop in control panel state to determine what's the actual query mode, so controls state mapping for chart controls must be initialized before mapStateToProps is called.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

When clicking on the "EXPLORE" button in SQL Lab:

Before:

Query is successful, but query mode is incorrectly set to "Aggregate":

After:

Query successfully switches to "Raw" mode:

TEST PLAN

Updated unit test + manual testing

ADDITIONAL INFORMATION

cc @kristw @serenajiang

@ktmud ktmud closed this Jul 9, 2020
@ktmud ktmud reopened this Jul 9, 2020
Comment on lines 137 to 139
if (controlPanelState.controls || !controlPanelState.isInitializing) {
applyMapStateToPropsToControl(controlState, controlPanelState);
}
Copy link
Member

Choose a reason for hiding this comment

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

you could make this something like:

const controlStateWithControlPanelProps = controlPanelState.controls || !controlPanelState.isInitializing 
  ? applyMapStateToPropsToControl(controlState, controlPanelState)
  : controlState;

and then use it below. With that context, it should be fairly clear that we want to continue to use the latest created state variable. especially since the function isn't massive, I don't think people would mistakenly use the old state in this function

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to use let. Not a big fan of having many variables. Always struggled with variable names and it quickly becomes confusing.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for the changes!

const slice = bootstrappedState.slice;
const sliceName = slice ? slice.slice_name : null;
// apply initial mapStateToProps for all controls, must execute AFTER
// bootstrappedState has initialized `controls`. Order of execution is not
Copy link

Choose a reason for hiding this comment

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

why order of execution is not guaranteed? it looks like a regular for loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought Object.keys(...) does not guarantee property order? Even if it does it's probably not a good idea to rely on it anyway.

@ktmud ktmud merged commit e94c980 into apache:master Jul 9, 2020
@ktmud ktmud deleted the explore-sql-result branch July 9, 2020 07:33
serenajiang pushed a commit to airbnb/superset-fork that referenced this pull request Jul 9, 2020
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants