@@ -32,6 +32,7 @@ import { RESERVED_VARIANT } from "../utilities"
32
32
interface CreateFormState {
33
33
loading : boolean
34
34
errorText ?: string
35
+ createButtonDisabled : boolean
35
36
backfill ?: IBackfill
36
37
dry_run : boolean
37
38
@@ -62,6 +63,7 @@ class CreateFormContainer extends React.Component<
62
63
this . setState ( {
63
64
loading : false ,
64
65
errorText : null ,
66
+ createButtonDisabled : false ,
65
67
backfill : null ,
66
68
dry_run : true ,
67
69
scan_size : 10000 ,
@@ -75,6 +77,45 @@ class CreateFormContainer extends React.Component<
75
77
} )
76
78
}
77
79
80
+ async handleClick ( ) {
81
+ this . setState ( { createButtonDisabled : true } )
82
+
83
+ try {
84
+ await new Promise ( resolve => { setTimeout ( resolve , 10000 ) } )
85
+ const response = await Axios . post (
86
+ `/services/${ this . service } /variants/${ this . variant } /create` ,
87
+ {
88
+ backfill_name : this . state . backfill . name ,
89
+ dry_run : this . state . dry_run ,
90
+ scan_size : this . state . scan_size ,
91
+ batch_size : this . state . batch_size ,
92
+ num_threads : this . state . num_threads ,
93
+ pkey_range_start : this . nullIfEmpty (
94
+ this . base64 ( this . state . pkey_range_start )
95
+ ) ,
96
+ pkey_range_end : this . nullIfEmpty (
97
+ this . base64 ( this . state . pkey_range_end )
98
+ ) ,
99
+ backoff_schedule : this . nullIfEmpty ( this . state . backoff_schedule ) ,
100
+ extra_sleep_ms : this . state . extra_sleep_ms ,
101
+ parameter_map : this . state . parameters
102
+ }
103
+ )
104
+
105
+ let id = response . data . backfill_run_id
106
+ let history = ( this . props as any ) . history
107
+ history . push ( `/app/backfills/${ id } ` )
108
+ } catch ( error ) {
109
+ console . log ( error )
110
+ this . setState ( {
111
+ loading : false ,
112
+ errorText : error . response . data
113
+ } )
114
+ } finally {
115
+ this . setState ( { createButtonDisabled : false } )
116
+ }
117
+ }
118
+
78
119
render ( ) {
79
120
let registeredBackfills = simpleSelectorGet ( this . props . simpleNetwork , [
80
121
this . registeredBackfills ,
@@ -246,43 +287,13 @@ class CreateFormContainer extends React.Component<
246
287
) }
247
288
< Button
248
289
onClick = { ( ) => {
249
- Axios . post (
250
- `/services/${ this . service } /variants/${ this . variant } /create` ,
251
- {
252
- backfill_name : this . state . backfill . name ,
253
- dry_run : this . state . dry_run ,
254
- scan_size : this . state . scan_size ,
255
- batch_size : this . state . batch_size ,
256
- num_threads : this . state . num_threads ,
257
- pkey_range_start : this . nullIfEmpty (
258
- this . base64 ( this . state . pkey_range_start )
259
- ) ,
260
- pkey_range_end : this . nullIfEmpty (
261
- this . base64 ( this . state . pkey_range_end )
262
- ) ,
263
- backoff_schedule : this . nullIfEmpty (
264
- this . state . backoff_schedule
265
- ) ,
266
- extra_sleep_ms : this . state . extra_sleep_ms ,
267
- parameter_map : this . state . parameters
268
- }
269
- )
270
- . then ( response => {
271
- let id = response . data . backfill_run_id
272
- let history = ( this . props as any ) . history
273
- history . push ( `/app/backfills/${ id } ` )
274
- } )
275
- . catch ( error => {
276
- console . log ( error )
277
- this . setState ( {
278
- loading : false ,
279
- errorText : error . response . data
280
- } )
281
- } )
290
+ this . handleClick ( )
282
291
} }
283
292
intent = { Intent . PRIMARY }
284
293
loading = { this . state . loading }
285
- disabled = { ! this . state . backfill }
294
+ disabled = {
295
+ this . state . createButtonDisabled || ! this . state . backfill
296
+ }
286
297
text = { "Create" }
287
298
/>
288
299
</ div >
0 commit comments