Skip to content

Commit ac26599

Browse files
authored
[dashboard] update document title on setup (#17603)
1 parent 7803f0b commit ac26599

File tree

8 files changed

+41
-35
lines changed

8 files changed

+41
-35
lines changed

components/dashboard/src/components/Header.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { useEffect } from "react";
87
import { useLocation } from "react-router";
8+
import { useDocumentTitle } from "../hooks/use-document-title";
99
import { Separator } from "./Separator";
1010
import TabMenuItem from "./TabMenuItem";
1111
import { Heading1, Subheading } from "./typography/headings";
1212

1313
export interface HeaderProps {
14-
title: string | React.ReactElement;
14+
title: string;
15+
complexTitle?: React.ReactElement;
1516
subtitle: string | React.ReactElement;
1617
tabs?: TabEntry[];
1718
}
@@ -24,17 +25,12 @@ export interface TabEntry {
2425

2526
export default function Header(p: HeaderProps) {
2627
const location = useLocation();
27-
useEffect(() => {
28-
if (typeof p.title !== "string") {
29-
return;
30-
}
31-
document.title = `${p.title} — Gitpod`;
32-
}, [p.title]);
28+
useDocumentTitle(`${p.title} — Gitpod`);
3329
return (
3430
<div className="app-container border-gray-200 dark:border-gray-800">
3531
<div className="flex pb-8 pt-6">
3632
<div className="">
37-
{typeof p.title === "string" ? <Heading1 tracking="tight">{p.title}</Heading1> : p.title}
33+
{p.complexTitle ? p.complexTitle : <Heading1 tracking="tight">{p.title}</Heading1>}
3834
{typeof p.subtitle === "string" ? (
3935
<Subheading tracking="wide">{p.subtitle}</Subheading>
4036
) : (

components/dashboard/src/components/UsageView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ function UsageView({ attributionId }: UsageViewProps) {
186186
return (
187187
<>
188188
<Header
189-
title={
189+
title="Usage"
190+
complexTitle={
190191
<div className="flex items-baseline">
191192
<Heading1 tracking="tight">Usage</Heading1>
192193
<Subheading className="ml-3">(updated every 15 minutes).</Subheading>

components/dashboard/src/dedicated-setup/DedicatedSetup.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import { UserContext } from "../user-context";
2121
import { OIDCClientConfig } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";
2222
import { useQueryParams } from "../hooks/use-query-params";
2323
import { forceDedicatedSetupParam } from "./use-check-dedicated-setup";
24+
import { useDocumentTitle } from "../hooks/use-document-title";
2425

2526
type Props = {
2627
onComplete: () => void;
2728
};
2829
const DedicatedSetup: FC<Props> = ({ onComplete }) => {
30+
useDocumentTitle("Welcome - Gitpod");
2931
const currentOrg = useCurrentOrg();
3032
const oidcClients = useOIDCClientsQuery();
3133

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useEffect } from "react";
8+
9+
export function useDocumentTitle(title?: string) {
10+
useEffect(() => {
11+
if (title && title.length > 0) {
12+
document.title = title;
13+
}
14+
}, [title]);
15+
}

components/dashboard/src/projects/Prebuild.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import dayjs from "dayjs";
87
import { PrebuildWithStatus, Project } from "@gitpod/gitpod-protocol";
9-
import { useEffect, useState } from "react";
8+
import dayjs from "dayjs";
9+
import { useEffect, useMemo, useState } from "react";
1010
import { Redirect, useHistory, useParams } from "react-router";
1111
import Header from "../components/Header";
1212
import PrebuildLogs from "../components/PrebuildLogs";
13+
import { Subheading } from "../components/typography/headings";
1314
import Spinner from "../icons/Spinner.svg";
1415
import { getGitpodService, gitpodHostUrl } from "../service/service";
15-
import { shortCommitMessage } from "./render-utils";
1616
import { useCurrentProject } from "./project-context";
17-
import { Heading1, Subheading } from "../components/typography/headings";
17+
import { shortCommitMessage } from "./render-utils";
1818

1919
export default function PrebuildPage() {
2020
const history = useHistory();
@@ -49,12 +49,12 @@ export default function PrebuildPage() {
4949
}).dispose;
5050
}, [prebuildId, project]);
5151

52-
const renderTitle = () => {
52+
const title = useMemo(() => {
5353
if (!prebuild) {
5454
return "unknown prebuild";
5555
}
56-
return <Heading1>{prebuild.info.branch} </Heading1>;
57-
};
56+
return prebuild.info.branch;
57+
}, [prebuild]);
5858

5959
const renderSubtitle = () => {
6060
if (!prebuild) {
@@ -130,17 +130,13 @@ export default function PrebuildPage() {
130130
}
131131
};
132132

133-
useEffect(() => {
134-
document.title = "Prebuild — Gitpod";
135-
}, []);
136-
137133
if (!loading && !project) {
138134
return <Redirect to={"/projects"} />;
139135
}
140136

141137
return (
142138
<>
143-
<Header title={renderTitle()} subtitle={renderSubtitle()} />
139+
<Header title={title} subtitle={renderSubtitle()} />
144140
<div className="app-container mt-8">
145141
<PrebuildLogs workspaceId={prebuild?.info?.buildWorkspaceId}>
146142
{["building", "queued"].includes(prebuild?.status || "") ? (

components/dashboard/src/start/StartPage.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66

77
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
8-
import { useEffect } from "react";
98
import Alert from "../components/Alert";
10-
import { Heading2 } from "../components/typography/headings";
119
import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal";
10+
import { Heading2 } from "../components/typography/headings";
11+
import { useDocumentTitle } from "../hooks/use-document-title";
1212
import gitpodIcon from "../icons/gitpod.svg";
13+
import CDEUniverseLogo from "../images/cdeuniverse.svg";
1314
import { gitpodHostUrl } from "../service/service";
1415
import { VerifyModal } from "./VerifyModal";
15-
import CDEUniverseLogo from "../images/cdeuniverse.svg";
1616

1717
export enum StartPhase {
1818
Checking = 0,
@@ -93,9 +93,7 @@ export interface StartWorkspaceError {
9393
export function StartPage(props: StartPageProps) {
9494
const { phase, error } = props;
9595
let title = props.title || getPhaseTitle(phase, error);
96-
useEffect(() => {
97-
document.title = "Starting — Gitpod";
98-
}, []);
96+
useDocumentTitle("Starting — Gitpod");
9997
return (
10098
<div className="w-screen h-screen align-middle">
10199
<div className="flex flex-col mx-auto items-center text-center h-screen">

components/dashboard/src/teams/JoinTeam.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { useEffect, useMemo, useState } from "react";
88
import { useHistory, useLocation } from "react-router-dom";
99
import { useOrganizationsInvalidator } from "../data/organizations/orgs-query";
10+
import { useDocumentTitle } from "../hooks/use-document-title";
1011
import { publicApiTeamToProtocol, teamsService } from "../service/public-api";
1112

1213
export default function JoinTeamPage() {
@@ -34,9 +35,7 @@ export default function JoinTeamPage() {
3435
})();
3536
}, [history, inviteId, orgInvalidator]);
3637

37-
useEffect(() => {
38-
document.title = "Joining Organization — Gitpod";
39-
}, []);
38+
useDocumentTitle("Joining Organization — Gitpod");
4039

4140
return joinError ? <div className="mt-16 text-center text-gitpod-red">{String(joinError)}</div> : <></>;
4241
}

components/dashboard/src/teams/NewTeam.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
*/
66

77
import { ConnectError } from "@bufbuild/connect-web";
8-
import { FormEvent, useEffect, useState } from "react";
8+
import { FormEvent, useState } from "react";
99
import { useHistory } from "react-router-dom";
1010
import { Heading1, Heading3, Subheading } from "../components/typography/headings";
1111
import { useOrganizationsInvalidator } from "../data/organizations/orgs-query";
12+
import { useDocumentTitle } from "../hooks/use-document-title";
1213
import { publicApiTeamToProtocol, teamsService } from "../service/public-api";
1314

1415
export default function NewTeamPage() {
@@ -36,9 +37,7 @@ export default function NewTeamPage() {
3637
}
3738
};
3839

39-
useEffect(() => {
40-
document.title = "New Organization — Gitpod";
41-
}, []);
40+
useDocumentTitle("New Organization — Gitpod");
4241

4342
return (
4443
<div className="flex flex-col w-96 mt-24 mx-auto items-center">

0 commit comments

Comments
 (0)