Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
58ecefa
feat: edit workspace schedule page
greyscaled May 24, 2022
3f73a6c
fixup! feat: edit workspace schedule page
greyscaled May 24, 2022
30dff81
Merge branch 'main' into vapurrmaid/gh-1455/part-3/page
greyscaled May 24, 2022
ecc6792
remove promise
greyscaled May 24, 2022
c0f28c3
Merge origin/main
greyscaled May 24, 2022
d61a332
refactor to map + add loading/disabled
greyscaled May 24, 2022
f60f59b
time validation
greyscaled May 24, 2022
406d465
more tests
greyscaled May 24, 2022
a6dff9d
Update site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx
greyscaled May 24, 2022
7a14859
fix routing
greyscaled May 25, 2022
1158645
handle formErrors
greyscaled May 25, 2022
7a050db
finalize machine
greyscaled May 25, 2022
1166924
add timezone
greyscaled May 25, 2022
947b4a0
switch to TTL (hours)
greyscaled May 25, 2022
4764e5c
adjust ttl
greyscaled May 25, 2022
ebc4965
initialization
greyscaled May 26, 2022
747b52f
fixup! initialization
greyscaled May 26, 2022
854f781
fixup! initialization
greyscaled May 26, 2022
8bedc8a
Merge origin/main
greyscaled May 26, 2022
6afbb74
improve error message
greyscaled May 26, 2022
5bacfb1
Apply suggestions from code review
greyscaled May 26, 2022
5b3adc3
Update site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tes…
greyscaled May 26, 2022
81e7e05
fix ttl initialization
greyscaled May 26, 2022
531df3e
Update site/src/util/schedule.test.ts
greyscaled May 26, 2022
7ae590a
Fix typo
greyscaled May 26, 2022
262d9e3
import ReactNode directly
greyscaled May 26, 2022
5d22197
guess timezone
greyscaled May 26, 2022
eda8ad8
fix test
greyscaled May 26, 2022
f59f056
lint
greyscaled May 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! feat: edit workspace schedule page
  • Loading branch information
greyscaled committed May 24, 2022
commit 3f73a6cef72cc152fafb668541dcfab123d85423
9 changes: 9 additions & 0 deletions site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CreateUserPage } from "./pages/UsersPage/CreateUserPage/CreateUserPage"
import { UsersPage } from "./pages/UsersPage/UsersPage"
import { WorkspaceBuildPage } from "./pages/WorkspaceBuildPage/WorkspaceBuildPage"
import { WorkspacePage } from "./pages/WorkspacePage/WorkspacePage"
import { WorkspaceSchedulePage } from "./pages/WorkspaceSchedulePage/WorkspaceSchedulePage"
import { WorkspaceSettingsPage } from "./pages/WorkspaceSettingsPage/WorkspaceSettingsPage"

const TerminalPage = React.lazy(() => import("./pages/TerminalPage/TerminalPage"))
Expand Down Expand Up @@ -73,6 +74,14 @@ export const AppRouter: React.FC = () => (
</AuthAndFrame>
}
/>
<Route
path="schedule"
element={
<AuthAndFrame>
<WorkspaceSchedulePage />
</AuthAndFrame>
}
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

A route /workspaces/:workspace/schedule was added to view the form

</Route>
</Route>

Expand Down
76 changes: 40 additions & 36 deletions site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,44 @@ import { Stack } from "../Stack/Stack"
dayjs.extend(duration)
dayjs.extend(relativeTime)

const autoStartLabel = (schedule: string): string => {
const prefix = "Start"

if (schedule) {
return `${prefix} (${extractTimezone(schedule)})`
} else {
return prefix
}
}

const autoStartDisplay = (schedule: string): string => {
if (schedule) {
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
}
return "Manual"
}
const Language = {
autoStartDisplay: (schedule: string): string => {
if (schedule) {
return cronstrue.toString(stripTimezone(schedule), { throwExceptionOnParseError: false })
}
return "Manual"
},
autoStartLabel: (schedule: string): string => {
const prefix = "Start"

const autoStopDisplay = (workspace: Workspace): string => {
const latest = workspace.latest_build
if (schedule) {
return `${prefix} (${extractTimezone(schedule)})`
} else {
return prefix
}
},
autoStopDisplay: (workspace: Workspace): string => {
const latest = workspace.latest_build

if (!workspace.ttl || workspace.ttl < 1) {
return "Manual"
}
if (!workspace.ttl || workspace.ttl < 1) {
return "Manual"
}

if (latest.transition === "start") {
const now = dayjs()
const updatedAt = dayjs(latest.updated_at)
const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms")
if (now.isAfter(deadline)) {
return "Workspace is shutting down now"
if (latest.transition === "start") {
const now = dayjs()
const updatedAt = dayjs(latest.updated_at)
const deadline = updatedAt.add(workspace.ttl / 1_000_000, "ms")
if (now.isAfter(deadline)) {
return "Workspace is shutting down now"
}
return now.to(deadline)
}
return now.to(deadline)
}

const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
return `${duration.humanize()} after start`
const duration = dayjs.duration(workspace.ttl / 1_000_000, "milliseconds")
return `${duration.humanize()} after start`
},
editScheduleLink: "Edit schedule",
schedule: "Schedule",
}

export interface WorkspaceScheduleProps {
Expand All @@ -65,18 +67,20 @@ export const WorkspaceSchedule: React.FC<WorkspaceScheduleProps> = ({ workspace
<Stack spacing={2}>
<Typography variant="body1" className={styles.title}>
<ScheduleIcon className={styles.scheduleIcon} />
Schedule
{Language.schedule}
</Typography>
<div>
<span className={styles.scheduleLabel}>{autoStartLabel(workspace.autostart_schedule)}</span>
<span className={styles.scheduleValue}>{autoStartDisplay(workspace.autostart_schedule)}</span>
<span className={styles.scheduleLabel}>{Language.autoStartLabel(workspace.autostart_schedule)}</span>
<span className={styles.scheduleValue}>{Language.autoStartDisplay(workspace.autostart_schedule)}</span>
</div>
<div>
<span className={styles.scheduleLabel}>Shutdown</span>
<span className={styles.scheduleValue}>{autoStopDisplay(workspace)}</span>
<span className={styles.scheduleValue}>{Language.autoStopDisplay(workspace)}</span>
</div>
<div>
<Link className={styles.scheduleAction}>Edit schedule</Link>
<Link className={styles.scheduleAction} href={`/workspace/${workspace.id}/schedule`}>
{Language.editScheduleLink}
</Link>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: The dashboard link to edit a workspace schedule now works!

</div>
</Stack>
</div>
Expand Down