-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Improve frontend handling of many projects #20151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fdb6839
36780b9
263b1b3
1480680
b76f4ae
1bb5fa8
6397c19
b711f1b
3357ed7
4c30e6a
bbd8559
1c5a88d
f246051
f30ace1
6124e2a
eea4d0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,17 @@ import { ReactComponent as RepositoryIcon } from "../icons/RepositoryWithColor.s | |
import { ReactComponent as GitpodRepositoryTemplate } from "../icons/GitpodRepositoryTemplate.svg"; | ||
import GitpodRepositoryTemplateSVG from "../icons/GitpodRepositoryTemplate.svg"; | ||
import { MiddleDot } from "./typography/MiddleDot"; | ||
import { useUnifiedRepositorySearch } from "../data/git-providers/unified-repositories-search-query"; | ||
import { | ||
deduplicateAndFilterRepositories, | ||
flattenPagedConfigurations, | ||
useUnifiedRepositorySearch, | ||
} from "../data/git-providers/unified-repositories-search-query"; | ||
import { useAuthProviderDescriptions } from "../data/auth-providers/auth-provider-descriptions-query"; | ||
import { ReactComponent as Exclamation2 } from "../images/exclamation2.svg"; | ||
import { AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; | ||
import { SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb"; | ||
import { PREDEFINED_REPOS } from "../data/git-providers/predefined-repos"; | ||
import { useConfiguration, useListConfigurations } from "../data/configurations/configuration-queries"; | ||
|
||
interface RepositoryFinderProps { | ||
selectedContextURL?: string; | ||
|
@@ -41,7 +46,7 @@ export default function RepositoryFinder({ | |
}: RepositoryFinderProps) { | ||
const [searchString, setSearchString] = useState(""); | ||
const { | ||
data: repos, | ||
data: unifiedRepos, | ||
isLoading, | ||
isSearching, | ||
hasMore, | ||
|
@@ -52,6 +57,59 @@ export default function RepositoryFinder({ | |
showExamples, | ||
}); | ||
|
||
// We search for the current context URL in order to have data for the selected suggestion | ||
const selectedItemSearch = useListConfigurations({ | ||
sortBy: "name", | ||
sortOrder: "desc", | ||
pageSize: 30, | ||
searchTerm: selectedContextURL, | ||
}); | ||
const flattenedSelectedItem = useMemo(() => { | ||
if (excludeConfigurations) { | ||
return []; | ||
} | ||
|
||
const flattened = flattenPagedConfigurations(selectedItemSearch.data); | ||
return flattened.map( | ||
(repo) => | ||
new SuggestedRepository({ | ||
configurationId: repo.id, | ||
configurationName: repo.name, | ||
url: repo.cloneUrl, | ||
}), | ||
); | ||
}, [excludeConfigurations, selectedItemSearch.data]); | ||
|
||
// We get the configuration by ID if one is selected | ||
const selectedConfiguration = useConfiguration(selectedConfigurationId); | ||
const selectedConfigurationSuggestion = useMemo(() => { | ||
if (!selectedConfiguration.data) { | ||
return undefined; | ||
} | ||
|
||
return new SuggestedRepository({ | ||
configurationId: selectedConfiguration.data.id, | ||
configurationName: selectedConfiguration.data.name, | ||
url: selectedConfiguration.data.cloneUrl, | ||
}); | ||
}, [selectedConfiguration.data]); | ||
|
||
const repos = useMemo(() => { | ||
return deduplicateAndFilterRepositories( | ||
searchString, | ||
excludeConfigurations, | ||
onlyConfigurations, | ||
[unifiedRepos, selectedConfigurationSuggestion, flattenedSelectedItem].flat().filter((r) => !!r), | ||
); | ||
}, [ | ||
searchString, | ||
excludeConfigurations, | ||
onlyConfigurations, | ||
selectedConfigurationSuggestion, | ||
flattenedSelectedItem, | ||
unifiedRepos, | ||
]); | ||
|
||
const authProviders = useAuthProviderDescriptions(); | ||
|
||
// This approach creates a memoized Map of the predefined repos, | ||
|
@@ -126,6 +184,11 @@ export default function RepositoryFinder({ | |
return repo.configurationId === selectedConfigurationId; | ||
} | ||
|
||
// todo(ft): normalize this more centrally | ||
if (repo.url.endsWith(".git")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🫧 We have similar code in the backend as well... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this piece is duplicated in so many places. We should try to have this somewhere more centralized. |
||
repo.url = repo.url.slice(0, -4); | ||
} | ||
|
||
return repo.url === selectedContextURL; | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ export const useSuggestedRepositories = ({ excludeConfigurations }: Props) => { | |
const { repositories } = await scmClient.listSuggestedRepositories({ | ||
organizationId: org.id, | ||
excludeConfigurations, | ||
pagination: { | ||
pageSize: 100, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now query at most 100 projects (SCM repos not included) for the initial load in repo selectors. Pagination is not implemented, but also not necessary yet |
||
}, | ||
}); | ||
return repositories; | ||
}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unified repo search has been changed to:
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing this because I was using a feature introduced in 5.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, which feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the Inferred Type Predicates, which lets us do
filter
with!== undefined
without having to use something likerepo is SuggestedRepository
, basically typescript being smart about the fact that when you check something isn't undefined, its type correctly changes.