import {Table, TableBody, TableCell, TableHead, TableRow, IconButton} from "@mui/material"; import Command, {CommandInterface} from "./elements/command"; import {useEffect, useState} from "react"; import PlayCircleOutline 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', { method: 'GET', headers: { 'Content-Type': 'application/json;charset=utf-8', 'X-Plugin-Token': 'passw0rd' }, }); const commands: CommandInterface[] = await response.json() setCommands(commands) setTimeout(() => refreshCommands, 1000) } useEffect(() => { refreshCommands() }, []) 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 runCommand = async () => { let url = `http://fmw.sipachev.sv/system-monitoring/commands/${command.name}/run` let data = command2data[command.name] || {} data['requestId'] = '123'; let response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8', 'X-Plugin-Token': 'passw0rd' }, body: JSON.stringify(data) }); } return ( ) })}
) }