show execute button in table

This commit is contained in:
proddy
2026-06-14 17:03:52 +02:00
parent e818a5a943
commit fe8cf2620d

View File

@@ -4,9 +4,11 @@ import { toast } from 'react-toastify';
import AddIcon from '@mui/icons-material/Add';
import CancelIcon from '@mui/icons-material/Cancel';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import WarningIcon from '@mui/icons-material/Warning';
import { Box, Button, Typography } from '@mui/material';
import { Box, Button, IconButton, Typography } from '@mui/material';
import { callAction } from '@/api/app';
import {
Body,
Cell,
@@ -46,7 +48,7 @@ const DEFAULT_COMMAND_ITEM: Omit<CommandItem, 'id'> = {
const commandsTheme = {
Table: `
--data-table-library_grid-template-columns: repeat(1, minmax(100px, 1fr)) repeat(1, minmax(100px, 1fr)) 160px;
--data-table-library_grid-template-columns: repeat(1, minmax(100px, 1fr)) repeat(1, minmax(100px, 1fr)) 160px 32px;
`,
BaseRow: `
font-size: 14px;
@@ -141,6 +143,21 @@ const CommandsPage = () => {
}
};
const { send: executeCommand } = useRequest(
(id: string) => callAction({ action: 'executeCommand', param: id }),
{ immediate: false }
)
.onSuccess(() => {
toast.success(LL.EXECUTE_COMMAND_SENT());
})
.onError((error) => {
toast.error(String(error.error?.message || 'An error occurred'));
});
const execute = async (name: string) => {
await executeCommand(name);
};
const editItem = (ci: CommandItem) => {
setCreating(false);
setSelectedItem(ci);
@@ -205,6 +222,7 @@ const CommandsPage = () => {
<HeaderCell stiff>{LL.COMMAND(0)}</HeaderCell>
<HeaderCell stiff>{LL.VALUE(0)}</HeaderCell>
<HeaderCell stiff>{LL.NAME(0)}</HeaderCell>
<HeaderCell></HeaderCell>
</HeaderRow>
</Header>
<Body>
@@ -213,6 +231,16 @@ const CommandsPage = () => {
<Cell>{ci.cmd}</Cell>
<Cell>{ci.value}</Cell>
<Cell>{ci.name}</Cell>
<Cell>
{numChanges === 0 && (
<IconButton
onClick={() => execute(ci.name)}
style={{ backgroundColor: 'transparent' }}
>
<PlayArrowIcon color="primary" sx={{ fontSize: 16 }} />
</IconButton>
)}
</Cell>
</Row>
))}
</Body>