@@ -9,10 +9,10 @@ import { getGitpodService } from "../service/service";
9
9
import { DropDown2 , DropDown2Element , DropDown2SelectedElement } from "./DropDown2" ;
10
10
import RepositorySVG from "../icons/Repository.svg" ;
11
11
import { ReactComponent as RepositoryIcon } from "../icons/RepositoryWithColor.svg" ;
12
- import { useSuggestedRepositories } from "../data/git-providers/suggested-repositories-query" ;
13
12
import { useFeatureFlag } from "../data/featureflag-query" ;
14
13
import { SuggestedRepository } from "@gitpod/gitpod-protocol" ;
15
14
import { MiddleDot } from "./typography/MiddleDot" ;
15
+ import { useUnifiedRepositorySearch } from "../data/git-providers/unified-repositories-search-query" ;
16
16
17
17
// TODO: Remove this once we've fully enabled `includeProjectsOnCreateWorkspace`
18
18
// flag (caches w/ react-query instead of local storage)
@@ -31,10 +31,12 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
31
31
const includeProjectsOnCreateWorkspace = useFeatureFlag ( "includeProjectsOnCreateWorkspace" ) ;
32
32
33
33
const [ suggestedContextURLs , setSuggestedContextURLs ] = useState < string [ ] > ( loadSearchData ( ) ) ;
34
- const { data : suggestedRepos , isLoading } = useSuggestedRepositories ( ) ;
34
+
35
+ const [ searchString , setSearchString ] = useState ( "" ) ;
36
+ const { data : repos , isLoading, isSearching } = useUnifiedRepositorySearch ( { searchString } ) ;
35
37
36
38
// TODO: remove this once includeProjectsOnCreateWorkspace is fully enabled
37
- const suggestedRepoURLs = useMemo ( ( ) => {
39
+ const normalizedRepos = useMemo ( ( ) => {
38
40
// If the flag is disabled continue to use suggestedContextURLs, but convert into SuggestedRepository objects
39
41
if ( ! includeProjectsOnCreateWorkspace ) {
40
42
return suggestedContextURLs . map (
@@ -44,8 +46,9 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
44
46
) ;
45
47
}
46
48
47
- return suggestedRepos || [ ] ;
48
- } , [ suggestedContextURLs , suggestedRepos , includeProjectsOnCreateWorkspace ] ) ;
49
+ // return suggestedRepos || [];
50
+ return repos ;
51
+ } , [ includeProjectsOnCreateWorkspace , repos , suggestedContextURLs ] ) ;
49
52
50
53
// TODO: remove this once includeProjectsOnCreateWorkspace is fully enabled
51
54
useEffect ( ( ) => {
@@ -60,7 +63,7 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
60
63
const handleSelectionChange = useCallback (
61
64
( selectedID : string ) => {
62
65
// selectedId is either projectId or repo url
63
- const matchingSuggestion = suggestedRepos ?. find ( ( repo ) => {
66
+ const matchingSuggestion = normalizedRepos ?. find ( ( repo ) => {
64
67
if ( repo . projectId ) {
65
68
return repo . projectId === selectedID ;
66
69
}
@@ -75,12 +78,12 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
75
78
// If we have no matching suggestion, it's a context URL they typed/pasted in, so just use that as the url
76
79
props . setSelection ( selectedID ) ;
77
80
} ,
78
- [ props , suggestedRepos ] ,
81
+ [ props , normalizedRepos ] ,
79
82
) ;
80
83
81
84
// Resolve the selected context url & project id props to a suggestion entry
82
85
const selectedSuggestion = useMemo ( ( ) => {
83
- let match = suggestedRepos ?. find ( ( repo ) => {
86
+ let match = normalizedRepos ?. find ( ( repo ) => {
84
87
if ( props . selectedProjectID ) {
85
88
return repo . projectId === props . selectedProjectID ;
86
89
}
@@ -105,65 +108,69 @@ export default function RepositoryFinder(props: RepositoryFinderProps) {
105
108
}
106
109
107
110
return match ;
108
- } , [ props . selectedProjectID , props . selectedContextURL , suggestedRepos ] ) ;
111
+ } , [ normalizedRepos , props . selectedContextURL , props . selectedProjectID ] ) ;
109
112
110
113
const getElements = useCallback (
111
114
( searchString : string ) => {
112
- const results = filterRepos ( searchString , suggestedRepoURLs ) ;
113
-
115
+ // TODO: remove once includeProjectsOnCreateWorkspace is fully enabled
114
116
// With the flag off, we only want to show the suggestedContextURLs
115
117
if ( ! includeProjectsOnCreateWorkspace ) {
116
- return results . map (
118
+ // w/o the flag on we still need to filter the repo as the search string changes
119
+ const filteredResults = filterRepos ( searchString , normalizedRepos ) ;
120
+ return filteredResults . map (
117
121
( repo ) =>
118
- ( {
119
- id : repo . url ,
120
- element : (
121
- < div className = "flex-col ml-1 mt-1 flex-grow" >
122
- < div className = "flex" >
123
- < div className = "text-gray-700 dark:text-gray-300 font-semibold" >
124
- { stripOffProtocol ( repo . url ) }
125
- </ div >
126
- < div className = "ml-1 text-gray-400" > { } </ div >
122
+ ( {
123
+ id : repo . url ,
124
+ element : (
125
+ < div className = "flex-col ml-1 mt-1 flex-grow" >
126
+ < div className = "flex" >
127
+ < div className = "text-gray-700 dark:text-gray-300 font-semibold" >
128
+ { stripOffProtocol ( repo . url ) }
127
129
</ div >
128
- < div className = "flex text-xs text-gray-400" > { } </ div >
130
+ < div className = "ml-1 text-gray-400" > { } </ div >
129
131
</ div >
130
- ) ,
131
- isSelectable : true ,
132
- } as DropDown2Element ) ,
132
+ < div className = "flex text-xs text-gray-400" > { } </ div >
133
+ </ div >
134
+ ) ,
135
+ isSelectable : true ,
136
+ } as DropDown2Element ) ,
133
137
) ;
134
138
}
135
139
136
- // Otherwise we show the suggestedRepos
137
- return results . map ( ( repo ) => {
140
+ // Otherwise we show the suggestedRepos (already filtered)
141
+ return normalizedRepos . map ( ( repo ) => {
138
142
return {
139
143
id : repo . projectId || repo . url ,
140
144
element : < SuggestedRepositoryOption repo = { repo } /> ,
141
145
isSelectable : true ,
142
146
} as DropDown2Element ;
143
147
} ) ;
144
148
} ,
145
- [ includeProjectsOnCreateWorkspace , suggestedRepoURLs ] ,
149
+ [ includeProjectsOnCreateWorkspace , normalizedRepos ] ,
146
150
) ;
147
151
148
152
return (
149
153
< DropDown2
150
154
getElements = { getElements }
151
155
expanded = { ! props . selectedContextURL }
156
+ // we use this to track the search string so we can search for repos via the api
152
157
onSelectionChange = { handleSelectionChange }
153
158
disabled = { props . disabled }
154
159
// Only consider the isLoading prop if we're including projects in list
155
160
loading = { isLoading && includeProjectsOnCreateWorkspace }
156
161
searchPlaceholder = "Paste repository URL or type to find suggestions"
162
+ onSearchChange = { setSearchString }
157
163
>
164
+ { /* TODO: add a subtle indicator for the isSearching state */ }
158
165
< DropDown2SelectedElement
159
166
icon = { RepositorySVG }
160
167
htmlTitle = { displayContextUrl ( props . selectedContextURL ) || "Repository" }
161
168
title = {
162
169
< div className = "truncate w-80" >
163
170
{ displayContextUrl (
164
171
selectedSuggestion ?. projectName ||
165
- selectedSuggestion ?. repositoryName ||
166
- selectedSuggestion ?. url ,
172
+ selectedSuggestion ?. repositoryName ||
173
+ selectedSuggestion ?. url ,
167
174
) || "Select a repository" }
168
175
</ div >
169
176
}
@@ -238,6 +245,7 @@ function saveSearchData(searchData: string[]): void {
238
245
}
239
246
}
240
247
248
+ // TODO: remove this and import from unified-repositories-search-query
241
249
function filterRepos ( searchString : string , suggestedRepos : SuggestedRepository [ ] ) {
242
250
let results = suggestedRepos ;
243
251
const normalizedSearchString = searchString . trim ( ) . toLowerCase ( ) ;
@@ -252,7 +260,7 @@ function filterRepos(searchString: string, suggestedRepos: SuggestedRepository[]
252
260
// If the normalizedSearchString is a URL, and it's not present in the proposed results, "artificially" add it here.
253
261
new URL ( normalizedSearchString ) ;
254
262
results . push ( { url : normalizedSearchString } ) ;
255
- } catch { }
263
+ } catch { }
256
264
}
257
265
}
258
266
0 commit comments