-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Conversation
@@ -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, { |
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 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
).
...inputFormData, | ||
let controlsState = getAllControlsState(vizType, datasourceType, { | ||
form_data: inputFormData, | ||
}); |
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.
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.
9f3f14b
to
011190e
Compare
@@ -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) { |
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.
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.
ece8446
to
1594576
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
1594576
to
769f9d0
Compare
769f9d0
to
c9bb5b4
Compare
? control.choices[0][0] | ||
: null, | ||
default: (control: ControlState) => | ||
control.choices?.[0]?.[0] || null, |
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.
How about ensureIsArray(control.choices)[0][0]
? I'm actually not sure which one is easier to read, up to you 🙂
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.
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 😄 )
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.
Yep! Let's keep it as it is 👍
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.
LGTM!
…e#20107) * fix(generic-chart-axes): set x-axis if unset and ff is enabled * simplify * simplify * continue cleanup * yet more cleanup
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 thegranularity_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 expectingControlPanelState
, all while having logic for when the value was in factnull
), 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