-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,29 @@ import { flatMap, isEmpty } from 'lodash'; | |
import { CHART_TYPE, TAB_TYPE } from './componentTypes'; | ||
import { getChartIdAndColumnFromFilterKey } from './getDashboardFilterKey'; | ||
|
||
function getChartIdsFromTabsNotInScope({ tabs = [], tabsInScope = [] }) { | ||
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); | ||
Comment on lines
+26
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this could probably be done more succinctly with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use So now i try to avoid using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol TIL! I do wonder what would happen if we all used |
||
} | ||
function getTabChildrenScope({ | ||
tabScopes, | ||
parentNodeValue, | ||
forceAggregate = false, | ||
hasChartSiblings = false, | ||
tabChildren = [], | ||
immuneChartSiblings = [], | ||
}) { | ||
// if all sub-tabs are in scope, or forceAggregate = true | ||
|
@@ -38,9 +56,24 @@ function getTabChildrenScope({ | |
([key, { scope }]) => scope && scope.length && key === scope[0], | ||
)) | ||
) { | ||
// get all charts from tabChildren that is not in scope | ||
const immuneChartIdsFromTabsNotInScope = getChartIdsFromTabsNotInScope({ | ||
tabs: tabChildren, | ||
tabsInScope: flatMap(tabScopes, ({ scope }) => scope), | ||
}); | ||
const immuneChartsFromTabsInScope = flatMap( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be called |
||
Object.values(tabScopes), | ||
({ immune }) => immune, | ||
); | ||
const immuneCharts = [ | ||
...new Set([ | ||
...immuneChartIdsFromTabsNotInScope, | ||
...immuneChartsFromTabsInScope, | ||
]), | ||
]; | ||
return { | ||
scope: [parentNodeValue], | ||
immune: flatMap(Object.values(tabScopes), ({ immune }) => immune), | ||
immune: immuneCharts, | ||
}; | ||
} | ||
|
||
|
@@ -96,6 +129,7 @@ function traverse({ currentNode = {}, filterId, checkedChartIds = [] }) { | |
tabScopes, | ||
parentNodeValue: currentValue, | ||
forceAggregate: true, | ||
tabChildren, | ||
}); | ||
return { | ||
scope, | ||
|
@@ -109,6 +143,7 @@ function traverse({ currentNode = {}, filterId, checkedChartIds = [] }) { | |
tabScopes, | ||
parentNodeValue: currentValue, | ||
hasChartSiblings: !isEmpty(chartChildren), | ||
tabChildren, | ||
immuneChartSiblings: chartsImmune, | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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?