-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUpdateDialog.tsx
92 lines (84 loc) · 2.22 KB
/
UpdateDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
Box,
Dialog,
DialogContent,
Skeleton,
Typography,
} from '@mui/material';
import React, { ReactElement, useEffect, useState } from 'react';
import { useDDClient } from '../../../services';
type Props = {
open: boolean,
onClose: () => void;
};
export const UpdateDialog = ({ open, onClose }: Props): ReactElement => {
const [logs, setLogs] = useState<string[]>([]);
const { client: ddClient, getBinary } = useDDClient();
const [isUpdating, setIsUpdating] = useState<boolean>(true);
useEffect(() => {
const binary = getBinary();
if (!binary) {
return;
}
const listener = ddClient.extension.host?.cli.exec(binary, ['update', 'docker-images'], {
stream: {
onOutput(data): void {
let resultStr = data.stdout
.replaceAll('â', '')
.replaceAll('â', '✅')
.replaceAll('â', '❌');
if (resultStr.includes('Updating docker images')) {
resultStr = 'Updating Docker images';
}
if (resultStr.endsWith('updated.')) {
resultStr = resultStr.concat(' 🔼');
}
setLogs((current) => [...current, resultStr]);
},
onError(error: unknown): void {
ddClient.desktopUI.toast.error('An error occurred');
console.log(error);
},
onClose(exitCode) {
setIsUpdating(false);
console.log(`onClose with exit code ${exitCode}`);
},
},
});
return () => {
listener.close();
setLogs([]);
};
}, []);
return (
<Dialog open={open} onClose={onClose}>
<DialogContent>
<Box m={2} width={500} height={400}>
{
logs.map(log => (
<>
<Typography>
{log}
</Typography>
<br />
</>
))
}
{
logs.length === 0 &&
<>
<Typography>
Updating Docker images
</Typography>
<br />
</>
}
{
isUpdating &&
<Skeleton animation='wave' />
}
</Box>
</DialogContent>
</Dialog >
);
};