Skip to content

Commit 0f31418

Browse files
committed
Add frontend
1 parent 8571215 commit 0f31418

File tree

7 files changed

+59
-1
lines changed

7 files changed

+59
-1
lines changed

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestAgent(t *testing.T) {
105105
var ok bool
106106
s, ok = (<-stats)
107107
return ok && s.NumConns > 0 && s.RxBytes > 0 && s.TxBytes > 0
108-
}, testutil.WaitShort, testutil.IntervalFast,
108+
}, testutil.WaitLong, testutil.IntervalFast,
109109
"never saw stats: %+v", s,
110110
)
111111
})

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ export interface Workspace {
514514
readonly name: string
515515
readonly autostart_schedule?: string
516516
readonly ttl_ms?: number
517+
readonly last_used_at: string
517518
}
518519

519520
// From codersdk/workspaceresources.go
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Theme, useTheme } from "@material-ui/core/styles"
2+
import { FC } from "react"
3+
4+
import dayjs from "dayjs"
5+
import relativeTime from "dayjs/plugin/relativeTime"
6+
7+
dayjs.extend(relativeTime)
8+
9+
interface WorkspaceLastUsedProps {
10+
lastUsedAt: string
11+
}
12+
13+
export const WorkspaceLastUsed: FC<WorkspaceLastUsedProps> = ({ lastUsedAt }) => {
14+
const theme: Theme = useTheme()
15+
16+
const t = dayjs(lastUsedAt)
17+
const now = dayjs()
18+
19+
let color = theme.palette.text.secondary
20+
let message = t.fromNow()
21+
22+
if (t.isBefore(now.subtract(100, "year"))) {
23+
color = theme.palette.error.main
24+
message = "Never"
25+
} else if (t.isBefore(now.subtract(1, "month"))) {
26+
color = theme.palette.warning.light
27+
} else if (t.isAfter(now.subtract(24, "hour"))) {
28+
// Since the agent reports on a regular interval,
29+
// we default to "Today" instead of showing a
30+
// potentially inaccurate value.
31+
color = theme.palette.success.main
32+
message = "Today"
33+
}
34+
35+
return <span style={{ color: color }}>{message}</span>
36+
}

site/src/components/WorkspacesTable/WorkspacesRow.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "../TableCellData/TableCellData"
1616
import { TableCellLink } from "../TableCellLink/TableCellLink"
1717
import { OutdatedHelpTooltip } from "../Tooltips"
18+
import { WorkspaceLastUsed } from "./WorkspaceLastUsed"
1819

1920
const Language = {
2021
upToDateLabel: "Up to date",
@@ -64,6 +65,12 @@ export const WorkspacesRow: FC<
6465
}
6566
/>
6667
</TableCellLink>
68+
<TableCellLink to={workspacePageLink}>
69+
<TableCellData>
70+
<WorkspaceLastUsed lastUsedAt={workspace.last_used_at} />
71+
</TableCellData>
72+
</TableCellLink>
73+
6774
<TableCellLink to={workspacePageLink}>
6875
{workspace.outdated ? (
6976
<span className={styles.outdatedLabel}>

site/src/components/WorkspacesTable/WorkspacesTable.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WorkspacesTableBody } from "./WorkspacesTableBody"
1111
const Language = {
1212
name: "Name",
1313
template: "Template",
14+
lastUsed: "Last Used",
1415
version: "Version",
1516
status: "Status",
1617
lastBuiltBy: "Last Built By",
@@ -34,6 +35,7 @@ export const WorkspacesTable: FC<React.PropsWithChildren<WorkspacesTableProps>>
3435
<TableRow>
3536
<TableCell width="25%">{Language.name}</TableCell>
3637
<TableCell width="35%">{Language.template}</TableCell>
38+
<TableCell width="20%">{Language.lastUsed}</TableCell>
3739
<TableCell width="20%">{Language.version}</TableCell>
3840
<TableCell width="20%">{Language.status}</TableCell>
3941
<TableCell width="1%"></TableCell>

site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentMeta, Story } from "@storybook/react"
2+
import dayjs from "dayjs"
23
import { spawn } from "xstate"
34
import { ProvisionerJobStatus, WorkspaceTransition } from "../../api/typesGenerated"
45
import { MockWorkspace } from "../../testHelpers/entities"
@@ -13,6 +14,7 @@ const createWorkspaceItemRef = (
1314
status: ProvisionerJobStatus,
1415
transition: WorkspaceTransition = "start",
1516
outdated = false,
17+
lastUsedAt = "0001-01-01",
1618
): WorkspaceItemMachineRef => {
1719
return spawn(
1820
workspaceItemMachine.withContext({
@@ -27,6 +29,7 @@ const createWorkspaceItemRef = (
2729
status: status,
2830
},
2931
},
32+
last_used_at: lastUsedAt,
3033
},
3134
}),
3235
)
@@ -48,6 +51,14 @@ const additionalWorkspaces: Record<string, WorkspaceItemMachineRef> = {
4851
succeededAndStop: createWorkspaceItemRef("succeeded", "stop"),
4952
runningAndDelete: createWorkspaceItemRef("running", "delete"),
5053
outdated: createWorkspaceItemRef("running", "delete", true),
54+
active: createWorkspaceItemRef("running", undefined, true, dayjs().toString()),
55+
old: createWorkspaceItemRef("running", undefined, true, dayjs().subtract(1, "week").toString()),
56+
veryOld: createWorkspaceItemRef(
57+
"running",
58+
undefined,
59+
true,
60+
dayjs().subtract(1, "month").subtract(4, "day").toString(),
61+
),
5162
}
5263

5364
export default {

site/src/testHelpers/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export const MockWorkspace: TypesGen.Workspace = {
236236
autostart_schedule: MockWorkspaceAutostartEnabled.schedule,
237237
ttl_ms: 2 * 60 * 60 * 1000, // 2 hours as milliseconds
238238
latest_build: MockWorkspaceBuild,
239+
last_used_at: "",
239240
}
240241

241242
export const MockStoppedWorkspace: TypesGen.Workspace = {

0 commit comments

Comments
 (0)