diff --git a/components/dashboard/src/components/RepositoryFinder.tsx b/components/dashboard/src/components/RepositoryFinder.tsx index 3fa6ca2486abe8..1d6efc6cf782de 100644 --- a/components/dashboard/src/components/RepositoryFinder.tsx +++ b/components/dashboard/src/components/RepositoryFinder.tsx @@ -8,16 +8,16 @@ import { FC, useCallback, useMemo, useState } from "react"; import { Combobox, ComboboxElement, ComboboxSelectedItem } from "./podkit/combobox/Combobox"; import RepositorySVG from "../icons/Repository.svg"; import { ReactComponent as RepositoryIcon } from "../icons/RepositoryWithColor.svg"; -import { SuggestedRepository } from "@gitpod/gitpod-protocol"; import { MiddleDot } from "./typography/MiddleDot"; import { 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"; interface RepositoryFinderProps { selectedContextURL?: string; - selectedProjectID?: string; + selectedConfigurationId?: string; disabled?: boolean; expanded?: boolean; excludeProjects?: boolean; @@ -26,7 +26,7 @@ interface RepositoryFinderProps { export default function RepositoryFinder({ selectedContextURL, - selectedProjectID, + selectedConfigurationId: selectedProjectID, disabled, expanded, excludeProjects = false, @@ -46,8 +46,8 @@ export default function RepositoryFinder({ (selectedID: string) => { // selectedId is either projectId or repo url const matchingSuggestion = repos?.find((repo) => { - if (repo.projectId) { - return repo.projectId === selectedID; + if (repo.configurationId) { + return repo.configurationId === selectedID; } return repo.url === selectedID; @@ -57,9 +57,11 @@ export default function RepositoryFinder({ return; } - onChange?.({ - url: selectedID, - }); + onChange?.( + new SuggestedRepository({ + url: selectedID, + }), + ); }, [onChange, repos], ); @@ -68,7 +70,7 @@ export default function RepositoryFinder({ const selectedSuggestion = useMemo(() => { let match = repos?.find((repo) => { if (selectedProjectID) { - return repo.projectId === selectedProjectID; + return repo.configurationId === selectedProjectID; } return repo.url === selectedContextURL; @@ -76,18 +78,15 @@ export default function RepositoryFinder({ // If no match, it's a context url that was typed/pasted in, so treat it like a suggestion w/ just a url if (!match && selectedContextURL) { - match = { + match = new SuggestedRepository({ url: selectedContextURL, - }; + }); } // This means we found a matching project, but the context url is different // user may be using a pr or branch url, so we want to make sure and use that w/ the matching project - if (match && match.projectId && selectedContextURL && match.url !== selectedContextURL) { - match = { - ...match, - url: selectedContextURL, - }; + if (match && match.configurationId && selectedContextURL && match.url !== selectedContextURL) { + match.url = selectedContextURL; } return match; @@ -99,7 +98,7 @@ export default function RepositoryFinder({ (searchString: string) => { const result = repos.map((repo) => { return { - id: repo.projectId || repo.url, + id: repo.configurationId || repo.url, element: , isSelectable: true, } as ComboboxElement; @@ -169,15 +168,15 @@ export default function RepositoryFinder({ title={
{displayContextUrl( - selectedSuggestion?.projectName || - selectedSuggestion?.repositoryName || + selectedSuggestion?.configurationName || + selectedSuggestion?.repoName || selectedSuggestion?.url, ) || "Select a repository"}
} subtitle={ // Only show the url if we have a project or repo name, otherwise it's redundant w/ the title - selectedSuggestion?.projectName || selectedSuggestion?.repositoryName + selectedSuggestion?.configurationName || selectedSuggestion?.repoName ? displayContextUrl(selectedSuggestion?.url) : undefined } @@ -191,13 +190,13 @@ type SuggestedRepositoryOptionProps = { repo: SuggestedRepository; }; const SuggestedRepositoryOption: FC = ({ repo }) => { - const name = repo.projectName || repo.repositoryName; + const name = repo.configurationName || repo.repoName; const repoPath = stripOffProtocol(repo.url); return (
diff --git a/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts b/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts index d56e6a728db82b..828e6a683f80a8 100644 --- a/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts +++ b/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts @@ -4,23 +4,23 @@ * See License.AGPL.txt in the project root for license information. */ -import { SuggestedRepository } from "@gitpod/gitpod-protocol"; +import { SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb"; import { deduplicateAndFilterRepositories } from "./unified-repositories-search-query"; function repo(name: string, project?: string): SuggestedRepository { - return { + return new SuggestedRepository({ url: `http://github.com/efu3he4rf/${name}`, - repositoryName: name, - projectName: project, - projectId: project, - }; + repoName: name, + configurationName: project, + configurationId: project, + }); } test("it should deduplicate non-project entries", () => { const suggestedRepos: SuggestedRepository[] = [repo("foo"), repo("foo2"), repo("foo", "project-foo")]; const deduplicated = deduplicateAndFilterRepositories("foo", false, suggestedRepos); expect(deduplicated.length).toEqual(2); - expect(deduplicated[1].projectName).toEqual("project-foo"); + expect(deduplicated[1].configurationName).toEqual("project-foo"); }); test("it should not deduplicate project entries", () => { @@ -41,8 +41,8 @@ test("it should exclude project entries", () => { ]; const deduplicated = deduplicateAndFilterRepositories("foo", true, suggestedRepos); expect(deduplicated.length).toEqual(2); - expect(deduplicated[0].repositoryName).toEqual("foo"); - expect(deduplicated[1].repositoryName).toEqual("foo2"); + expect(deduplicated[0].repoName).toEqual("foo"); + expect(deduplicated[1].repoName).toEqual("foo2"); }); test("it should match entries in url as well as poject name", () => { @@ -72,10 +72,10 @@ test("it keeps the order", () => { repo("bar", "FOOtest"), ]; const deduplicated = deduplicateAndFilterRepositories("foot", false, suggestedRepos); - expect(deduplicated[0].repositoryName).toEqual("somefOOtest"); - expect(deduplicated[1].repositoryName).toEqual("Footest"); - expect(deduplicated[2].projectName).toEqual("someFootest"); - expect(deduplicated[3].projectName).toEqual("FOOtest"); + expect(deduplicated[0].repoName).toEqual("somefOOtest"); + expect(deduplicated[1].repoName).toEqual("Footest"); + expect(deduplicated[2].configurationName).toEqual("someFootest"); + expect(deduplicated[3].configurationName).toEqual("FOOtest"); }); test("it should return all repositories without duplicates when excludeProjects is true", () => { @@ -88,6 +88,6 @@ test("it should return all repositories without duplicates when excludeProjects ]; const deduplicated = deduplicateAndFilterRepositories("foo", true, suggestedRepos); expect(deduplicated.length).toEqual(2); - expect(deduplicated[0].repositoryName).toEqual("foo"); - expect(deduplicated[1].repositoryName).toEqual("bar"); + expect(deduplicated[0].repoName).toEqual("foo"); + expect(deduplicated[1].repoName).toEqual("bar"); }); 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 4ad1c834ff969c..197c45aa777a4d 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 @@ -4,7 +4,7 @@ * See License.AGPL.txt in the project root for license information. */ -import { SuggestedRepository } from "@gitpod/gitpod-protocol"; +import { SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb"; import { useSearchRepositories } from "./search-repositories-query"; import { useSuggestedRepositories } from "./suggested-repositories-query"; import { useMemo } from "react"; @@ -47,22 +47,22 @@ export function deduplicateAndFilterRepositories( const reposWithProject = new Set(); if (!excludeProjects) { suggestedRepos.forEach((r) => { - if (r.projectId) { + if (r.configurationId) { reposWithProject.add(r.url); } }); } for (const repo of suggestedRepos) { // filter out project-less entries if an entry with a project exists - if (!repo.projectId && reposWithProject.has(repo.url)) { + if (!repo.configurationId && reposWithProject.has(repo.url)) { continue; } // filter out entries that don't match the search string - if (!`${repo.url}${repo.projectName || ""}`.toLowerCase().includes(normalizedSearchString)) { + if (!`${repo.url}${repo.configurationName || ""}`.toLowerCase().includes(normalizedSearchString)) { continue; } // filter out duplicates - const key = `${repo.url}:${excludeProjects ? "" : repo.projectId || "no-project"}`; + const key = `${repo.url}:${excludeProjects ? "" : repo.configurationId || "no-project"}`; if (collected.has(key)) { continue; } @@ -74,7 +74,11 @@ export function deduplicateAndFilterRepositories( try { // If the normalizedSearchString is a URL, and it's not present in the proposed results, "artificially" add it here. new URL(normalizedSearchString); - results.push({ url: normalizedSearchString }); + results.push( + new SuggestedRepository({ + url: normalizedSearchString, + }), + ); } catch {} } diff --git a/components/dashboard/src/projects/create-project-modal/CreateProjectModal.tsx b/components/dashboard/src/projects/create-project-modal/CreateProjectModal.tsx index 67b4ec803622f1..ed238f442a5bc8 100644 --- a/components/dashboard/src/projects/create-project-modal/CreateProjectModal.tsx +++ b/components/dashboard/src/projects/create-project-modal/CreateProjectModal.tsx @@ -8,11 +8,12 @@ import { FC, useCallback, useState } from "react"; import Modal, { ModalBody, ModalFooter, ModalFooterAlert, ModalHeader } from "../../components/Modal"; import { Button } from "../../components/Button"; import { CreateProjectArgs, useCreateProject } from "../../data/projects/create-project-mutation"; -import { Project, SuggestedRepository } from "@gitpod/gitpod-protocol"; +import { Project } from "@gitpod/gitpod-protocol"; import RepositoryFinder from "../../components/RepositoryFinder"; import { InputField } from "../../components/forms/InputField"; import { AuthorizeGit, useNeedsGitAuthorization } from "../../components/AuthorizeGit"; import { useTemporaryState } from "../../hooks/use-temporary-value"; +import { SuggestedRepository } from "@gitpod/public-api/lib/gitpod/v1/scm_pb"; type Props = { onCreated: (project: Project) => void; @@ -61,7 +62,7 @@ export const CreateProjectModal: FC = ({ onClose, onCreated }) => { diff --git a/components/dashboard/src/repositories/create/ImportRepositoryModal.tsx b/components/dashboard/src/repositories/create/ImportRepositoryModal.tsx index 7777aa6df8d3af..92bec1f63e9e05 100644 --- a/components/dashboard/src/repositories/create/ImportRepositoryModal.tsx +++ b/components/dashboard/src/repositories/create/ImportRepositoryModal.tsx @@ -61,7 +61,7 @@ export const ImportRepositoryModal: FC = ({ onClose, onCreated }) => { diff --git a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx index 25db0b676de797..bace526dec4a9d 100644 --- a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx +++ b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx @@ -393,7 +393,7 @@ export function CreateWorkspacePage() {