Skip to content

Commit

Permalink
Merge pull request #46 from kaleido-io/spinners
Browse files Browse the repository at this point in the history
Spinners
  • Loading branch information
dechdev authored Apr 13, 2022
2 parents 598a855 + ce0f3cb commit 2be19a5
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 186 deletions.
88 changes: 44 additions & 44 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { summarizeFetchError } from './utils/fetches';

// TODO: Make dynamic
export const SELECTED_NS = 'default';
// TODO: Figure out why this works
let dumbAwaitedEventID: string | undefined = undefined;

function App() {
const [initialized, setInitialized] = useState(true);
Expand Down Expand Up @@ -101,23 +103,35 @@ function App() {

const txMap = deepCopyMap.get(event.tx);
if (txMap !== undefined) {
const isComplete = event.reference === dumbAwaitedEventID;
if (isComplete) dumbAwaitedEventID = undefined;

return new Map(
deepCopyMap.set(event.tx, {
events: [...txMap.events, event],
events: [event, ...txMap.events],
created: event.created,
// TODO: Need better logic
isComplete,
})
);
} else {
return new Map(
deepCopyMap.set(event.tx, {
events: [event],
created: event.created,
isComplete: event.reference === dumbAwaitedEventID,
})
);
}
});
};

const addAwaitedEventID = (apiRes: any) => {
if (apiRes?.id && apiRes?.id) {
dumbAwaitedEventID = apiRes.id;
}
};

if (initialized) {
return (
<SnackbarContext.Provider
Expand All @@ -144,6 +158,8 @@ function App() {
value={{
logHistory,
addLogToHistory,
dumbAwaitedEventID,
addAwaitedEventID,
}}
>
<StyledEngineProvider injectFirst>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/Accordion/ContractStateAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const ContractStateAccordion: React.FC = () => {
<Grid container>
{contractListeners
?.filter((l) => l.address === api.address)
.map((l) => {
.map((l, idx) => {
return (
<Grid
item
Expand All @@ -137,6 +137,7 @@ export const ContractStateAccordion: React.FC = () => {
direction="row"
justifyContent="space-between"
alignItems="flex-start"
key={idx}
>
<Grid item>
<FFAccordionText
Expand Down
87 changes: 63 additions & 24 deletions ui/src/components/Buttons/RunButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { ArrowForwardIos } from '@mui/icons-material';
import { Alert, Button, Snackbar, Typography } from '@mui/material';
import { useContext, useState } from 'react';
import {
Alert,
Button,
CircularProgress,
Grid,
Snackbar,
Typography,
} from '@mui/material';
import { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ApplicationContext } from '../../contexts/ApplicationContext';
import { EventContext } from '../../contexts/EventContext';
import { DEFAULT_BORDER_RADIUS } from '../../theme';

interface Props {
Expand All @@ -16,6 +24,9 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
const [showSnackbar, setShowSnackbar] = useState(false);
const { activeForm, setApiStatus, setApiResponse, payloadMissingFields } =
useContext(ApplicationContext);
const { dumbAwaitedEventID, addAwaitedEventID } = useContext(EventContext);
// TODO: Remove soon
const [justSubmitted, setJustSubmitted] = useState<boolean>(false);

const handleCloseSnackbar = (_: any, reason?: string) => {
if (reason === 'clickaway') {
Expand All @@ -25,6 +36,11 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
setShowSnackbar(false);
};

// TODO: Remove soon
useEffect(() => {
setJustSubmitted(false);
}, [dumbAwaitedEventID]);

const handlePost = () => {
const blobUpload = activeForm.includes('blob');
managePayload();
Expand All @@ -48,6 +64,8 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
.then((data) => {
setShowSnackbar(true);
setApiResponse(data);
setJustSubmitted(true);
addAwaitedEventID(data);
})
.catch((err) => {
setShowSnackbar(true);
Expand Down Expand Up @@ -82,29 +100,50 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {

return (
<>
<Button
endIcon={<ArrowForwardIos />}
variant="contained"
disabled={disabled || payloadMissingFields}
sx={{ borderRadius: DEFAULT_BORDER_RADIUS }}
onClick={handlePost}
>
<Typography>{t('run')}</Typography>
</Button>
<Snackbar
open={showSnackbar}
autoHideDuration={6000}
onClose={handleCloseSnackbar}
>
<Alert
onClose={handleCloseSnackbar}
severity={'info'}
sx={{ width: '100%' }}
variant={'filled'}
{dumbAwaitedEventID || justSubmitted ? (
<Grid
justifyContent="space-between"
direction="row"
container
alignItems={'center'}
>
{`${t('postSentTo')}${endpoint}`}
</Alert>
</Snackbar>
<Grid item xs={11}>
<Typography sx={{ fontSize: '14px', fontWeight: '500' }}>
{t('waitingForTxEventsToFinish')}
</Typography>
</Grid>
<Grid item xs={1} container justifyContent="flex-end">
<CircularProgress size={16} color="warning" />
</Grid>
</Grid>
) : (
<>
<Button
endIcon={<ArrowForwardIos />}
variant="contained"
disabled={disabled || payloadMissingFields}
sx={{ borderRadius: DEFAULT_BORDER_RADIUS }}
onClick={handlePost}
size="small"
>
<Typography>{t('run')}</Typography>
</Button>
<Snackbar
open={showSnackbar}
autoHideDuration={6000}
onClose={handleCloseSnackbar}
>
<Alert
onClose={handleCloseSnackbar}
severity={'success'}
sx={{ width: '100%' }}
variant={'filled'}
>
{`${t('postSentTo')}${endpoint}`}
</Alert>
</Snackbar>
</>
)}
</>
);
};
4 changes: 3 additions & 1 deletion ui/src/contexts/EventContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import { IEvent } from '../interfaces/api';
import { IEventHistoryItem } from '../interfaces/events';

export interface IEventContext {
logHistory: Map<string, IEventHistoryItem>;
addLogToHistory: (event: IEvent) => void;
logHistory: Map<string, IEventHistoryItem>;
dumbAwaitedEventID: string | undefined;
addAwaitedEventID: (apiRes: any) => void;
}

export const EventContext = createContext({} as IEventContext);
Loading

0 comments on commit 2be19a5

Please sign in to comment.