Merge pull request #814 from BeeBombshell/duplicateConfirmation

Added confirmation for Duplicate Row button
This commit is contained in:
Bobby Wang
2022-09-16 23:50:52 +07:00
committed by GitHub
2 changed files with 56 additions and 12 deletions

View File

@@ -137,6 +137,12 @@ export default function MenuContents({ onClose }: IMenuContentsProps) {
// Row actions
if (row) {
const handleDuplicate = () => {
addRow({
row,
setId: addRowIdType === "custom" ? "decrement" : addRowIdType,
});
};
const handleDelete = () => deleteRow(row._rowy_ref.path);
const rowActions = [
{
@@ -179,13 +185,28 @@ export default function MenuContents({ onClose }: IMenuContentsProps) {
disabled:
tableSettings.tableType === "collectionGroup" ||
(!userRoles.includes("ADMIN") && tableSettings.readOnly),
onClick: () => {
addRow({
row,
setId: addRowIdType === "custom" ? "decrement" : addRowIdType,
});
onClose();
},
onClick: altPress
? handleDuplicate
: () => {
confirm({
title: "Duplicate row?",
body: (
<>
Row path:
<br />
<code
style={{ userSelect: "all", wordBreak: "break-all" }}
>
{row._rowy_ref.path}
</code>
</>
),
confirm: "Duplicate",
confirmColor: "success",
handleConfirm: handleDuplicate,
});
onClose();
},
},
{
label: altPress ? "Delete" : "Delete…",

View File

@@ -31,6 +31,12 @@ export default function FinalColumn({ row }: FormatterProps<TableRow, any>) {
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;
@@ -42,11 +48,28 @@ export default function FinalColumn({ row }: FormatterProps<TableRow, any>) {
size="small"
color="inherit"
disabled={tableSettings.tableType === "collectionGroup"}
onClick={() =>
addRow({
row,
setId: addRowIdType === "custom" ? "decrement" : addRowIdType,
})
onClick={
altPress
? handleDuplicate
: () => {
confirm({
title: "Duplicate row?",
body: (
<>
Row path:
<br />
<code
style={{ userSelect: "all", wordBreak: "break-all" }}
>
{row._rowy_ref.path}
</code>
</>
),
confirm: "Duplicate",
confirmColor: "success",
handleConfirm: handleDuplicate,
});
}
}
aria-label="Duplicate row"
className="row-hover-iconButton"