mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-07-18 10:11:24 +00:00
Support locking tables on canvas (#475)
* Lock tables * Add lock flag in addTable
This commit is contained in:
@@ -104,6 +104,8 @@ export default function Canvas() {
|
|||||||
const elements = [];
|
const elements = [];
|
||||||
|
|
||||||
tables.forEach((table) => {
|
tables.forEach((table) => {
|
||||||
|
if (table.locked) return;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isInsideRect(
|
isInsideRect(
|
||||||
{
|
{
|
||||||
@@ -319,6 +321,9 @@ export default function Canvas() {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
} else if (dragging.element === ObjectType.TABLE && dragging.id !== null) {
|
} else if (dragging.element === ObjectType.TABLE && dragging.id !== null) {
|
||||||
|
const table = tables.find((t) => t.id === dragging.id);
|
||||||
|
if (table.locked) return;
|
||||||
|
|
||||||
updateTable(dragging.id, {
|
updateTable(dragging.id, {
|
||||||
x: pointer.spaces.diagram.x + grabOffset.x,
|
x: pointer.spaces.diagram.x + grabOffset.x,
|
||||||
y: pointer.spaces.diagram.y + grabOffset.y,
|
y: pointer.spaces.diagram.y + grabOffset.y,
|
||||||
|
@@ -12,6 +12,8 @@ import {
|
|||||||
IconMinus,
|
IconMinus,
|
||||||
IconDeleteStroked,
|
IconDeleteStroked,
|
||||||
IconKeyStroked,
|
IconKeyStroked,
|
||||||
|
IconLock,
|
||||||
|
IconUnlock,
|
||||||
} from "@douyinfe/semi-icons";
|
} from "@douyinfe/semi-icons";
|
||||||
import { Popover, Tag, Button, SideSheet } from "@douyinfe/semi-ui";
|
import { Popover, Tag, Button, SideSheet } from "@douyinfe/semi-ui";
|
||||||
import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks";
|
import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks";
|
||||||
@@ -32,7 +34,7 @@ export default function Table(props) {
|
|||||||
setLinkingLine,
|
setLinkingLine,
|
||||||
} = props;
|
} = props;
|
||||||
const { layout } = useLayout();
|
const { layout } = useLayout();
|
||||||
const { deleteTable, deleteField } = useDiagram();
|
const { deleteTable, deleteField, updateTable } = useDiagram();
|
||||||
const { settings } = useSettings();
|
const { settings } = useSettings();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { selectedElement, setSelectedElement, bulkSelectedElements } =
|
const { selectedElement, setSelectedElement, bulkSelectedElements } =
|
||||||
@@ -56,6 +58,9 @@ export default function Table(props) {
|
|||||||
);
|
);
|
||||||
}, [selectedElement, tableData, bulkSelectedElements]);
|
}, [selectedElement, tableData, bulkSelectedElements]);
|
||||||
|
|
||||||
|
const lockUnlockTable = () =>
|
||||||
|
updateTable(tableData.id, { locked: !tableData.locked });
|
||||||
|
|
||||||
const openEditor = () => {
|
const openEditor = () => {
|
||||||
if (!layout.sidebar) {
|
if (!layout.sidebar) {
|
||||||
setSelectedElement((prev) => ({
|
setSelectedElement((prev) => ({
|
||||||
@@ -109,18 +114,26 @@ export default function Table(props) {
|
|||||||
settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
|
settings.mode === "light" ? "bg-zinc-200" : "bg-zinc-900"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className=" px-3 overflow-hidden text-ellipsis whitespace-nowrap">
|
<div className="px-3 overflow-hidden text-ellipsis whitespace-nowrap">
|
||||||
{tableData.name}
|
{tableData.name}
|
||||||
</div>
|
</div>
|
||||||
<div className="hidden group-hover:block">
|
<div className="hidden group-hover:block">
|
||||||
<div className="flex justify-end items-center mx-2">
|
<div className="flex justify-end items-center mx-2 space-x-1.5">
|
||||||
|
<Button
|
||||||
|
icon={tableData.locked ? <IconLock /> : <IconUnlock />}
|
||||||
|
size="small"
|
||||||
|
theme="solid"
|
||||||
|
style={{
|
||||||
|
backgroundColor: "#2f68adb3",
|
||||||
|
}}
|
||||||
|
onClick={lockUnlockTable}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
icon={<IconEdit />}
|
icon={<IconEdit />}
|
||||||
size="small"
|
size="small"
|
||||||
theme="solid"
|
theme="solid"
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: "#2f68adb3",
|
backgroundColor: "#2f68adb3",
|
||||||
marginRight: "6px",
|
|
||||||
}}
|
}}
|
||||||
onClick={openEditor}
|
onClick={openEditor}
|
||||||
/>
|
/>
|
||||||
|
@@ -32,6 +32,7 @@ export default function DiagramContextProvider({ children }) {
|
|||||||
name: `table_${prev.length}`,
|
name: `table_${prev.length}`,
|
||||||
x: transform.pan.x,
|
x: transform.pan.x,
|
||||||
y: transform.pan.y,
|
y: transform.pan.y,
|
||||||
|
locked: false,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "id",
|
name: "id",
|
||||||
|
@@ -38,6 +38,7 @@ export const tableSchema = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
comment: { type: "string" },
|
comment: { type: "string" },
|
||||||
|
locked: { type: "boolean" },
|
||||||
indices: {
|
indices: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: {
|
||||||
|
Reference in New Issue
Block a user