Skip to content

Commit

Permalink
Merge pull request #20 from orijtech/loading-bits
Browse files Browse the repository at this point in the history
ui: improve ux by showing a spinner disabling further user inputs
  • Loading branch information
willpoint authored Dec 19, 2022
2 parents ffaf757 + b5f05d8 commit 91a354f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 45 deletions.
36 changes: 36 additions & 0 deletions ui/src/components/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FC } from 'react';
import CircularProgress from '@mui/material/CircularProgress';

interface Props {
loading: boolean;
};

export const Spinner: FC<Props> = ({ loading }) => {
const styles: {[key: string]: number|string} = {
position: 'absolute',
top: '0%',
left: '0%',
right: '0%',
bottom: '0%',
visibility: 'hidden',
backgroundColor: '#ffffff00',
transition: 'background-color 200ms ease-in-out',
zIndex: -1,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
};

if (loading) {
styles['visibility'] = 'visible';
styles['backgroundColor'] = '#ffffffd9';
styles['zIndex'] = 999;
styles['opacity'] = 0.5;
}

return (
<div style={styles}>
<CircularProgress size={100} color='info' />
</div>
);
};
93 changes: 48 additions & 45 deletions ui/src/components/load-tester/LoadTester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import Alert from '@mui/material/Alert';
import Button from '@mui/material/Button';

import {
LoadtestServiceClient,
} from 'src/gen/orijtech/cosmosloadtester/v1/Loadtest_serviceServiceClientPb';
import {
RunLoadtestRequest,
RunLoadtestResponse,
} from 'src/gen/orijtech/cosmosloadtester/v1/loadtest_service_pb';

import * as timestamp_pb from 'google-protobuf/google/protobuf/timestamp_pb';


import { LoadtestServiceClient } from 'src/gen/orijtech/cosmosloadtester/v1/Loadtest_serviceServiceClientPb';
import { RunLoadtestRequest, RunLoadtestResponse } from 'src/gen/orijtech/cosmosloadtester/v1/loadtest_service_pb';
import { Spinner } from 'src/components/Spinner';
import Inputs from 'src/components/inputs/Inputs';
import Outputs from 'src/components/output/Outputs';

import { fields } from './Fields';

const service = new LoadtestServiceClient('');
Expand Down Expand Up @@ -52,7 +48,11 @@ export default function LoadTester() {
.setTransactionSizeBytes(data.transactionSizeBytes)
.setTransactionsPerSecond(data.transactionsPerSecond)
.setConnectionCount(data.connectionCount);

await (new Promise((resolve) => setTimeout(resolve, 3000)));

const result = await service.runLoadtest(request, null);

setData(result.toObject());
console.log(result.toObject());
} catch (e: any) {
Expand All @@ -64,42 +64,45 @@ export default function LoadTester() {
};

return (
<Paper elevation={0} sx={{ mt: 3, p: 3 }}>
<Alert severity='info' sx={{ mb: 3 }} variant='standard'>
<Typography variant="caption">
Enter TM Parameters
</Typography>
</Alert>
<Inputs
handleFormSubmission={onFormSubmit}
fields={fields}
submitRef={submitRef}
/>
<Button
disableElevation={true}
disabled={running}
color={running ? 'inherit' : 'info'}
sx={{ textTransform: 'none' }}
variant='contained'
onClick={() => submitRef.current?.click()}
>
{running ? 'Running load testing...' : 'Run load testing'}
</Button>
<>
<Spinner loading={running} />
<Paper elevation={0} sx={{ mt: 3, p: 3 }}>
<Alert severity='info' sx={{ mb: 3 }} variant='standard'>
<Typography variant="caption">
Enter TM Parameters
</Typography>
</Alert>
<Inputs
handleFormSubmission={onFormSubmit}
fields={fields}
submitRef={submitRef}
/>
<Button
disableElevation={true}
disabled={running}
color={running ? 'inherit' : 'info'}
sx={{ textTransform: 'none' }}
variant='contained'
onClick={() => submitRef.current?.click()}
>
{running ? 'Running load testing...' : 'Run load testing'}
</Button>

{/* display errors if any occured */}
{error !== '' && <Typography component='h6' variant='caption'>{error}</Typography>}
{/* render data if it exists */}
{
data !== undefined &&
<>
<Alert severity='success' sx={{ my: 3 }}>
<Typography variant='caption'>
Load Testing Results
</Typography>
</Alert>
<Outputs data={data} />
</>
}
</Paper>
{/* display errors if any occured */}
{error !== '' && <Typography component='h6' variant='caption'>{error}</Typography>}
{/* render data if it exists */}
{
data !== undefined &&
<>
<Alert severity='success' sx={{ my: 3 }}>
<Typography variant='caption'>
Load Testing Results
</Typography>
</Alert>
<Outputs data={data} />
</>
}
</Paper>
</>
);
}

0 comments on commit 91a354f

Please sign in to comment.