diff --git a/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx b/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx index d8e22609a606b..8ca13cd5ce0a4 100644 --- a/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx +++ b/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx @@ -132,15 +132,18 @@ export function ClusterResources({ const canCreate = teleCtx.storeUser.getTokenAccess().create; const [loadClusterError, setLoadClusterError] = useState(''); - const { params, setParams, replaceHistory, pathname } = useUrlFiltering({ - sort: { - fieldName: 'name', - dir: 'ASC', + const { params, setParams, replaceHistory, pathname } = useUrlFiltering( + { + sort: { + fieldName: 'name', + dir: 'ASC', + }, + pinnedOnly: + preferences?.unifiedResourcePreferences?.defaultTab === + DefaultTab.PINNED, }, - includedResourceMode: availabilityFilter?.mode, - pinnedOnly: - preferences?.unifiedResourcePreferences?.defaultTab === DefaultTab.PINNED, - }); + availabilityFilter?.mode + ); const getCurrentClusterPinnedResources = useCallback( () => getClusterPinnedResources(clusterId), diff --git a/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts b/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts index fa2bc1ce175a1..78f4195dd4292 100644 --- a/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts +++ b/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts @@ -21,6 +21,7 @@ import { useLocation } from 'react-router'; import { SortType } from 'design/DataTable/types'; import { makeAdvancedSearchQueryForLabel } from 'shared/utils/advancedSearchLabelQuery'; +import { IncludedResourceMode } from 'shared/components/UnifiedResources'; import history from 'teleport/services/history'; import { ResourceFilter, ResourceLabel } from 'teleport/services/agents'; @@ -38,8 +39,11 @@ export interface UrlFilteringState { search: string; } +type URLResourceFilter = Omit; + export function useUrlFiltering( - initialParams: Partial + initialParams: URLResourceFilter, + includedResourceMode?: IncludedResourceMode ): UrlFilteringState { const { search, pathname } = useLocation(); @@ -66,14 +70,15 @@ export function useUrlFiltering( return { ...initialParamsState, ...urlParams, + includedResourceMode, pinnedOnly: urlParams.pinnedOnly !== undefined ? urlParams.pinnedOnly : initialParamsState.pinnedOnly, }; - }, [search]); + }, [search, includedResourceMode]); - function setParams(newParams: ResourceFilter) { + function setParams(newParams: URLResourceFilter) { replaceHistory( encodeUrlQueryParams({ pathname,