Skip to content

fix(site): Show job error on updating template variables #6674

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 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 1 addition & 10 deletions site/src/components/FullPageForm/FullPageHorizontalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PageHeaderSubtitle,
} from "components/PageHeader/PageHeader"
import Button from "@material-ui/core/Button"
import { makeStyles } from "@material-ui/core/styles"

export interface FullPageHorizontalFormProps {
title: string
Expand All @@ -17,8 +16,6 @@ export interface FullPageHorizontalFormProps {
export const FullPageHorizontalForm: FC<
React.PropsWithChildren<FullPageHorizontalFormProps>
> = ({ title, detail, onCancel, children }) => {
const styles = useStyles()

return (
<Margins size="medium">
<PageHeader
Expand All @@ -34,13 +31,7 @@ export const FullPageHorizontalForm: FC<
{detail && <PageHeaderSubtitle>{detail}</PageHeaderSubtitle>}
</PageHeader>

<main className={styles.form}>{children}</main>
<main>{children}</main>
</Margins>
)
}

const useStyles = makeStyles((theme) => ({
form: {
marginTop: theme.spacing(1),
},
}))
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const TemplateVariablesPage: FC = () => {
templateVariables,
getTemplateDataError,
updateTemplateError,
jobError,
} = state.context

const { t } = useTranslation("templateVariablesPage")
Expand All @@ -52,6 +53,7 @@ export const TemplateVariablesPage: FC = () => {
errors={{
getTemplateDataError,
updateTemplateError,
jobError,
}}
onCancel={() => {
navigate(`/templates/${templateName}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ WithUpdateTemplateError.args = {
onSubmit: action("onSubmit"),
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"),
}
74 changes: 42 additions & 32 deletions site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface TemplateVariablesPageViewProps {
errors?: {
getTemplateDataError?: unknown
updateTemplateError?: unknown
jobError?: TemplateVersion["job"]["error"]
}
initialTouched?: ComponentProps<
typeof TemplateVariablesForm
Expand All @@ -46,44 +47,53 @@ export const TemplateVariablesPageView: FC<TemplateVariablesPageViewProps> = ({
const { t } = useTranslation("templateVariablesPage")

return (
<FullPageHorizontalForm title={t("title")} onCancel={onCancel}>
{Boolean(errors.getTemplateDataError) && (
<Stack className={classes.errorContainer}>
<AlertBanner severity="error" error={errors.getTemplateDataError} />
</Stack>
)}
{Boolean(errors.updateTemplateError) && (
<Stack className={classes.errorContainer}>
<AlertBanner severity="error" error={errors.updateTemplateError} />
</Stack>
)}
{isLoading && <Loader />}
{templateVersion && templateVariables && templateVariables.length > 0 && (
<TemplateVariablesForm
initialTouched={initialTouched}
isSubmitting={isSubmitting}
templateVersion={templateVersion}
templateVariables={templateVariables}
onSubmit={onSubmit}
onCancel={onCancel}
error={errors.updateTemplateError}
/>
)}
{templateVariables && templateVariables.length === 0 && (
<div>
<AlertBanner severity="info" text={t("unusedVariablesNotice")} />
<div className={classes.goBackSection}>
<GoBackButton onClick={onCancel} />
<>
<FullPageHorizontalForm title={t("title")} onCancel={onCancel}>
{Boolean(errors.getTemplateDataError) && (
<Stack className={classes.errorContainer}>
<AlertBanner severity="error" error={errors.getTemplateDataError} />
</Stack>
)}
{Boolean(errors.updateTemplateError) && (
<Stack className={classes.errorContainer}>
<AlertBanner severity="error" error={errors.updateTemplateError} />
</Stack>
)}
{Boolean(errors.jobError) && (
<Stack className={classes.errorContainer}>
<AlertBanner severity="error" text={errors.jobError} />
</Stack>
)}
Copy link
Member

Choose a reason for hiding this comment

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

Will all three of these errors show up at once? Curious if we can simplify into one AlertBanner that accepts an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can for the other two, but not for jobError because it is a string. But I will take a look ok this!

{isLoading && <Loader />}
{templateVersion &&
templateVariables &&
templateVariables.length > 0 && (
<TemplateVariablesForm
initialTouched={initialTouched}
isSubmitting={isSubmitting}
templateVersion={templateVersion}
templateVariables={templateVariables}
onSubmit={onSubmit}
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>
)}
</FullPageHorizontalForm>
)}
</FullPageHorizontalForm>
</>
)
}

const useStyles = makeStyles((theme) => ({
errorContainer: {
marginBottom: theme.spacing(2),
marginBottom: theme.spacing(8),
},
goBackSection: {
display: "flex",
Expand Down
20 changes: 19 additions & 1 deletion site/src/xServices/template/templateVariablesXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type TemplateVariablesContext = {

getTemplateDataError?: Error | unknown
updateTemplateError?: Error | unknown

jobError?: TemplateVersion["job"]["error"]
}

type UpdateTemplateEvent = {
Expand Down Expand Up @@ -117,7 +119,7 @@ export const templateVariablesMachine = createMachine(
fillingParams: {
on: {
UPDATE_TEMPLATE_EVENT: {
actions: ["assignCreateTemplateVersionRequest"],
actions: ["assignCreateTemplateVersionRequest", "clearJobError"],
target: "creatingTemplateVersion",
},
},
Expand All @@ -141,6 +143,11 @@ export const templateVariablesMachine = createMachine(
invoke: {
src: "waitForJobToBeCompleted",
onDone: [
{
target: "fillingParams",
cond: "hasJobError",
actions: ["assignJobError"],
},
{
actions: ["assignNewTemplateVersion"],
target: "updatingTemplate",
Expand Down Expand Up @@ -258,6 +265,17 @@ export const templateVariablesMachine = createMachine(
clearUpdateTemplateError: assign({
updateTemplateError: (_) => undefined,
}),
assignJobError: assign({
jobError: (_, event) => event.data.job.error,
}),
clearJobError: assign({
jobError: (_) => undefined,
}),
},
guards: {
hasJobError: (_, { data }) => {
return Boolean(data.job.error)
},
},
},
)