Skip to content

Commit 91a354f

Browse files
authored
Merge pull request #20 from orijtech/loading-bits
ui: improve ux by showing a spinner disabling further user inputs
2 parents ffaf757 + b5f05d8 commit 91a354f

File tree

2 files changed

+84
-45
lines changed

2 files changed

+84
-45
lines changed

ui/src/components/Spinner.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { FC } from 'react';
2+
import CircularProgress from '@mui/material/CircularProgress';
3+
4+
interface Props {
5+
loading: boolean;
6+
};
7+
8+
export const Spinner: FC<Props> = ({ loading }) => {
9+
const styles: {[key: string]: number|string} = {
10+
position: 'absolute',
11+
top: '0%',
12+
left: '0%',
13+
right: '0%',
14+
bottom: '0%',
15+
visibility: 'hidden',
16+
backgroundColor: '#ffffff00',
17+
transition: 'background-color 200ms ease-in-out',
18+
zIndex: -1,
19+
display: 'flex',
20+
justifyContent: 'center',
21+
alignItems: 'center'
22+
};
23+
24+
if (loading) {
25+
styles['visibility'] = 'visible';
26+
styles['backgroundColor'] = '#ffffffd9';
27+
styles['zIndex'] = 999;
28+
styles['opacity'] = 0.5;
29+
}
30+
31+
return (
32+
<div style={styles}>
33+
<CircularProgress size={100} color='info' />
34+
</div>
35+
);
36+
};

ui/src/components/load-tester/LoadTester.tsx

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ import Paper from '@mui/material/Paper';
33
import Typography from '@mui/material/Typography';
44
import Alert from '@mui/material/Alert';
55
import Button from '@mui/material/Button';
6-
7-
import {
8-
LoadtestServiceClient,
9-
} from 'src/gen/orijtech/cosmosloadtester/v1/Loadtest_serviceServiceClientPb';
10-
import {
11-
RunLoadtestRequest,
12-
RunLoadtestResponse,
13-
} from 'src/gen/orijtech/cosmosloadtester/v1/loadtest_service_pb';
14-
156
import * as timestamp_pb from 'google-protobuf/google/protobuf/timestamp_pb';
167

8+
9+
import { LoadtestServiceClient } from 'src/gen/orijtech/cosmosloadtester/v1/Loadtest_serviceServiceClientPb';
10+
import { RunLoadtestRequest, RunLoadtestResponse } from 'src/gen/orijtech/cosmosloadtester/v1/loadtest_service_pb';
11+
import { Spinner } from 'src/components/Spinner';
1712
import Inputs from 'src/components/inputs/Inputs';
1813
import Outputs from 'src/components/output/Outputs';
14+
1915
import { fields } from './Fields';
2016

2117
const service = new LoadtestServiceClient('');
@@ -52,7 +48,11 @@ export default function LoadTester() {
5248
.setTransactionSizeBytes(data.transactionSizeBytes)
5349
.setTransactionsPerSecond(data.transactionsPerSecond)
5450
.setConnectionCount(data.connectionCount);
51+
52+
await (new Promise((resolve) => setTimeout(resolve, 3000)));
53+
5554
const result = await service.runLoadtest(request, null);
55+
5656
setData(result.toObject());
5757
console.log(result.toObject());
5858
} catch (e: any) {
@@ -64,42 +64,45 @@ export default function LoadTester() {
6464
};
6565

6666
return (
67-
<Paper elevation={0} sx={{ mt: 3, p: 3 }}>
68-
<Alert severity='info' sx={{ mb: 3 }} variant='standard'>
69-
<Typography variant="caption">
70-
Enter TM Parameters
71-
</Typography>
72-
</Alert>
73-
<Inputs
74-
handleFormSubmission={onFormSubmit}
75-
fields={fields}
76-
submitRef={submitRef}
77-
/>
78-
<Button
79-
disableElevation={true}
80-
disabled={running}
81-
color={running ? 'inherit' : 'info'}
82-
sx={{ textTransform: 'none' }}
83-
variant='contained'
84-
onClick={() => submitRef.current?.click()}
85-
>
86-
{running ? 'Running load testing...' : 'Run load testing'}
87-
</Button>
67+
<>
68+
<Spinner loading={running} />
69+
<Paper elevation={0} sx={{ mt: 3, p: 3 }}>
70+
<Alert severity='info' sx={{ mb: 3 }} variant='standard'>
71+
<Typography variant="caption">
72+
Enter TM Parameters
73+
</Typography>
74+
</Alert>
75+
<Inputs
76+
handleFormSubmission={onFormSubmit}
77+
fields={fields}
78+
submitRef={submitRef}
79+
/>
80+
<Button
81+
disableElevation={true}
82+
disabled={running}
83+
color={running ? 'inherit' : 'info'}
84+
sx={{ textTransform: 'none' }}
85+
variant='contained'
86+
onClick={() => submitRef.current?.click()}
87+
>
88+
{running ? 'Running load testing...' : 'Run load testing'}
89+
</Button>
8890

89-
{/* display errors if any occured */}
90-
{error !== '' && <Typography component='h6' variant='caption'>{error}</Typography>}
91-
{/* render data if it exists */}
92-
{
93-
data !== undefined &&
94-
<>
95-
<Alert severity='success' sx={{ my: 3 }}>
96-
<Typography variant='caption'>
97-
Load Testing Results
98-
</Typography>
99-
</Alert>
100-
<Outputs data={data} />
101-
</>
102-
}
103-
</Paper>
91+
{/* display errors if any occured */}
92+
{error !== '' && <Typography component='h6' variant='caption'>{error}</Typography>}
93+
{/* render data if it exists */}
94+
{
95+
data !== undefined &&
96+
<>
97+
<Alert severity='success' sx={{ my: 3 }}>
98+
<Typography variant='caption'>
99+
Load Testing Results
100+
</Typography>
101+
</Alert>
102+
<Outputs data={data} />
103+
</>
104+
}
105+
</Paper>
106+
</>
104107
);
105108
}

0 commit comments

Comments
 (0)