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

feat(native-filters): Hide filters which don't affect any visible charts #15063

Merged
merged 6 commits into from
Jun 11, 2021

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Jun 9, 2021

SUMMARY

This PR changes the behaviour of hiding native filters out of scope, which was originally implemented in #14933.
Before, we considered filters to be "in scope" if they were placed in the last clicked tab. This approach presented several issues. The most significant issue was that in case of dashboards without top level tabs, there was no way to have charts unattached to any tab to be considered in scope once some row level tab had been clicked (as the scope was set only by clicking tabs).
The new proposal, implemented in this PR, is that we consider all visible charts to be "in scope". That means that in order to determine if a filter is in scope, we no longer check only the last clicked tab, but the whole tabs tree of the dashboard. For details, see attached recordings of the new native filters behaviour presented on dashboards with (the first video) and without (second video) top level tabs

Potential improvement: rename "Filters out of scope" section or add a label for filters in scope to make it clear for the user why specific filters are out of scope. If you have any ideas, I'm open for suggestions 🙂

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before: see #14933
After:
https://user-images.githubusercontent.com/15073128/121371437-d6de1a00-c93d-11eb-9776-5ba53f35ab33.mov
https://user-images.githubusercontent.com/15073128/121371703-0ab93f80-c93e-11eb-8b92-3d216a049450.mov

TESTING INSTRUCTIONS

  1. Set DASHBOARD_NATIVE_FILTERS feature flag to True
  2. Create dashboards with tabs (top level and/or row level)
  3. Add some native filters, go crazy with their scopes
  4. Verify that filters that don't have any visible charts in scope are moved to "Out of scope" panel
  5. Edit native filters's scopes and dashboard's layout (add some new tabs or charts) and verify that the feature "picked up" the changes

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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

CC: @junlincc @villebro @michael-s-molina

@kgabryje kgabryje requested a review from villebro June 9, 2021 14:20
@kgabryje kgabryje requested a review from zhaoyongjie June 9, 2021 14:25
@kgabryje kgabryje closed this Jun 9, 2021
@kgabryje kgabryje reopened this Jun 9, 2021
@junlincc
Copy link
Member

junlincc commented Jun 9, 2021

/testenv up DASHBOARD_NATIVE_FILTERS = True

@junlincc junlincc added the dashboard:native-filters Related to the native filters of the Dashboard label Jun 9, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 9, 2021

@junlincc Ephemeral environment spinning up at http://34.213.155.134:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

// Filter is in scope if any of it's charts is visible.
// Chart is visible if it's placed in an active tab tree or if it's not attached to any tab.
// Chart is in an active tab tree if all of it's ancestors of type TAB are active
const isFilterInScope = cascadeFilters[index].chartsInScope?.some(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isFilterInScope = cascadeFilters[index].chartsInScope?.some(
const isFilterInScope = filter.chartsInScope?.some(

Copy link
Member Author

Choose a reason for hiding this comment

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

Riiiight 🤦 Done

const tabParents = chartLayoutItem?.parents.filter(
(parent: string) => dashboardLayout[parent].type === TAB_TYPE,
);
return (
Copy link
Member

Choose a reason for hiding this comment

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

I'd love to see this logic moved out of components into a library of redux selectors, such as selectActiveTabbedCharts(), selectFiltersInScope(), selectChartsInScopeByFilter() etc. That way the state logic will be in a central location and easier to manage.

It will also allow calculations to be memoized between different components. This is a triple-nested loop, which could become nasty on a dashboard with a lot of charts, tabs, and filters with significant numbers of charts in scope. And I know similar loops are running elsewhere in the app.

Copy link
Member Author

@kgabryje kgabryje Jun 11, 2021

Choose a reason for hiding this comment

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

I split some of that logic and moved it to superset/superset-frontend/src/dashboard/components/nativeFilters/state.ts, but I'm not sure if that's exactly what you expected. Can you take another look?

@kgabryje
Copy link
Member Author

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=True

@github-actions
Copy link
Contributor

@kgabryje Ephemeral environment spinning up at http://54.203.224.120:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@codecov
Copy link

codecov bot commented Jun 11, 2021

Codecov Report

Merging #15063 (85ebda2) into master (3456dd5) will decrease coverage by 0.00%.
The diff coverage is 66.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15063      +/-   ##
==========================================
- Coverage   77.54%   77.53%   -0.01%     
==========================================
  Files         967      967              
  Lines       49759    49787      +28     
  Branches     6352     6358       +6     
==========================================
+ Hits        38585    38602      +17     
- Misses      10972    10983      +11     
  Partials      202      202              
Flag Coverage Δ
javascript 72.43% <66.03%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
superset-frontend/src/dashboard/actions/hydrate.js 1.72% <ø> (ø)
...nd/src/dashboard/containers/DashboardComponent.jsx 92.30% <ø> (ø)
...-frontend/src/dashboard/reducers/dashboardState.js 73.33% <0.00%> (ø)
...t-frontend/src/dashboard/actions/dashboardState.js 28.65% <33.33%> (ø)
...nd/src/dashboard/components/nativeFilters/state.ts 75.00% <64.10%> (-25.00%) ⬇️
...d/src/dashboard/components/gridComponents/Tabs.jsx 86.79% <85.71%> (-0.71%) ⬇️
...ilters/FilterBar/FilterControls/FilterControls.tsx 80.00% <100.00%> (+2.41%) ⬆️

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 3456dd5...85ebda2. Read the comment docs.

Copy link
Member

@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

@kgabryje kgabryje merged commit 51f0d4f into apache:master Jun 11, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
…rts (apache#15063)

* feat(native-filters): Hide filters which don't affect any visible charts

* Fix lint errors

* Add comments

* Code review fix

* Fix tests

* Refactor logic in FilterControls
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
…rts (apache#15063)

* feat(native-filters): Hide filters which don't affect any visible charts

* Fix lint errors

* Add comments

* Code review fix

* Fix tests

* Refactor logic in FilterControls
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
…rts (apache#15063)

* feat(native-filters): Hide filters which don't affect any visible charts

* Fix lint errors

* Add comments

* Code review fix

* Fix tests

* Refactor logic in FilterControls
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 12, 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 dashboard:native-filters Related to the native filters of the Dashboard size/L 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants