-
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
refactor(explore): convert ControlPanelsContainer to typescript #13221
Conversation
export const REMOVE_CONTROL_PANEL_ALERT = 'REMOVE_CONTROL_PANEL_ALERT'; | ||
export function removeControlPanelAlert() { | ||
return { type: REMOVE_CONTROL_PANEL_ALERT }; | ||
} |
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.
@@ -161,29 +178,39 @@ class ControlPanelsContainer extends React.Component { | |||
validationErrors={validationErrors} | |||
actions={actions} | |||
formData={provideFormDataToProps ? formData : null} | |||
datasource={formData?.datasource} |
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.
Remove this exposed datasource
prop from #12609 since it's already available in formData
, plus The typing would not conform with datasource
for DatasourceControl
, which uses the assigns datasource
prop with the whole metadata of a datasource in mapStateToProps
.
yeah, you are getting ready to work on dynamic controls thanks! |
705b500
to
91cd91c
Compare
2679eae
to
53964e5
Compare
Moved debounce delay updates to another PR: #13250 Will rebase once merged. |
53964e5
to
1f4b063
Compare
name: string; | ||
onChange: (timeRange: string) => void; | ||
value?: string; | ||
endpoints?: TimeRangeEndpoints; | ||
datasource?: string; | ||
datasource?: DatasourceMeta; |
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.
Will update the shared control to pass in datasource
object instead of datasource string from form_data.
@@ -270,7 +262,7 @@ class AdhocFilterControl extends React.Component { | |||
optionsForSelect(props) { | |||
const options = [ | |||
...props.columns, | |||
...[...(props.formData.metrics || []), props.formData.metric].map( | |||
...[...(props.selectedMetrics || [])].map( |
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 is used for allowing selecting adhoc metrics in adhoc filters, but it has stopping working:
#13249
The new selectedMetrics
will be added by a superset-ui
PR.
const { value } = event.target as HTMLInputElement; | ||
this.setState({ value }, () => { | ||
this.debouncedOnChange(value); | ||
}); |
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.
Did more refactoring based on: #13211 (comment)
09ebe62
to
b8725fb
Compare
@@ -226,6 +227,7 @@ module.exports = { | |||
'no-mixed-operators': 0, | |||
'no-multi-assign': 0, | |||
'no-multi-spaces': 0, | |||
'no-nested-ternary': 0, |
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.
Disabling as we have seen fairly often nested-ternary in TypeScript extends
. It should not be that hard to understand the code with prettier
's help.
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.
nested ternary was used in this code:
const controlName =
typeof item === 'string'
? item
: item && 'name' in item
? item.name
: 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.
Yeah, I'm a fan of nested ternaries when used sparingly. however, couldn't this be simplified to:
const controlName =
typeof item === 'string'
? item
: (item || {})?.name ?? null;
or something like that?
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.
Not sure if that's really cleaner, but it doesn't use a nested ternary
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.
2dd459a
to
71a3b5d
Compare
Codecov Report
@@ Coverage Diff @@
## master #13221 +/- ##
==========================================
- Coverage 77.12% 72.73% -4.40%
==========================================
Files 894 595 -299
Lines 45672 21247 -24425
Branches 5492 5490 -2
==========================================
- Hits 35223 15453 -19770
+ Misses 10325 5668 -4657
- Partials 124 126 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
718ff04
to
a2630e1
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.
@villebro @pkdotson @zhaoyongjie @kgabryje could you take a look at this when you have time?
Thanks!
@@ -28,7 +28,7 @@ describe('Visualization > Pivot Table', () => { | |||
adhoc_filters: [], | |||
groupby: ['name'], | |||
columns: ['state'], | |||
row_limit: 50000, | |||
row_limit: 5000, |
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.
Reduce row limit to speed up the test (a little bit)
// for direct column select controls | ||
controlState.valueKey === 'column_name' || | ||
// for all other controls | ||
'columns' in controlState |
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.
Instead of check control types, I check whether the control uses column select.
controls: explore.controls, | ||
exploreState: explore, | ||
}; | ||
} |
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.
Move to inline function to use inferred types.
@@ -69,12 +69,6 @@ export default class CollectionControl extends React.Component { | |||
this.onAdd = this.onAdd.bind(this); | |||
} | |||
|
|||
componentDidUpdate(prevProps) { | |||
if (prevProps.datasource.name !== this.props.datasource.name) { |
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 one does not work anyway (i.e. change datasource will not reset Time-series Table columns, and the filters collection in FilterBox) since previously props.datasource
is passed as a string.
I don't plan to implement this reset because these control values should not be reset when changing datasource.
frame === 'No filter' | ||
guessedFrame === 'Common' || | ||
guessedFrame === 'Calendar' || | ||
guessedFrame === 'No filter' |
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.
Always use guessedFrame
to tooltip and actual time range display because when passing in a new value
and the popover is not open, the current frame may be inconsistent with the actual value.
This makes sure Last week
is always displayed in the pill instead of tooltip.
@@ -123,9 +123,6 @@ export default class AdhocMetricEditPopover extends React.PureComponent { | |||
adhocMetricLabel: this.state.adhocMetric?.getDefaultLabel(), | |||
}); | |||
} | |||
if (prevProps.datasource !== this.props.datasource) { | |||
this.props.onChange(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.
Clean up the datasource
prop from adhoc metric popovers as they don't seem to affect the ability of the controls to reset values when changing datasource.
@pkdotson do you remember what was these for when you added them?
@@ -55,12 +55,7 @@ export const HAVING_OPERATORS = [ | |||
OPERATORS['>='], | |||
OPERATORS['<='], | |||
]; | |||
export const MULTI_OPERATORS = new Set([ | |||
OPERATORS.in, |
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.
OPERATORS.in
and OPERATORS['not in']
are undefined
, as identified by converting to typescript, so cleaning them up. AchocFilter
already always convert the operator into uppercase.
formData[controlName] = control.value; | ||
}); | ||
return formData; | ||
} |
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.
Split functions in controlUtils
to TypeScript one by one...
action.datasource.type !== state.datasource.type | ||
) { | ||
newFormData.time_range = DEFAULT_TIME_RANGE; | ||
} |
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.
Instead of checking control types, I now check whether a control depends on datasource columns.
} | ||
}); | ||
} | ||
} |
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.
Moved the resetting logic to reducers as each of these setControlValue
call here will cause another re-rendering.
9efcc03
to
cb1dd58
Compare
Close to re-trigger full CI to fix test coverage report. |
Good call. I did a sweep and managed to find one place that I could optimize: caf3b60 |
caf3b60
to
430874c
Compare
@ktmud I found this typescript error: It's happening because I was going to fix it, but I was afraid of not having all the necessary context since this touches Shouldn't CI catch this? |
@michael-s-molina Did you run I'm pretty sure this was updated here: https://github.com/apache-superset/superset-ui/pull/962/files#diff-efc1b32a915b3738e7689b97eab6576ac7b206bc95d46e1ecaac6c8646287a65R27 The |
@ktmud Strangely I ran |
SUMMARY
Convert ControlPanelsContainer and some other related components to TypeScript.
Big refactoring are coming to chart controls and the Explore page, in order to support reading query results in controls, which is needed for things like ad-hoc column formatting in table chart.
Also did some refactoring to redo #12782 and #12609 . See comments for details.
Upgraded
superset-ui
to v0.17.11 to bring in:apache-superset/superset-ui#962
apache-superset/superset-ui#969
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
There should be no visible change.
TEST PLAN
CI and manual testing the chart control area.
ADDITIONAL INFORMATION