kgabryje opened a new pull request #14661:
URL: https://github.com/apache/superset/pull/14661


   ### SUMMARY
   Requires https://github.com/apache-superset/superset-ui/pull/1114
   
   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 in `superset-ui/plugins/plugin-chart-table/src/controlPanel.tsx`. 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.
   
   
https://user-images.githubusercontent.com/15073128/118467247-ef269480-b703-11eb-936d-24980c31cc65.mov
   
   CC: @villebro @junlincc 
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <img width="1791" alt="Screenshot 2021-05-17 at 10 45 42" 
src="https://user-images.githubusercontent.com/15073128/118467253-f188ee80-b703-11eb-9b75-b87d17204308.png";>
   
   ### TEST PLAN
   Pull https://github.com/apache-superset/superset-ui/pull/1114, link 
superset-ui/core and superset-ui/plugin-chart-table. Then create some new 
charts and verify that metrics is empty by default and time range filter is set 
to "No filter". Create a table chart and verify that at least 1 of Groupby, 
Metrics and Percentage Metrics must have a value to send a query, otherwise a 
warning message should be displayed.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] 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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to