Remove popconfirm from canvas field delete

This commit is contained in:
1ilit 2024-01-22 18:16:21 +02:00
parent 3efbb0de2a
commit b8f7ac2812

View File

@ -17,7 +17,6 @@ import {
IconColorPalette, IconColorPalette,
} from "@douyinfe/semi-icons"; } from "@douyinfe/semi-icons";
import { import {
Popconfirm,
Select, Select,
Input, Input,
TextArea, TextArea,
@ -73,27 +72,24 @@ export default function Table(props) {
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}
> >
<div <div
className={`border-2 ${ className={`border-2 ${isHovered
isHovered
? "border-dashed border-blue-500" ? "border-dashed border-blue-500"
: selectedElement.element === ObjectType.TABLE && : selectedElement.element === ObjectType.TABLE &&
selectedElement.id === props.tableData.id selectedElement.id === props.tableData.id
? "border-blue-500" ? "border-blue-500"
: "border-slate-400" : "border-slate-400"
} select-none rounded-lg w-full ${ } select-none rounded-lg w-full ${settings.mode === "light"
settings.mode === "light"
? "bg-zinc-100 text-zinc-800" ? "bg-zinc-100 text-zinc-800"
: "bg-zinc-800 text-zinc-200" : "bg-zinc-800 text-zinc-200"
}`} }`}
> >
<div <div
className={`h-[10px] w-full rounded-t-md`} className={`h-[10px] w-full rounded-t-md`}
style={{ backgroundColor: props.tableData.color }} style={{ backgroundColor: props.tableData.color }}
/> />
<div <div
className={`font-bold h-[40px] flex justify-between items-center border-b border-gray-400 ${ className={`font-bold h-[40px] flex justify-between items-center border-b border-gray-400 ${settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900" }`}
}`}
> >
<div className="px-3"> <div className="px-3">
{isHovered {isHovered
@ -101,8 +97,8 @@ export default function Table(props) {
? props.tableData.name ? props.tableData.name
: `${props.tableData.name.substring(0, 10)}...` : `${props.tableData.name.substring(0, 10)}...`
: props.tableData.name.length < 16 : props.tableData.name.length < 16
? props.tableData.name ? props.tableData.name
: `${props.tableData.name.substring(0, 16)}...`} : `${props.tableData.name.substring(0, 16)}...`}
</div> </div>
{isHovered && ( {isHovered && (
<div className="flex justify-end items-center mx-2"> <div className="flex justify-end items-center mx-2">
@ -151,9 +147,8 @@ export default function Table(props) {
</div> </div>
<div> <div>
<strong <strong
className={`${ className={`${props.tableData.indices.length === 0 ? "" : "block"
props.tableData.indices.length === 0 ? "" : "block" }`}
}`}
> >
Indices : Indices :
</strong>{" "} </strong>{" "}
@ -164,11 +159,10 @@ export default function Table(props) {
{props.tableData.indices.map((index, k) => ( {props.tableData.indices.map((index, k) => (
<div <div
key={k} key={k}
className={`flex items-center my-1 px-2 py-1 rounded ${ className={`flex items-center my-1 px-2 py-1 rounded ${settings.mode === "light"
settings.mode === "light"
? "bg-gray-100" ? "bg-gray-100"
: "bg-zinc-800" : "bg-zinc-800"
}`} }`}
> >
<i className="fa-solid fa-thumbtack me-2 mt-1 text-slate-500"></i> <i className="fa-solid fa-thumbtack me-2 mt-1 text-slate-500"></i>
<div> <div>
@ -437,9 +431,8 @@ export default function Table(props) {
fid: j, fid: j,
undo: { notNull: f.notNull }, undo: { notNull: f.notNull },
redo: { notNull: !f.notNull }, redo: { notNull: !f.notNull },
message: `Edit table field to${ message: `Edit table field to${f.notNull ? "" : " not"
f.notNull ? "" : " not" } null`,
} null`,
}, },
]); ]);
setRedoStack([]); setRedoStack([]);
@ -465,9 +458,8 @@ export default function Table(props) {
fid: j, fid: j,
undo: { primary: f.primary }, undo: { primary: f.primary },
redo: { primary: !f.primary }, redo: { primary: !f.primary },
message: `Edit table field to${ message: `Edit table field to${f.primary ? " not" : ""
f.primary ? " not" : "" } primary`,
} primary`,
}, },
]); ]);
setRedoStack([]); setRedoStack([]);
@ -699,9 +691,8 @@ export default function Table(props) {
[checkedValues.target.value]: [checkedValues.target.value]:
checkedValues.target.checked, checkedValues.target.checked,
}, },
message: `Edit table field to${ message: `Edit table field to${f.unique ? " not" : ""
f.unique ? " not" : "" } unique`,
} unique`,
}, },
]); ]);
setRedoStack([]); setRedoStack([]);
@ -741,9 +732,8 @@ export default function Table(props) {
[checkedValues.target.value]: [checkedValues.target.value]:
checkedValues.target.checked, checkedValues.target.checked,
}, },
message: `Edit table field to${ message: `Edit table field to${f.primary ? " not" : ""
f.primary ? " not" : "" } auto increment`,
} auto increment`,
}, },
]); ]);
setRedoStack([]); setRedoStack([]);
@ -906,10 +896,10 @@ export default function Table(props) {
indices: props.tableData.indices.map((index) => indices: props.tableData.indices.map((index) =>
index.id === k index.id === k
? { ? {
...index, ...index,
fields: [...value], fields: [...value],
name: `${value.join("_")}_index`, name: `${value.join("_")}_index`,
} }
: index : index
), ),
}); });
@ -946,9 +936,8 @@ export default function Table(props) {
[checkedValues.target.value]: [checkedValues.target.value]:
checkedValues.target.checked, checkedValues.target.checked,
}, },
message: `Edit table field to${ message: `Edit table field to${idx.unique ? " not" : ""
idx.unique ? " not" : "" } unique`,
} unique`,
}, },
]); ]);
setRedoStack([]); setRedoStack([]);
@ -956,10 +945,10 @@ export default function Table(props) {
indices: props.tableData.indices.map((index) => indices: props.tableData.indices.map((index) =>
index.id === k index.id === k
? { ? {
...index, ...index,
[checkedValues.target.value]: [checkedValues.target.value]:
checkedValues.target.checked, checkedValues.target.checked,
} }
: index : index
), ),
}); });
@ -1242,11 +1231,10 @@ export default function Table(props) {
function field(fieldData, index) { function field(fieldData, index) {
return ( return (
<div <div
className={`${ className={`${index === props.tableData.fields.length - 1
index === props.tableData.fields.length - 1
? "" ? ""
: "border-b border-gray-400" : "border-b border-gray-400"
} h-[36px] px-2 py-1 flex justify-between`} } h-[36px] px-2 py-1 flex justify-between`}
onMouseEnter={() => { onMouseEnter={() => {
setHoveredField(index); setHoveredField(index);
props.setOnRect({ props.setOnRect({
@ -1278,10 +1266,16 @@ export default function Table(props) {
</div> </div>
<div className="text-zinc-400"> <div className="text-zinc-400">
{hoveredField === index ? ( {hoveredField === index ? (
<Popconfirm
title="Are you sure you want to delete this field?" <Button
content="This modification will be irreversible" theme="solid"
onConfirm={() => { size="small"
style={{
opacity: "0.7",
backgroundColor: "#d42020",
}}
icon={<IconMinus />}
onClick={() => {
setUndoStack((prev) => [ setUndoStack((prev) => [
...prev, ...prev,
{ {
@ -1347,18 +1341,7 @@ export default function Table(props) {
}), }),
}); });
}} }}
onCancel={() => {}} ></Button>
>
<Button
theme="solid"
size="small"
style={{
opacity: "0.7",
backgroundColor: "#d42020",
}}
icon={<IconMinus />}
></Button>
</Popconfirm>
) : ( ) : (
fieldData.type fieldData.type
)} )}