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