Path: blob/master/docker/dd-extension/ui/src/components/ShowCommand.tsx
1085 views
import { useState } from "react";1import { Row } from "react-bootstrap";2import Form from "react-bootstrap/Form";3import { useDockerDesktopClient } from "../hooks/useDockerDesktopClient";4import Loader from "./Loader";56interface ShowCommandProps {7validated: boolean;8command: string;9curlPort: string;10}1112export default function ShowCommand({13validated,14command,15curlPort,16}: ShowCommandProps) {17const [isRunningCommand, setRunningCommand] = useState(false);18const ddClient = useDockerDesktopClient();1920if (!validated) return null;2122function copyToClipboard() {23navigator.clipboard24.writeText(command)25.then(() => {26ddClient.desktopUI.toast.success("Text copied to clipboard!");27})28.catch((err) => {29ddClient.desktopUI.toast.error(`Failed to copy text: ${err}`);30});31}3233function runCommand() {34setRunningCommand(true);35// Generate list of run options36console.debug(command);37const cmd: Array<string> = command.match(/[^ ]+/g)?.slice(2) || [];38// Run in the background39if (!cmd.includes("-d")) {40cmd.unshift("-d");41}4243ddClient.docker.cli44.exec("run", cmd)45.then(async (result) => {46console.debug(result);47setRunningCommand(false);48ddClient.desktopUI.toast.success("Command Ran Successfully.");49await ddClient.desktopUI.navigate.viewContainer(result.stdout.trim());50})51.catch((e) => {52setRunningCommand(false);53console.error(e);54ddClient.desktopUI.toast.error(`Run Command Failed: ${e.stderr.trim()}`);55});56}5758const curlCommand = curlPort ? (59<div>60<p className="card-title mt-3 mb-0" style={{ display: "inline-block" }}>61To use the SDK endpoint call:{" "}62</p>63<code>64{" "}65curl -F "upload=@my_file.jpg" http://localhost:{curlPort}66/v1/plate-reader/67</code>68</div>69) : null;7071return (72<Form.Group as={Row} className="mb-3">73<div style={{ display: "block" }}>74<div className="mt-3 card" style={{ display: "block" }}>75<div className="card-body">76<p className="card-title">77You can now start {curlPort ? "Snapshot" : "Stream"}. Open a terminal and78type the command below. You can save this command for future use.79</p>80<code className="card-text d-block">{command}</code>81<div className="mt-3">82<button83className="btn btn-sm btn-success mx-2"84style={{ borderRadius: 15 }}85type="button"86onClick={runCommand}87>88<Loader isLoading={isRunningCommand} /> Run89</button>90<button91className="btn btn-sm btn-warning mx-2"92style={{ borderRadius: 15 }}93type="button"94onClick={copyToClipboard}95>96copy to clipboard97</button>98<span className="ms-2" style={{ fontSize: 13, color: "green" }} />99</div>100{curlCommand}101</div>102</div>103</div>104</Form.Group>105);106}107108109