Skip to content

Commit 64dc605

Browse files
authored
Fix inconsistencies in Health Diagnostics UI (#2239)
1 parent 75fa88e commit 64dc605

File tree

2 files changed

+65
-66
lines changed

2 files changed

+65
-66
lines changed

portal-ui/src/screens/Console/HealthInfo/HealthInfo.tsx

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
//
1414
// You should have received a copy of the GNU Affero General Public License
1515
// 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";
1718
import {
1819
ICloseEvent,
1920
IMessageEvent,
@@ -72,19 +73,19 @@ const styles = (theme: Theme) =>
7273
textAlign: "center",
7374
marginBottom: 10,
7475
},
75-
startDiagnostic: {
76-
textAlign: "center",
77-
marginBottom: 25,
78-
},
7976
progressResult: {
8077
textAlign: "center",
8178
marginBottom: 25,
8279
},
83-
diagNew: {
80+
startDiagnostic: {
8481
textAlign: "right",
8582
margin: 25,
8683
marginBottom: 0,
8784
},
85+
startDiagnosticCenter: {
86+
textAlign: "center",
87+
marginTop: 0,
88+
},
8889
...actionsTray,
8990
...containerForHeader(theme.spacing(4)),
9091
});
@@ -104,12 +105,17 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
104105
(state: AppState) => state.system.serverDiagnosticStatus
105106
);
106107
const [startDiagnostic, setStartDiagnostic] = useState(false);
107-
const [diagStarted, setDiagStarted] = useState<boolean>(false);
108108
const [downloadDisabled, setDownloadDisabled] = useState(true);
109109
const [localMessage, setMessage] = useState<string>("");
110+
const [buttonStartText, setButtonStartText] =
111+
useState<string>("Start Diagnostic");
110112
const [title, setTitle] = useState<string>("New Diagnostic");
111113
const [diagFileContent, setDiagFileContent] = useState<string>("");
112114

115+
const isDiagnosticComplete =
116+
serverDiagnosticStatus === DiagStatSuccess ||
117+
serverDiagnosticStatus === DiagStatError;
118+
113119
const download = () => {
114120
let element = document.createElement("a");
115121
element.setAttribute(
@@ -129,19 +135,26 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
129135
useEffect(() => {
130136
if (serverDiagnosticStatus === DiagStatInProgress) {
131137
setTitle("Diagnostic in progress...");
138+
setMessage(
139+
"Diagnostic started. Please do not refresh page during diagnosis."
140+
);
132141
return;
133142
}
134143

135-
if (serverDiagnosticStatus === DiagStatSuccess && diagStarted) {
144+
if (serverDiagnosticStatus === DiagStatSuccess) {
136145
setTitle("Diagnostic complete");
146+
setMessage("Diagnostic file is ready to be downloaded.");
147+
setButtonStartText("Start New Diagnostic");
137148
return;
138149
}
139150

140151
if (serverDiagnosticStatus === DiagStatError) {
141152
setTitle("Error");
153+
setMessage("An error occurred while getting the Diagnostic file.");
154+
setButtonStartText("Retry Diagnostic");
142155
return;
143156
}
144-
}, [serverDiagnosticStatus, startDiagnostic, diagStarted]);
157+
}, [serverDiagnosticStatus, startDiagnostic]);
145158

146159
useEffect(() => {
147160
if (
@@ -186,7 +199,6 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
186199
interval = setInterval(() => {
187200
c.send("ok");
188201
}, 10 * 1000);
189-
setDiagStarted(true);
190202
setMessage(
191203
"Diagnostic started. Please do not refresh page during diagnosis."
192204
);
@@ -219,7 +231,7 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
219231
) {
220232
// handle close with error
221233
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.");
223235
dispatch(setServerDiagStat(DiagStatError));
224236
} else {
225237
console.log("connection closed by server");
@@ -242,39 +254,21 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
242254
<Grid item xs={12} className={classes.boxy}>
243255
<TestWrapper title={title} advancedVisible={false}>
244256
<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 && (
278272
<Button
279273
type="submit"
280274
variant="contained"
@@ -285,31 +279,36 @@ const HealthInfo = ({ classes }: IHealthInfo) => {
285279
Download
286280
</Button>
287281
)}
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>
304303
</Grid>
305304
</TestWrapper>
306305
</Grid>
307-
{!diagStarted && (
306+
{!startDiagnostic && (
308307
<Fragment>
309308
<br />
310309
<HelpBox
311310
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."
313312
}
314313
iconComponent={<WarnIcon />}
315314
help={<Fragment />}

portal-ui/tests/permissions-5/diagnostics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test("Download button exists after Diagnostic is completed", async (t) => {
6363
// Only proceed if there is no error
6464
const matchingElement = ClientFunction(() =>
6565
document.evaluate(
66-
"//div[text()='An error occurred while getting Diagnostic file.']",
66+
"//div[text()='An error occurred while getting the Diagnostic file.']",
6767
document,
6868
null,
6969
XPathResult.FIRST_ORDERED_NODE_TYPE,
@@ -87,7 +87,7 @@ test("Download button is clickable after Diagnostic is completed", async (t) =>
8787
// Only proceed if there is no error
8888
const matchingElement = ClientFunction(() =>
8989
document.evaluate(
90-
"//div[text()='An error occurred while getting Diagnostic file.']",
90+
"//div[text()='An error occurred while getting the Diagnostic file.']",
9191
document,
9292
null,
9393
XPathResult.FIRST_ORDERED_NODE_TYPE,
@@ -111,7 +111,7 @@ test("Start New Diagnostic button exists after Diagnostic is completed", async (
111111
// Only proceed if there is no error
112112
const matchingElement = ClientFunction(() =>
113113
document.evaluate(
114-
"//div[text()='An error occurred while getting Diagnostic file.']",
114+
"//div[text()='An error occurred while getting the Diagnostic file.']",
115115
document,
116116
null,
117117
XPathResult.FIRST_ORDERED_NODE_TYPE,
@@ -139,7 +139,7 @@ test("Start New Diagnostic button is clickable after Diagnostic is completed", a
139139
// Only proceed if there is no error
140140
const matchingElement = ClientFunction(() =>
141141
document.evaluate(
142-
"//div[text()='An error occurred while getting Diagnostic file.']",
142+
"//div[text()='An error occurred while getting the Diagnostic file.']",
143143
document,
144144
null,
145145
XPathResult.FIRST_ORDERED_NODE_TYPE,

0 commit comments

Comments
 (0)