Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/docker/dd-extension/ui/src/components/Uninstall.tsx
1091 views
1
import { useState } from "react";
2
import { Button, Row } from "react-bootstrap";
3
import Form from "react-bootstrap/Form";
4
import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient";
5
6
import Loader from "./Loader";
7
8
interface UninstallProps {
9
isEnabled: boolean;
10
image: string;
11
}
12
export default function Uninstall({ isEnabled, image }: UninstallProps) {
13
const [isLoading, setLoading] = useState(false);
14
const ddClient = useDockerDesktopClient();
15
16
if (!isEnabled) return null;
17
18
const handleUninstall = () => {
19
setLoading(true);
20
ddClient.docker.cli
21
.exec("ps", [
22
"--all",
23
"--format",
24
'"{{json .}}"',
25
"--filter",
26
`ancestor=${image}`,
27
])
28
.then(async (result) => {
29
// result.parseJsonLines() parses the output of the command into an array of objects
30
const containers = result.parseJsonLines();
31
for (let index = 0; index < containers.length; index++) {
32
const container = containers[index];
33
await ddClient.docker.cli.exec("container", ["rm", container.ID]);
34
}
35
const rmiResult = await ddClient.docker.cli.exec("rmi", [image, "-f"]);
36
console.debug(rmiResult);
37
await ddClient.docker.cli.exec("image", ["prune", "-f"]);
38
setLoading(false);
39
})
40
.catch((err) => {
41
ddClient.desktopUI.toast.error(`Uninstall Snapshot Error`);
42
console.error(err);
43
setLoading(false);
44
});
45
};
46
47
return (
48
<Form.Group as={Row} className="mb-3">
49
<div className="col-2">
50
<Button
51
className="btn btn-danger"
52
type="button"
53
onClick={handleUninstall}
54
id="uninstall-button"
55
>
56
<Loader isLoading={isLoading} />
57
Uninstall
58
</Button>
59
</div>
60
<label
61
className="col-auto align-self-center form-label"
62
htmlFor="uninstall-button"
63
>
64
Remove the Docker image and mark the product as uninstalled.
65
</label>
66
</Form.Group>
67
);
68
}
69
70