Skip to content

Commit 2006a6c

Browse files
committed
[dashboard] easy cleanup
1 parent 12b58f4 commit 2006a6c

File tree

1 file changed

+67
-18
lines changed

1 file changed

+67
-18
lines changed

components/dashboard/src/workspaces/Workspaces.tsx

+67-18
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ import { User } from "@gitpod/gitpod-protocol";
1818
import { useLocation } from "react-router";
1919
import { StartWorkspaceModalContext, StartWorkspaceModalKeyBinding } from "./start-workspace-modal-context";
2020
import SelectIDEModal from "../settings/SelectIDEModal";
21+
import Arrow from "../components/Arrow";
22+
import ConfirmationModal from "../components/ConfirmationModal";
2123

2224
export interface WorkspacesProps {}
2325

2426
export interface WorkspacesState {
2527
workspaces: WorkspaceInfo[];
2628
isTemplateModelOpen: boolean;
2729
repos: WhitelistedRepository[];
30+
showInactive: boolean;
31+
deleteModalVisible: boolean;
2832
}
2933

3034
export default function () {
@@ -35,6 +39,8 @@ export default function () {
3539
const [activeWorkspaces, setActiveWorkspaces] = useState<WorkspaceInfo[]>([]);
3640
const [inactiveWorkspaces, setInactiveWorkspaces] = useState<WorkspaceInfo[]>([]);
3741
const [workspaceModel, setWorkspaceModel] = useState<WorkspaceModel>();
42+
const [showInactive, setShowInactive] = useState<boolean>();
43+
const [deleteModalVisible, setDeleteModalVisible] = useState<boolean>();
3844
const { setIsStartWorkspaceModalVisible } = useContext(StartWorkspaceModalContext);
3945

4046
useEffect(() => {
@@ -50,6 +56,18 @@ export default function () {
5056
<>
5157
<Header title="Workspaces" subtitle="Manage recent and stopped workspaces." />
5258

59+
<ConfirmationModal
60+
title="Delete Inactive Workspaces"
61+
areYouSureText="You are about to permanently delete your inactive workspaces."
62+
buttonText="Delete Inactive Workspaces"
63+
visible={!!deleteModalVisible}
64+
onClose={() => setDeleteModalVisible(false)}
65+
onConfirm={() => {
66+
inactiveWorkspaces.forEach((ws) => workspaceModel?.deleteWorkspace(ws.workspace.id));
67+
setDeleteModalVisible(false);
68+
}}
69+
></ConfirmationModal>
70+
5371
{isOnboardingUser && <SelectIDEModal location={"workspace_list"} />}
5472

5573
{workspaceModel?.initialized &&
@@ -128,27 +146,58 @@ export default function () {
128146
})}
129147
{activeWorkspaces.length > 0 && <div className="py-6"></div>}
130148
{inactiveWorkspaces.length > 0 && (
131-
<div className="p-3 text-gray-400 bg-gray-50 dark:bg-gray-800 rounded-xl text-sm text-center">
132-
Unpinned workspaces that have been inactive for more than 14 days will be
133-
automatically deleted.{" "}
134-
<a
135-
className="gp-link"
136-
href="https://www.gitpod.io/docs/life-of-workspace/#garbage-collection"
149+
<div className="pt-14">
150+
<div className="border-t border-gray-200 dark:border-gray-800"></div>
151+
<div
152+
onClick={() => setShowInactive(!showInactive)}
153+
className="flex cursor-pointer py-6"
137154
>
138-
Learn more
139-
</a>
155+
<div className="flex flex-col">
156+
<h2 className="">Inactive Workspaces</h2>
157+
</div>
158+
<div>
159+
<Arrow
160+
up={!!showInactive}
161+
customBorderClasses="text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400"
162+
/>
163+
</div>
164+
</div>
165+
{showInactive ? (
166+
<>
167+
<div className="flex flex-row p-3 text-gray-400 bg-gray-50 dark:bg-gray-800 rounded-xl">
168+
<div className="text-sm flex-auto py-3">
169+
Unpinned workspaces that have been inactive for more than 14 days
170+
will be automatically deleted.{" "}
171+
<a
172+
className="gp-link"
173+
href="https://www.gitpod.io/docs/life-of-workspace/#garbage-collection"
174+
>
175+
Learn more
176+
</a>
177+
</div>
178+
<button
179+
onClick={() => setDeleteModalVisible(true)}
180+
className="ml-2 danger secondary w-64 p-2"
181+
>
182+
Delete Inactive Workspaces
183+
</button>
184+
</div>
185+
{inactiveWorkspaces.map((e) => {
186+
return (
187+
<WorkspaceEntry
188+
key={e.workspace.id}
189+
desc={e}
190+
model={workspaceModel}
191+
stopWorkspace={(wsId) =>
192+
getGitpodService().server.stopWorkspace(wsId)
193+
}
194+
/>
195+
);
196+
})}
197+
</>
198+
) : null}
140199
</div>
141200
)}
142-
{inactiveWorkspaces.map((e) => {
143-
return (
144-
<WorkspaceEntry
145-
key={e.workspace.id}
146-
desc={e}
147-
model={workspaceModel}
148-
stopWorkspace={(wsId) => getGitpodService().server.stopWorkspace(wsId)}
149-
/>
150-
);
151-
})}
152201
</ItemsList>
153202
</>
154203
) : (

0 commit comments

Comments
 (0)