Skip to content

ENG-1477: Convert a tldraw arrow to a DG relation#1082

Open
sid597 wants to merge 5 commits into
mainfrom
eng-1477-implement-ability-to-convert-a-tldraw-arrow-to-a-dg-relation
Open

ENG-1477: Convert a tldraw arrow to a DG relation#1082
sid597 wants to merge 5 commits into
mainfrom
eng-1477-implement-ability-to-convert-a-tldraw-arrow-to-a-dg-relation

Conversation

@sid597

@sid597 sid597 commented May 25, 2026

Copy link
Copy Markdown
Collaborator

https://www.loom.com/share/2f7d93f683d74868b0a0193c1d1e7dac

This PR adds arrow-to-relation conversion without changing the existing relation storage decision. Both default relation creation and arrow conversion delegate persistence to the existing canvas relation util, which already chooses stored/reified relations vs legacy triples based on getStoredRelationsEnabled().

The split here is deliberate:

  • shared helpers for same-question logic: valid relation lookup, directional label, persistence plumbing
  • separate lifecycle functions for different behavior: fresh drag-handle relation creation vs converting an existing arrow

That keeps the old drag-handle behavior default-centered while allowing conversion to preserve the user’s existing arrow geometry and only delete the original arrow after persistence succeeds.

Right-click a plain tldraw arrow connecting two discourse-graph nodes to
get a "Relation" submenu listing the relation types valid between those
node types. Selecting one creates the discourse relation (persisted to
Roam) and replaces the plain arrow with the relation arrow.

Extract the relation-creation logic shared with the node drag-handle flow
into overlays/relationCreation.ts (createRelationBetweenNodes,
getValidRelationTypesBetween); DragHandleOverlay and RelationTypeDropdown
now delegate to it.
@linear-code

linear-code Bot commented May 25, 2026

Copy link
Copy Markdown

ENG-1477

@supabase

supabase Bot commented May 25, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08c8fb265e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/roam/src/components/canvas/uiOverrides.tsx Outdated
sid597 added 3 commits May 25, 2026 15:21
Converting a plain arrow deleted the original immediately after the new
relation shape was created, but persistence runs asynchronously and
deletes the new arrow on failure (e.g. canvas page UID lookup fails),
which could leave neither arrow.

Await handleCreateRelationsInRoam and treat the new arrow surviving as
success; the convert action now removes the original only when the
relation persisted. The drag-handle caller voids the now-async helper
(no original arrow to lose, behavior unchanged).
Drop the `sourceNode?.type ?? ""` lie that quietly proceeded past a
deleted source/target shape and let the binding step fail silently,
losing the original arrow with no toast. Return null early instead.

Also drop the `?? newArrow` fallback when re-reading the shape before
persistence; the read happens synchronously after createShape +
bindings, so there is no scenario where it returns undefined that we
should paper over.
@graphite-app

graphite-app Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

PR size/scope check

This PR is over our review-size guideline.

  • Recommended: ~200 lines changed
  • Acceptable limit: up to 400 lines when well-scoped/self-contained
  • Preferred file count: fewer than 5 files

Please split this into smaller PRs unless there is a clear reason the changes need to land together.

If keeping it as one PR, please add a brief justification covering:

  • What single problem this PR solves
  • Why the files/changes are coupled

…conversion

Pull the directional-label rule and the Roam-persistence call into shared
getDirectionalRelationLabel and persistRelationArrow helpers, used by both
the drag-handle creator and the conversion path (the label rule previously
lived in three places).

Convert now sets the relation's visual contract explicitly instead of
spreading the original arrow's props: it inherits only geometry (bend,
start, end, labelPosition) and forces color, label, arrowheads, dash, size,
font, scale, fill. Arrowheads encode relation direction, so a converted
double- or reverse-headed arrow would otherwise render a misdirected
relation; explicit props also stop future tldraw arrow props from leaking
into converted relations.
normalizedAnchor: { x: 0.5, y: 0.5 },
isPrecise: false,
isExact: false,
void createDefaultRelationBetweenNodes({

Copy link
Copy Markdown
Collaborator Author

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.

return validTypes;
};

export const createDefaultRelationBetweenNodes = async ({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally the default/fresh relation creation path. It keeps the drag-handle behavior centered and default-styled; existing-arrow conversion lives separately because that flow has a different lifecycle and rollback contract.

"label" | "complement" | "source" | "destination"
>;

export const getDirectionalRelationLabel = ({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directional label/complement rule is shared because it is the same question in the dropdown, default creation, and arrow conversion paths. This keeps label selection single-source without merging the different shape-creation lifecycles.

normalizedAnchor: { ...binding.props.normalizedAnchor },
});

const convertArrowToRelation = async ({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversion is intentionally separate from default relation creation. Here we transform an existing user-drawn arrow, so we preserve layout/bindings and only delete the original after relation persistence succeeds.

opacity: arrow.opacity,
isLocked: arrow.isLocked,
meta: { ...arrow.meta },
props: {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only geometry is inherited from the plain arrow (bend, terminals, label position). The DG relation visual contract is forced here so converted relations show the same direction/style as relations created through the drag-handle flow.

return validTypes;
}, [editor, sourceId, targetId]);
const validRelationTypes = useMemo(
() => getValidRelationTypesBetween(editor, sourceId, targetId),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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.

@sid597 sid597 requested a review from mdroidian June 16, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant