Skip to content

Commit

Permalink
fix(native-filters): chartsInScope were not recalculated in some cases (
Browse files Browse the repository at this point in the history
#15498)

* fix(native-filters): chartsInScope were not recalculated in some cases

* Small refactor
  • Loading branch information
kgabryje committed Jul 1, 2021
1 parent baf42bc commit 0ff3253
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Expand Up @@ -68,36 +68,38 @@ const DashboardContainer: FC<DashboardContainerProps> = ({ topLevelTabs }) => {
}, [getLeafComponentIdFromPath(directPathToChild)]);

// recalculate charts and tabs in scopes of native filters only when a scope or dashboard layout changes
const nativeFiltersValues = Object.values(nativeFilters);
const scopes = nativeFiltersValues.map(filter => filter.scope);
const filterScopes = Object.values(nativeFilters).map(filter => ({
id: filter.id,
scope: filter.scope,
}));
useEffect(() => {
if (
!isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) ||
nativeFiltersValues.length === 0
filterScopes.length === 0
) {
return;
}
const filterScopes = nativeFiltersValues.map(filter => {
const filterScope = filter.scope;
const scopes = filterScopes.map(filterScope => {
const { scope } = filterScope;
const chartsInScope: number[] = getChartIdsInFilterScope({
filterScope: {
scope: filterScope.rootPath,
scope: scope.rootPath,
// @ts-ignore
immune: filterScope.excluded,
immune: scope.excluded,
},
});
const tabsInScope = findTabsWithChartsInScope(
dashboardLayout,
chartsInScope,
);
return {
filterId: filter.id,
filterId: filterScope.id,
tabsInScope: Array.from(tabsInScope),
chartsInScope,
};
});
dispatch(setInScopeStatusOfFilters(filterScopes));
}, [JSON.stringify(scopes), JSON.stringify(dashboardLayout)]);
dispatch(setInScopeStatusOfFilters(scopes));
}, [JSON.stringify(filterScopes), dashboardLayout, dispatch]);

const childIds: string[] = topLevelTabs
? topLevelTabs.children
Expand Down
Expand Up @@ -130,7 +130,7 @@ const FilterFocusHighlight = React.forwardRef(

if (focusedNativeFilterId) {
if (
nativeFilters.filters[focusedNativeFilterId].chartsInScope.includes(
nativeFilters.filters[focusedNativeFilterId].chartsInScope?.includes(
chartId,
)
) {
Expand Down

0 comments on commit 0ff3253

Please sign in to comment.