-
Notifications
You must be signed in to change notification settings - Fork 6
ENG-1477: Convert a tldraw arrow to a DG relation #1082
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
Merged
sid597
merged 7 commits into
main
from
eng-1477-implement-ability-to-convert-a-tldraw-arrow-to-a-dg-relation
Jul 3, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08c8fb2
ENG-1477: Convert a tldraw arrow to a DG relation
sid597 0a799cc
ENG-1477: Keep original arrow until relation persistence succeeds
sid597 42cce45
ENG-1477: Bail when bound nodes are missing in convert flow
sid597 dc41755
ENG-1477: Preserve arrow geometry when converting
sid597 5015301
ENG-1477: Extract relation helpers and enforce DG visual contract on …
sid597 522d870
Merge remote-tracking branch 'origin/main' into eng-1477-implement-ab…
sid597 067af94
ENG-1477 Reject self-loop arrows from relation conversion
sid597 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,6 @@ | ||
| import React, { useCallback, useEffect, useMemo, useRef } from "react"; | ||
| import { TLShapeId, useEditor, DefaultColorThemePalette } from "tldraw"; | ||
| import { getRelationColor } from "~/components/canvas/DiscourseRelationShape/DiscourseRelationUtil"; | ||
| import { | ||
| checkConnectionType, | ||
| getAllRelations, | ||
| isDiscourseNodeShape, | ||
| } from "~/components/canvas/canvasUtils"; | ||
| import { isRelationComplete } from "~/utils/isRelationComplete"; | ||
| import { getDiscourseNodeTypeId } from "~/components/canvas/DiscourseNodeUtil"; | ||
| import { TLShapeId, useEditor } from "tldraw"; | ||
| import { getValidRelationTypesBetween } from "./relationCreation"; | ||
|
|
||
| type RelationTypeDropdownProps = { | ||
| sourceId: TLShapeId; | ||
|
|
@@ -27,50 +20,10 @@ export const RelationTypeDropdown = ({ | |
| const editor = useEditor(); | ||
| const dropdownRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| // Get valid relation types based on source/target node types | ||
| const validRelationTypes = useMemo(() => { | ||
| const startNode = editor.getShape(sourceId); | ||
| const endNode = editor.getShape(targetId); | ||
| if (!startNode || !endNode) return []; | ||
|
|
||
| // Verify both are discourse nodes | ||
| if ( | ||
| !isDiscourseNodeShape(editor, startNode) || | ||
| !isDiscourseNodeShape(editor, endNode) | ||
| ) | ||
| return []; | ||
|
|
||
| const startNodeType = getDiscourseNodeTypeId({ shape: startNode }); | ||
| const endNodeType = getDiscourseNodeTypeId({ shape: endNode }); | ||
|
|
||
| const colorPalette = DefaultColorThemePalette.lightMode; | ||
| const validTypes: { id: string; label: string; color: string }[] = []; | ||
| const allRelations = getAllRelations(); | ||
| const seenLabels = new Set<string>(); | ||
|
|
||
| for (const relation of allRelations) { | ||
| if (!isRelationComplete(relation)) continue; | ||
| const { isDirect: isForward, isReverse } = checkConnectionType( | ||
| relation, | ||
| startNodeType, | ||
| endNodeType, | ||
| ); | ||
|
|
||
| if (!isForward && !isReverse) continue; | ||
|
|
||
| const label = | ||
| isReverse && relation.complement ? relation.complement : relation.label; | ||
|
|
||
| if (!seenLabels.has(label)) { | ||
| seenLabels.add(label); | ||
| const tldrawColor = getRelationColor(relation.label); | ||
| const hexColor = colorPalette[tldrawColor]?.solid ?? "#333"; | ||
| validTypes.push({ id: relation.id, label, color: hexColor }); | ||
| } | ||
| } | ||
|
|
||
| return validTypes; | ||
| }, [editor, sourceId, targetId]); | ||
| const validRelationTypes = useMemo( | ||
| () => getValidRelationTypesBetween(editor, sourceId, targetId), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This keeps the dropdown's relation filtering behavior the same, but reuses the same valid-relation lookup that the new arrow context menu needs. |
||
| [editor, sourceId, targetId], | ||
| ); | ||
|
|
||
| // Handle click outside | ||
| useEffect(() => { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replaces the old inline drag-handle relation creation block with the same default-create path in a named helper. The drag flow still creates a fresh relation arrow with default geometry and center bindings; conversion does not use this helper because it has to preserve an existing arrow's geometry.