From 557ce72961cc6ba5f5e5880479b490b0561d230b Mon Sep 17 00:00:00 2001
From: 1ilit <1ilit@proton.me>
Date: Sat, 7 Sep 2024 23:52:03 +0400
Subject: [PATCH] Add sidesheet for editing relationships
---
src/components/EditorCanvas/Canvas.jsx | 8 +
src/components/EditorCanvas/Relationship.jsx | 145 +++++++-----
.../RelationshipsTab/RelationshipInfo.jsx | 208 ++++++++----------
.../RelationshipsTab/RelationshipsTab.jsx | 69 +++---
src/components/SimpleCanvas.jsx | 2 +-
5 files changed, 230 insertions(+), 202 deletions(-)
diff --git a/src/components/EditorCanvas/Canvas.jsx b/src/components/EditorCanvas/Canvas.jsx
index 7587f12..1f15384 100644
--- a/src/components/EditorCanvas/Canvas.jsx
+++ b/src/components/EditorCanvas/Canvas.jsx
@@ -87,6 +87,8 @@ export default function Canvas() {
* @param {ObjectType[keyof ObjectType]} type
*/
const handlePointerDownOnElement = (e, id, type) => {
+ if (selectedElement.open && !layout.sidebar) return;
+
if (!e.isPrimary) return;
if (type === ObjectType.TABLE) {
@@ -138,6 +140,8 @@ export default function Canvas() {
* @param {PointerEvent} e
*/
const handlePointerMove = (e) => {
+ if (selectedElement.open && !layout.sidebar) return;
+
if (!e.isPrimary) return;
if (linking) {
@@ -226,6 +230,8 @@ export default function Canvas() {
* @param {PointerEvent} e
*/
const handlePointerDown = (e) => {
+ if (selectedElement.open && !layout.sidebar) return;
+
if (!e.isPrimary) return;
// don't pan if the sidesheet for editing a table is open
@@ -309,6 +315,8 @@ export default function Canvas() {
* @param {PointerEvent} e
*/
const handlePointerUp = (e) => {
+ if (selectedElement.open && !layout.sidebar) return;
+
if (!e.isPrimary) return;
if (coordsDidUpdate(dragging.element)) {
diff --git a/src/components/EditorCanvas/Relationship.jsx b/src/components/EditorCanvas/Relationship.jsx
index 331fdeb..9f512a9 100644
--- a/src/components/EditorCanvas/Relationship.jsx
+++ b/src/components/EditorCanvas/Relationship.jsx
@@ -3,6 +3,8 @@ import { Cardinality, ObjectType, Tab } from "../../data/constants";
import { calcPath } from "../../utils/calcPath";
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
import { useTranslation } from "react-i18next";
+import { SideSheet } from "@douyinfe/semi-ui";
+import RelationshipInfo from "../EditorSidePanel/RelationshipsTab/RelationshipInfo";
export default function Relationship({ data }) {
const { settings } = useSettings();
@@ -79,67 +81,90 @@ export default function Relationship({ data }) {
};
return (
-
-
+
+
+ {pathRef.current && settings.showCardinality && (
+ <>
+
+
+ {cardinalityStart}
+
+
+
+ {cardinalityEnd}
+
+ >
)}
- stroke="gray"
- className="group-hover:stroke-sky-700"
- fill="none"
- strokeWidth={2}
- cursor="pointer"
- />
- {pathRef.current && settings.showCardinality && (
- <>
-
-
- {cardinalityStart}
-
-
-
- {cardinalityEnd}
-
- >
- )}
-
+
+ {
+ setSelectedElement((prev) => ({
+ ...prev,
+ open: false,
+ }));
+ }}
+ style={{ paddingBottom: "16px" }}
+ >
+
+
+
+
+ >
);
}
diff --git a/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx b/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
index 114afcc..bc184f1 100644
--- a/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
+++ b/src/components/EditorSidePanel/RelationshipsTab/RelationshipInfo.jsx
@@ -1,12 +1,4 @@
-import {
- Collapse,
- Row,
- Col,
- Select,
- Button,
- Popover,
- Table,
-} from "@douyinfe/semi-ui";
+import { Row, Col, Select, Button, Popover, Table } from "@douyinfe/semi-ui";
import {
IconDeleteStroked,
IconLoopTextStroked,
@@ -128,110 +120,100 @@ export default function RelationshipInfo({ data }) {
};
return (
-
-
- {data.name}
-
- }
- itemKey={`${data.id}`}
- >
-
-
- {t("primary")}:
- {tables[data.endTableId].name}
-
-
- {t("foreign")}:
- {tables[data.startTableId].name}
-
-
-
-
-
- }
- block
- onClick={swapKeys}
- >
- {t("swap")}
-
-
-
- }
- trigger="click"
- position="rightTop"
- showArrow
- >
-
} type="tertiary" />
-
-
+ <>
+
+
+ {t("primary")}:
+ {tables[data.endTableId].name}
-
{t("cardinality")}:
-
+
+ {t("foreign")}:
+ {tables[data.startTableId].name}
+
+
+
+
+
+ }
+ block
+ onClick={swapKeys}
+ >
+ {t("swap")}
+
+
+
+ }
+ trigger="click"
+ position="rightTop"
+ showArrow
+ >
+ } type="tertiary" />
+
+
+
+ {t("cardinality")}:
+ ({
+ label: t(v),
+ value: v,
+ }))}
+ value={data.cardinality}
+ className="w-full"
+ onChange={changeCardinality}
+ />
+
+
+ {t("on_update")}:
+ ({
+ label: v,
+ value: v,
+ }))}
+ value={data.updateConstraint}
+ className="w-full"
+ onChange={(value) => changeConstraint("update", value)}
+ />
+
+
+ {t("on_delete")}:
+ ({
+ label: v,
+ value: v,
+ }))}
+ value={data.deleteConstraint}
+ className="w-full"
+ onChange={(value) => changeConstraint("delete", value)}
+ />
+
+
+ }
+ block
+ type="danger"
+ onClick={() => deleteRelationship(data.id)}
+ >
+ {t("delete")}
+
+ >
);
}
diff --git a/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx b/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx
index 99f80d7..e492a96 100644
--- a/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx
+++ b/src/components/EditorSidePanel/RelationshipsTab/RelationshipsTab.jsx
@@ -14,34 +14,47 @@ export default function RelationshipsTab() {
return (
<>
-
- setSelectedElement((prev) => ({
- ...prev,
- open: true,
- id: parseInt(k),
- element: ObjectType.RELATIONSHIP,
- }))
- }
- accordion
- >
- {relationships.length <= 0 ? (
-
- ) : (
- relationships.map((r) => )
- )}
-
+ {relationships.length <= 0 ? (
+
+ ) : (
+
+ setSelectedElement((prev) => ({
+ ...prev,
+ open: true,
+ id: parseInt(k),
+ element: ObjectType.RELATIONSHIP,
+ }))
+ }
+ accordion
+ >
+ {relationships.map((r) => (
+
+
+ {r.name}
+
+ }
+ itemKey={`${r.id}`}
+ >
+
+
+
+ ))}
+
+ )}
>
);
}
diff --git a/src/components/SimpleCanvas.jsx b/src/components/SimpleCanvas.jsx
index 78a2840..1ed5d94 100644
--- a/src/components/SimpleCanvas.jsx
+++ b/src/components/SimpleCanvas.jsx
@@ -117,7 +117,7 @@ function Relationship({ relationship, tables }) {
}
return (
- console.log(pathRef.current)}>
+