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