Skip to content

Conversation

@trangdoan982
Copy link
Collaborator

@trangdoan982 trangdoan982 commented Jan 25, 2026

https://www.loom.com/share/e89289108cd14d529e1fc81573dceae2

Adds auto-linking for Evidence and Source nodes to automatically create relationships when nodes are created from a contextual page.

This PR enhances the ModifyNodeModal to detect the current file's node type and the type of node being created, then suggests relevant relationships. Upon creation, the selected relationship is automatically added to the frontmatter of both linked nodes, streamlining the workflow for users creating related content.


Linear Issue: ENG-1332

Open in Cursor Open in Web


Open with Devin

Summary by CodeRabbit

  • New Features
    • Introduced "Source" node type for organizing reference materials
    • Added "derivedFrom" relationship type to connect Evidence nodes to sources
    • Enabled relationship selection during node creation with a new dropdown interface
    • Integrated relationship creation across node creation workflows

✏️ Tip: You can customize this high-level summary in your review settings.

@cursor
Copy link

cursor bot commented Jan 25, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@linear
Copy link

linear bot commented Jan 25, 2026

@supabase
Copy link

supabase bot commented Jan 25, 2026

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 ↗︎.

@trangdoan982 trangdoan982 changed the title Automatic node relationships [ENG-1332] Automatic node relationships Jan 25, 2026
@trangdoan982 trangdoan982 marked this pull request as ready for review January 25, 2026 22:05
@trangdoan982
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

✅ Actions performed

Full review triggered.

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View issues and 4 additional flags in Devin Review.

Open in Devin Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

The changes introduce relationship-aware node creation by adding currentFile context and relationship metadata (relationshipTypeId, relationshipTargetFile) throughout the modal, form, and node creation flows. New UI allows users to select relationships when creating nodes. Submission payloads are extended to carry relationship fields, and addRelationToFrontmatter is invoked when relationships are specified. Constants define a new Source node type and derivedFrom relation type.

Changes

Cohort / File(s) Summary
Modal and Form Components
apps/obsidian/src/components/ModifyNodeModal.tsx
Added currentFile context prop and relationship-aware creation flow; derived availableRelationships from node type combinations; added UI select for relationship selection in create mode; extended onSubmit payload to include relationshipTypeId and relationshipTargetFile; header text updated in create mode; minor refactoring of props passed to form.
Node Creation Utilities
apps/obsidian/src/components/canvas/utils/nodeCreationFlow.ts, apps/obsidian/src/utils/registerCommands.ts, apps/obsidian/src/utils/tagNodeHandler.ts
Integrated addRelationToFrontmatter invocation when relationship fields are provided; propagated currentFile (canvasFile or active file) and relationship metadata through modal submission and node creation flows; extended NodeCreationParams and onSubmit signatures to accept relationshipTypeId and relationshipTargetFile.
Node Creation Conversion Utility
apps/obsidian/src/components/canvas/utils/convertToDiscourseNode.ts
Reformatted onSubmit callback parameter destructuring across multiple lines and renamed nodeType to selectedNodeType for consistency.
Constants and Type Definitions
apps/obsidian/src/constants.ts
Added new Source node type entry to DEFAULT_NODE_TYPES; added new derivedFrom relation type to DEFAULT_RELATION_TYPES; added Evidence-to-Source discourse relation to DEFAULT_SETTINGS.discourseRelations.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as ModifyNodeModal
    participant Form as ModifyNodeForm
    participant Flow as nodeCreationFlow
    participant FM as addRelationToFrontmatter

    User->>Modal: Opens modal (passes currentFile)
    Modal->>Form: Passes currentFile, mode=create
    Form->>Form: Derives availableRelationships from currentFile & selectedNodeType
    User->>Form: Selects node type and relationship
    Form->>Form: Updates selectedRelationshipTypeId state
    User->>Form: Submits form
    Form->>Modal: handleConfirm() with relationshipTypeId, relationshipTargetFile
    Modal->>Flow: onSubmit() with all params including relationship fields
    Flow->>Flow: Creates node via standard flow
    alt relationshipTypeId provided
        Flow->>FM: addRelationToFrontmatter(newFile, targetFile, relationshipTypeId)
        FM->>FM: Updates frontmatter with relationship
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title '[ENG-1332] Automatic node relationships' accurately summarizes the main change: adding automatic relationship linking between Evidence and Source nodes during creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/obsidian/src/components/ModifyNodeModal.tsx`:
- Around line 321-323: In ModifyNodeModal (use the isEditMode boolean that
controls the header), fix the create-mode header string by replacing "Create
discourse nodeeeee" with the correct text "Create discourse node" so the <h2>
shows "Modify discourse node" when isEditMode is true and "Create discourse
node" when false.
🧹 Nitpick comments (2)
apps/obsidian/src/utils/registerCommands.ts (1)

24-58: Consider extracting duplicated relationship handling logic.

The relationship handling logic (getting currentFile, passing it to modal, and calling addRelationToFrontmatter) is duplicated between both commands. Consider extracting a helper function.

♻️ Suggested refactor
// Helper function to create the modal with relationship support
const createNodeWithRelationship = async ({
  plugin,
  editor,
  newFile,
  relationshipTypeId,
  relationshipTargetFile,
}: {
  plugin: DiscourseGraphPlugin;
  editor: Editor;
  newFile: TFile | null;
  relationshipTypeId?: string;
  relationshipTargetFile?: TFile;
}) => {
  if (newFile && relationshipTypeId && relationshipTargetFile) {
    await addRelationToFrontmatter({
      app: plugin.app,
      plugin,
      sourceFile: newFile,
      targetFile: relationshipTargetFile,
      relationTypeId: relationshipTypeId,
    });
  }
};

This helper could be used in both command callbacks to reduce duplication.

apps/obsidian/src/components/ModifyNodeModal.tsx (1)

190-195: Consider resetting selectedRelationshipTypeId when availableRelationships changes.

The current logic only sets the initial value when selectedRelationshipTypeId is empty. If the user changes the node type and availableRelationships changes to a different set, the previously selected relationship may no longer be valid.

♻️ Suggested improvement
  useEffect(() => {
-   if (!selectedRelationshipTypeId && availableRelationships[0]) {
+   // Reset selection when available relationships change
+   const isCurrentSelectionValid = availableRelationships.some(
+     (rel) => rel.relationTypeId === selectedRelationshipTypeId
+   );
+   if (!isCurrentSelectionValid && availableRelationships[0]) {
      setSelectedRelationshipTypeId(availableRelationships[0].relationTypeId);
+   } else if (!isCurrentSelectionValid) {
+     setSelectedRelationshipTypeId("");
    }
-   // eslint-disable-next-line react-hooks/exhaustive-deps -- only run when availableRelationships changes
-  }, [availableRelationships]);
+  }, [availableRelationships, selectedRelationshipTypeId]);

cursoragent and others added 6 commits February 9, 2026 22:13
Co-authored-by: doantranghp2000 <doantranghp2000@gmail.com>
- Add relationship dropdown to ModifyNodeModal
- Auto-detect current page context when creating nodes
- Auto-suggest relationships based on node types
- Create bidirectional relationships in frontmatter
- Support relationships in tag handler and canvas node creation

Co-authored-by: doantranghp2000 <doantranghp2000@gmail.com>
Co-authored-by: doantranghp2000 <doantranghp2000@gmail.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@trangdoan982 trangdoan982 force-pushed the cursor/ENG-1332-automatic-node-relationships-efe0 branch from 3077985 to 964865e Compare February 10, 2026 03:13
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

View 8 additional findings in Devin Review.

Open in Devin Review

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

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.

2 participants