Skip to content

Commit

Permalink
[dashboard] Treat today's workspaces as active
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge committed Jun 9, 2022
1 parent 2006a6c commit d5940c9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/src/components/Arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Arrow(props: { up: boolean; customBorderClasses?: string }) {
className={
"mx-2 " +
(props.customBorderClasses ||
"border-gray-400 dark:border-gray-600 group-hover:border-gray-600 dark:group-hover:border-gray-400")
"border-gray-400 dark:border-gray-500 group-hover:border-gray-600 dark:group-hover:border-gray-400")
}
style={{
marginTop: 2,
Expand Down
63 changes: 35 additions & 28 deletions components/dashboard/src/workspaces/Workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function () {

<ConfirmationModal
title="Delete Inactive Workspaces"
areYouSureText="You are about to permanently delete your inactive workspaces."
areYouSureText="Are you sure you want to delete all inactive workspaces?"
buttonText="Delete Inactive Workspaces"
visible={!!deleteModalVisible}
onClose={() => setDeleteModalVisible(false)}
Expand Down Expand Up @@ -146,42 +146,49 @@ export default function () {
})}
{activeWorkspaces.length > 0 && <div className="py-6"></div>}
{inactiveWorkspaces.length > 0 && (
<div className="pt-14">
<div className="border-t border-gray-200 dark:border-gray-800"></div>
<div>
<div
onClick={() => setShowInactive(!showInactive)}
className="flex cursor-pointer py-6"
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"
>
<div className="flex flex-col">
<h2 className="">Inactive Workspaces</h2>
<div className="pr-2">
<Arrow up={!!showInactive} />
</div>
<div>
<Arrow
up={!!showInactive}
customBorderClasses="text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-400"
/>
<div className="flex flex-grow flex-col ">
<div className="font-medium text-gray-500 dark:text-gray-200 truncate">
<span>Inactive Workspaces&nbsp;</span>
<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">
{inactiveWorkspaces.length}
</span>
</div>
<div className="text-sm flex-auto">
Unpinned workspaces that have been inactive for more than 14 days will
be automatically deleted.{" "}
<a
className="gp-link"
href="https://www.gitpod.io/docs/life-of-workspace/#garbage-collection"
onClick={(evt) => evt.stopPropagation()}
>
Learn more
</a>
</div>
</div>
</div>
{showInactive ? (
<>
<div className="flex flex-row p-3 text-gray-400 bg-gray-50 dark:bg-gray-800 rounded-xl">
<div className="text-sm flex-auto py-3">
Unpinned workspaces that have been inactive for more than 14 days
will be automatically deleted.{" "}
<a
className="gp-link"
href="https://www.gitpod.io/docs/life-of-workspace/#garbage-collection"
>
Learn more
</a>
</div>
<div className="self-center">
{showInactive ? (
<button
onClick={() => setDeleteModalVisible(true)}
className="ml-2 danger secondary w-64 p-2"
onClick={(evt) => {
setDeleteModalVisible(true);
evt.stopPropagation();
}}
className="secondary danger"
>
Delete Inactive Workspaces
</button>
</div>
) : null}
</div>
</div>
{showInactive ? (
<>
{inactiveWorkspaces.map((e) => {
return (
<WorkspaceEntry
Expand Down
7 changes: 6 additions & 1 deletion components/dashboard/src/workspaces/workspace-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WorkspaceInfo,
WorkspaceInstance,
} from "@gitpod/gitpod-protocol";
import { hoursBefore, isDateSmallerOrEqual } from "@gitpod/gitpod-protocol/lib/util/timeutil";
import { getGitpodService } from "../service/service";

export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
Expand Down Expand Up @@ -145,8 +146,12 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
}

protected isActive(info: WorkspaceInfo): boolean {
const lastSessionStart = WorkspaceInfo.lastActiveISODate(info);
const twentyfourHoursAgo = hoursBefore(new Date().toISOString(), 24);
return (
(info.workspace.pinned || (!!info.latestInstance && info.latestInstance.status?.phase !== "stopped")) &&
(info.workspace.pinned ||
(!!info.latestInstance && info.latestInstance.status?.phase !== "stopped") ||
isDateSmallerOrEqual(twentyfourHoursAgo, lastSessionStart)) &&
!info.workspace.softDeleted
);
}
Expand Down
6 changes: 6 additions & 0 deletions components/gitpod-protocol/src/util/timeutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const orderAsc = (d1: string, d2: string): number => liftDate(d1, d2, (d1
export const liftDate1 = <T>(d1: string, f: (d1: Date) => T): T => f(new Date(d1));
export const liftDate = <T>(d1: string, d2: string, f: (d1: Date, d2: Date) => T): T => f(new Date(d1), new Date(d2));

export function hoursBefore(date: string, hours: number): string {
const result = new Date(date);
result.setHours(result.getHours() - hours);
return result.toISOString();
}

export function hoursLater(date: string, hours: number): string {
const result = new Date(date);
result.setHours(result.getHours() + hours);
Expand Down

0 comments on commit d5940c9

Please sign in to comment.