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: dashboard filter scope bug #13695

Merged

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented Mar 18, 2021

SUMMARY

This PR is to fix a logic bug in dashboard filter scope.
When calculate filter's scope, if a filter applicable to multiple child nodes (like sub-tab(s), and a chart), we aggregate the filter scope up to their common parent node level, and mark those chart type children that not applicable to the filter as immune. The bug was in the aggregate function, which didn't collect all the immune charts.

TEST PLAN

added new unit test.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

a few comments

// - chart_103
// - chart_104

const nodes3 = [
Copy link
Member

Choose a reason for hiding this comment

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

this const can live in the test case right? since it's not being used by any other tests

Copy link
Author

Choose a reason for hiding this comment

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

yes! fixed.

@@ -22,11 +22,29 @@ import { flatMap, isEmpty } from 'lodash';
import { CHART_TYPE, TAB_TYPE } from './componentTypes';
import { getChartIdAndColumnFromFilterKey } from './getDashboardFilterKey';

function getChartsFromTabsNotInScope({ tabs = [], tabsInScope = [] }) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe getChartIdsFromTabsNotInScope? To clarify that this isn't returning chart objects

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines +26 to +40
const chartsNotInScope = [];
tabs.forEach(({ value: tab, children: tabChildren }) => {
if (tabChildren && !tabsInScope.includes(tab)) {
tabChildren.forEach(({ value: subTab, children: subTabChildren }) => {
if (subTabChildren && !tabsInScope.includes(subTab)) {
chartsNotInScope.push(
...subTabChildren.filter(({ type }) => type === CHART_TYPE),
);
}
});
}
});

// return chartId only
return chartsNotInScope.map(({ value }) => value);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this could probably be done more succinctly with a reduce? I can try to work my way through it as a suggestion if you'd like

Copy link
Author

Choose a reason for hiding this comment

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

I would use reduce a few month ago...Recently @ktmud gave me a code review comment and says reduce is hard to read (for many ppl)...like this thread 🤣
https://twitter.com/jaffathecake/status/1213077702300852224?lang=en

So now i try to avoid using reduce. Sorry i can't find original PR :)

Copy link
Member

Choose a reason for hiding this comment

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

lol TIL!

I do wonder what would happen if we all used reduce more often; maybe it would be as easy to read as map! But this works :D

@codecov
Copy link

codecov bot commented Mar 19, 2021

Codecov Report

Merging #13695 (133f0dd) into master (ebd4a91) will decrease coverage by 4.28%.
The diff coverage is 88.23%.

❗ Current head 133f0dd differs from pull request most recent head 2b74465. Consider uploading reports for the commit 2b74465 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13695      +/-   ##
==========================================
- Coverage   77.39%   73.10%   -4.29%     
==========================================
  Files         927      615     -312     
  Lines       47003    21866   -25137     
  Branches     5806     5719      -87     
==========================================
- Hits        36377    15986   -20391     
+ Misses      10483     5737    -4746     
  Partials      143      143              
Flag Coverage Δ
cypress 56.43% <0.00%> (-0.07%) ⬇️
hive ?
javascript 63.15% <88.23%> (+0.02%) ⬆️
mysql ?
postgres ?
presto ?
python ?
sqlite ?

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

Impacted Files Coverage Δ
...ontend/src/common/hooks/usePrevious/usePrevious.ts 100.00% <ø> (ø)
...dashboard/components/FiltersBadge/DetailsPanel.tsx 67.30% <0.00%> (+2.49%) ⬆️
.../src/dashboard/util/getFilterScopeFromNodesTree.js 93.33% <93.33%> (-0.15%) ⬇️
...set-frontend/src/common/hooks/usePrevious/index.ts 100.00% <100.00%> (ø)
...et-frontend/src/dashboard/components/Dashboard.jsx 85.26% <0.00%> (-4.22%) ⬇️
...set-frontend/src/dashboard/util/getDropPosition.js 90.90% <0.00%> (-1.52%) ⬇️
superset/db_engine_specs/hive.py
superset/queries/schemas.py
superset/dashboards/commands/delete.py
superset/examples/big_data.py
... and 310 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 ebd4a91...2b74465. Read the comment docs.

Copy link
Member

@etr2460 etr2460 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 fix!

Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

I feel I may never understand the filter scope code any more but I trust the test cases!

Just a couple of small comments about variable names.

tabs: tabChildren,
tabsInScope: flatMap(tabScopes, ({ scope }) => scope),
});
const immuneChartsFromTabsInScope = flatMap(
Copy link
Member

Choose a reason for hiding this comment

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

Should this be called immuneChartIdsFromTabsInScope, too?

@@ -22,11 +22,29 @@ import { flatMap, isEmpty } from 'lodash';
import { CHART_TYPE, TAB_TYPE } from './componentTypes';
import { getChartIdAndColumnFromFilterKey } from './getDashboardFilterKey';

function getChartIdsFromTabsNotInScope({ tabs = [], tabsInScope = [] }) {
Copy link
Member

Choose a reason for hiding this comment

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

Hate to make function names even longer, but do you think getImmuneChartIdsFromTabsNotInScope would make this easier to understand?

@graceguo-supercat graceguo-supercat merged commit fa072cd into apache:master Mar 19, 2021
graceguo-supercat pushed a commit to airbnb/superset-fork that referenced this pull request Mar 19, 2021
* fix: dashboard filter scope bug

* fix comments

* fix function/variables name

(cherry picked from commit fa072cd)
@willbarrett
Copy link
Member

LGTM

allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
* fix: dashboard filter scope bug

* fix comments

* fix function/variables name
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.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 size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants