Skip to content

Commit 2be19a5

Browse files
authored
Merge pull request #46 from kaleido-io/spinners
Spinners
2 parents 598a855 + ce0f3cb commit 2be19a5

10 files changed

Lines changed: 251 additions & 186 deletions

File tree

ui/package-lock.json

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/App.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { summarizeFetchError } from './utils/fetches';
2020

2121
// TODO: Make dynamic
2222
export const SELECTED_NS = 'default';
23+
// TODO: Figure out why this works
24+
let dumbAwaitedEventID: string | undefined = undefined;
2325

2426
function App() {
2527
const [initialized, setInitialized] = useState(true);
@@ -101,23 +103,35 @@ function App() {
101103

102104
const txMap = deepCopyMap.get(event.tx);
103105
if (txMap !== undefined) {
106+
const isComplete = event.reference === dumbAwaitedEventID;
107+
if (isComplete) dumbAwaitedEventID = undefined;
108+
104109
return new Map(
105110
deepCopyMap.set(event.tx, {
106-
events: [...txMap.events, event],
111+
events: [event, ...txMap.events],
107112
created: event.created,
113+
// TODO: Need better logic
114+
isComplete,
108115
})
109116
);
110117
} else {
111118
return new Map(
112119
deepCopyMap.set(event.tx, {
113120
events: [event],
114121
created: event.created,
122+
isComplete: event.reference === dumbAwaitedEventID,
115123
})
116124
);
117125
}
118126
});
119127
};
120128

129+
const addAwaitedEventID = (apiRes: any) => {
130+
if (apiRes?.id && apiRes?.id) {
131+
dumbAwaitedEventID = apiRes.id;
132+
}
133+
};
134+
121135
if (initialized) {
122136
return (
123137
<SnackbarContext.Provider
@@ -144,6 +158,8 @@ function App() {
144158
value={{
145159
logHistory,
146160
addLogToHistory,
161+
dumbAwaitedEventID,
162+
addAwaitedEventID,
147163
}}
148164
>
149165
<StyledEngineProvider injectFirst>

ui/src/components/Accordion/ContractStateAccordion.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const ContractStateAccordion: React.FC = () => {
127127
<Grid container>
128128
{contractListeners
129129
?.filter((l) => l.address === api.address)
130-
.map((l) => {
130+
.map((l, idx) => {
131131
return (
132132
<Grid
133133
item
@@ -137,6 +137,7 @@ export const ContractStateAccordion: React.FC = () => {
137137
direction="row"
138138
justifyContent="space-between"
139139
alignItems="flex-start"
140+
key={idx}
140141
>
141142
<Grid item>
142143
<FFAccordionText

ui/src/components/Buttons/RunButton.tsx

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { ArrowForwardIos } from '@mui/icons-material';
2-
import { Alert, Button, Snackbar, Typography } from '@mui/material';
3-
import { useContext, useState } from 'react';
2+
import {
3+
Alert,
4+
Button,
5+
CircularProgress,
6+
Grid,
7+
Snackbar,
8+
Typography,
9+
} from '@mui/material';
10+
import { useContext, useEffect, useState } from 'react';
411
import { useTranslation } from 'react-i18next';
512
import { ApplicationContext } from '../../contexts/ApplicationContext';
13+
import { EventContext } from '../../contexts/EventContext';
614
import { DEFAULT_BORDER_RADIUS } from '../../theme';
715

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

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

39+
// TODO: Remove soon
40+
useEffect(() => {
41+
setJustSubmitted(false);
42+
}, [dumbAwaitedEventID]);
43+
2844
const handlePost = () => {
2945
const blobUpload = activeForm.includes('blob');
3046
managePayload();
@@ -48,6 +64,8 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
4864
.then((data) => {
4965
setShowSnackbar(true);
5066
setApiResponse(data);
67+
setJustSubmitted(true);
68+
addAwaitedEventID(data);
5169
})
5270
.catch((err) => {
5371
setShowSnackbar(true);
@@ -82,29 +100,50 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
82100

83101
return (
84102
<>
85-
<Button
86-
endIcon={<ArrowForwardIos />}
87-
variant="contained"
88-
disabled={disabled || payloadMissingFields}
89-
sx={{ borderRadius: DEFAULT_BORDER_RADIUS }}
90-
onClick={handlePost}
91-
>
92-
<Typography>{t('run')}</Typography>
93-
</Button>
94-
<Snackbar
95-
open={showSnackbar}
96-
autoHideDuration={6000}
97-
onClose={handleCloseSnackbar}
98-
>
99-
<Alert
100-
onClose={handleCloseSnackbar}
101-
severity={'info'}
102-
sx={{ width: '100%' }}
103-
variant={'filled'}
103+
{dumbAwaitedEventID || justSubmitted ? (
104+
<Grid
105+
justifyContent="space-between"
106+
direction="row"
107+
container
108+
alignItems={'center'}
104109
>
105-
{`${t('postSentTo')}${endpoint}`}
106-
</Alert>
107-
</Snackbar>
110+
<Grid item xs={11}>
111+
<Typography sx={{ fontSize: '14px', fontWeight: '500' }}>
112+
{t('waitingForTxEventsToFinish')}
113+
</Typography>
114+
</Grid>
115+
<Grid item xs={1} container justifyContent="flex-end">
116+
<CircularProgress size={16} color="warning" />
117+
</Grid>
118+
</Grid>
119+
) : (
120+
<>
121+
<Button
122+
endIcon={<ArrowForwardIos />}
123+
variant="contained"
124+
disabled={disabled || payloadMissingFields}
125+
sx={{ borderRadius: DEFAULT_BORDER_RADIUS }}
126+
onClick={handlePost}
127+
size="small"
128+
>
129+
<Typography>{t('run')}</Typography>
130+
</Button>
131+
<Snackbar
132+
open={showSnackbar}
133+
autoHideDuration={6000}
134+
onClose={handleCloseSnackbar}
135+
>
136+
<Alert
137+
onClose={handleCloseSnackbar}
138+
severity={'success'}
139+
sx={{ width: '100%' }}
140+
variant={'filled'}
141+
>
142+
{`${t('postSentTo')}${endpoint}`}
143+
</Alert>
144+
</Snackbar>
145+
</>
146+
)}
108147
</>
109148
);
110149
};

ui/src/contexts/EventContext.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import { IEvent } from '../interfaces/api';
1919
import { IEventHistoryItem } from '../interfaces/events';
2020

2121
export interface IEventContext {
22-
logHistory: Map<string, IEventHistoryItem>;
2322
addLogToHistory: (event: IEvent) => void;
23+
logHistory: Map<string, IEventHistoryItem>;
24+
dumbAwaitedEventID: string | undefined;
25+
addAwaitedEventID: (apiRes: any) => void;
2426
}
2527

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

0 commit comments

Comments
 (0)