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 {useContext, useEffect, useState} from "react"; import PlayCircleOutline from '@mui/icons-material/PlayCircleOutline'; import ConfirmDialog from "../confirm-dialog"; import TabContext from "../../../context/tab"; import {TabEnum} from "../../../pages"; import smClient from "../../../api/sm/sm-client"; import Send from "@mui/icons-material/Send" export default function Commands() { const {setTab} = useContext(TabContext) const [commands, setCommands] = useState([]); const [selectedCommand, setSelectedCommand] = useState(null); const [optionList, setOptionList] = useState>({}); const [argumentList, setArgumentList] = useState>({}); const [value, setValue] = useState(''); const [open, setOpen] = useState(false); let refreshCommands = async () => { const { data: commands } = await smClient.getCommands() setCommands(commands) } useEffect(() => { 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) => { setOptionList(optionList) setArgumentList(argumentList) } let lock = false let runCommand = async (dialogId: string) => { if (!selectedCommand) { return } if (lock) { return } lock = true await smClient.runCommand({ commandName: selectedCommand.name, options: optionList, arguments: argumentList, requestId: dialogId, }) lock = false setTab(TabEnum.Processes) } return ( <>
{ setValue(newValue); }} disablePortal id="combo-box-demo" options={variants} renderInput={(params) => } /> selectedCommand && setOpen(true)} title={`Execute`} aria-label="Execute">
{selectedCommand && setOpen(false)}> } ) }