13
13
//
14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- import React , { Fragment , useEffect , useState } from "react" ;
16
+ import { Fragment , useEffect , useState } from "react" ;
17
+ import clsx from "clsx" ;
17
18
import {
18
19
ICloseEvent ,
19
20
IMessageEvent ,
@@ -72,19 +73,19 @@ const styles = (theme: Theme) =>
72
73
textAlign : "center" ,
73
74
marginBottom : 10 ,
74
75
} ,
75
- startDiagnostic : {
76
- textAlign : "center" ,
77
- marginBottom : 25 ,
78
- } ,
79
76
progressResult : {
80
77
textAlign : "center" ,
81
78
marginBottom : 25 ,
82
79
} ,
83
- diagNew : {
80
+ startDiagnostic : {
84
81
textAlign : "right" ,
85
82
margin : 25 ,
86
83
marginBottom : 0 ,
87
84
} ,
85
+ startDiagnosticCenter : {
86
+ textAlign : "center" ,
87
+ marginTop : 0 ,
88
+ } ,
88
89
...actionsTray ,
89
90
...containerForHeader ( theme . spacing ( 4 ) ) ,
90
91
} ) ;
@@ -104,12 +105,17 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
104
105
( state : AppState ) => state . system . serverDiagnosticStatus
105
106
) ;
106
107
const [ startDiagnostic , setStartDiagnostic ] = useState ( false ) ;
107
- const [ diagStarted , setDiagStarted ] = useState < boolean > ( false ) ;
108
108
const [ downloadDisabled , setDownloadDisabled ] = useState ( true ) ;
109
109
const [ localMessage , setMessage ] = useState < string > ( "" ) ;
110
+ const [ buttonStartText , setButtonStartText ] =
111
+ useState < string > ( "Start Diagnostic" ) ;
110
112
const [ title , setTitle ] = useState < string > ( "New Diagnostic" ) ;
111
113
const [ diagFileContent , setDiagFileContent ] = useState < string > ( "" ) ;
112
114
115
+ const isDiagnosticComplete =
116
+ serverDiagnosticStatus === DiagStatSuccess ||
117
+ serverDiagnosticStatus === DiagStatError ;
118
+
113
119
const download = ( ) => {
114
120
let element = document . createElement ( "a" ) ;
115
121
element . setAttribute (
@@ -129,19 +135,26 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
129
135
useEffect ( ( ) => {
130
136
if ( serverDiagnosticStatus === DiagStatInProgress ) {
131
137
setTitle ( "Diagnostic in progress..." ) ;
138
+ setMessage (
139
+ "Diagnostic started. Please do not refresh page during diagnosis."
140
+ ) ;
132
141
return ;
133
142
}
134
143
135
- if ( serverDiagnosticStatus === DiagStatSuccess && diagStarted ) {
144
+ if ( serverDiagnosticStatus === DiagStatSuccess ) {
136
145
setTitle ( "Diagnostic complete" ) ;
146
+ setMessage ( "Diagnostic file is ready to be downloaded." ) ;
147
+ setButtonStartText ( "Start New Diagnostic" ) ;
137
148
return ;
138
149
}
139
150
140
151
if ( serverDiagnosticStatus === DiagStatError ) {
141
152
setTitle ( "Error" ) ;
153
+ setMessage ( "An error occurred while getting the Diagnostic file." ) ;
154
+ setButtonStartText ( "Retry Diagnostic" ) ;
142
155
return ;
143
156
}
144
- } , [ serverDiagnosticStatus , startDiagnostic , diagStarted ] ) ;
157
+ } , [ serverDiagnosticStatus , startDiagnostic ] ) ;
145
158
146
159
useEffect ( ( ) => {
147
160
if (
@@ -186,7 +199,6 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
186
199
interval = setInterval ( ( ) => {
187
200
c . send ( "ok" ) ;
188
201
} , 10 * 1000 ) ;
189
- setDiagStarted ( true ) ;
190
202
setMessage (
191
203
"Diagnostic started. Please do not refresh page during diagnosis."
192
204
) ;
@@ -219,7 +231,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
219
231
) {
220
232
// handle close with error
221
233
console . log ( "connection closed by server with code:" , event . code ) ;
222
- setMessage ( "An error occurred while getting Diagnostic file." ) ;
234
+ setMessage ( "An error occurred while getting the Diagnostic file." ) ;
223
235
dispatch ( setServerDiagStat ( DiagStatError ) ) ;
224
236
} else {
225
237
console . log ( "connection closed by server" ) ;
@@ -242,39 +254,21 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
242
254
< Grid item xs = { 12 } className = { classes . boxy } >
243
255
< TestWrapper title = { title } advancedVisible = { false } >
244
256
< Grid container className = { classes . buttons } >
245
- { ! diagStarted && (
246
- < Grid
247
- key = "start-diag"
248
- item
249
- xs = { 12 }
250
- className = { classes . startDiagnostic }
251
- >
252
- < Button
253
- type = "submit"
254
- variant = "contained"
255
- color = "primary"
256
- disabled = { startDiagnostic }
257
- onClick = { ( ) => setStartDiagnostic ( true ) }
258
- >
259
- Start Diagnostic
260
- </ Button >
261
- </ Grid >
262
- ) }
263
- { diagStarted && (
264
- < Grid
265
- key = "start-download"
266
- item
267
- xs = { 12 }
268
- className = { classes . progressResult }
269
- >
270
- < div className = { classes . localMessage } > { localMessage } </ div >
271
- { serverDiagnosticStatus === DiagStatInProgress ? (
272
- < div className = { classes . loading } >
273
- < Loader style = { { width : 25 , height : 25 } } />
274
- </ div >
275
- ) : (
276
- < Fragment >
277
- { serverDiagnosticStatus !== DiagStatError && (
257
+ < Grid
258
+ key = "start-download"
259
+ item
260
+ xs = { 12 }
261
+ className = { classes . progressResult }
262
+ >
263
+ < div className = { classes . localMessage } > { localMessage } </ div >
264
+ { serverDiagnosticStatus === DiagStatInProgress ? (
265
+ < div className = { classes . loading } >
266
+ < Loader style = { { width : 25 , height : 25 } } />
267
+ </ div >
268
+ ) : (
269
+ < Fragment >
270
+ { serverDiagnosticStatus !== DiagStatError &&
271
+ ! downloadDisabled && (
278
272
< Button
279
273
type = "submit"
280
274
variant = "contained"
@@ -285,31 +279,36 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
285
279
Download
286
280
</ Button >
287
281
) }
288
- < Grid item xs = { 12 } className = { classes . diagNew } >
289
- < Button
290
- id = "start-new-diagnostic"
291
- type = "submit"
292
- variant = "contained"
293
- color = "primary"
294
- disabled = { startDiagnostic }
295
- onClick = { ( ) => setStartDiagnostic ( true ) }
296
- >
297
- Start New Diagnostic
298
- </ Button >
299
- </ Grid >
300
- </ Fragment >
301
- ) }
302
- </ Grid >
303
- ) }
282
+ < Grid
283
+ item
284
+ xs = { 12 }
285
+ className = { clsx ( classes . startDiagnostic , {
286
+ [ classes . startDiagnosticCenter ] : ! isDiagnosticComplete ,
287
+ } ) }
288
+ >
289
+ < Button
290
+ id = "start-new-diagnostic"
291
+ type = "submit"
292
+ variant = "contained"
293
+ color = "primary"
294
+ disabled = { startDiagnostic }
295
+ onClick = { ( ) => setStartDiagnostic ( true ) }
296
+ >
297
+ { buttonStartText }
298
+ </ Button >
299
+ </ Grid >
300
+ </ Fragment >
301
+ ) }
302
+ </ Grid >
304
303
</ Grid >
305
304
</ TestWrapper >
306
305
</ Grid >
307
- { ! diagStarted && (
306
+ { ! startDiagnostic && (
308
307
< Fragment >
309
308
< br />
310
309
< HelpBox
311
310
title = {
312
- "During the health diagnostics run all production traffic will be suspended."
311
+ "During the health diagnostics run, all production traffic will be suspended."
313
312
}
314
313
iconComponent = { < WarnIcon /> }
315
314
help = { < Fragment /> }
0 commit comments