Skip to content

feat: edit workspace schedule page #1701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -83,6 +84,14 @@ export const AppRouter: React.FC = () => (
</AuthAndFrame>
}
/>
<Route
path="schedule"
element={
<RequireAuth>
<WorkspaceSchedulePage />
</RequireAuth>
}
/>
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
5 changes: 4 additions & 1 deletion site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dayjs from "dayjs"
import duration from "dayjs/plugin/duration"
import relativeTime from "dayjs/plugin/relativeTime"
import React from "react"
import { Link as RouterLink } from "react-router-dom"
import { Workspace } from "../../api/typesGenerated"
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
import { extractTimezone, stripTimezone } from "../../util/schedule"
Expand Down Expand Up @@ -78,7 +79,9 @@ export const WorkspaceSchedule: React.FC<WorkspaceScheduleProps> = ({ workspace
<span className={styles.scheduleValue}>{Language.autoStopDisplay(workspace)}</span>
</div>
<div>
<Link className={styles.scheduleAction}>{Language.editScheduleLink}</Link>
<Link className={styles.scheduleAction} component={RouterLink} to={`/workspaces/${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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ const Template: Story<WorkspaceScheduleFormProps> = (args) => <WorkspaceSchedule
export const Example = Template.bind({})
Example.args = {
onCancel: () => action("onCancel"),
onSubmit: () => {
action("onSubmit")
return Promise.resolve()
},
onSubmit: () => action("onSubmit"),
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:

You'll see this show up in the WorkspaceScheduleForm component as well: I un-promisified onSubmit. I did this because the model goes to a new state once the promises resolve and the API calls are success. We use that state to navigate away from the page.

In other words, there is a bit of a 'fire-n-forget' from Formik's point of view, but since we also pass in isLoading to the form, which stems from the model, it still works out OK.

}
60 changes: 58 additions & 2 deletions site/src/components/WorkspaceStats/WorkspaceScheduleForm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const valid: WorkspaceScheduleFormValues = {
saturday: false,

startTime: "09:30",
timezone: "Canada/Eastern",
ttl: 120,
}

Expand All @@ -25,14 +26,15 @@ describe("validationSchema", () => {
saturday: false,

startTime: "",
timezone: "",
ttl: 0,
}
const validate = () => validationSchema.validateSync(values)
expect(validate).not.toThrow()
})

it("disallows ttl to be negative", () => {
const values = {
const values: WorkspaceScheduleFormValues = {
...valid,
ttl: -1,
}
Expand All @@ -41,7 +43,7 @@ describe("validationSchema", () => {
})

it("disallows all days-of-week to be false when startTime is set", () => {
const values = {
const values: WorkspaceScheduleFormValues = {
...valid,
sunday: false,
monday: false,
Expand All @@ -54,4 +56,58 @@ describe("validationSchema", () => {
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorNoDayOfWeek)
})

it("allows startTime 16:20", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
startTime: "16:20",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).not.toThrow()
})

it("disallows startTime to be H:mm", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
startTime: "9:30",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorTime)
})

it("disallows startTime to be HH:m", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
startTime: "09:5",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorTime)
})

it("disallows an invalid startTime 24:01", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
startTime: "24:01",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorTime)
})

it("disallows an invalid startTime 09:60", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
startTime: "09:60",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorTime)
})

it("disallows an invalid timezone Canada/North", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
timezone: "Canada/North",
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError(Language.errorTimezone)
})
})
Loading