diff --git a/components/dashboard/src/projects/Events.tsx b/components/dashboard/src/projects/Events.tsx index eb47ca2be4810d..7044fc8a168e62 100644 --- a/components/dashboard/src/projects/Events.tsx +++ b/components/dashboard/src/projects/Events.tsx @@ -5,7 +5,7 @@ */ import dayjs from "dayjs"; -import { PrebuildEvent, Project } from "@gitpod/gitpod-protocol"; +import { PrebuildEvent } from "@gitpod/gitpod-protocol"; import { useCallback, useEffect, useState } from "react"; import Header from "../components/Header"; import { ItemsList, Item, ItemField } from "../components/ItemsList"; @@ -209,7 +209,7 @@ export default function EventsPage() { {event.prebuildId && ( {status} diff --git a/components/dashboard/src/projects/NewProject.tsx b/components/dashboard/src/projects/NewProject.tsx index 7123ab2f6b0004..315f4b33da6e6c 100644 --- a/components/dashboard/src/projects/NewProject.tsx +++ b/components/dashboard/src/projects/NewProject.tsx @@ -64,7 +64,7 @@ export default function NewProject() { Project Created Created{" "} - + {project.name} {" "} {!currentTeam ? ( @@ -81,7 +81,7 @@ export default function NewProject() {
- + diff --git a/components/dashboard/src/projects/Prebuild.tsx b/components/dashboard/src/projects/Prebuild.tsx index 44753a5e39e04f..f95251f77c8914 100644 --- a/components/dashboard/src/projects/Prebuild.tsx +++ b/components/dashboard/src/projects/Prebuild.tsx @@ -4,7 +4,7 @@ * See License.AGPL.txt in the project root for license information. */ -import { PrebuildWithStatus, Project } from "@gitpod/gitpod-protocol"; +import { PrebuildWithStatus } from "@gitpod/gitpod-protocol"; import dayjs from "dayjs"; import { useEffect, useMemo, useState } from "react"; import { Redirect, useHistory, useParams } from "react-router"; @@ -108,7 +108,9 @@ export default function PrebuildPage() { setIsRerunningPrebuild(true); await getGitpodService().server.triggerPrebuild(prebuild.info.projectId, prebuild.info.branch); // TODO: Open a Prebuilds page that's specific to `prebuild.info.branch`? - history.push(`/projects/${Project.slug(project!)}/prebuilds`); + if (project) { + history.push(`/projects/${project.id}/prebuilds`); + } } catch (error) { console.error("Could not rerun prebuild", error); } finally { diff --git a/components/dashboard/src/projects/Prebuilds.tsx b/components/dashboard/src/projects/Prebuilds.tsx index e9044a61e7a7e1..9b1fa2b75ec582 100644 --- a/components/dashboard/src/projects/Prebuilds.tsx +++ b/components/dashboard/src/projects/Prebuilds.tsx @@ -198,7 +198,7 @@ export default function PrebuildsPage(props: { project?: Project; isAdminDashboa .filter(filter) .sort(prebuildSorter) .map((p, index) => ( - + diff --git a/components/dashboard/src/projects/ProjectListItem.tsx b/components/dashboard/src/projects/ProjectListItem.tsx index c0f3298af25079..40d6038be9b697 100644 --- a/components/dashboard/src/projects/ProjectListItem.tsx +++ b/components/dashboard/src/projects/ProjectListItem.tsx @@ -44,7 +44,7 @@ export const ProjectListItem: FunctionComponent = ({ proje }, { title: "Settings", - link: `/projects/${Project.slug(project)}/settings`, + link: `/projects/${project.id}/settings`, separator: true, }, { @@ -65,11 +65,11 @@ export const ProjectListItem: FunctionComponent = ({ proje
- Branches + Branches ยท - Prebuilds + Prebuilds
@@ -77,7 +77,7 @@ export const ProjectListItem: FunctionComponent = ({ proje {!enablePrebuilds ? (
Enable Prebuilds → @@ -86,7 +86,7 @@ export const ProjectListItem: FunctionComponent = ({ proje ) : prebuild ? (
{prebuildStatusIcon(prebuild)} @@ -104,7 +104,7 @@ export const ProjectListItem: FunctionComponent = ({ proje View All → @@ -136,7 +136,7 @@ type ProjectLinkProps = { }; const ProjectLink: FunctionComponent = ({ project }) => { return ( - + {project.name} ); diff --git a/components/dashboard/src/projects/project-context.tsx b/components/dashboard/src/projects/project-context.tsx index d0192dc6e44714..7503dbea7234d4 100644 --- a/components/dashboard/src/projects/project-context.tsx +++ b/components/dashboard/src/projects/project-context.tsx @@ -27,50 +27,13 @@ export const ProjectContextProvider: React.FC = ({ children }) => { return {children}; }; -interface ProjectInfo { - id: string; - name?: string; -} - -export function useProjectInfo(): ProjectInfo | undefined { - const projectsRouteMatch = useRouteMatch<{ projectSlug?: string }>("/projects/:projectSlug"); - - return useMemo(() => { - const projectSlug = projectsRouteMatch?.params.projectSlug; - if (!projectSlug) { - return undefined; - } - const result = parseProjectSlug(projectSlug); - if (!result) { - return undefined; - } - return result; - }, [projectsRouteMatch?.params.projectSlug]); -} - -const pattern: RegExp = /^((.+)-)?([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$/; -function parseProjectSlug(slug: string): ProjectInfo | undefined { - const match = slug.match(pattern); - - if (match) { - const name = match[2]; - const id = match[3]; - return { - name, - id, - }; - } else { - return undefined; - } -} - export function useCurrentProject(): { project: Project | undefined; loading: boolean } { const { project, setProject } = useContext(ProjectContext); const [loading, setLoading] = useState(true); const user = useCurrentUser(); const org = useCurrentOrg(); const orgs = useOrganizations(); - const projectInfo = useProjectInfo(); + const projectIdFromRoute = useRouteMatch<{ projectId?: string }>("/projects/:projectId")?.params?.projectId; const location = useLocation(); const history = useHistory(); const listProjects = useListProjectsQuery(); @@ -82,7 +45,7 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo // without a user we are still consider this loading return; } - if (!projectInfo) { + if (!projectIdFromRoute) { setProject(undefined); setLoading(false); return; @@ -97,7 +60,7 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo const projects = listProjects.data?.projects || []; // Find project matching with slug, otherwise with name - const project = projects.find((p) => p.id === projectInfo.id); + const project = projects.find((p) => p.id === projectIdFromRoute); if (!project && orgs.data) { // check other orgs for (const t of orgs.data || []) { @@ -105,7 +68,7 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo continue; } const projects = await listAllProjects({ orgId: t.id }); - const project = projects.find((p) => p.id === projectInfo.id); + const project = projects.find((p) => p.id === projectIdFromRoute); if (project) { // redirect to the other org history.push(location.pathname + "?org=" + t.id); @@ -115,7 +78,7 @@ export function useCurrentProject(): { project: Project | undefined; loading: bo setProject(project); setLoading(false); })(); - }, [setProject, org.data, user, orgs.data, location, history, projectInfo, listProjects.data]); + }, [setProject, org.data, user, orgs.data, location, history, listProjects.data, projectIdFromRoute]); return { project, loading }; } diff --git a/components/dashboard/src/projects/projects.routes.ts b/components/dashboard/src/projects/projects.routes.ts index dcf9eda5bfd057..1978fb013cd32d 100644 --- a/components/dashboard/src/projects/projects.routes.ts +++ b/components/dashboard/src/projects/projects.routes.ts @@ -17,26 +17,25 @@ export function getProjectTabs(project: Project | undefined): TabEntry[] { if (!project) { return []; } - const projectSlug = Project.slug(project); return [ { title: "Branches", - link: `/projects/${projectSlug}`, + link: `/projects/${project.id}`, }, { title: "Prebuilds", - link: `/projects/${projectSlug}/prebuilds`, + link: `/projects/${project.id}/prebuilds`, }, { title: "Settings", - link: `/projects/${projectSlug}/settings`, + link: `/projects/${project.id}/settings`, alternatives: getProjectSettingsMenu(project).flatMap((e) => e.link), }, ]; } export function getProjectSettingsMenu(project?: Project) { - const slug = project ? Project.slug(project) : "unknown"; + const slug = project?.id ?? "unknown"; return [ { title: "General", diff --git a/components/gitpod-protocol/src/teams-projects-protocol.ts b/components/gitpod-protocol/src/teams-projects-protocol.ts index a499a2c90b6b9e..bf0b274b09bace 100644 --- a/components/gitpod-protocol/src/teams-projects-protocol.ts +++ b/components/gitpod-protocol/src/teams-projects-protocol.ts @@ -74,10 +74,6 @@ export namespace Project { }; }; - export function slug(p: Project): string { - return p.name + "-" + p.id; - } - export type PrebuildSettingsWithDefaults = Required> & PrebuildSettings; export const PREBUILD_SETTINGS_DEFAULTS: PrebuildSettingsWithDefaults = {