mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix(site): Show job error on updating template variables (#6674)
This commit is contained in:
@ -6,7 +6,6 @@ import {
|
|||||||
PageHeaderSubtitle,
|
PageHeaderSubtitle,
|
||||||
} from "components/PageHeader/PageHeader"
|
} from "components/PageHeader/PageHeader"
|
||||||
import Button from "@material-ui/core/Button"
|
import Button from "@material-ui/core/Button"
|
||||||
import { makeStyles } from "@material-ui/core/styles"
|
|
||||||
|
|
||||||
export interface FullPageHorizontalFormProps {
|
export interface FullPageHorizontalFormProps {
|
||||||
title: string
|
title: string
|
||||||
@ -17,8 +16,6 @@ export interface FullPageHorizontalFormProps {
|
|||||||
export const FullPageHorizontalForm: FC<
|
export const FullPageHorizontalForm: FC<
|
||||||
React.PropsWithChildren<FullPageHorizontalFormProps>
|
React.PropsWithChildren<FullPageHorizontalFormProps>
|
||||||
> = ({ title, detail, onCancel, children }) => {
|
> = ({ title, detail, onCancel, children }) => {
|
||||||
const styles = useStyles()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Margins size="medium">
|
<Margins size="medium">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
@ -34,13 +31,7 @@ export const FullPageHorizontalForm: FC<
|
|||||||
{detail && <PageHeaderSubtitle>{detail}</PageHeaderSubtitle>}
|
{detail && <PageHeaderSubtitle>{detail}</PageHeaderSubtitle>}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
<main className={styles.form}>{children}</main>
|
<main>{children}</main>
|
||||||
</Margins>
|
</Margins>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
|
||||||
form: {
|
|
||||||
marginTop: theme.spacing(1),
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
@ -36,6 +36,7 @@ export const TemplateVariablesPage: FC = () => {
|
|||||||
templateVariables,
|
templateVariables,
|
||||||
getTemplateDataError,
|
getTemplateDataError,
|
||||||
updateTemplateError,
|
updateTemplateError,
|
||||||
|
jobError,
|
||||||
} = state.context
|
} = state.context
|
||||||
|
|
||||||
const { t } = useTranslation("templateVariablesPage")
|
const { t } = useTranslation("templateVariablesPage")
|
||||||
@ -52,6 +53,7 @@ export const TemplateVariablesPage: FC = () => {
|
|||||||
errors={{
|
errors={{
|
||||||
getTemplateDataError,
|
getTemplateDataError,
|
||||||
updateTemplateError,
|
updateTemplateError,
|
||||||
|
jobError,
|
||||||
}}
|
}}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
navigate(`/templates/${templateName}`)
|
navigate(`/templates/${templateName}`)
|
||||||
|
@ -76,3 +76,20 @@ WithUpdateTemplateError.args = {
|
|||||||
onSubmit: action("onSubmit"),
|
onSubmit: action("onSubmit"),
|
||||||
onCancel: action("cancel"),
|
onCancel: action("cancel"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const WithJobError = TemplateVariables.bind({})
|
||||||
|
WithJobError.args = {
|
||||||
|
templateVersion: MockTemplateVersion,
|
||||||
|
templateVariables: [
|
||||||
|
MockTemplateVersionVariable1,
|
||||||
|
MockTemplateVersionVariable2,
|
||||||
|
MockTemplateVersionVariable3,
|
||||||
|
MockTemplateVersionVariable4,
|
||||||
|
],
|
||||||
|
errors: {
|
||||||
|
jobError:
|
||||||
|
"template import provision for start: recv import provision: plan terraform: terraform plan: exit status 1",
|
||||||
|
},
|
||||||
|
onSubmit: action("onSubmit"),
|
||||||
|
onCancel: action("cancel"),
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ export interface TemplateVariablesPageViewProps {
|
|||||||
errors?: {
|
errors?: {
|
||||||
getTemplateDataError?: unknown
|
getTemplateDataError?: unknown
|
||||||
updateTemplateError?: unknown
|
updateTemplateError?: unknown
|
||||||
|
jobError?: TemplateVersion["job"]["error"]
|
||||||
}
|
}
|
||||||
initialTouched?: ComponentProps<
|
initialTouched?: ComponentProps<
|
||||||
typeof TemplateVariablesForm
|
typeof TemplateVariablesForm
|
||||||
@ -46,44 +47,53 @@ export const TemplateVariablesPageView: FC<TemplateVariablesPageViewProps> = ({
|
|||||||
const { t } = useTranslation("templateVariablesPage")
|
const { t } = useTranslation("templateVariablesPage")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullPageHorizontalForm title={t("title")} onCancel={onCancel}>
|
<>
|
||||||
{Boolean(errors.getTemplateDataError) && (
|
<FullPageHorizontalForm title={t("title")} onCancel={onCancel}>
|
||||||
<Stack className={classes.errorContainer}>
|
{Boolean(errors.getTemplateDataError) && (
|
||||||
<AlertBanner severity="error" error={errors.getTemplateDataError} />
|
<Stack className={classes.errorContainer}>
|
||||||
</Stack>
|
<AlertBanner severity="error" error={errors.getTemplateDataError} />
|
||||||
)}
|
</Stack>
|
||||||
{Boolean(errors.updateTemplateError) && (
|
)}
|
||||||
<Stack className={classes.errorContainer}>
|
{Boolean(errors.updateTemplateError) && (
|
||||||
<AlertBanner severity="error" error={errors.updateTemplateError} />
|
<Stack className={classes.errorContainer}>
|
||||||
</Stack>
|
<AlertBanner severity="error" error={errors.updateTemplateError} />
|
||||||
)}
|
</Stack>
|
||||||
{isLoading && <Loader />}
|
)}
|
||||||
{templateVersion && templateVariables && templateVariables.length > 0 && (
|
{Boolean(errors.jobError) && (
|
||||||
<TemplateVariablesForm
|
<Stack className={classes.errorContainer}>
|
||||||
initialTouched={initialTouched}
|
<AlertBanner severity="error" text={errors.jobError} />
|
||||||
isSubmitting={isSubmitting}
|
</Stack>
|
||||||
templateVersion={templateVersion}
|
)}
|
||||||
templateVariables={templateVariables}
|
{isLoading && <Loader />}
|
||||||
onSubmit={onSubmit}
|
{templateVersion &&
|
||||||
onCancel={onCancel}
|
templateVariables &&
|
||||||
error={errors.updateTemplateError}
|
templateVariables.length > 0 && (
|
||||||
/>
|
<TemplateVariablesForm
|
||||||
)}
|
initialTouched={initialTouched}
|
||||||
{templateVariables && templateVariables.length === 0 && (
|
isSubmitting={isSubmitting}
|
||||||
<div>
|
templateVersion={templateVersion}
|
||||||
<AlertBanner severity="info" text={t("unusedVariablesNotice")} />
|
templateVariables={templateVariables}
|
||||||
<div className={classes.goBackSection}>
|
onSubmit={onSubmit}
|
||||||
<GoBackButton onClick={onCancel} />
|
onCancel={onCancel}
|
||||||
|
error={errors.updateTemplateError}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{templateVariables && templateVariables.length === 0 && (
|
||||||
|
<div>
|
||||||
|
<AlertBanner severity="info" text={t("unusedVariablesNotice")} />
|
||||||
|
<div className={classes.goBackSection}>
|
||||||
|
<GoBackButton onClick={onCancel} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</FullPageHorizontalForm>
|
||||||
</FullPageHorizontalForm>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
errorContainer: {
|
errorContainer: {
|
||||||
marginBottom: theme.spacing(2),
|
marginBottom: theme.spacing(8),
|
||||||
},
|
},
|
||||||
goBackSection: {
|
goBackSection: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -28,6 +28,8 @@ type TemplateVariablesContext = {
|
|||||||
|
|
||||||
getTemplateDataError?: Error | unknown
|
getTemplateDataError?: Error | unknown
|
||||||
updateTemplateError?: Error | unknown
|
updateTemplateError?: Error | unknown
|
||||||
|
|
||||||
|
jobError?: TemplateVersion["job"]["error"]
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateTemplateEvent = {
|
type UpdateTemplateEvent = {
|
||||||
@ -117,7 +119,7 @@ export const templateVariablesMachine = createMachine(
|
|||||||
fillingParams: {
|
fillingParams: {
|
||||||
on: {
|
on: {
|
||||||
UPDATE_TEMPLATE_EVENT: {
|
UPDATE_TEMPLATE_EVENT: {
|
||||||
actions: ["assignCreateTemplateVersionRequest"],
|
actions: ["assignCreateTemplateVersionRequest", "clearJobError"],
|
||||||
target: "creatingTemplateVersion",
|
target: "creatingTemplateVersion",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -141,6 +143,11 @@ export const templateVariablesMachine = createMachine(
|
|||||||
invoke: {
|
invoke: {
|
||||||
src: "waitForJobToBeCompleted",
|
src: "waitForJobToBeCompleted",
|
||||||
onDone: [
|
onDone: [
|
||||||
|
{
|
||||||
|
target: "fillingParams",
|
||||||
|
cond: "hasJobError",
|
||||||
|
actions: ["assignJobError"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
actions: ["assignNewTemplateVersion"],
|
actions: ["assignNewTemplateVersion"],
|
||||||
target: "updatingTemplate",
|
target: "updatingTemplate",
|
||||||
@ -258,6 +265,17 @@ export const templateVariablesMachine = createMachine(
|
|||||||
clearUpdateTemplateError: assign({
|
clearUpdateTemplateError: assign({
|
||||||
updateTemplateError: (_) => undefined,
|
updateTemplateError: (_) => undefined,
|
||||||
}),
|
}),
|
||||||
|
assignJobError: assign({
|
||||||
|
jobError: (_, event) => event.data.job.error,
|
||||||
|
}),
|
||||||
|
clearJobError: assign({
|
||||||
|
jobError: (_) => undefined,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
guards: {
|
||||||
|
hasJobError: (_, { data }) => {
|
||||||
|
return Boolean(data.job.error)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user