@@ -17,7 +17,7 @@ import ISMTemplates from "../../components/ISMTemplates";
17
17
import States from "../../components/States" ;
18
18
import CreateState from "../CreateState" ;
19
19
import { getErrorMessage } from "../../../../utils/helpers" ;
20
- import { getUpdatedStates } from "../../utils/helpers" ;
20
+ import { getUpdatedPolicy , getUpdatedStates } from "../../utils/helpers" ;
21
21
import ErrorNotification from "../ErrorNotification" ;
22
22
23
23
interface VisualCreatePolicyProps extends RouteComponentProps {
@@ -171,13 +171,13 @@ export default class VisualCreatePolicy extends Component<VisualCreatePolicyProp
171
171
this . context . notifications . toasts . addSuccess ( `Created policy: ${ response . response . _id } ` ) ;
172
172
this . props . history . push ( ROUTES . INDEX_POLICIES ) ;
173
173
} else {
174
- this . setState ( { submitError : response . error } ) ;
174
+ this . setState ( { submitError : response . error , isSubmitting : false } ) ;
175
175
this . context . notifications . toasts . addDanger ( `Failed to create policy: ${ response . error } ` ) ;
176
176
}
177
177
} catch ( err ) {
178
178
const errorMessage = getErrorMessage ( err , "There was a problem creating the policy" ) ;
179
179
this . context . notifications . toasts . addDanger ( errorMessage ) ;
180
- this . setState ( { submitError : errorMessage } ) ;
180
+ this . setState ( { submitError : errorMessage , isSubmitting : false } ) ;
181
181
}
182
182
} ;
183
183
@@ -195,12 +195,12 @@ export default class VisualCreatePolicy extends Component<VisualCreatePolicyProp
195
195
this . props . history . push ( ROUTES . INDEX_POLICIES ) ;
196
196
} else {
197
197
this . context . notifications . toasts . addDanger ( `Failed to update policy: ${ response . error } ` ) ;
198
- this . setState ( { submitError : response . error } ) ;
198
+ this . setState ( { submitError : response . error , isSubmitting : false } ) ;
199
199
}
200
200
} catch ( err ) {
201
201
const errorMessage = getErrorMessage ( err , "There was a problem updating the policy" ) ;
202
202
this . context . notifications . toasts . addDanger ( errorMessage ) ;
203
- this . setState ( { submitError : errorMessage } ) ;
203
+ this . setState ( { submitError : errorMessage , isSubmitting : false } ) ;
204
204
}
205
205
} ;
206
206
@@ -223,9 +223,15 @@ export default class VisualCreatePolicy extends Component<VisualCreatePolicyProp
223
223
} catch ( err ) {
224
224
this . context . notifications . toasts . addDanger ( "Invalid Policy" ) ;
225
225
console . error ( err ) ;
226
+ this . setState ( { isSubmitting : false } ) ;
226
227
}
228
+ } ;
227
229
228
- this . setState ( { isSubmitting : false } ) ;
230
+ onSaveState = ( state : State , states : State [ ] , order : string , afterBeforeState : string ) => {
231
+ const { policy, editingState } = this . state ;
232
+ const updatedPolicy = getUpdatedPolicy ( policy , state , editingState , states , order , afterBeforeState ) ;
233
+ this . setState ( { policy : updatedPolicy } ) ;
234
+ this . onCloseFlyout ( ) ;
229
235
} ;
230
236
231
237
render ( ) {
@@ -272,25 +278,7 @@ export default class VisualCreatePolicy extends Component<VisualCreatePolicyProp
272
278
< EuiSpacer size = "m" />
273
279
274
280
{ showFlyout && (
275
- < CreateState
276
- state = { editingState }
277
- policy = { policy }
278
- onSaveState = { ( state : State , editingState : State | null , states : State [ ] , order : string , afterBeforeState : string ) => {
279
- const updatedStates = getUpdatedStates ( state , editingState , states , order , afterBeforeState ) ;
280
- let defaultState = policy . default_state ;
281
- // If we are creating the first state, set the default state to it
282
- if ( updatedStates . length === 1 ) defaultState = updatedStates [ 0 ] . name ;
283
- this . setState ( {
284
- policy : {
285
- ...policy ,
286
- states : updatedStates ,
287
- default_state : defaultState ,
288
- } ,
289
- } ) ;
290
- this . onCloseFlyout ( ) ;
291
- } }
292
- onCloseFlyout = { this . onCloseFlyout }
293
- />
281
+ < CreateState state = { editingState } policy = { policy } onSaveState = { this . onSaveState } onCloseFlyout = { this . onCloseFlyout } />
294
282
) }
295
283
296
284
< EuiFlexGroup alignItems = "center" justifyContent = "flexEnd" >
0 commit comments