Skip to content

fix: UX issues in template settings form's default auto-stop field #5330

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 8 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Format
  • Loading branch information
presleyp committed Dec 6, 2022
commit 6a339d7c460282895f554e8b7d064def364fd214
28 changes: 15 additions & 13 deletions site/src/pages/TemplateSettingsPage/TemplateSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ export const Language = {
"Please enter a limit that is less than or equal to 168 hours (7 days).",
descriptionMaxError:
"Please enter a description that is less than or equal to 128 characters.",
ttlHelperText: (ttl: number): string => ttl === 1 ?
`Workspaces created from this template will default to stopping after ${ttl} hour.` :
`Workspaces created from this template will default to stopping after ${ttl} hours.`,
noTTL: "Workspaces created from this template will run until stopped manually."
ttlHelperText: (ttl: number): string =>
ttl === 1
? `Workspaces created from this template will default to stopping after ${ttl} hour.`
: `Workspaces created from this template will default to stopping after ${ttl} hours.`,
noTTL:
"Workspaces created from this template will run until stopped manually.",
}

const TTLHelperText = ({ ttl }: { ttl?: number }) => (
ttl !== undefined ? <span>
{ttl === 0 ? Language.noTTL : Language.ttlHelperText(ttl)}
</span> : null
)
const TTLHelperText = ({ ttl }: { ttl?: number }) =>
ttl !== undefined ? (
<span>{ttl === 0 ? Language.noTTL : Language.ttlHelperText(ttl)}</span>
) : null

const MAX_DESCRIPTION_CHAR_LIMIT = 128
const MAX_TTL_DAYS = 7
Expand Down Expand Up @@ -120,9 +121,6 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({

const { t } = useTranslation("templatePage")

console.log(form)
console.log(getFieldHelpers("default_ttl_ms"))

return (
<form onSubmit={form.handleSubmit} aria-label={Language.formAriaLabel}>
<Stack>
Expand Down Expand Up @@ -215,7 +213,11 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
</div>

<TextField
{...getFieldHelpers("default_ttl_ms", <TTLHelperText ttl={form.values.default_ttl_ms} />, "Time until auto-stop")}
{...getFieldHelpers(
"default_ttl_ms",
<TTLHelperText ttl={form.values.default_ttl_ms} />,
"Time until auto-stop",
)}
disabled={isSubmitting}
fullWidth
inputProps={{ min: 0, step: 1 }}
Expand Down
5 changes: 4 additions & 1 deletion site/src/util/formUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const getFormHelpers =
const apiError = getIn(apiValidationErrors, name)
const frontendError = getIn(form.errors, name)
const returnError = apiError ?? frontendError
const friendlyError = friendlyLabel && returnError ? returnError.replace(name, friendlyLabel) : returnError
const friendlyError =
friendlyLabel && returnError
? returnError.replace(name, friendlyLabel)
: returnError
return {
...form.getFieldProps(name),
id: name,
Expand Down