Skip to content
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: Pivot Table Conditional Formatting Doesn't Show All Options #19071

Conversation

diegomedina248
Copy link
Contributor

SUMMARY

The Pivot Table conditional formatting was not updating the metric list when changes where made.
The problem is that the conditional formatting only executed the mapStateToProps function once, on startup, and thus, changing the information on the metrics without triggering a rerender in any other way caused the panel to have obsolete data.

This pointed to a brittle way the panel were recomputing their properties: It was only done if the number of arguments of the mapStateToProps equals to three.
Instead, this PR adds a function shouldMapStateToProps to the panel config interface to allow controls to request updates if they need to.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen.Recording.2022-03-08.at.17.24.59.mov

TESTING INSTRUCTIONS

  1. Create a pivot table
  2. Add one metric
  3. In Customize, select that metric for conditional formatting
  4. Add a second metric
  5. Try to select the metric in conditional formatting

Ensure the second added metric displays in the conditional formatting panel.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #19071 (6ed0c68) into master (f9c7405) will increase coverage by 0.00%.
The diff coverage is 44.44%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #19071   +/-   ##
=======================================
  Coverage   66.50%   66.50%           
=======================================
  Files        1642     1643    +1     
  Lines       63442    63466   +24     
  Branches     6439     6450   +11     
=======================================
+ Hits        42191    42207   +16     
- Misses      19582    19589    +7     
- Partials     1669     1670    +1     
Flag Coverage Δ
javascript 51.24% <44.44%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...d/packages/superset-ui-chart-controls/src/types.ts 100.00% <ø> (ø)
...ns/plugin-chart-echarts/src/Radar/controlPanel.tsx 30.00% <0.00%> (-3.34%) ⬇️
...ugin-chart-pivot-table/src/plugin/controlPanel.tsx 12.50% <ø> (ø)
...nd/plugins/plugin-chart-table/src/controlPanel.tsx 16.17% <0.00%> (-0.50%) ⬇️
.../src/explore/components/ControlPanelsContainer.tsx 77.77% <66.66%> (+0.11%) ⬆️
...frontend/src/SqlLab/components/SqlEditor/index.jsx 50.84% <0.00%> (-0.60%) ⬇️
superset-frontend/src/views/CRUD/hooks.ts 47.15% <0.00%> (ø)
...perset-frontend/src/addSlice/AddSliceContainer.tsx 61.76% <0.00%> (ø)
...rontend/src/visualizations/TimeTable/TimeTable.jsx 0.00% <0.00%> (ø)
superset-frontend/src/utils/sortNumericValues.ts 100.00% <0.00%> (ø)
... and 1 more

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 f9c7405...6ed0c68. Read the comment docs.

@rusackas rusackas requested a review from kgabryje March 9, 2022 00:06
Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diegomedina248 Thanks for contribution! The problem with shouldMapStateToProps always returning True is that we'll run mapStateToProps on every change. We actually only need to update the conditional formatting component when metrics change. We can achieve that by using rerender field, like so:

--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
@@ -66,6 +66,7 @@ const config: ControlPanelConfig = {
             config: {
               ...sharedControls.metrics,
               validators: [validateNonEmpty],
+              rerender: ['conditional_formatting'],
             },
           },
         ],

That will trigger rerendering of conditional_formatting each time metrics value changes. You can check out how that works in Table chart - at least 1 of the fields metrics, groupby, percentage_metrics must have a value and they all rerender each other to determine if error message should be displayed.

I do agree that determining if mapStateToProps should be run based on number of arguments is very brittle and needs to be improved. In my opinion your approach handles it well, I think we should keep it! But in the case of pivot table it's not necessary and rerendering when metrics change seems to be sufficient.

@diegomedina248
Copy link
Contributor Author

@kgabryje thanks for that clarification & explanation.
Updated the PR to address it.

@@ -108,6 +108,9 @@ const all_columns: typeof sharedControls.groupby = {
optionRenderer: c => <ColumnOption showType column={c} />,
valueRenderer: c => <ColumnOption column={c} />,
valueKey: 'column_name',
shouldMapStateToProps() {
Copy link
Member

@kgabryje kgabryje Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it here and in dnd_all_columns and percent_metrics? mapStateToProps has only 2 arguments, so we do not need to run it every time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're correct, treated the object as two params

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, lgtm!

@rusackas rusackas merged commit 0e0bece into apache:master Mar 9, 2022
villebro pushed a commit that referenced this pull request Apr 3, 2022
)

* fix: Pivot Table Conditional Formatting Doesn't Show All Options

* PR comments

* PR comments

(cherry picked from commit 0e0bece)
@mistercrunch mistercrunch added 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels lts-v1 size/M 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants