-
Notifications
You must be signed in to change notification settings - Fork 4
[ENG-641] Allow reverse relation creation #623
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
base: main
Are you sure you want to change the base?
[ENG-641] Allow reverse relation creation #623
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe changes enhance discourse relation binding validation to support bidirectional connections. A new directional validation system is introduced via Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx (1)
814-819: Consider returning early after deleting the shape.After
deleteShapes([shape.id])is called on line 817, the shape no longer exists. Returningupdateon line 818 is redundant and could potentially cause issues if the editor tries to apply the update to a deleted shape.🔎 Suggested improvement:
dispatchToastEvent({ id: `tldraw-invalid-connection-${shape.id}`, title: "Invalid Connection", description: errorMessage, severity: "error", }); removeArrowBinding(this.editor, shape, handleId); - update.props![handleId] = { x: handle.x, y: handle.y }; this.editor.deleteShapes([shape.id]); - return update; + return; }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx(1 hunks)apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx(6 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/main.mdc)
**/*.{ts,tsx}: Use Tailwind CSS for styling where possible
When refactoring inline styles, use tailwind classes
Prefertypeoverinterfacein TypeScript
Use explicit return types for functions
Avoidanytypes when possible
Prefer arrow functions over regular function declarations
Use named parameters (object destructuring) when a function has more than 2 parameters
Use PascalCase for components and types
Use camelCase for variables and functions
Use UPPERCASE for constants
Function names should describe their purpose clearly
Prefer early returns over nested conditionals for better readability
Files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
apps/roam/**/*.{js,ts,tsx,jsx,json}
📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)
Prefer existing dependencies from package.json when working on the Roam Research extension
Files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
apps/roam/**/*.{ts,tsx,jsx,js,css,scss}
📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)
Use BlueprintJS 3 components and Tailwind CSS for platform-native UI in the Roam Research extension
Files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
apps/roam/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)
apps/roam/**/*.{ts,tsx,js,jsx}: Use the roamAlphaApi docs from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj when implementing Roam functionality
Use Roam Depot/Extension API docs from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU when implementing extension functionality
Files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
apps/roam/**
📄 CodeRabbit inference engine (.cursor/rules/roam.mdc)
Implement the Discourse Graph protocol in the Roam Research extension
Files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
🧠 Learnings (2)
📚 Learning: 2025-06-17T23:42:29.279Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 220
File: apps/roam/src/utils/conceptConversion.ts:95-104
Timestamp: 2025-06-17T23:42:29.279Z
Learning: In the DiscourseGraphs/discourse-graph codebase, DiscourseRelation type properties are either string or Triple[], and the STANDARD_ROLES filter in conceptConversion.ts excludes Triple[] properties, so only string values remain after filtering.
Applied to files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsxapps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx
📚 Learning: 2025-07-13T16:47:14.352Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.
Applied to files:
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx
🧬 Code graph analysis (2)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx (1)
apps/roam/src/components/canvas/Tldraw.tsx (1)
discourseContext(112-117)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx (3)
apps/roam/src/components/canvas/Tldraw.tsx (1)
discourseContext(112-117)apps/roam/src/components/canvas/ToastListener.tsx (1)
dispatchToastEvent(4-8)apps/roam/src/components/canvas/DiscourseRelationShape/helpers.tsx (1)
removeArrowBinding(1629-1639)
🔇 Additional comments (6)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx (1)
365-380: LGTM! Bidirectional starting node validation looks correct.The logic properly extends valid starting nodes to include both source and destination types, enabling reverse relation creation. The
flatMapwithfilter(Boolean)safely handles potentially undefined node texts, and deduplication viaSetensures clean user messaging.apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx (5)
1552-1584: LGTM! Clean helper methods for connection validation.The
checkConnectionTypeandisValidNodeConnectionmethods provide a clear and reusable API for directional validation. The logic correctly identifies both direct and reverse connections.
899-928: LGTM! Dynamic text update based on direction.The logic correctly updates the arrow label to use
relation.complementfor reverse connections andrelation.labelfor direct connections. The check on line 922 prevents unnecessary updates when text hasn't changed.
569-572: Good practice refreshing the shape reference after mutation.Correctly re-fetches the arrow shape after
updateShapesto ensure subsequent operations use the updated state.
550-567: LGTM! Comprehensive error messaging for invalid connections.The logic correctly aggregates valid target types from both forward and reverse relation directions, providing clear feedback to users about which node types are acceptable.
592-594: Verify if symmetric relation handling is intentional and documented.When a relation type is symmetric (source and destination are the same node type), both
isDirectandisReversewill betrue, causingisOriginalto befalse. The code treats this case as a reverse relation by defaulting torelation.labelinstead ofrelation.complement. This behavior should be explicitly documented or tested to clarify whether it's the intended semantics for symmetric discourse relations.
Summary by CodeRabbit
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.