From 92865fcb0a99e3b15cc77cbe012eae5bc4715832 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Tue, 17 Jan 2023 18:52:14 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B4=D0=B8=D0=B7=D0=B0=D0=B9=D0=BD=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/elements/commands/index.tsx | 130 +++++++++++------- .../elements/commands/styles.module.css | 3 + 2 files changed, 81 insertions(+), 52 deletions(-) diff --git a/components/elements/commands/index.tsx b/components/elements/commands/index.tsx index e2a00ff..827ca9b 100644 --- a/components/elements/commands/index.tsx +++ b/components/elements/commands/index.tsx @@ -1,4 +1,5 @@ -import {Table, TableBody, TableCell, TableHead, TableRow, IconButton} from "@mui/material"; +import styles from './styles.module.css' +import {Table, TableBody, TableCell, TableHead, TableRow, IconButton, Autocomplete, TextField} from "@mui/material"; import Command, {CommandInterface} from "./elements/command"; import {useEffect, useState} from "react"; import PlayCircleOutline from '@mui/icons-material/PlayCircleOutline'; @@ -6,7 +7,9 @@ import { v4 } from "uuid" export default function Commands() { const [commands, setCommands] = useState([]); + const [selectedCommand, setSelectedCommand] = useState(null); const [command2data, setCommand2data] = useState>({}); + const [value, setValue] = useState(''); let requestId = v4() let refreshCommands = async () => { @@ -25,57 +28,80 @@ export default function Commands() { refreshCommands() }, []) + useEffect(() => { + let command = commands.filter((command) => command.name === value) + setSelectedCommand(command[0] || null) + }, [value]) + + let variants = commands.map((command: CommandInterface, index: number) => command.name); + + let callback = (name: string, optionList: Record, argumentList: Record) => { + let temp = { + ...command2data + } + temp[name] = { + options: optionList, + arguments: argumentList, + } + setCommand2data(temp) + } + let lock = false + let runCommand = async () => { + if (lock) { + return + } + if (!selectedCommand) { + return + } + lock = true + let url = `http://fmw.sipachev.sv/system-monitoring/commands/${selectedCommand.name}/run` + let data = command2data[selectedCommand.name] || {} + data['requestId'] = requestId; + let response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + 'X-Plugin-Token': 'passw0rd' + }, + body: JSON.stringify(data) + }); + lock = false + } + return ( - - - - Name - Action - - - - {commands.map((command: CommandInterface, index: number) => { - let callback = (name: string, optionList: Record, argumentList: Record) => { - let temp = { - ...command2data - } - temp[name] = { - options: optionList, - arguments: argumentList, - } - setCommand2data(temp) - } - let lock = false - let runCommand = async () => { - if (lock) { - return - } - lock = true - let url = `http://fmw.sipachev.sv/system-monitoring/commands/${command.name}/run` - let data = command2data[command.name] || {} - data['requestId'] = requestId; - let response = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json;charset=utf-8', - 'X-Plugin-Token': 'passw0rd' - }, - body: JSON.stringify(data) - }); - lock = false - } - return ( - - - - - - - - - ) - })} - -
+ <> +
+
+ { + setValue(newValue); + }} + disablePortal + id="combo-box-demo" + options={variants} + renderInput={(params) => } + /> +
+ + + + + Name + Action + + + + {selectedCommand && + + + + + + + } + +
+ ) } diff --git a/components/elements/commands/styles.module.css b/components/elements/commands/styles.module.css index e69de29..4474b1f 100644 --- a/components/elements/commands/styles.module.css +++ b/components/elements/commands/styles.module.css @@ -0,0 +1,3 @@ +.autocomplete { + width: 100%; +}