Add warnings to destructive operations

This commit is contained in:
1ilit 2024-04-11 10:30:42 +03:00
parent f87f969b35
commit 2f7702a593

View File

@ -19,6 +19,7 @@ import {
Tooltip, Tooltip,
Spin, Spin,
Toast, Toast,
Popconfirm,
} from "@douyinfe/semi-ui"; } from "@douyinfe/semi-ui";
import { toPng, toJpeg, toSvg } from "html-to-image"; import { toPng, toJpeg, toSvg } from "html-to-image";
import { saveAs } from "file-saver"; import { saveAs } from "file-saver";
@ -715,6 +716,11 @@ export default function ControlPanel({
}, },
}, },
"Delete diagram": { "Delete diagram": {
warning: {
title: "Delete diagram",
message:
"Are you sure you want to delete this diagram? This operation is irreversible.",
},
function: async () => { function: async () => {
await db.diagrams await db.diagrams
.delete(diagramId) .delete(diagramId)
@ -1090,6 +1096,11 @@ export default function ControlPanel({
function: () => setModal(MODAL.TABLE_WIDTH), function: () => setModal(MODAL.TABLE_WIDTH),
}, },
"Flush storage": { "Flush storage": {
warning: {
title: "Flush storage",
message:
"Are you sure you want to flush the storage? This will irreversibly delete all your diagrams and custom templates.",
},
function: async () => { function: async () => {
db.delete() db.delete()
.then(() => { .then(() => {
@ -1399,7 +1410,7 @@ export default function ControlPanel({
<Dropdown <Dropdown
style={{ width: "120px" }} style={{ width: "120px" }}
key={item} key={item}
position={"rightTop"} position="rightTop"
render={ render={
<Dropdown.Menu> <Dropdown.Menu>
{menu[category][item].children.map( {menu[category][item].children.map(
@ -1429,6 +1440,19 @@ export default function ControlPanel({
</Dropdown> </Dropdown>
); );
} }
if (menu[category][item].warning) {
return (
<Popconfirm
key={index}
title={menu[category][item].warning.title}
content={menu[category][item].warning.message}
onConfirm={menu[category][item].function}
position="right"
>
<Dropdown.Item>{item}</Dropdown.Item>
</Popconfirm>
);
}
return ( return (
<Dropdown.Item <Dropdown.Item
key={index} key={index}