Skip to content

Commit b0df62e

Browse files
committed
Update dashboard
1 parent 8bc26b0 commit b0df62e

9 files changed

+73
-179
lines changed

components/dashboard/src/components/SelectWorkspaceClassComponent.tsx

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

7-
import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class";
87
import { FC, useCallback, useEffect, useMemo } from "react";
9-
import WorkspaceClass from "../icons/WorkspaceClass.svg";
8+
import WorkspaceClassIcon from "../icons/WorkspaceClass.svg";
109
import { Combobox, ComboboxElement, ComboboxSelectedItem } from "./podkit/combobox/Combobox";
1110
import { useWorkspaceClasses } from "../data/workspaces/workspace-classes-query";
11+
import { WorkspaceClass } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1212

1313
interface SelectWorkspaceClassProps {
1414
selectedWorkspaceClass?: string;
@@ -78,7 +78,7 @@ export default function SelectWorkspaceClassComponent({
7878
}
7979

8080
type WorkspaceClassDropDownElementSelectedProps = {
81-
wsClass?: SupportedWorkspaceClass;
81+
wsClass?: WorkspaceClass;
8282
loading?: boolean;
8383
};
8484

@@ -90,7 +90,7 @@ const WorkspaceClassDropDownElementSelected: FC<WorkspaceClassDropDownElementSel
9090

9191
return (
9292
<ComboboxSelectedItem
93-
icon={WorkspaceClass}
93+
icon={WorkspaceClassIcon}
9494
loading={loading}
9595
htmlTitle={title}
9696
title={<div className="truncate">{title}</div>}
@@ -106,7 +106,7 @@ const WorkspaceClassDropDownElementSelected: FC<WorkspaceClassDropDownElementSel
106106
);
107107
};
108108

109-
function WorkspaceClassDropDownElement(props: { wsClass: SupportedWorkspaceClass }): JSX.Element {
109+
function WorkspaceClassDropDownElement(props: { wsClass: WorkspaceClass }): JSX.Element {
110110
const c = props.wsClass;
111111
return (
112112
<div className="flex ml-1 mt-1 flex-grow">

components/dashboard/src/data/workspaces/list-workspaces-query.ts

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

7-
import { useQuery } from "@tanstack/react-query";
7+
import { useQuery, useQueryClient } from "@tanstack/react-query";
88
import { useCurrentOrg } from "../organizations/orgs-query";
99
import { workspaceClient } from "../../service/public-api";
1010
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
@@ -57,3 +57,19 @@ export function getListWorkspacesQueryKey(orgId?: string) {
5757
}
5858
return ["workspaces", "list", orgId];
5959
}
60+
61+
export const useUpdateWorkspaceInCache = () => {
62+
const queryClient = useQueryClient();
63+
const org = useCurrentOrg();
64+
return (newWorkspace: Workspace) => {
65+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
66+
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {
67+
return oldWorkspacesData?.map((info) => {
68+
if (info.id !== newWorkspace.id) {
69+
return info;
70+
}
71+
return newWorkspace;
72+
});
73+
});
74+
};
75+
};

components/dashboard/src/data/workspaces/toggle-workspace-pinned-mutation.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

components/dashboard/src/data/workspaces/toggle-workspace-shared-mutation.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

components/dashboard/src/data/workspaces/update-workspace-description-mutation.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 { useMutation } from "@tanstack/react-query";
8+
import { useUpdateWorkspaceInCache } from "./list-workspaces-query";
9+
import { UpdateWorkspaceRequest } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
10+
import { PartialMessage } from "@bufbuild/protobuf";
11+
import { workspaceClient } from "../../service/public-api";
12+
13+
export const useUpdateWorkspaceMutation = () => {
14+
const updateWorkspace = useUpdateWorkspaceInCache();
15+
16+
return useMutation({
17+
mutationFn: async (data: PartialMessage<UpdateWorkspaceRequest>) => {
18+
return await workspaceClient.updateWorkspace(data);
19+
},
20+
onSuccess: (data) => {
21+
if (data.workspace) {
22+
updateWorkspace(data.workspace);
23+
}
24+
},
25+
});
26+
};

components/dashboard/src/data/workspaces/workspace-classes-query.ts

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

7-
import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class";
87
import { useQuery } from "@tanstack/react-query";
9-
import { getGitpodService } from "../../service/service";
8+
import { workspaceClient } from "../../service/public-api";
9+
import { WorkspaceClass } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1010

1111
export const useWorkspaceClasses = () => {
12-
return useQuery<SupportedWorkspaceClass[]>({
12+
return useQuery<WorkspaceClass[]>({
1313
queryKey: ["workspace-classes"],
1414
queryFn: async () => {
15-
return getGitpodService().server.getSupportedWorkspaceClasses();
15+
const response = await workspaceClient.listWorkspaceClasses({});
16+
return response.workspaceClasses;
1617
},
1718
cacheTime: 1000 * 60 * 60, // 1h
1819
staleTime: 1000 * 60 * 60, // 1h

components/dashboard/src/workspaces/RenameWorkspaceModal.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@
66

77
import { FunctionComponent, useCallback, useState } from "react";
88
import Modal, { ModalBody, ModalFooter, ModalHeader } from "../components/Modal";
9-
import { useUpdateWorkspaceDescriptionMutation } from "../data/workspaces/update-workspace-description-mutation";
109
import { Button } from "../components/Button";
1110
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
11+
import { useUpdateWorkspaceMutation } from "../data/workspaces/update-workspace-mutation";
1212

1313
type Props = {
1414
workspace: Workspace;
1515
onClose(): void;
1616
};
1717
export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onClose }) => {
1818
const [errorMessage, setErrorMessage] = useState("");
19-
const [description, setDescription] = useState(workspace.name || "");
20-
const updateDescription = useUpdateWorkspaceDescriptionMutation();
19+
const [name, setName] = useState(workspace.name || "");
20+
const updateWorkspace = useUpdateWorkspaceMutation();
2121

2222
const updateWorkspaceDescription = useCallback(async () => {
2323
try {
24-
if (description.length === 0) {
24+
if (name.length === 0) {
2525
setErrorMessage("Description cannot not be empty.");
2626
return;
2727
}
2828

29-
if (description.length > 250) {
29+
if (name.length > 250) {
3030
setErrorMessage("Description is too long for readability.");
3131
return;
3232
}
3333

3434
setErrorMessage("");
3535

3636
// Using mutateAsync here so we can close the modal after it completes successfully
37-
await updateDescription.mutateAsync({ workspaceId: workspace.id, newDescription: description });
37+
await updateWorkspace.mutateAsync({ workspaceId: workspace.id, name });
3838

3939
// Close the modal
4040
onClose();
4141
} catch (error) {
4242
setErrorMessage("Something went wrong. Please try renaming again.");
4343
}
44-
}, [description, onClose, updateDescription, workspace.id]);
44+
}, [name, onClose, updateWorkspace, workspace.id]);
4545

4646
return (
4747
<Modal visible onClose={onClose} onSubmit={updateWorkspaceDescription}>
@@ -54,20 +54,20 @@ export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
5454
autoFocus
5555
className="w-full truncate"
5656
type="text"
57-
value={description}
58-
disabled={updateDescription.isLoading}
59-
onChange={(e) => setDescription(e.target.value)}
57+
value={name}
58+
disabled={updateWorkspace.isLoading}
59+
onChange={(e) => setName(e.target.value)}
6060
/>
6161
<div className="mt-1">
6262
<p className="text-gray-500">Change the description to make it easier to go back to a workspace.</p>
6363
<p className="text-gray-500">Workspace URLs and endpoints will remain the same.</p>
6464
</div>
6565
</ModalBody>
6666
<ModalFooter>
67-
<Button type="secondary" disabled={updateDescription.isLoading} onClick={onClose}>
67+
<Button type="secondary" disabled={updateWorkspace.isLoading} onClick={onClose}>
6868
Cancel
6969
</Button>
70-
<Button htmlType="submit" loading={updateDescription.isLoading}>
70+
<Button htmlType="submit" loading={updateWorkspace.isLoading}>
7171
Update Description
7272
</Button>
7373
</ModalFooter>

components/dashboard/src/workspaces/WorkspaceOverflowMenu.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import { FunctionComponent, useCallback, useMemo, useState } from "react";
99
import { ContextMenuEntry } from "../components/ContextMenu";
1010
import { ItemFieldContextMenu } from "../components/ItemsList";
1111
import { useStopWorkspaceMutation } from "../data/workspaces/stop-workspace-mutation";
12-
import { useToggleWorkspacedPinnedMutation } from "../data/workspaces/toggle-workspace-pinned-mutation";
13-
import { useToggleWorkspaceSharedMutation } from "../data/workspaces/toggle-workspace-shared-mutation";
1412
import { getGitpodService } from "../service/service";
1513
import ConnectToSSHModal from "./ConnectToSSHModal";
1614
import { DeleteWorkspaceModal } from "./DeleteWorkspaceModal";
1715
import { useToast } from "../components/toasts/Toasts";
1816
import { RenameWorkspaceModal } from "./RenameWorkspaceModal";
1917
import { AdmissionLevel, Workspace, WorkspacePhase_Phase } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
18+
import { useUpdateWorkspaceMutation } from "../data/workspaces/update-workspace-mutation";
2019

2120
type WorkspaceEntryOverflowMenuProps = {
2221
info: Workspace;
@@ -34,8 +33,7 @@ export const WorkspaceEntryOverflowMenu: FunctionComponent<WorkspaceEntryOverflo
3433
const { toast } = useToast();
3534

3635
const stopWorkspace = useStopWorkspaceMutation();
37-
const toggleWorkspaceShared = useToggleWorkspaceSharedMutation();
38-
const toggleWorkspacePinned = useToggleWorkspacedPinnedMutation();
36+
const updateWorkspace = useUpdateWorkspaceMutation();
3937

4038
const workspace = info;
4139
const state: WorkspacePhase_Phase = info?.status?.phase?.name || WorkspacePhase_Phase.STOPPED;
@@ -64,17 +62,18 @@ export const WorkspaceEntryOverflowMenu: FunctionComponent<WorkspaceEntryOverflo
6462
? AdmissionLevel.OWNER_ONLY
6563
: AdmissionLevel.EVERYONE;
6664

67-
toggleWorkspaceShared.mutate({
65+
updateWorkspace.mutate({
6866
workspaceId: workspace.id,
69-
level: newLevel,
67+
admission: newLevel,
7068
});
71-
}, [toggleWorkspaceShared, workspace.id, workspace.status?.admission]);
69+
}, [updateWorkspace, workspace.id, workspace.status?.admission]);
7270

7371
const togglePinned = useCallback(() => {
74-
toggleWorkspacePinned.mutate({
72+
updateWorkspace.mutate({
7573
workspaceId: workspace.id,
74+
pinned: !workspace.pinned,
7675
});
77-
}, [toggleWorkspacePinned, workspace.id]);
76+
}, [updateWorkspace, workspace.id, workspace.pinned]);
7877

7978
// Can we use `/start#${workspace.id}` instead?
8079
const startUrl = useMemo(

0 commit comments

Comments
 (0)