From cd1e66f65644307ffd88a6b8ffcdc4588e1fef43 Mon Sep 17 00:00:00 2001
From: Yassine Bounekhla <56373201+rudream@users.noreply.github.com>
Date: Wed, 4 Dec 2024 11:29:34 -0500
Subject: [PATCH] fix rerendering loop when searching unified resources
(#49744)
---
.../Console/DocumentNodes/DocumentNodes.tsx | 4 ---
.../src/UnifiedResources/UnifiedResources.tsx | 27 +++----------------
.../components/NodeList/NodeList.story.tsx | 2 --
.../src/components/NodeList/NodeList.tsx | 6 -----
.../useServerSideSearchPanel.ts | 27 +------------------
.../hooks/useUrlFiltering/useUrlFiltering.ts | 2 +-
6 files changed, 5 insertions(+), 63 deletions(-)
diff --git a/web/packages/teleport/src/Console/DocumentNodes/DocumentNodes.tsx b/web/packages/teleport/src/Console/DocumentNodes/DocumentNodes.tsx
index f76058c7b3941..93c5691848897 100644
--- a/web/packages/teleport/src/Console/DocumentNodes/DocumentNodes.tsx
+++ b/web/packages/teleport/src/Console/DocumentNodes/DocumentNodes.tsx
@@ -47,8 +47,6 @@ export default function DocumentNodes(props: Props) {
params,
setParams,
setSort,
- pathname,
- replaceHistory,
fetchStatus,
attempt,
createSshSession,
@@ -112,8 +110,6 @@ export default function DocumentNodes(props: Props) {
params={params}
setParams={setParams}
setSort={setSort}
- pathname={pathname}
- replaceHistory={replaceHistory}
onLabelClick={onLabelClick}
/>
)}
diff --git a/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx b/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx
index 8ca13cd5ce0a4..0e2b314736e12 100644
--- a/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx
+++ b/web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx
@@ -46,7 +46,6 @@ import {
import { useNoMinWidth } from 'teleport/Main';
import AgentButtonAdd from 'teleport/components/AgentButtonAdd';
import { SearchResource } from 'teleport/Discover/SelectResource';
-import { encodeUrlQueryParams } from 'teleport/components/hooks/useUrlFiltering';
import Empty, { EmptyStateInfo } from 'teleport/components/Empty';
import { FeatureFlags } from 'teleport/types';
import { UnifiedResource } from 'teleport/services/agents';
@@ -132,7 +131,7 @@ export function ClusterResources({
const canCreate = teleCtx.storeUser.getTokenAccess().create;
const [loadClusterError, setLoadClusterError] = useState('');
- const { params, setParams, replaceHistory, pathname } = useUrlFiltering(
+ const { params, setParams } = useUrlFiltering(
{
sort: {
fieldName: 'name',
@@ -274,22 +273,7 @@ export function ClusterResources({
) || ,
},
}))}
- setParams={newParams => {
- setParams(newParams);
- const isAdvancedSearch = !!newParams.query;
- replaceHistory(
- encodeUrlQueryParams({
- pathname,
- searchString: isAdvancedSearch
- ? newParams.query
- : newParams.search,
- sort: newParams.sort,
- kinds: newParams.kinds,
- isAdvancedSearch,
- pinnedOnly: newParams.pinnedOnly,
- })
- );
- }}
+ setParams={setParams}
Header={
<>
-
+
>
}
diff --git a/web/packages/teleport/src/components/NodeList/NodeList.story.tsx b/web/packages/teleport/src/components/NodeList/NodeList.story.tsx
index b1c821cfb8935..24725b27e557f 100644
--- a/web/packages/teleport/src/components/NodeList/NodeList.story.tsx
+++ b/web/packages/teleport/src/components/NodeList/NodeList.story.tsx
@@ -54,13 +54,11 @@ export const Default = () => {
fetchNext={() => {}}
fetchPrev={() => {}}
fetchStatus={''}
- pathname={''}
onLabelClick={() => {}}
onLoginMenuOpen={() => []}
onLoginSelect={() => {}}
pageIndicators={{ from: 1, to: 2, totalCount: 2 }}
setSort={() => {}}
- replaceHistory={() => {}}
/>
);
};
diff --git a/web/packages/teleport/src/components/NodeList/NodeList.tsx b/web/packages/teleport/src/components/NodeList/NodeList.tsx
index 6a98cb42e8abf..70df17053cfb9 100644
--- a/web/packages/teleport/src/components/NodeList/NodeList.tsx
+++ b/web/packages/teleport/src/components/NodeList/NodeList.tsx
@@ -42,8 +42,6 @@ export function NodeList(props: {
params: ResourceFilter;
setParams: (params: ResourceFilter) => void;
setSort: (sort: SortType) => void;
- pathname: string;
- replaceHistory: (path: string) => void;
onLabelClick: (label: ResourceLabel) => void;
pageIndicators: PageIndicators;
}) {
@@ -58,8 +56,6 @@ export function NodeList(props: {
params,
setParams,
setSort,
- pathname,
- replaceHistory,
onLabelClick,
pageIndicators,
} = props;
@@ -108,8 +104,6 @@ export function NodeList(props: {
pageIndicators={pageIndicators}
params={params}
setParams={setParams}
- pathname={pathname}
- replaceHistory={replaceHistory}
disabled={fetchStatus === 'loading'}
/>
),
diff --git a/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts b/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts
index d2ed418da3e9a..844c55c3141f9 100644
--- a/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts
+++ b/web/packages/teleport/src/components/ServersideSearchPanel/useServerSideSearchPanel.ts
@@ -20,20 +20,14 @@ import { useEffect, useState } from 'react';
import { ResourceFilter } from 'teleport/services/agents';
-import {
- decodeUrlQueryParam,
- encodeUrlQueryParams,
-} from 'teleport/components/hooks/useUrlFiltering';
+import { decodeUrlQueryParam } from 'teleport/components/hooks/useUrlFiltering';
export default function useServersideSearchPanel({
- pathname,
params,
setParams,
- replaceHistory,
}: HookProps) {
const [searchString, setSearchString] = useState('');
const [isAdvancedSearch, setIsAdvancedSearch] = useState(false);
- const [isInitialLoad, setIsInitialLoad] = useState(true);
function onSubmitSearch(e: React.FormEvent) {
e.preventDefault();
@@ -54,16 +48,6 @@ export default function useServersideSearchPanel({
search: searchString,
});
}
- replaceHistory(
- encodeUrlQueryParams({
- pathname,
- searchString,
- sort: params.sort,
- kinds: params.kinds,
- isAdvancedSearch,
- pinnedOnly: params.pinnedOnly,
- })
- );
}
// Populate search bar with existing query
@@ -77,13 +61,6 @@ export default function useServersideSearchPanel({
}
}, [params.query, params.search]);
- useEffect(() => {
- if (!isInitialLoad) {
- submitSearch();
- }
- setIsInitialLoad(false);
- }, [params.sort]);
-
return {
searchString,
setSearchString,
@@ -94,8 +71,6 @@ export default function useServersideSearchPanel({
}
export type HookProps = {
- pathname: string;
- replaceHistory: (path: string) => void;
params: ResourceFilter;
setParams: (params: ResourceFilter) => void;
};
diff --git a/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts b/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts
index 78f4195dd4292..1154feaf9b344 100644
--- a/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts
+++ b/web/packages/teleport/src/components/hooks/useUrlFiltering/useUrlFiltering.ts
@@ -85,7 +85,7 @@ export function useUrlFiltering(
searchString: newParams.search || newParams.query,
sort: newParams.sort,
kinds: newParams.kinds,
- isAdvancedSearch: !!params.query,
+ isAdvancedSearch: !!newParams.query,
pinnedOnly: newParams.pinnedOnly,
})
);