-
Notifications
You must be signed in to change notification settings - Fork 272
feat(core): remove defaults for time range filter and Metrics #1114
feat(core): remove defaults for time range filter and Metrics #1114
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/superset/superset-ui/CtYkZCBgrMxq32MdfQK994RUhq4p |
Codecov Report
@@ Coverage Diff @@
## master #1114 +/- ##
==========================================
- Coverage 28.98% 28.96% -0.03%
==========================================
Files 462 462
Lines 9262 9269 +7
Branches 1473 1476 +3
==========================================
Hits 2685 2685
- Misses 6367 6374 +7
Partials 210 210
Continue to review full report at Codecov.
|
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 - my only concern is only painting groupby
red, as all three controls are jointly in an error state if at least one value is unpopulated. Would be curious to hear others thoughts on this.
mapStateToProps: (state: ControlPanelState, controlState: ExtraControlProps) => { | ||
const newState: ExtraControlProps = {}; | ||
if (state.datasource) { | ||
const options = state.datasource.columns.filter(c => c.groupby); | ||
if (controlState.includeTime) { | ||
options.unshift(TIME_COLUMN_OPTION); | ||
} | ||
newState.options = options; | ||
} | ||
newState.externalValidationErrors = | ||
ensureIsArray(state.controls.metrics?.value).length === 0 && | ||
ensureIsArray(state.controls.percent_metrics?.value).length === 0 && | ||
ensureIsArray(controlState.value).length === 0 | ||
? ['Group by, metrics or percentage metrics must have a value'] | ||
: []; | ||
return newState; | ||
}, |
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.
I think it would be nice if we did the same check on metrics
and percent_metrics
to paint them red, too.
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.
Done. Check out the new video in PR description
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.
LGT with one minor nit
05401c4
to
22cfbae
Compare
22cfbae
to
edb6df8
Compare
Changes default Time Range from "Last week" to "No filter"
Changes using "COUNT(*)" or other saved metric as a default metric to empty metrics control.
In the case of Table chart, removing default metric was a bit more complex. We use Groupby, Metrics and Percentage Metrics there, and at least one of them must have a value to construct a correct query. However, we can only write control validator that use values of its own control - for instance, we can't create a validator for groupby that checks if metrics or percentage_metrics are empty or not. We also couldn't simply mark all 3 controls as required, as only 1 is really required. The result was that upon creating a table chart, an incorrect request to backend was sent and we displayed an
Empty query?
error. It was quite a bad user experience - a strange error was the first thing that user sees after creating a chart (and what's more, we sent a query that we knew would fail).For that reason, I created something like a "dynamic" validator - we check the state of groupby, metrics and percentage_metrics in
mapStateToProps
field of groupby. If all of those fields are empty, we set an error in a new fieldexternalValidationErrors
. SincemapStateToProps
function is run only when the field changes, we needed a way to trigger it when not only groupby, but also metrics or percentage_metrics fields change. To achieve that, I added a fieldrerender: ['groupby']
to metrics and percentage_metrics. It is later checked insuperset/superset-frontend/src/explore/reducers
- ifrerender
array exists, it triggersgetControlStateFromControlConfig
for each control inrerender
array, which in turn triggersmapStateToProps
of that control. Then,externalValidationErrors
are merged with calculatedvalidationErrors
.Checkout the video to see the result.
Screen.Recording.2021-05-17.at.15.13.27.mov
To test, see apache/superset#14661.
CC: @villebro @junlincc