Add sidesheet for editing relationships
This commit is contained in:
parent
6cd0a691dc
commit
557ce72961
@ -87,6 +87,8 @@ export default function Canvas() {
|
|||||||
* @param {ObjectType[keyof ObjectType]} type
|
* @param {ObjectType[keyof ObjectType]} type
|
||||||
*/
|
*/
|
||||||
const handlePointerDownOnElement = (e, id, type) => {
|
const handlePointerDownOnElement = (e, id, type) => {
|
||||||
|
if (selectedElement.open && !layout.sidebar) return;
|
||||||
|
|
||||||
if (!e.isPrimary) return;
|
if (!e.isPrimary) return;
|
||||||
|
|
||||||
if (type === ObjectType.TABLE) {
|
if (type === ObjectType.TABLE) {
|
||||||
@ -138,6 +140,8 @@ export default function Canvas() {
|
|||||||
* @param {PointerEvent} e
|
* @param {PointerEvent} e
|
||||||
*/
|
*/
|
||||||
const handlePointerMove = (e) => {
|
const handlePointerMove = (e) => {
|
||||||
|
if (selectedElement.open && !layout.sidebar) return;
|
||||||
|
|
||||||
if (!e.isPrimary) return;
|
if (!e.isPrimary) return;
|
||||||
|
|
||||||
if (linking) {
|
if (linking) {
|
||||||
@ -226,6 +230,8 @@ export default function Canvas() {
|
|||||||
* @param {PointerEvent} e
|
* @param {PointerEvent} e
|
||||||
*/
|
*/
|
||||||
const handlePointerDown = (e) => {
|
const handlePointerDown = (e) => {
|
||||||
|
if (selectedElement.open && !layout.sidebar) return;
|
||||||
|
|
||||||
if (!e.isPrimary) return;
|
if (!e.isPrimary) return;
|
||||||
|
|
||||||
// don't pan if the sidesheet for editing a table is open
|
// don't pan if the sidesheet for editing a table is open
|
||||||
@ -309,6 +315,8 @@ export default function Canvas() {
|
|||||||
* @param {PointerEvent} e
|
* @param {PointerEvent} e
|
||||||
*/
|
*/
|
||||||
const handlePointerUp = (e) => {
|
const handlePointerUp = (e) => {
|
||||||
|
if (selectedElement.open && !layout.sidebar) return;
|
||||||
|
|
||||||
if (!e.isPrimary) return;
|
if (!e.isPrimary) return;
|
||||||
|
|
||||||
if (coordsDidUpdate(dragging.element)) {
|
if (coordsDidUpdate(dragging.element)) {
|
||||||
|
@ -3,6 +3,8 @@ import { Cardinality, ObjectType, Tab } from "../../data/constants";
|
|||||||
import { calcPath } from "../../utils/calcPath";
|
import { calcPath } from "../../utils/calcPath";
|
||||||
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
|
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { SideSheet } from "@douyinfe/semi-ui";
|
||||||
|
import RelationshipInfo from "../EditorSidePanel/RelationshipsTab/RelationshipInfo";
|
||||||
|
|
||||||
export default function Relationship({ data }) {
|
export default function Relationship({ data }) {
|
||||||
const { settings } = useSettings();
|
const { settings } = useSettings();
|
||||||
@ -79,6 +81,7 @@ export default function Relationship({ data }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<g className="select-none group" onDoubleClick={edit}>
|
<g className="select-none group" onDoubleClick={edit}>
|
||||||
<path
|
<path
|
||||||
ref={pathRef}
|
ref={pathRef}
|
||||||
@ -141,5 +144,27 @@ export default function Relationship({ data }) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</g>
|
</g>
|
||||||
|
<SideSheet
|
||||||
|
title={t("edit")}
|
||||||
|
size="small"
|
||||||
|
visible={
|
||||||
|
selectedElement.element === ObjectType.RELATIONSHIP &&
|
||||||
|
selectedElement.id === data.id &&
|
||||||
|
selectedElement.open &&
|
||||||
|
!layout.sidebar
|
||||||
|
}
|
||||||
|
onCancel={() => {
|
||||||
|
setSelectedElement((prev) => ({
|
||||||
|
...prev,
|
||||||
|
open: false,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
style={{ paddingBottom: "16px" }}
|
||||||
|
>
|
||||||
|
<div className="sidesheet-theme">
|
||||||
|
<RelationshipInfo data={data} />
|
||||||
|
</div>
|
||||||
|
</SideSheet>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,4 @@
|
|||||||
import {
|
import { Row, Col, Select, Button, Popover, Table } from "@douyinfe/semi-ui";
|
||||||
Collapse,
|
|
||||||
Row,
|
|
||||||
Col,
|
|
||||||
Select,
|
|
||||||
Button,
|
|
||||||
Popover,
|
|
||||||
Table,
|
|
||||||
} from "@douyinfe/semi-ui";
|
|
||||||
import {
|
import {
|
||||||
IconDeleteStroked,
|
IconDeleteStroked,
|
||||||
IconLoopTextStroked,
|
IconLoopTextStroked,
|
||||||
@ -128,15 +120,7 @@ export default function RelationshipInfo({ data }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id={`scroll_ref_${data.id}`}>
|
<>
|
||||||
<Collapse.Panel
|
|
||||||
header={
|
|
||||||
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
|
|
||||||
{data.name}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
itemKey={`${data.id}`}
|
|
||||||
>
|
|
||||||
<div className="flex justify-between items-center mb-3">
|
<div className="flex justify-between items-center mb-3">
|
||||||
<div className="me-3">
|
<div className="me-3">
|
||||||
<span className="font-semibold">{t("primary")}: </span>
|
<span className="font-semibold">{t("primary")}: </span>
|
||||||
@ -156,8 +140,7 @@ export default function RelationshipInfo({ data }) {
|
|||||||
{
|
{
|
||||||
key: "1",
|
key: "1",
|
||||||
foreign: `${tables[data.startTableId].name}(${
|
foreign: `${tables[data.startTableId].name}(${
|
||||||
tables[data.startTableId].fields[data.startFieldId]
|
tables[data.startTableId].fields[data.startFieldId].name
|
||||||
.name
|
|
||||||
})`,
|
})`,
|
||||||
primary: `${tables[data.endTableId].name}(${
|
primary: `${tables[data.endTableId].name}(${
|
||||||
tables[data.endTableId].fields[data.endFieldId].name
|
tables[data.endTableId].fields[data.endFieldId].name
|
||||||
@ -231,7 +214,6 @@ export default function RelationshipInfo({ data }) {
|
|||||||
>
|
>
|
||||||
{t("delete")}
|
{t("delete")}
|
||||||
</Button>
|
</Button>
|
||||||
</Collapse.Panel>
|
</>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,12 @@ export default function RelationshipsTab() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchBar />
|
<SearchBar />
|
||||||
|
{relationships.length <= 0 ? (
|
||||||
|
<Empty
|
||||||
|
title={t("no_relationships")}
|
||||||
|
text={t("no_relationships_text")}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<Collapse
|
<Collapse
|
||||||
activeKey={
|
activeKey={
|
||||||
selectedElement.open &&
|
selectedElement.open &&
|
||||||
@ -33,15 +39,22 @@ export default function RelationshipsTab() {
|
|||||||
}
|
}
|
||||||
accordion
|
accordion
|
||||||
>
|
>
|
||||||
{relationships.length <= 0 ? (
|
{relationships.map((r) => (
|
||||||
<Empty
|
<div id={`scroll_ref_${r.id}`} key={"relationship_" + r.id}>
|
||||||
title={t("no_relationships")}
|
<Collapse.Panel
|
||||||
text={t("no_relationships_text")}
|
header={
|
||||||
/>
|
<div className="overflow-hidden text-ellipsis whitespace-nowrap">
|
||||||
) : (
|
{r.name}
|
||||||
relationships.map((r) => <RelationshipInfo key={r.id} data={r} />)
|
</div>
|
||||||
)}
|
}
|
||||||
|
itemKey={`${r.id}`}
|
||||||
|
>
|
||||||
|
<RelationshipInfo data={r} />
|
||||||
|
</Collapse.Panel>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ function Relationship({ relationship, tables }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g className="select-none" onClick={() => console.log(pathRef.current)}>
|
<g className="select-none">
|
||||||
<path
|
<path
|
||||||
ref={pathRef}
|
ref={pathRef}
|
||||||
d={calcPath({
|
d={calcPath({
|
||||||
|
Loading…
Reference in New Issue
Block a user