Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight when editing relationship #175

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: highlight using selectedElement
  • Loading branch information
huyjs9 committed Jul 29, 2024
commit 2490cb8c01105e8b34dc899ffcbe3ee7a68cfbc4
25 changes: 2 additions & 23 deletions src/components/EditorCanvas/Relationship.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState, useRef } from "react";
import { Cardinality, ObjectType, Tab } from "../../data/constants";
import { RELATIONSHIP_EDITING } from "../../data/customEvents";
import { calcPath } from "../../utils/calcPath";
import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks";
import { cn } from "../../utils/cn";
Expand All @@ -14,28 +13,8 @@ export default function Relationship({ data }) {
const pathRef = useRef();

useEffect(() => {
const handleEditing = (event) => {
setEditing(event.detail.id === data.id);
};

document.addEventListener(RELATIONSHIP_EDITING, handleEditing);
return () => {
document.removeEventListener(RELATIONSHIP_EDITING, handleEditing);
};
}, [data.id]);

useEffect(() => {
const handleClickAway = (event) => {
if (pathRef.current && !pathRef.current.contains(event.target)) {
setEditing(false);
}
};

document.addEventListener("mousedown", handleClickAway);
return () => {
document.removeEventListener("mousedown", handleClickAway);
};
}, [pathRef]);
setEditing(data.id === selectedElement.id);
}, [data.id, selectedElement.id]);

let cardinalityStart = "1";
let cardinalityEnd = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Empty from "../Empty";
import SearchBar from "./SearchBar";
import RelationshipInfo from "./RelationshipInfo";
import { ObjectType } from "../../../data/constants";
import { RELATIONSHIP_EDITING } from "../../../data/customEvents";
import { useTranslation } from "react-i18next";

export default function RelationshipsTab() {
Expand All @@ -24,20 +23,14 @@ export default function RelationshipsTab() {
}
keepDOM
lazyRender
onChange={(k) => {
const newId = parseInt(k);
const event = new CustomEvent(RELATIONSHIP_EDITING, {
detail: { id: newId },
});
document.dispatchEvent(event);

onChange={(k) =>
setSelectedElement((prev) => ({
...prev,
open: true,
id: newId,
id: parseInt(k),
element: ObjectType.RELATIONSHIP,
}));
}}
}))
}
accordion
>
{relationships.length <= 0 ? (
Expand Down
1 change: 0 additions & 1 deletion src/data/customEvents.js

This file was deleted.

Loading