From 58395a23fd657df00b61c27cef76392fe112b35d Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Fri, 23 Sep 2022 11:34:49 -0400 Subject: [PATCH] Updates graph searchability - clears search results when invalid - hides search when gated --- src/webviews/apps/plus/graph/GraphWrapper.tsx | 48 ++++++++++++++------------- src/webviews/apps/plus/graph/graph.tsx | 6 +++- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/webviews/apps/plus/graph/GraphWrapper.tsx b/src/webviews/apps/plus/graph/GraphWrapper.tsx index cfaf17a..54b3c71 100644 --- a/src/webviews/apps/plus/graph/GraphWrapper.tsx +++ b/src/webviews/apps/plus/graph/GraphWrapper.tsx @@ -38,7 +38,7 @@ export interface GraphWrapperProps extends State { onColumnChange?: (name: string, settings: GraphColumnConfig) => void; onMissingAvatars?: (emails: { [email: string]: string }) => void; onMoreCommits?: (id?: string) => void; - onSearchCommits?: (search: SearchPattern) => void; + onSearchCommits?: (search: SearchPattern | undefined) => void; onSearchCommitsPromise?: ( search: SearchPattern, options?: { more?: boolean | { limit?: number } }, @@ -351,12 +351,12 @@ export function GraphWrapper({ const detail = e.detail; setSearch(detail); - if (detail.pattern.length < 3) { + const isValid = detail.pattern.length < 3; + if (isValid) { setSearchResultKey(undefined); setSearchResultIds(undefined); - return; } - onSearchCommits?.(detail); + onSearchCommits?.(isValid ? detail : undefined); }; useLayoutEffect(() => { @@ -617,25 +617,27 @@ export function GraphWrapper({ )} {renderAlertContent()} -
-
- handleSearchInput(e as CustomEvent)} - onPrevious={() => handleSearchNavigation(false)} - onNext={() => handleSearchNavigation(true)} - /> - 2)} - more={hasMoreSearchResults} - onPrevious={() => handleSearchNavigation(false)} - onNext={() => handleSearchNavigation(true)} - /> -
-
+ {isAllowed && ( +
+
+ handleSearchInput(e as CustomEvent)} + onPrevious={() => handleSearchNavigation(false)} + onNext={() => handleSearchNavigation(true)} + /> + 2)} + more={hasMoreSearchResults} + onPrevious={() => handleSearchNavigation(false)} + onNext={() => handleSearchNavigation(true)} + /> +
+
+ )}
{ return this.sendCommand(GetMoreCommitsCommandType, { sha: sha }); } - private onSearchCommits(search: SearchPattern) { + private onSearchCommits(search: SearchPattern | undefined) { + if (search == null) { + this.state.searchResults = undefined; + return; + } return this.sendCommand(SearchCommitsCommandType, { search: search }); }