mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-06-15 04:16:27 +03:00
show execute button in table
This commit is contained in:
@@ -4,9 +4,11 @@ import { toast } from 'react-toastify';
|
|||||||
|
|
||||||
import AddIcon from '@mui/icons-material/Add';
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
import CancelIcon from '@mui/icons-material/Cancel';
|
import CancelIcon from '@mui/icons-material/Cancel';
|
||||||
|
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||||
import WarningIcon from '@mui/icons-material/Warning';
|
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 {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Cell,
|
Cell,
|
||||||
@@ -46,7 +48,7 @@ const DEFAULT_COMMAND_ITEM: Omit<CommandItem, 'id'> = {
|
|||||||
|
|
||||||
const commandsTheme = {
|
const commandsTheme = {
|
||||||
Table: `
|
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: `
|
BaseRow: `
|
||||||
font-size: 14px;
|
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) => {
|
const editItem = (ci: CommandItem) => {
|
||||||
setCreating(false);
|
setCreating(false);
|
||||||
setSelectedItem(ci);
|
setSelectedItem(ci);
|
||||||
@@ -205,6 +222,7 @@ const CommandsPage = () => {
|
|||||||
<HeaderCell stiff>{LL.COMMAND(0)}</HeaderCell>
|
<HeaderCell stiff>{LL.COMMAND(0)}</HeaderCell>
|
||||||
<HeaderCell stiff>{LL.VALUE(0)}</HeaderCell>
|
<HeaderCell stiff>{LL.VALUE(0)}</HeaderCell>
|
||||||
<HeaderCell stiff>{LL.NAME(0)}</HeaderCell>
|
<HeaderCell stiff>{LL.NAME(0)}</HeaderCell>
|
||||||
|
<HeaderCell></HeaderCell>
|
||||||
</HeaderRow>
|
</HeaderRow>
|
||||||
</Header>
|
</Header>
|
||||||
<Body>
|
<Body>
|
||||||
@@ -213,6 +231,16 @@ const CommandsPage = () => {
|
|||||||
<Cell>{ci.cmd}</Cell>
|
<Cell>{ci.cmd}</Cell>
|
||||||
<Cell>{ci.value}</Cell>
|
<Cell>{ci.value}</Cell>
|
||||||
<Cell>{ci.name}</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>
|
</Row>
|
||||||
))}
|
))}
|
||||||
</Body>
|
</Body>
|
||||||
|
|||||||
Reference in New Issue
Block a user