From 563c635d9139b10ac724a201eafc284d108b0a61 Mon Sep 17 00:00:00 2001 From: Brad Harris Date: Wed, 11 Oct 2023 22:31:55 +0000 Subject: [PATCH] simplify --- .../unified-repositories-search-query.ts | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts b/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts index 5e791c0eff5d42..deed38043fd159 100644 --- a/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts +++ b/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts @@ -21,9 +21,10 @@ export const useUnifiedRepositorySearch = ({ searchString, excludeProjects = fal const filteredRepos = useMemo(() => { const repoMap = new Map(); + // combine & flatten suggestions and search results, then merge them into a map + const flattenedRepos = [suggestedQuery.data || [], searchQuery.data || []].flat(); - // Add suggested results to map - for (const repo of suggestedQuery.data || []) { + for (const repo of flattenedRepos) { const key = excludeProjects ? repo.url : `${repo.url}:${repo.projectId || ""}`; const newEntry = { @@ -38,21 +39,6 @@ export const useUnifiedRepositorySearch = ({ searchString, excludeProjects = fal repoMap.set(key, newEntry); } - // Merge the search results into the suggested results - for (const repo of searchQuery.data || []) { - const key = excludeProjects ? repo.url : `${repo.url}:${repo.projectId || ""}`; - - const newEntry = { - ...(repoMap.get(key) || {}), - ...repo, - }; - if (excludeProjects) { - newEntry.repositoryName = newEntry.repositoryName || newEntry.projectName; - newEntry.projectName = undefined; - } - repoMap.set(key, newEntry); - } - return filterRepos(searchString, Array.from(repoMap.values())); }, [excludeProjects, searchQuery.data, searchString, suggestedQuery.data]);