From bb977edb2c9f0b9fe38d02f86f15bcd91e11e88f Mon Sep 17 00:00:00 2001 From: Rinsvent Date: Sat, 14 Jan 2023 00:49:15 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D0=BA=D0=BD?= =?UTF-8?q?=D0=BE=D0=BF=D0=BA=D1=83=20=D0=BD=D0=B0=D0=B2=D0=B5=D1=80=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/elements/command/index.tsx | 34 +++++---------- components/elements/commands/index.tsx | 43 ++++++++++++++++--- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/components/elements/commands/elements/command/index.tsx b/components/elements/commands/elements/command/index.tsx index 5060ef0..7f0c0d5 100644 --- a/components/elements/commands/elements/command/index.tsx +++ b/components/elements/commands/elements/command/index.tsx @@ -4,7 +4,7 @@ import Arguments from "../arguments"; import {OptionInterface} from "../option"; import {ArgumentInterface} from "../argument"; import {Provider} from "./context"; -import {useState} from "react"; +import {useEffect, useState} from "react"; export interface CommandInterface { class: string, @@ -14,28 +14,19 @@ export interface CommandInterface { arguments: ArgumentInterface[], } -export default function Command(command: CommandInterface) { +interface CommandComponentInterface { + command: CommandInterface, + callback: any, +} + +export default function Command({command, callback}: CommandComponentInterface) { const [optionList, setOptionList] = useState>({}); const [argumentList, setArgumentList] = useState>({}); - let onClick = async (event: any) => { - let url = `http://fmw.sipachev.sv/system-monitoring/commands/${command.name}/run` - let data = { - options: optionList, - arguments: argumentList, - } - console.log('data', data) - let response = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json;charset=utf-8', - 'X-Plugin-Token': 'passw0rd' - }, - body: JSON.stringify(data) - }); - let result = await response.json(); - console.log('result', result) - } + useEffect(() => { + callback && callback(command.name, optionList, argumentList) + }, [optionList, argumentList]) + return (
@@ -44,9 +35,6 @@ export default function Command(command: CommandInterface) {
-
- -
) diff --git a/components/elements/commands/index.tsx b/components/elements/commands/index.tsx index e3c18e4..adf4752 100644 --- a/components/elements/commands/index.tsx +++ b/components/elements/commands/index.tsx @@ -1,9 +1,11 @@ -import {Table, TableBody, TableCell, TableHead, TableRow} from "@mui/material"; +import {Table, TableBody, TableCell, TableHead, TableRow, IconButton} from "@mui/material"; import Command, {CommandInterface} from "./elements/command"; import {useEffect, useState} from "react"; +import PlayCircleOutlineIcon from '@mui/icons-material/PlayCircleOutline'; export default function Commands() { const [commands, setCommands] = useState([]); + const [command2data, setCommand2data] = useState>({}); let refreshCommands = async () => { let response = await fetch('http://fmw.sipachev.sv/system-monitoring/commands', { @@ -31,11 +33,40 @@ export default function Commands() { - {commands.map((command: CommandInterface, index: number) => ( - - - - ))} + {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 runCommand = async () => { + let url = `http://fmw.sipachev.sv/system-monitoring/commands/${command.name}/run` + let data = command2data[command.name] || {} + let response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + 'X-Plugin-Token': 'passw0rd' + }, + body: JSON.stringify(data) + }); + } + return ( + + + + + + + + + ) + })} )