@@ -21,6 +21,7 @@ import {
21
21
import { useWorkflowEngineFeatureGate } from 'sentry/components/workflowEngine/useWorkflowEngineFeatureGate' ;
22
22
import { t } from 'sentry/locale' ;
23
23
import { space } from 'sentry/styles/space' ;
24
+ import type { Automation } from 'sentry/types/workflowEngine/automations' ;
24
25
import { useNavigate } from 'sentry/utils/useNavigate' ;
25
26
import useOrganization from 'sentry/utils/useOrganization' ;
26
27
import { useParams } from 'sentry/utils/useParams' ;
@@ -36,6 +37,7 @@ import type {AutomationFormData} from 'sentry/views/automations/components/autom
36
37
import {
37
38
getAutomationFormData ,
38
39
getNewAutomationData ,
40
+ validateAutomationBuilderState ,
39
41
} from 'sentry/views/automations/components/automationFormData' ;
40
42
import { EditableAutomationName } from 'sentry/views/automations/components/editableAutomationName' ;
41
43
import { useAutomationQuery , useUpdateAutomation } from 'sentry/views/automations/hooks' ;
@@ -67,10 +69,7 @@ function AutomationBreadcrumbs({automationId}: {automationId: string}) {
67
69
}
68
70
69
71
export default function AutomationEdit ( ) {
70
- const navigate = useNavigate ( ) ;
71
- const organization = useOrganization ( ) ;
72
72
const params = useParams < { automationId : string } > ( ) ;
73
- const { mutateAsync : updateAutomation } = useUpdateAutomation ( ) ;
74
73
75
74
useWorkflowEngineFeatureGate ( { redirect : true } ) ;
76
75
@@ -81,6 +80,23 @@ export default function AutomationEdit() {
81
80
refetch,
82
81
} = useAutomationQuery ( params . automationId ) ;
83
82
83
+ if ( isPending ) {
84
+ return < LoadingIndicator /> ;
85
+ }
86
+
87
+ if ( isError || ! automation ) {
88
+ return < LoadingError onRetry = { refetch } /> ;
89
+ }
90
+
91
+ return < AutomationEditForm automation = { automation } /> ;
92
+ }
93
+
94
+ function AutomationEditForm ( { automation} : { automation : Automation } ) {
95
+ const navigate = useNavigate ( ) ;
96
+ const organization = useOrganization ( ) ;
97
+ const params = useParams < { automationId : string } > ( ) ;
98
+ const { mutateAsync : updateAutomation } = useUpdateAutomation ( ) ;
99
+
84
100
const initialData = useMemo ( ( ) : Record < string , FieldValue > | undefined => {
85
101
if ( ! automation ) {
86
102
return undefined ;
@@ -115,25 +131,22 @@ export default function AutomationEdit() {
115
131
116
132
const handleFormSubmit = useCallback < OnSubmitCallback > (
117
133
async ( data , _ , __ , ___ , ____ ) => {
118
- const formData = getNewAutomationData ( data as AutomationFormData , state ) ;
119
- const updatedData = {
120
- automationId : params . automationId ,
121
- ...formData ,
122
- } ;
123
- const updatedAutomation = await updateAutomation ( updatedData ) ;
124
- navigate ( makeAutomationDetailsPathname ( organization . slug , updatedAutomation . id ) ) ;
134
+ const errors = validateAutomationBuilderState ( state ) ;
135
+ setAutomationBuilderErrors ( errors ) ;
136
+
137
+ if ( Object . keys ( errors ) . length === 0 ) {
138
+ const formData = getNewAutomationData ( data as AutomationFormData , state ) ;
139
+ const updatedData = {
140
+ automationId : params . automationId ,
141
+ ...formData ,
142
+ } ;
143
+ const updatedAutomation = await updateAutomation ( updatedData ) ;
144
+ navigate ( makeAutomationDetailsPathname ( organization . slug , updatedAutomation . id ) ) ;
145
+ }
125
146
} ,
126
147
[ params . automationId , organization . slug , navigate , updateAutomation , state ]
127
148
) ;
128
149
129
- if ( isPending && ! initialData ) {
130
- return < LoadingIndicator /> ;
131
- }
132
-
133
- if ( isError || ! automation || ! initialData ) {
134
- return < LoadingError onRetry = { refetch } /> ;
135
- }
136
-
137
150
return (
138
151
< FullHeightForm
139
152
hideFooter
0 commit comments