Skip to content

Commit 64ce757

Browse files
authored
[dashboard] enable naming of workspaces (#20017)
1 parent fd1604d commit 64ce757

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
3636
import { PartialMessage } from "@bufbuild/protobuf";
3737
import { trackEvent } from "../Analytics";
38+
import { fromWorkspaceName } from "../workspaces/RenameWorkspaceModal";
3839

3940
const sessionId = v4();
4041

@@ -562,7 +563,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
562563
<div className="rounded-full w-3 h-3 text-sm bg-green-500">&nbsp;</div>
563564
<div>
564565
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">
565-
{this.state.workspace.id}
566+
{fromWorkspaceName(this.state.workspace) || this.state.workspace.id}
566567
</p>
567568
<a target="_parent" href={contextURL}>
568569
<p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400">
@@ -667,7 +668,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
667668
<div className="rounded-full w-3 h-3 text-sm bg-kumquat-ripe">&nbsp;</div>
668669
<div>
669670
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">
670-
{this.state.workspace.id}
671+
{fromWorkspaceName(this.state.workspace) || this.state.workspace.id}
671672
</p>
672673
<a target="_parent" href={contextURL}>
673674
<p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400">
@@ -712,7 +713,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
712713
<div className="rounded-full w-3 h-3 text-sm bg-gray-300">&nbsp;</div>
713714
<div>
714715
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">
715-
{this.state.workspace.id}
716+
{fromWorkspaceName(this.state.workspace) || this.state.workspace.id}
716717
</p>
717718
<a target="_parent" href={contextURL}>
718719
<p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400">

components/dashboard/src/workspaces/DeleteWorkspaceModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ConfirmationModal from "../components/ConfirmationModal";
99
import { useDeleteWorkspaceMutation } from "../data/workspaces/delete-workspace-mutation";
1010
import { useToast } from "../components/toasts/Toasts";
1111
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
12+
import { fromWorkspaceName } from "./RenameWorkspaceModal";
1213

1314
type Props = {
1415
workspace: Workspace;
@@ -33,7 +34,7 @@ export const DeleteWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
3334
areYouSureText="Are you sure you want to delete this workspace?"
3435
children={{
3536
name: workspace.id,
36-
description: workspace.metadata?.name,
37+
description: fromWorkspaceName(workspace),
3738
}}
3839
buttonText="Delete Workspace"
3940
warningText={deleteWorkspace.isError ? "There was a problem deleting your workspace." : undefined}

components/dashboard/src/workspaces/RenameWorkspaceModal.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,42 @@ import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1111
import { useUpdateWorkspaceMutation } from "../data/workspaces/update-workspace-mutation";
1212
import { LoadingButton } from "@podkit/buttons/LoadingButton";
1313

14+
export const NAME_PREFIX = "named:";
15+
export function toWorkspaceName(name: string): string {
16+
// unsetting the name
17+
if (name.trim().length === 0) {
18+
return "no-name";
19+
}
20+
return `${NAME_PREFIX}${name}`;
21+
}
22+
23+
export function fromWorkspaceName(workspace?: Workspace): string | undefined {
24+
if (workspace?.metadata?.name?.startsWith(NAME_PREFIX)) {
25+
return workspace.metadata.name.slice(NAME_PREFIX.length);
26+
}
27+
return undefined;
28+
}
29+
1430
type Props = {
1531
workspace: Workspace;
1632
onClose(): void;
1733
};
1834
export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onClose }) => {
1935
const [errorMessage, setErrorMessage] = useState("");
20-
const [name, setName] = useState(workspace.metadata?.name || "");
36+
const [name, setName] = useState(fromWorkspaceName(workspace) || "");
2137
const updateWorkspace = useUpdateWorkspaceMutation();
2238

2339
const updateWorkspaceDescription = useCallback(async () => {
2440
try {
25-
if (name.length === 0) {
26-
setErrorMessage("Description cannot not be empty.");
27-
return;
28-
}
29-
3041
if (name.length > 250) {
31-
setErrorMessage("Description is too long for readability.");
42+
setErrorMessage("Name is too long for readability.");
3243
return;
3344
}
3445

3546
setErrorMessage("");
3647

3748
// Using mutateAsync here so we can close the modal after it completes successfully
38-
await updateWorkspace.mutateAsync({ workspaceId: workspace.id, metadata: { name } });
49+
await updateWorkspace.mutateAsync({ workspaceId: workspace.id, metadata: { name: toWorkspaceName(name) } });
3950

4051
// Close the modal
4152
onClose();
@@ -46,7 +57,7 @@ export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
4657

4758
return (
4859
<Modal visible onClose={onClose} onSubmit={updateWorkspaceDescription}>
49-
<ModalHeader>Rename Workspace Description</ModalHeader>
60+
<ModalHeader>Rename Workspace</ModalHeader>
5061
<ModalBody>
5162
{errorMessage.length > 0 ? (
5263
<div className="bg-kumquat-light rounded-md p-3 text-gitpod-red text-sm mb-2">{errorMessage}</div>
@@ -60,7 +71,7 @@ export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
6071
onChange={(e) => setName(e.target.value)}
6172
/>
6273
<div className="mt-1">
63-
<p className="text-gray-500">Change the description to make it easier to go back to a workspace.</p>
74+
<p className="text-gray-500">Change the name to better identify the workspace.</p>
6475
<p className="text-gray-500">Workspace URLs and endpoints will remain the same.</p>
6576
</div>
6677
</ModalBody>
@@ -69,7 +80,7 @@ export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
6980
Cancel
7081
</Button>
7182
<LoadingButton type="submit" loading={updateWorkspace.isLoading}>
72-
Update Description
83+
Update Name
7384
</LoadingButton>
7485
</ModalFooter>
7586
</Modal>

components/dashboard/src/workspaces/WorkspaceEntry.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { WorkspaceStatusIndicator } from "./WorkspaceStatusIndicator";
1515
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1616
import { GitBranchIcon, PinIcon } from "lucide-react";
1717
import { useUpdateWorkspaceMutation } from "../data/workspaces/update-workspace-mutation";
18+
import { fromWorkspaceName } from "./RenameWorkspaceModal";
1819

1920
type Props = {
2021
info: Workspace;
@@ -68,11 +69,13 @@ export const WorkspaceEntry: FunctionComponent<Props> = ({ info, shortVersion })
6869
<WorkspaceStatusIndicator status={workspace?.status} />
6970
</ItemFieldIcon>
7071
<div className="flex-grow flex flex-col h-full py-auto truncate">
71-
<a href={startUrl}>
72-
<div className="font-medium text-gray-800 dark:text-gray-200 truncate hover:text-blue-600 dark:hover:text-blue-400">
73-
{info.id}
74-
</div>
75-
</a>
72+
<Tooltip content={info.id} allowWrap={true}>
73+
<a href={startUrl}>
74+
<div className="font-medium text-gray-800 dark:text-gray-200 truncate hover:text-blue-600 dark:hover:text-blue-400">
75+
{fromWorkspaceName(info) || info.id}
76+
</div>
77+
</a>
78+
</Tooltip>
7679
<Tooltip content={project ? "https://" + project : ""} allowWrap={true}>
7780
<a href={project ? "https://" + project : undefined}>
7881
<div className="text-sm overflow-ellipsis truncate text-gray-400 dark:text-gray-500 hover:text-blue-600 dark:hover:text-blue-400">

components/dashboard/src/workspaces/WorkspaceOverflowMenu.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ export const WorkspaceEntryOverflowMenu: FunctionComponent<WorkspaceEntryOverflo
105105
title: "Open",
106106
href: startUrl.toString(),
107107
},
108-
// {
109-
// title: "Rename",
110-
// href: "",
111-
// onClick: () => setRenameModalVisible(true),
112-
// },
108+
{
109+
title: "Rename",
110+
href: "",
111+
onClick: () => setRenameModalVisible(true),
112+
},
113113
];
114114

115115
if (state === WorkspacePhase_Phase.RUNNING) {

0 commit comments

Comments
 (0)