Skip to content

Commit 28c4b23

Browse files
svenefftingeroboquat
authored andcommitted
[dashboard] Treat today's workspaces as active
1 parent 27e16e5 commit 28c4b23

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

components/dashboard/src/components/Arrow.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Arrow(props: { up: boolean; customBorderClasses?: string }) {
1010
className={
1111
"mx-2 " +
1212
(props.customBorderClasses ||
13-
"border-gray-400 dark:border-gray-600 group-hover:border-gray-600 dark:group-hover:border-gray-400")
13+
"border-gray-400 dark:border-gray-500 group-hover:border-gray-600 dark:group-hover:border-gray-400")
1414
}
1515
style={{
1616
marginTop: 2,

components/dashboard/src/workspaces/Workspaces.tsx

+35-28
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function () {
5858

5959
<ConfirmationModal
6060
title="Delete Inactive Workspaces"
61-
areYouSureText="You are about to permanently delete your inactive workspaces."
61+
areYouSureText="Are you sure you want to delete all inactive workspaces?"
6262
buttonText="Delete Inactive Workspaces"
6363
visible={!!deleteModalVisible}
6464
onClose={() => setDeleteModalVisible(false)}
@@ -146,42 +146,49 @@ export default function () {
146146
})}
147147
{activeWorkspaces.length > 0 && <div className="py-6"></div>}
148148
{inactiveWorkspaces.length > 0 && (
149-
<div className="pt-14">
150-
<div className="border-t border-gray-200 dark:border-gray-800"></div>
149+
<div>
151150
<div
152151
onClick={() => setShowInactive(!showInactive)}
153-
className="flex cursor-pointer py-6"
152+
className="flex cursor-pointer py-6 px-6 flex-row text-gray-400 bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded-xl mb-2"
154153
>
155-
<div className="flex flex-col">
156-
<h2 className="">Inactive Workspaces</h2>
154+
<div className="pr-2">
155+
<Arrow up={!!showInactive} />
157156
</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-
/>
157+
<div className="flex flex-grow flex-col ">
158+
<div className="font-medium text-gray-500 dark:text-gray-200 truncate">
159+
<span>Inactive Workspaces&nbsp;</span>
160+
<span className="text-gray-400 dark:text-gray-400 bg-gray-200 dark:bg-gray-600 rounded-xl px-2 py-0.5 text-xs">
161+
{inactiveWorkspaces.length}
162+
</span>
163+
</div>
164+
<div className="text-sm flex-auto">
165+
Unpinned workspaces that have been inactive for more than 14 days will
166+
be automatically deleted.{" "}
167+
<a
168+
className="gp-link"
169+
href="https://www.gitpod.io/docs/life-of-workspace/#garbage-collection"
170+
onClick={(evt) => evt.stopPropagation()}
171+
>
172+
Learn more
173+
</a>
174+
</div>
163175
</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>
176+
<div className="self-center">
177+
{showInactive ? (
178178
<button
179-
onClick={() => setDeleteModalVisible(true)}
180-
className="ml-2 danger secondary w-64 p-2"
179+
onClick={(evt) => {
180+
setDeleteModalVisible(true);
181+
evt.stopPropagation();
182+
}}
183+
className="secondary danger"
181184
>
182185
Delete Inactive Workspaces
183186
</button>
184-
</div>
187+
) : null}
188+
</div>
189+
</div>
190+
{showInactive ? (
191+
<>
185192
{inactiveWorkspaces.map((e) => {
186193
return (
187194
<WorkspaceEntry

components/dashboard/src/workspaces/workspace-model.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
WorkspaceInfo,
1212
WorkspaceInstance,
1313
} from "@gitpod/gitpod-protocol";
14+
import { hoursBefore, isDateSmallerOrEqual } from "@gitpod/gitpod-protocol/lib/util/timeutil";
1415
import { getGitpodService } from "../service/service";
1516

1617
export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
@@ -145,8 +146,12 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
145146
}
146147

147148
protected isActive(info: WorkspaceInfo): boolean {
149+
const lastSessionStart = WorkspaceInfo.lastActiveISODate(info);
150+
const twentyfourHoursAgo = hoursBefore(new Date().toISOString(), 24);
148151
return (
149-
(info.workspace.pinned || (!!info.latestInstance && info.latestInstance.status?.phase !== "stopped")) &&
152+
(info.workspace.pinned ||
153+
(!!info.latestInstance && info.latestInstance.status?.phase !== "stopped") ||
154+
isDateSmallerOrEqual(twentyfourHoursAgo, lastSessionStart)) &&
150155
!info.workspace.softDeleted
151156
);
152157
}

components/gitpod-protocol/src/util/timeutil.ts

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export const orderAsc = (d1: string, d2: string): number => liftDate(d1, d2, (d1
4747
export const liftDate1 = <T>(d1: string, f: (d1: Date) => T): T => f(new Date(d1));
4848
export const liftDate = <T>(d1: string, d2: string, f: (d1: Date, d2: Date) => T): T => f(new Date(d1), new Date(d2));
4949

50+
export function hoursBefore(date: string, hours: number): string {
51+
const result = new Date(date);
52+
result.setHours(result.getHours() - hours);
53+
return result.toISOString();
54+
}
55+
5056
export function hoursLater(date: string, hours: number): string {
5157
const result = new Date(date);
5258
result.setHours(result.getHours() + hours);

0 commit comments

Comments
 (0)