-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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(dashboard/native-filters): Hide filters out of scope of current tab #14933
Changes from all commits
51b27bb
91cada4
6f30ad8
28e8c40
1de1426
c2bd1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
import { ParentSize } from '@vx/responsive'; | ||
import Tabs from 'src/components/Tabs'; | ||
import React, { FC, useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import DashboardGrid from 'src/dashboard/containers/DashboardGrid'; | ||
import getLeafComponentIdFromPath from 'src/dashboard/util/getLeafComponentIdFromPath'; | ||
import { DashboardLayout, LayoutItem, RootState } from 'src/dashboard/types'; | ||
|
@@ -30,6 +30,10 @@ import { | |
DASHBOARD_ROOT_DEPTH, | ||
} from 'src/dashboard/util/constants'; | ||
import { getRootLevelTabIndex } from './utils'; | ||
import { Filters } from '../../reducers/types'; | ||
import { getChartIdsInFilterScope } from '../../util/activeDashboardFilters'; | ||
import { findTabsWithChartsInScope } from '../nativeFilters/utils'; | ||
import { setFilterConfiguration } from '../../actions/nativeFilters'; | ||
|
||
type DashboardContainerProps = { | ||
topLevelTabs?: LayoutItem; | ||
|
@@ -39,17 +43,47 @@ const DashboardContainer: FC<DashboardContainerProps> = ({ topLevelTabs }) => { | |
const dashboardLayout = useSelector<RootState, DashboardLayout>( | ||
state => state.dashboardLayout.present, | ||
); | ||
const nativeFilters = useSelector<RootState, Filters>( | ||
state => state.nativeFilters.filters, | ||
); | ||
const directPathToChild = useSelector<RootState, string[]>( | ||
state => state.dashboardState.directPathToChild, | ||
); | ||
const [tabIndex, setTabIndex] = useState( | ||
getRootLevelTabIndex(dashboardLayout, directPathToChild), | ||
); | ||
|
||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
setTabIndex(getRootLevelTabIndex(dashboardLayout, directPathToChild)); | ||
}, [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); | ||
useEffect(() => { | ||
nativeFiltersValues.forEach(filter => { | ||
const filterScope = filter.scope; | ||
const chartsInScope = getChartIdsInFilterScope({ | ||
filterScope: { | ||
scope: filterScope.rootPath, | ||
// @ts-ignore | ||
immune: filterScope.excluded, | ||
}, | ||
}); | ||
const tabsInScope = findTabsWithChartsInScope( | ||
dashboardLayout, | ||
chartsInScope, | ||
); | ||
Object.assign(filter, { | ||
chartsInScope, | ||
tabsInScope: Array.from(tabsInScope), | ||
}); | ||
}); | ||
dispatch(setFilterConfiguration(nativeFiltersValues)); | ||
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. @kgabryje This update function is called every time a user opens a dashboard, even without any change. This is not a correct behavior. |
||
}, [JSON.stringify(scopes), JSON.stringify(dashboardLayout)]); | ||
|
||
const childIds: string[] = topLevelTabs | ||
? topLevelTabs.children | ||
: [DASHBOARD_GRID_ID]; | ||
|
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.
wow, this was unexpected, bycatch fixing and re-enabling a flaky test 😄