From cc66a2490cab018eb91b2e7b40bd7df593a296ca Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Mon, 20 Mar 2023 14:45:03 +0000 Subject: [PATCH] fix(site): Show job error on updating template variables --- .../FullPageForm/FullPageHorizontalForm.tsx | 11 +-- .../TemplateVariablesPage.tsx | 2 + .../TemplateVariablesPageView.stories.tsx | 17 +++++ .../TemplateVariablesPageView.tsx | 74 +++++++++++-------- .../template/templateVariablesXService.ts | 20 ++++- 5 files changed, 81 insertions(+), 43 deletions(-) diff --git a/site/src/components/FullPageForm/FullPageHorizontalForm.tsx b/site/src/components/FullPageForm/FullPageHorizontalForm.tsx index 7697dc7ba1da1..e31c37f003898 100644 --- a/site/src/components/FullPageForm/FullPageHorizontalForm.tsx +++ b/site/src/components/FullPageForm/FullPageHorizontalForm.tsx @@ -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 @@ -17,8 +16,6 @@ export interface FullPageHorizontalFormProps { export const FullPageHorizontalForm: FC< React.PropsWithChildren > = ({ title, detail, onCancel, children }) => { - const styles = useStyles() - return ( {detail}} -
{children}
+
{children}
) } - -const useStyles = makeStyles((theme) => ({ - form: { - marginTop: theme.spacing(1), - }, -})) diff --git a/site/src/pages/TemplateVariablesPage/TemplateVariablesPage.tsx b/site/src/pages/TemplateVariablesPage/TemplateVariablesPage.tsx index 5a3e94e0af978..93c4379571e60 100644 --- a/site/src/pages/TemplateVariablesPage/TemplateVariablesPage.tsx +++ b/site/src/pages/TemplateVariablesPage/TemplateVariablesPage.tsx @@ -36,6 +36,7 @@ export const TemplateVariablesPage: FC = () => { templateVariables, getTemplateDataError, updateTemplateError, + jobError, } = state.context const { t } = useTranslation("templateVariablesPage") @@ -52,6 +53,7 @@ export const TemplateVariablesPage: FC = () => { errors={{ getTemplateDataError, updateTemplateError, + jobError, }} onCancel={() => { navigate(`/templates/${templateName}`) diff --git a/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.stories.tsx b/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.stories.tsx index 00fa2aff55d4c..2638196cc8540 100644 --- a/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.stories.tsx +++ b/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.stories.tsx @@ -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"), +} diff --git a/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.tsx b/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.tsx index 9048c6bdcfe69..d59675f5ac903 100644 --- a/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.tsx +++ b/site/src/pages/TemplateVariablesPage/TemplateVariablesPageView.tsx @@ -22,6 +22,7 @@ export interface TemplateVariablesPageViewProps { errors?: { getTemplateDataError?: unknown updateTemplateError?: unknown + jobError?: TemplateVersion["job"]["error"] } initialTouched?: ComponentProps< typeof TemplateVariablesForm @@ -46,44 +47,53 @@ export const TemplateVariablesPageView: FC = ({ const { t } = useTranslation("templateVariablesPage") return ( - - {Boolean(errors.getTemplateDataError) && ( - - - - )} - {Boolean(errors.updateTemplateError) && ( - - - - )} - {isLoading && } - {templateVersion && templateVariables && templateVariables.length > 0 && ( - - )} - {templateVariables && templateVariables.length === 0 && ( -
- -
- + <> + + {Boolean(errors.getTemplateDataError) && ( + + + + )} + {Boolean(errors.updateTemplateError) && ( + + + + )} + {Boolean(errors.jobError) && ( + + + + )} + {isLoading && } + {templateVersion && + templateVariables && + templateVariables.length > 0 && ( + + )} + {templateVariables && templateVariables.length === 0 && ( +
+ +
+ +
-
- )} - + )} + + ) } const useStyles = makeStyles((theme) => ({ errorContainer: { - marginBottom: theme.spacing(2), + marginBottom: theme.spacing(8), }, goBackSection: { display: "flex", diff --git a/site/src/xServices/template/templateVariablesXService.ts b/site/src/xServices/template/templateVariablesXService.ts index 898670c8bf5b5..bdeda05c84f76 100644 --- a/site/src/xServices/template/templateVariablesXService.ts +++ b/site/src/xServices/template/templateVariablesXService.ts @@ -28,6 +28,8 @@ type TemplateVariablesContext = { getTemplateDataError?: Error | unknown updateTemplateError?: Error | unknown + + jobError?: TemplateVersion["job"]["error"] } type UpdateTemplateEvent = { @@ -117,7 +119,7 @@ export const templateVariablesMachine = createMachine( fillingParams: { on: { UPDATE_TEMPLATE_EVENT: { - actions: ["assignCreateTemplateVersionRequest"], + actions: ["assignCreateTemplateVersionRequest", "clearJobError"], target: "creatingTemplateVersion", }, }, @@ -141,6 +143,11 @@ export const templateVariablesMachine = createMachine( invoke: { src: "waitForJobToBeCompleted", onDone: [ + { + target: "fillingParams", + cond: "hasJobError", + actions: ["assignJobError"], + }, { actions: ["assignNewTemplateVersion"], target: "updatingTemplate", @@ -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) + }, }, }, )