|
|
|
@ -7,12 +7,14 @@ 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<CommandInterface[]>([]); |
|
|
|
|
const [selectedCommand, setSelectedCommand] = useState<CommandInterface|null>(null); |
|
|
|
|
const [command2data, setCommand2data] = useState<Record<string, any>>({}); |
|
|
|
|
const [optionList, setOptionList] = useState<Record<string, any>>({}); |
|
|
|
|
const [argumentList, setArgumentList] = useState<Record<string, any>>({}); |
|
|
|
|
const [value, setValue] = useState<string | null>(''); |
|
|
|
|
const [open, setOpen] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
@ -33,29 +35,23 @@ export default function Commands() { |
|
|
|
|
let variants = commands.map((command: CommandInterface, index: number) => command.name); |
|
|
|
|
|
|
|
|
|
let callback = (name: string, optionList: Record<string, any>, argumentList: Record<string, any>) => { |
|
|
|
|
let temp = { |
|
|
|
|
...command2data |
|
|
|
|
} |
|
|
|
|
temp[name] = { |
|
|
|
|
options: optionList, |
|
|
|
|
arguments: argumentList, |
|
|
|
|
} |
|
|
|
|
setCommand2data(temp) |
|
|
|
|
setOptionList(optionList) |
|
|
|
|
setArgumentList(argumentList) |
|
|
|
|
} |
|
|
|
|
let lock = false |
|
|
|
|
let runCommand = async (dialogId: string) => { |
|
|
|
|
if (lock) { |
|
|
|
|
if (!selectedCommand) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (!selectedCommand) { |
|
|
|
|
if (lock) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
lock = true |
|
|
|
|
let data = command2data[selectedCommand.name] || {} |
|
|
|
|
data['requestId'] = dialogId; |
|
|
|
|
await smClient.runCommand({ |
|
|
|
|
commandName: selectedCommand.name, |
|
|
|
|
...data |
|
|
|
|
options: optionList, |
|
|
|
|
arguments: argumentList, |
|
|
|
|
requestId: dialogId, |
|
|
|
|
}) |
|
|
|
|
lock = false |
|
|
|
|
setTab(TabEnum.Processes) |
|
|
|
@ -75,27 +71,13 @@ export default function Commands() { |
|
|
|
|
options={variants} |
|
|
|
|
renderInput={(params) => <TextField {...params} label="Commands" />} |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<Table> |
|
|
|
|
<TableHead> |
|
|
|
|
<TableRow> |
|
|
|
|
<TableCell>Name</TableCell> |
|
|
|
|
<TableCell>Action</TableCell> |
|
|
|
|
</TableRow> |
|
|
|
|
</TableHead> |
|
|
|
|
<TableBody> |
|
|
|
|
{selectedCommand && <TableRow key={selectedCommand.name}> |
|
|
|
|
<TableCell><Command command={selectedCommand} callback={callback} /></TableCell> |
|
|
|
|
<TableCell> |
|
|
|
|
<IconButton onClick={() => setOpen(true)} aria-label="run"> |
|
|
|
|
<PlayCircleOutline /> |
|
|
|
|
<IconButton onClick={() => selectedCommand && setOpen(true)} title={`Execute`} aria-label="Execute"> |
|
|
|
|
<Send color={selectedCommand ? 'primary' : 'inherit'} /> |
|
|
|
|
</IconButton> |
|
|
|
|
</TableCell> |
|
|
|
|
</TableRow>} |
|
|
|
|
</TableBody> |
|
|
|
|
</Table> |
|
|
|
|
<ConfirmDialog open={open} text={'$$$'} agreeCallback={runCommand} closeCallback={() => setOpen(false)}/> |
|
|
|
|
</div> |
|
|
|
|
{selectedCommand && <ConfirmDialog title={selectedCommand.name} open={open} agreeCallback={runCommand} closeCallback={() => setOpen(false)}> |
|
|
|
|
<Command command={selectedCommand} callback={callback} /> |
|
|
|
|
</ConfirmDialog>} |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|