|
1 | | -import React, { useState } from "react"; |
2 | | -import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient"; |
3 | | -import Form from "react-bootstrap/Form"; |
4 | | -import { |
5 | | - Row, |
6 | | -} from "react-bootstrap"; |
7 | | -import Loader from "./Loader"; |
8 | | - |
9 | | -interface ShowCommandProps { |
10 | | - validated: boolean; |
11 | | - command: string; |
12 | | - curlPort: string; |
13 | | -} |
14 | | - |
15 | | -export default function ShowCommand({ |
16 | | - validated, |
17 | | - command, |
18 | | - curlPort, |
19 | | -}: ShowCommandProps) { |
20 | | - const [isRunningCommand, setRunningCommand] = useState(false); |
21 | | - |
22 | | - if (!validated) { |
23 | | - return null; |
24 | | - } |
25 | | - const ddClient = useDockerDesktopClient(); |
26 | | - |
27 | | - function copyToClipboard() { |
28 | | - navigator.clipboard |
29 | | - .writeText(command) |
30 | | - .then(() => { |
31 | | - ddClient.desktopUI.toast.success("Text copied to clipboard!"); |
32 | | - }) |
33 | | - .catch((err) => { |
34 | | - ddClient.desktopUI.toast.error(`Failed to copy text: ${err}`); |
35 | | - }); |
36 | | - } |
37 | | - |
38 | | - function runCommand(){ |
39 | | - setRunningCommand(true); |
40 | | - // Generate list of run options |
41 | | - console.debug(command); |
42 | | - const cmd:Array<string> = command.match(/[^ ]+/g)?.slice(2) || []; |
43 | | - // Run in the background |
44 | | - if (!cmd.includes('-d')){ |
45 | | - cmd.unshift('-d') |
46 | | - } |
47 | | - |
48 | | - ddClient.docker.cli.exec("run", cmd).then(async (result) => { |
49 | | - console.debug(result); |
50 | | - setRunningCommand(false); |
51 | | - ddClient.desktopUI.toast.success('Command Ran Successfully.'); |
52 | | - await ddClient.desktopUI.navigate.viewContainer(result.stdout.trim()) |
53 | | - }).catch(e => { |
54 | | - setRunningCommand(false); |
55 | | - console.error(e); |
56 | | - ddClient.desktopUI.toast.error(`Run Command Failed: ${e.stderr.trim()}`); |
57 | | - }) |
58 | | - } |
59 | | - |
60 | | - const curlCommand = curlPort ? ( |
61 | | - <div> |
62 | | - <p className="card-title mt-3 mb-0" style={{ display: "inline-block" }}> |
63 | | - To use the SDK endpoint call:{" "} |
64 | | - </p> |
65 | | - <code> |
66 | | - {" "} |
67 | | - curl -F "upload=@my_file.jpg" http://localhost:{curlPort} |
68 | | - /v1/plate-reader/ |
69 | | - </code> |
70 | | - </div> |
71 | | - ) : null; |
72 | | - |
73 | | - return ( |
74 | | - <Form.Group as={Row} className="mb-3"> |
75 | | - <div style={{ display: "block" }}> |
76 | | - <div className="mt-3 card" style={{ display: "block" }}> |
77 | | - <div className="card-body"> |
78 | | - <p className="card-title"> |
79 | | - You can now start {curlPort ? 'Snapshot' : 'Stream'}. Open a terminal and type the command |
80 | | - below. You can save this command for future use. |
81 | | - </p> |
82 | | - <code className="card-text d-block">{command}</code> |
83 | | - <div className="mt-3"> |
84 | | - <button |
85 | | - className="btn btn-sm btn-success mx-2" |
86 | | - style={{ borderRadius: 15 }} |
87 | | - type="button" |
88 | | - onClick={runCommand} |
89 | | - > |
90 | | - <Loader isLoading={isRunningCommand} /> Run |
91 | | - </button> |
92 | | - <button |
93 | | - className="btn btn-sm btn-warning mx-2" |
94 | | - style={{ borderRadius: 15 }} |
95 | | - type="button" |
96 | | - onClick={copyToClipboard} |
97 | | - > |
98 | | - copy to clipboard |
99 | | - </button> |
100 | | - <span className="ms-2" style={{ fontSize: 13, color: "green" }} /> |
101 | | - </div> |
102 | | - {curlCommand} |
103 | | - </div> |
104 | | - </div> |
105 | | - </div> |
106 | | - </Form.Group> |
107 | | - ); |
108 | | -} |
| 1 | +import { useState } from "react"; |
| 2 | +import { Row } from "react-bootstrap"; |
| 3 | +import Form from "react-bootstrap/Form"; |
| 4 | +import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient"; |
| 5 | +import Loader from "./Loader"; |
| 6 | + |
| 7 | +interface ShowCommandProps { |
| 8 | + validated: boolean; |
| 9 | + command: string; |
| 10 | + curlPort: string; |
| 11 | +} |
| 12 | + |
| 13 | +export default function ShowCommand({ |
| 14 | + validated, |
| 15 | + command, |
| 16 | + curlPort, |
| 17 | +}: ShowCommandProps) { |
| 18 | + const [isRunningCommand, setRunningCommand] = useState(false); |
| 19 | + |
| 20 | + if (!validated) { |
| 21 | + return null; |
| 22 | + } |
| 23 | + const ddClient = useDockerDesktopClient(); |
| 24 | + |
| 25 | + function copyToClipboard() { |
| 26 | + navigator.clipboard |
| 27 | + .writeText(command) |
| 28 | + .then(() => { |
| 29 | + ddClient.desktopUI.toast.success("Text copied to clipboard!"); |
| 30 | + }) |
| 31 | + .catch((err) => { |
| 32 | + ddClient.desktopUI.toast.error(`Failed to copy text: ${err}`); |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + function runCommand() { |
| 37 | + setRunningCommand(true); |
| 38 | + // Generate list of run options |
| 39 | + console.debug(command); |
| 40 | + const cmd: Array<string> = command.match(/[^ ]+/g)?.slice(2) || []; |
| 41 | + // Run in the background |
| 42 | + if (!cmd.includes("-d")) { |
| 43 | + cmd.unshift("-d"); |
| 44 | + } |
| 45 | + |
| 46 | + ddClient.docker.cli |
| 47 | + .exec("run", cmd) |
| 48 | + .then(async (result) => { |
| 49 | + console.debug(result); |
| 50 | + setRunningCommand(false); |
| 51 | + ddClient.desktopUI.toast.success("Command Ran Successfully."); |
| 52 | + await ddClient.desktopUI.navigate.viewContainer(result.stdout.trim()); |
| 53 | + }) |
| 54 | + .catch((e) => { |
| 55 | + setRunningCommand(false); |
| 56 | + console.error(e); |
| 57 | + ddClient.desktopUI.toast.error(`Run Command Failed: ${e.stderr.trim()}`); |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + const curlCommand = curlPort ? ( |
| 62 | + <div> |
| 63 | + <p className="card-title mt-3 mb-0" style={{ display: "inline-block" }}> |
| 64 | + To use the SDK endpoint call:{" "} |
| 65 | + </p> |
| 66 | + <code> |
| 67 | + {" "} |
| 68 | + curl -F "upload=@my_file.jpg" http://localhost:{curlPort} |
| 69 | + /v1/plate-reader/ |
| 70 | + </code> |
| 71 | + </div> |
| 72 | + ) : null; |
| 73 | + |
| 74 | + return ( |
| 75 | + <Form.Group as={Row} className="mb-3"> |
| 76 | + <div style={{ display: "block" }}> |
| 77 | + <div className="mt-3 card" style={{ display: "block" }}> |
| 78 | + <div className="card-body"> |
| 79 | + <p className="card-title"> |
| 80 | + You can now start {curlPort ? "Snapshot" : "Stream"}. Open a terminal and |
| 81 | + type the command below. You can save this command for future use. |
| 82 | + </p> |
| 83 | + <code className="card-text d-block">{command}</code> |
| 84 | + <div className="mt-3"> |
| 85 | + <button |
| 86 | + className="btn btn-sm btn-success mx-2" |
| 87 | + style={{ borderRadius: 15 }} |
| 88 | + type="button" |
| 89 | + onClick={runCommand} |
| 90 | + > |
| 91 | + <Loader isLoading={isRunningCommand} /> Run |
| 92 | + </button> |
| 93 | + <button |
| 94 | + className="btn btn-sm btn-warning mx-2" |
| 95 | + style={{ borderRadius: 15 }} |
| 96 | + type="button" |
| 97 | + onClick={copyToClipboard} |
| 98 | + > |
| 99 | + copy to clipboard |
| 100 | + </button> |
| 101 | + <span className="ms-2" style={{ fontSize: 13, color: "green" }} /> |
| 102 | + </div> |
| 103 | + {curlCommand} |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </Form.Group> |
| 108 | + ); |
| 109 | +} |
0 commit comments