Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat(core): remove defaults for time range filter and Metrics #1114

Merged
merged 4 commits into from
May 25, 2021

Conversation

kgabryje
Copy link
Contributor

@kgabryje kgabryje commented May 17, 2021

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 field externalValidationErrors. Since mapStateToProps 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 field rerender: ['groupby'] to metrics and percentage_metrics. It is later checked in superset/superset-frontend/src/explore/reducers - if rerender array exists, it triggers getControlStateFromControlConfig for each control in rerender array, which in turn triggers mapStateToProps of that control. Then, externalValidationErrors are merged with calculated validationErrors.
Checkout the video to see the result.

Screen.Recording.2021-05-17.at.15.13.27.mov

Screenshot 2021-05-17 at 10 45 42

To test, see apache/superset#14661.
CC: @villebro @junlincc

@kgabryje kgabryje requested a review from a team as a code owner May 17, 2021 09:31
@vercel
Copy link

vercel bot commented May 17, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/CtYkZCBgrMxq32MdfQK994RUhq4p
✅ Preview: https://superset-ui-git-fork-kgabryje-feat-no-default-values-superset.vercel.app

@codecov
Copy link

codecov bot commented May 17, 2021

Codecov Report

Merging #1114 (edb6df8) into master (5c48c09) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
...chart-controls/src/shared-controls/dndControls.tsx 40.00% <ø> (+3.63%) ⬆️
...et-ui-chart-controls/src/shared-controls/index.tsx 37.23% <ø> (+1.15%) ⬆️
plugins/plugin-chart-table/src/controlPanel.tsx 0.00% <0.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 5c48c09...edb6df8. Read the comment docs.

Copy link
Contributor

@villebro villebro left a 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.

Comment on lines 143 to 195
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;
},
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@villebro villebro left a 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

@kgabryje kgabryje force-pushed the feat/no-default-values branch from 22cfbae to edb6df8 Compare May 25, 2021 10:36
@kgabryje kgabryje merged commit 36ce97e into apache-superset:master May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants