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(generic-chart-axes): set x-axis if unset and ff is enabled #20107

Merged
merged 5 commits into from
May 19, 2022

Conversation

villebro
Copy link
Member

@villebro villebro commented May 18, 2022

SUMMARY

After enabling the GENERIC_CHART_AXES feature flag, timeseries charts that were created before enabling the flag won't render in Explore due to the required x-axis control being unset. This PR checks if the feature flag is enabled, and sets the default value of the x-axis control to the value of the granularity_sqla flag if the value of the x-axis control is unset.

Due to mixing of JS and TS and inconsistent function calls (e.g. calling a function with null when it was expecting ControlPanelState, all while having logic for when the value was in fact null), some of this code was slightly difficult to follow. I tried to refactor it to be more intuitive, but even minor refactoring seemed to cause weird regressions, so I decided to postpone the refactor to a follow-up PR.

AFTER

Now the timeseries chart that was saved before the feature flag was enabled opens up correctly:

default-after.mp4

BEFORE

Previously, the chart would not render, as the required x-axis control was unset in the chart form data:

default-before.mp4

TESTING INSTRUCTIONS

  1. Create a Chart using the Time - Series Bar Chart V2.
  2. Add it to a Dashboard.
  3. Enable the GENERIC_CHART_AXES FF.
  4. Access the Dashboard - note that the Chart is still working.
  5. Click on "Edit Chart" and notice how the chart no longer renders in Explore
  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@@ -64,8 +64,14 @@ export function getControlsState(state, inputFormData) {
export function applyDefaultFormData(inputFormData) {
const datasourceType = inputFormData.datasource.split('__')[1];
const vizType = inputFormData.viz_type;
const controlsState = getAllControlsState(vizType, datasourceType, null, {
Copy link
Member Author

@villebro villebro May 18, 2022

Choose a reason for hiding this comment

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

This would previously have caused a type error if this file were TypeScript: the signature of getAllControlsState requires the third parameter to be ControlPanelState (here null).

Comment on lines 68 to 69
...inputFormData,
let controlsState = getAllControlsState(vizType, datasourceType, {
form_data: inputFormData,
});
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I'm removing the shallow copy of inputFormData and placing it in the Partial<ControlPanelState> object, as I didn't see any downstream code mutating the object.

@villebro villebro requested a review from kgabryje May 18, 2022 09:53
@villebro villebro force-pushed the villebro/default-x-axis branch 2 times, most recently from 9f3f14b to 011190e Compare May 18, 2022 10:42
@@ -90,7 +85,7 @@ export function applyMapStateToPropsToControl<T = ControlType>(
const { mapStateToProps } = controlState;
let state = { ...controlState };
let { value } = state; // value is current user-input value
if (mapStateToProps && controlPanelState) {
Copy link
Member Author

Choose a reason for hiding this comment

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

we seem to be checking for truthiness of controlPanelState here and in a few other places, despite the signature stating it will always be truthy.

@villebro villebro force-pushed the villebro/default-x-axis branch 3 times, most recently from ece8446 to 1594576 Compare May 18, 2022 16:27
@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #20107 (c9bb5b4) into master (660af40) will decrease coverage by 0.00%.
The diff coverage is 20.00%.

@@            Coverage Diff             @@
##           master   #20107      +/-   ##
==========================================
- Coverage   66.47%   66.46%   -0.01%     
==========================================
  Files        1721     1721              
  Lines       64477    64483       +6     
  Branches     6795     6796       +1     
==========================================
- Hits        42858    42857       -1     
- Misses      19891    19898       +7     
  Partials     1728     1728              
Flag Coverage Δ
javascript 51.34% <20.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...egacy-plugin-chart-event-flow/src/controlPanel.tsx 14.28% <0.00%> (ø)
...tend/plugins/plugin-chart-echarts/src/controls.tsx 56.66% <0.00%> (-17.25%) ⬇️
...ontend/src/explore/controlUtils/getControlState.ts 85.18% <100.00%> (-0.27%) ⬇️
superset-frontend/src/explore/store.js 58.33% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 660af40...c9bb5b4. Read the comment docs.

? control.choices[0][0]
: null,
default: (control: ControlState) =>
control.choices?.[0]?.[0] || null,
Copy link
Member

Choose a reason for hiding this comment

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

How about ensureIsArray(control.choices)[0][0]? I'm actually not sure which one is easier to read, up to you 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't it need to be ensureIsArray(control.choices)[0]?.[0] ? If so, I think the current one is probably ok (mind you, I agree it's pretty ugly 😄 )

Copy link
Member

Choose a reason for hiding this comment

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

Yep! Let's keep it as it is 👍

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

LGTM!

@villebro villebro merged commit 0b3d3dd into apache:master May 19, 2022
philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
…e#20107)

* fix(generic-chart-axes): set x-axis if unset and ff is enabled

* simplify

* simplify

* continue cleanup

* yet more cleanup
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 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 preset-io size/M 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants