feat: dropdown for edit, delete, duplicate robot
This commit is contained in:
@@ -9,8 +9,8 @@ import TablePagination from '@mui/material/TablePagination';
|
|||||||
import TableRow from '@mui/material/TableRow';
|
import TableRow from '@mui/material/TableRow';
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { WorkflowFile } from "maxun-core";
|
import { WorkflowFile } from "maxun-core";
|
||||||
import { IconButton, Button, Box, Typography, TextField } from "@mui/material";
|
import { IconButton, Button, Box, Typography, TextField, MenuItem, Menu, ListItemIcon, ListItemText } from "@mui/material";
|
||||||
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power } from "@mui/icons-material";
|
import { Schedule, DeleteForever, Edit, PlayCircle, Settings, Power, ContentCopy, } from "@mui/icons-material";
|
||||||
import LinkIcon from '@mui/icons-material/Link';
|
import LinkIcon from '@mui/icons-material/Link';
|
||||||
import { useGlobalInfoStore } from "../../context/globalInfo";
|
import { useGlobalInfoStore } from "../../context/globalInfo";
|
||||||
import { deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
import { deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
||||||
@@ -18,7 +18,7 @@ import { Add } from "@mui/icons-material";
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { stopRecording } from "../../api/recording";
|
import { stopRecording } from "../../api/recording";
|
||||||
import { GenericModal } from '../atoms/GenericModal';
|
import { GenericModal } from '../atoms/GenericModal';
|
||||||
|
import { Menu as MenuIcon } from '@mui/icons-material';
|
||||||
|
|
||||||
/** TODO:
|
/** TODO:
|
||||||
* 1. allow editing existing robot after persisting browser steps
|
* 1. allow editing existing robot after persisting browser steps
|
||||||
@@ -26,7 +26,7 @@ import { GenericModal } from '../atoms/GenericModal';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
interface Column {
|
interface Column {
|
||||||
id: 'interpret' | 'name' | 'delete' | 'schedule' | 'integrate' | 'settings' | 'options';
|
id: 'interpret' | 'name' | 'options' | 'schedule' | 'integrate' | 'settings';
|
||||||
label: string;
|
label: string;
|
||||||
minWidth?: number;
|
minWidth?: number;
|
||||||
align?: 'right';
|
align?: 'right';
|
||||||
@@ -68,11 +68,6 @@ const columns: readonly Column[] = [
|
|||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'delete',
|
|
||||||
label: 'Delete',
|
|
||||||
minWidth: 80,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'options',
|
id: 'options',
|
||||||
label: 'Options',
|
label: 'Options',
|
||||||
@@ -253,22 +248,27 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
<IntegrateButton handleIntegrate={() => handleIntegrateRecording(row.id, row.name, row.params || [])} />
|
<IntegrateButton handleIntegrate={() => handleIntegrateRecording(row.id, row.name, row.params || [])} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
);
|
);
|
||||||
case 'delete':
|
case 'options':
|
||||||
return (
|
return (
|
||||||
<TableCell key={column.id} align={column.align}>
|
<TableCell key={column.id} align={column.align}>
|
||||||
<IconButton aria-label="add" size="small" onClick={() => {
|
<OptionsButton
|
||||||
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
handleEdit={() => handleEditRecording(row.id, row.name)}
|
||||||
if (result) {
|
handleDelete={() => {
|
||||||
setRows([]);
|
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
||||||
notify('success', 'Recording deleted successfully');
|
if (result) {
|
||||||
fetchRecordings();
|
setRows([]);
|
||||||
}
|
notify('success', 'Recording deleted successfully');
|
||||||
})
|
fetchRecordings();
|
||||||
}}>
|
}
|
||||||
<DeleteForever />
|
})
|
||||||
</IconButton>
|
}}
|
||||||
</TableCell>
|
handleDuplicate={() => {
|
||||||
);
|
notify('info', 'Duplicating recording...');
|
||||||
|
// Implement duplication logic here
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
);
|
||||||
case 'settings':
|
case 'settings':
|
||||||
return (
|
return (
|
||||||
<TableCell key={column.id} align={column.align}>
|
<TableCell key={column.id} align={column.align}>
|
||||||
@@ -382,6 +382,60 @@ const SettingsButton = ({ handleSettings }: SettingsButtonProps) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OptionsButtonProps {
|
||||||
|
handleEdit: () => void;
|
||||||
|
handleDelete: () => void;
|
||||||
|
handleDuplicate: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsButtonProps) => {
|
||||||
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||||
|
|
||||||
|
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
|
setAnchorEl(event.currentTarget);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<IconButton
|
||||||
|
aria-label="options"
|
||||||
|
size="small"
|
||||||
|
onClick={handleClick}
|
||||||
|
>
|
||||||
|
<MenuIcon />
|
||||||
|
</IconButton>
|
||||||
|
<Menu
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
open={Boolean(anchorEl)}
|
||||||
|
onClose={handleClose}
|
||||||
|
>
|
||||||
|
<MenuItem onClick={() => { handleEdit(); handleClose(); }}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<Edit fontSize="small" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Edit</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem onClick={() => { handleDelete(); handleClose(); }}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<DeleteForever fontSize="small" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Delete</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem onClick={() => { handleDuplicate(); handleClose(); }}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<ContentCopy fontSize="small" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>Duplicate</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const modalStyle = {
|
const modalStyle = {
|
||||||
top: '50%',
|
top: '50%',
|
||||||
left: '50%',
|
left: '50%',
|
||||||
|
|||||||
Reference in New Issue
Block a user