diff --git a/src/components/EditorCanvas/Canvas.jsx b/src/components/EditorCanvas/Canvas.jsx index d4ceecbf..6b60ab50 100644 --- a/src/components/EditorCanvas/Canvas.jsx +++ b/src/components/EditorCanvas/Canvas.jsx @@ -8,6 +8,7 @@ import { gridSize, gridCircleRadius, minAreaSize, + defaultBlue, } from "../../data/constants"; import { Toast } from "@douyinfe/semi-ui"; import Table from "./Table"; @@ -624,6 +625,7 @@ export default function Canvas() { deleteConstraint: Constraint.NONE, name: `fk_${startTableName}_${startField.name}_${endTableName}`, id: nanoid(), + color: defaultBlue }; delete newRelationship.startX; delete newRelationship.startY; diff --git a/src/components/EditorCanvas/Relationship.jsx b/src/components/EditorCanvas/Relationship.jsx index 72457de9..0ff82fa8 100644 --- a/src/components/EditorCanvas/Relationship.jsx +++ b/src/components/EditorCanvas/Relationship.jsx @@ -1,5 +1,10 @@ import { useMemo, useRef, useState, useEffect } from "react"; -import { Cardinality, ObjectType, Tab } from "../../data/constants"; +import { + Cardinality, + defaultBlue, + ObjectType, + Tab, +} from "../../data/constants"; import { calcPath } from "../../utils/calcPath"; import { useDiagram, useSettings, useLayout, useSelect } from "../../hooks"; import { useTranslation } from "react-i18next"; @@ -127,6 +132,7 @@ export default function Relationship({ data }) { className="relationship-path" fill="none" cursor="pointer" + style={{ stroke: data.color ?? defaultBlue }} /> {settings.showRelationshipLabels && ( > )} @@ -181,7 +189,7 @@ export default function Relationship({ data }) { ); } -function CardinalityLabel({ x, y, text, r = 12, padding = 14 }) { +function CardinalityLabel({ x, y, text, r = 12, padding = 14 , color = "grey"}) { const [textWidth, setTextWidth] = useState(0); const textRef = useRef(null); @@ -201,7 +209,7 @@ function CardinalityLabel({ x, y, text, r = 12, padding = 14 }) { ry={r} width={textWidth + padding} height={r * 2} - fill="grey" + fill={color} className="group-hover:fill-sky-600" /> { const { fields: startTableFields, name: startTableName } = tables.find( @@ -141,6 +145,41 @@ export default function RelationshipInfo({ data }) { updateRelationship(data.id, { [undoKey]: value }); }; + const handleColorPick = (color) => { + setUndoStack((prev) => { + let undoColor = initialColorRef.current; + const lastColorChange = prev.findLast( + (e) => + e.element === ObjectType.RELATIONSHIP && + e.rid === data.id && + e.action === Action.EDIT && + e.redo?.color, + ); + if (lastColorChange) { + undoColor = lastColorChange.redo.color; + } + + if (color === undoColor) return prev; + + const newStack = [ + ...prev, + { + action: Action.EDIT, + element: ObjectType.RELATIONSHIP, + rid: data.id, + undo: { color: undoColor }, + redo: { color: color }, + message: t("edit_relationship", { + refName: data.name, + extra: "[color]", + }), + }, + ]; + return newStack; + }); + setRedoStack([]); + }; + return ( <> @@ -173,6 +212,15 @@ export default function RelationshipInfo({ data }) { setRedoStack([]); }} /> + + updateRelationship(data.id, { color })} + onColorPick={(color) => handleColorPick(color)} + /> +