[ENG-1547] Relation creation via drag handle (Obsidian)#909
[ENG-1547] Relation creation via drag handle (Obsidian)#909trangdoan982 wants to merge 10 commits intomainfrom
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
75c8668 to
0ebe9ce
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mdroidian
left a comment
There was a problem hiding this comment.
-
CI is failing.
-
This PR is ~50% over the line change limit. I understand this might be required (or ideal) in this case, that being said, would you mind creating a Loom video walking through this code and code choices?
The biggest concern I have doing a quick review was the code possibly not being as DRY as possible. I worry we might be duplicating work, specifically in the relation/arrow drag handling logic and potential relations checking.
apps/obsidian/src/components/canvas/overlays/RelationTypeDropdown.tsx
Outdated
Show resolved
Hide resolved
apps/obsidian/src/components/canvas/overlays/RelationTypeDropdown.tsx
Outdated
Show resolved
Hide resolved
apps/obsidian/src/components/canvas/overlays/RelationTypeDropdown.tsx
Outdated
Show resolved
Hide resolved
apps/obsidian/src/components/canvas/overlays/RelationTypeDropdown.tsx
Outdated
Show resolved
Hide resolved
apps/obsidian/src/components/canvas/overlays/RelationTypeDropdown.tsx
Outdated
Show resolved
Hide resolved
apps/obsidian/src/components/canvas/overlays/DragHandleOverlay.tsx
Outdated
Show resolved
Hide resolved
|
@mdroidian video explain file structure here: https://youtu.be/BBAKm1G-zXM |
| targetNodeTypeId: string, | ||
| relationTypeId: string, | ||
| ): boolean { | ||
| const plugin = this.options.plugin; | ||
|
|
||
| // Check direct connection (source -> target) | ||
| const directConnection = plugin.settings.discourseRelations.some( | ||
| (relation) => | ||
| relation.relationshipTypeId === relationTypeId && | ||
| relation.sourceId === sourceNodeTypeId && | ||
| relation.destinationId === targetNodeTypeId, | ||
| ); | ||
|
|
||
| if (directConnection) return true; | ||
|
|
||
| // Check reverse connection (target -> source) | ||
| // This handles bidirectional relations where the complement is used | ||
| const reverseConnection = plugin.settings.discourseRelations.some( | ||
| (relation) => | ||
| relation.relationshipTypeId === relationTypeId && | ||
| relation.sourceId === targetNodeTypeId && | ||
| relation.destinationId === sourceNodeTypeId, | ||
| ); | ||
|
|
||
| return reverseConnection; | ||
| return isValidRelationConnection({ | ||
| discourseRelations: this.options.plugin.settings.discourseRelations, | ||
| relationTypeId, | ||
| sourceNodeTypeId, | ||
| targetNodeTypeId, | ||
| }); | ||
| } |
There was a problem hiding this comment.
(Refers to lines 1117-1128)
📝 Info: isValidNodeConnection method is now dead code
The isValidNodeConnection method on DiscourseRelationUtil (DiscourseRelationShape.tsx:1117-1128) was refactored to delegate to the new isValidRelationConnection utility. However, its only call site in onHandleDrag was changed to call isValidRelationConnection directly (DiscourseRelationShape.tsx:349). A search confirms isValidNodeConnection has no remaining callers anywhere in the codebase. It could be removed to reduce confusion.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
(Refers to lines 139-143)
📝 Info: Dead code: unreachable !target branch in DiscourseRelationTool
At line 139, the check if (!target) is unreachable because target was already validated as non-null at line 110 (if (!target || target.type !== 'discourse-node')), which returns early if null. This means this.createArrowShape() on line 140 can never be called from this branch. This is a pre-existing issue (not introduced by this PR), but since the surrounding code was modified by the refactoring, it's worth noting.
Was this helpful? React with 👍 or 👎 to provide feedback.
mdroidian
left a comment
There was a problem hiding this comment.
Nothing blocking approval from me, but this looks like a good candidate for a small DRY follow-up later. DragHandleOverlay seems to reimplement part of the existing relation-arrow flow that already lives in DiscourseRelationTool / DiscourseRelationUtil.onHandleDrag, especially around > arrow creation, end-handle binding updates, and finalization/reification. Not suggesting we hold this PR for it, just flagging it as a worthwhile cleanup > target.
There was a couple interesting Devin comments that might be worth looking at as well.
| ); | ||
|
|
||
| // Auto-dismiss if arrow is deleted | ||
| useEffect(() => { |
There was a problem hiding this comment.
This is worrisome. What case is this handling that cannot be handled directly via a user event? EG: on escape and on clickoutside are already handled.
| ); | ||
|
|
||
| // Handle click outside | ||
| useEffect(() => { |
There was a problem hiding this comment.
Could the click/escape be handled with onBlur on the dropdown itself?
https://www.loom.com/share/ee0d603ff9db4025a1c8f857f2b01aec
Summary
relations.jsonin-place (preservingid,created,author, etc.)updateRelationType()helper torelationsStore.tsTest plan
relations.jsontypefield updated in-place🤖 Generated with Claude Code