8000 Template settings fixes/kira pilot by Kira-Pilot · Pull Request #3668 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

Template settings fixes/kira pilot #3668

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 13 commits into from
Aug 24, 2022
Prev Previous commit
Next Next commit
checking out
  • Loading branch information
Kira-Pilot committed Aug 24, 2022
commit 8b8882fe240837271d7e8ec04481a7a7aae6f665
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const Language = {
errorTime: "Time must be in HH:mm format (24 hours)",
errorTimezone: "Invalid timezone",
errorNoStop: "Time until shutdown must be greater than zero when auto-stop is enabled",
errorTtlMax: "Please enter a limit that is less than or equal to 168 hours (7 days).",
daysOfWeekLabel: "Days of Week",
daySundayLabel: "Sunday",
dayMondayLabel: "Monday",
Expand Down Expand Up @@ -159,7 +160,7 @@ export const validationSchema = Yup.object({
ttl: Yup.number()
.integer()
.min(0)
.max(24 * 7 /* 7 days */)
.max(24 * 7 /* 7 days */, Language.errorTtlMax)
.test("positive-if-auto-stop", Language.errorNoStop, function (value) {
const parent = this.parent as WorkspaceScheduleFormValues
if (parent.autoStopEnabled) {
Expand Down
12 changes: 2 additions & 10 deletions site/src/pages/TemplateSettingsPage/TemplateSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ export const Language = {
descriptionLabel: "Description",
maxTtlLabel: "Auto-stop limit",
iconLabel: "Icon",
// This is the same from the CLI on https://github.com/coder/coder/blob/546157b63ef9204658acf58cb653aa9936b70c49/cli/templateedit.go#L59
maxTtlHelperText: "Edit the template maximum time before shutdown in hours",
formAriaLabel: "Template settings form",
selectEmoji: "Select emoji",
ttlMaxError: "Please enter a limit that is less than or equal to 168 hours (7 days).",
}

export const validationSchema = Yup.object({
name: nameValidator(Language.nameLabel),
description: Yup.string(),
max_ttl_ms: Yup.number(),
max_ttl_ms: Yup.number().integer().min(0).max(168, Language.ttlMaxError),
})

export interface TemplateSettingsForm {
Expand Down Expand Up @@ -148,18 +147,11 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({

<TextField
{...getFieldHelpers("max_ttl_ms")}
helperText={Language.maxTtlHelperText}
disabled={isSubmitting}
fullWidth
inputProps={{ min: 0, step: 1 }}
label={Language.maxTtlLabel}
variant="outlined"
// Display hours from ms
value={form.values.max_ttl_ms ? form.values.max_ttl_ms / 3600000 : ""}
// Convert hours to ms
onChange={(event) =>
form.setFieldValue("max_ttl_ms", Number(event.currentTarget.value) * 3600000)
}
/>
</Stack>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UpdateTemplateMeta } from "api/typesGenerated"
import { Language as FooterFormLanguage } from "components/FormFooter/FormFooter"
import { MockTemplate } from "../../testHelpers/entities"
import { renderWithAuth } from "../../testHelpers/renderHelpers"
import { Language as FormLanguage } from "./TemplateSettingsForm"
import { Language as FormLanguage, validationSchema } from "./TemplateSettingsForm"
import { TemplateSettingsPage } from "./TemplateSettingsPage"
import { Language as ViewLanguage } from "./TemplateSettingsPageView"

Expand All @@ -19,6 +19,14 @@ const renderTemplateSettingsPage = async () => {
return renderResult
}

const validFormValues: UpdateTemplateMeta = {
name: "A name",
description: "A description",
icon: "A string",
max_ttl_ms: 24,
min_autostart_interval_ms: 24,
}

const fillAndSubmitForm = async ({
name,
description,
Expand Down Expand Up @@ -99,4 +107,22 @@ describe("TemplateSettingsPage", () => {
),
)
})

it("allows a ttl of 7 days", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
max_ttl_ms: 24 * 7,
}
const validate = () => validationSchema.validateSync(values)
expect(validate).not.toThrowError()
})

it("disallows a ttl of 7 days + 1 hour", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
max_ttl_ms: 24 * 7 + 1,
}
const validate = () => validationSchema.validateSync(values)
expect(validate).toThrowError("ttl must be less than or equal to 168")
})
})
0