@@ -23,6 +23,15 @@ import { SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
23
23
import { PREDEFINED_REPOS } from "../data/git-providers/predefined-repos" ;
24
24
import { useConfiguration , useListConfigurations } from "../data/configurations/configuration-queries" ;
25
25
26
+ const isPredefined = ( repo : SuggestedRepository ) : boolean => {
27
+ return PREDEFINED_REPOS . some ( ( predefined ) => predefined . url === repo . url ) && ! repo . configurationId ;
28
+ } ;
29
+
30
+ const resolveIcon = ( contextUrl ?: string ) : string => {
31
+ if ( ! contextUrl ) return RepositorySVG ;
32
+ return PREDEFINED_REPOS . some ( ( repo ) => repo . url === contextUrl ) ? GitpodRepositoryTemplateSVG : RepositorySVG ;
33
+ } ;
34
+
26
35
interface RepositoryFinderProps {
27
36
selectedContextURL ?: string ;
28
37
selectedConfigurationId ?: string ;
@@ -54,7 +63,6 @@ export default function RepositoryFinder({
54
63
searchString,
55
64
excludeConfigurations,
56
65
onlyConfigurations,
57
- showExamples,
58
66
} ) ;
59
67
60
68
// We search for the current context URL in order to have data for the selected suggestion
@@ -112,12 +120,6 @@ export default function RepositoryFinder({
112
120
113
121
const authProviders = useAuthProviderDescriptions ( ) ;
114
122
115
- // This approach creates a memoized Map of the predefined repos,
116
- // which can be more efficient for lookups if we would have a large number of predefined repos
117
- const memoizedPredefinedRepos = useMemo ( ( ) => {
118
- return new Map ( PREDEFINED_REPOS . map ( ( repo ) => [ repo . url , repo ] ) ) ;
119
- } , [ ] ) ;
120
-
121
123
const handleSelectionChange = useCallback (
122
124
( selectedID : string ) => {
123
125
const matchingSuggestion = repos ?. find (
@@ -129,7 +131,7 @@ export default function RepositoryFinder({
129
131
return ;
130
132
}
131
133
132
- const matchingPredefinedRepo = memoizedPredefinedRepos . get ( selectedID ) ;
134
+ const matchingPredefinedRepo = PREDEFINED_REPOS . find ( ( repo ) => repo . url === selectedID ) ;
133
135
if ( matchingPredefinedRepo ) {
134
136
onChange ?.(
135
137
new SuggestedRepository ( {
@@ -142,20 +144,15 @@ export default function RepositoryFinder({
142
144
143
145
onChange ?.( new SuggestedRepository ( { url : selectedID } ) ) ;
144
146
} ,
145
- [ onChange , repos , memoizedPredefinedRepos ] ,
147
+ [ onChange , repos ] ,
146
148
) ;
147
149
148
150
const [ selectedSuggestion , setSelectedSuggestion ] = useState < SuggestedRepository | undefined > ( undefined ) ;
149
151
const [ hasStartedSearching , setHasStartedSearching ] = useState ( false ) ;
150
152
const [ isShowingExamples , setIsShowingExamples ] = useState ( showExamples ) ;
151
153
152
154
type PredefinedRepositoryOptionProps = {
153
- repo : {
154
- url : string ;
155
- repoName : string ;
156
- description : string ;
157
- repoPath : string ;
158
- } ;
155
+ repo : typeof PREDEFINED_REPOS [ number ] ;
159
156
} ;
160
157
161
158
const PredefinedRepositoryOption : FC < PredefinedRepositoryOptionProps > = ( { repo } ) => {
@@ -235,6 +232,10 @@ export default function RepositoryFinder({
235
232
return ;
236
233
}
237
234
235
+ if ( isPredefined ( selectedSuggestion ) ) {
236
+ return PREDEFINED_REPOS . find ( ( repo ) => repo . url === selectedSuggestion . url ) ?. repoName ;
237
+ }
238
+
238
239
if ( ! selectedSuggestion ?. configurationName ) {
239
240
return displayContextUrl ( selectedSuggestion ?. repoName || selectedSuggestion ?. url ) ;
240
241
}
@@ -256,19 +257,22 @@ export default function RepositoryFinder({
256
257
257
258
const getElements = useCallback (
258
259
( searchString : string ) : ComboboxElement [ ] => {
259
- if ( isShowingExamples && searchString . length === 0 && ! onlyConfigurations ) {
260
+ if ( isShowingExamples && ! onlyConfigurations ) {
260
261
return PREDEFINED_REPOS . map ( ( repo ) => ( {
261
262
id : repo . url ,
262
263
element : < PredefinedRepositoryOption repo = { repo } /> ,
263
264
isSelectable : true ,
264
265
} ) ) ;
265
266
}
266
267
267
- const result = repos . map ( ( repo ) => ( {
268
- id : repo . configurationId || repo . url ,
269
- element : < SuggestedRepositoryOption repo = { repo } /> ,
270
- isSelectable : true ,
271
- } ) ) ;
268
+ // We deduplicate predefined repos, because we artificially add them to the list just below
269
+ const result = repos
270
+ . filter ( ( repo ) => ! isPredefined ( repo ) )
271
+ . map ( ( repo ) => ( {
272
+ id : repo . configurationId || repo . url ,
273
+ element : < SuggestedRepositoryOption repo = { repo } /> ,
274
+ isSelectable : true ,
275
+ } ) ) ;
272
276
273
277
if ( ! onlyConfigurations ) {
274
278
// Add predefined repos to end of the list.
@@ -332,11 +336,6 @@ export default function RepositoryFinder({
332
336
[ repos , hasMore , authProviders . data , onlyConfigurations , isShowingExamples ] ,
333
337
) ;
334
338
335
- const resolveIcon = useCallback ( ( contextUrl ?: string ) => {
336
- if ( ! contextUrl ) return RepositorySVG ;
337
- return PREDEFINED_REPOS . some ( ( repo ) => repo . url === contextUrl ) ? GitpodRepositoryTemplateSVG : RepositorySVG ;
338
- } , [ ] ) ;
339
-
340
339
return (
341
340
< Combobox
342
341
getElements = { getElements }
0 commit comments