import { useAtom, useSetAtom } from "jotai"; import type { FormatterProps } from "react-data-grid"; import { Stack, Tooltip, IconButton, alpha } from "@mui/material"; import { CopyCells as CopyCellsIcon } from "@src/assets/icons"; import DeleteIcon from "@mui/icons-material/DeleteOutlined"; import { projectScope, userRolesAtom, tableAddRowIdTypeAtom, altPressAtom, confirmDialogAtom, } from "@src/atoms/projectScope"; import { tableScope, tableSettingsAtom, addRowAtom, deleteRowAtom, } from "@src/atoms/tableScope"; import { TableRow } from "@src/types/table"; export default function FinalColumn({ row }: FormatterProps) { const [userRoles] = useAtom(userRolesAtom, projectScope); const [addRowIdType] = useAtom(tableAddRowIdTypeAtom, projectScope); const confirm = useSetAtom(confirmDialogAtom, projectScope); const [tableSettings] = useAtom(tableSettingsAtom, tableScope); const addRow = useSetAtom(addRowAtom, tableScope); const deleteRow = useSetAtom(deleteRowAtom, tableScope); const [altPress] = useAtom(altPressAtom, projectScope); const handleDelete = () => deleteRow(row._rowy_ref.path); const handleDuplicate = () => { addRow({ row, setId: addRowIdType === "custom" ? "decrement" : addRowIdType, }); }; if (!userRoles.includes("ADMIN") && tableSettings.readOnly === true) return null; return ( { confirm({ title: "Duplicate row?", body: ( <> Row path:
{row._rowy_ref.path} ), confirm: "Duplicate", confirmColor: "success", handleConfirm: handleDuplicate, }); } } aria-label="Duplicate row" className="row-hover-iconButton" >
{ confirm({ title: "Delete row?", body: ( <> Row path:
{row._rowy_ref.path} ), confirm: "Delete", confirmColor: "error", handleConfirm: handleDelete, }); } } aria-label={`Delete row${altPress ? "" : "…"}`} className="row-hover-iconButton" sx={{ ".rdg-row:hover .row-hover-iconButton&&": { color: "error.main", backgroundColor: (theme) => alpha( theme.palette.error.main, theme.palette.action.hoverOpacity * 2 ), }, }} disabled={!row._rowy_ref.path} >
); }