Skip to content

Conversation

@trangdoan982
Copy link
Collaborator

@trangdoan982 trangdoan982 commented Jun 6, 2025

https://www.loom.com/share/912e32efc0ba4fceacfe322cbac9bce5

Summary by CodeRabbit

  • New Features

    • Introduced a modal for creating nodes without requiring a text selection.
    • Added a new command to create nodes directly from the command palette.
  • Improvements

    • Enhanced the node creation workflow, allowing users to select node type and enter a title in a user-friendly modal.
    • Streamlined command behavior to support node creation both with and without selected text.
  • Bug Fixes

    • Improved input validation and error handling during node creation.

@linear
Copy link

linear bot commented Jun 6, 2025

@vercel
Copy link

vercel bot commented Jun 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
discourse-graph ⬜️ Skipped (Inspect) Jun 10, 2025 10:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

A new modal component for node creation was introduced, enabling users to create nodes even without text selection. The command logic was updated to support this new modal, and a new command was added for direct node creation. Utility functions for node creation were refactored for improved separation of concerns.

Changes

File(s) Change Summary
apps/obsidian/src/components/CreateNodeModal.tsx Added new CreateNodeModal component for creating nodes via a modal UI.
apps/obsidian/src/components/NodeTypeModal.tsx,
apps/obsidian/src/index.ts
Updated import paths for processTextToDiscourseNode to reflect refactored utility location.
apps/obsidian/src/utils/createNode.ts Refactored node creation utilities: renamed and split functions, improved parameter handling, and decoupled text extraction logic.
apps/obsidian/src/utils/registerCommands.ts Modified command to open different modals based on selection; added new command for direct node creation; removed unused imports.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ObsidianApp
    participant CreateNodeModal
    participant NodeTypeModal
    participant createDiscourseNode

    User->>ObsidianApp: Triggers "open-node-type-menu" command
    ObsidianApp->>ObsidianApp: Checks if editor has selection
    alt Selection exists
        ObsidianApp->>NodeTypeModal: Open NodeTypeModal
    else No selection
        ObsidianApp->>CreateNodeModal: Open CreateNodeModal
        CreateNodeModal->>User: User enters title and selects type
        User->>CreateNodeModal: Confirms creation
        CreateNodeModal->>createDiscourseNode: Create node with title and type
    end

    User->>ObsidianApp: Triggers "create-discourse-node" command
    ObsidianApp->>CreateNodeModal: Open CreateNodeModal
    CreateNodeModal->>User: User enters title and selects type
    User->>CreateNodeModal: Confirms creation
    CreateNodeModal->>createDiscourseNode: Create node with title and type
Loading

Suggested reviewers

  • mdroidian

Poem

In the garden of nodes, a new modal appears,
Letting bunnies create, with hops and with cheers!
Whether text is selected, or the editor’s bare,
A node can be crafted with whimsical flair.
With dropdowns and titles, the workflow’s refined—
More carrots for thought, and less left behind!
🥕✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@trangdoan982
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

✅ Actions performed

Full review triggered.

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: 0

🧹 Nitpick comments (2)
apps/obsidian/src/components/CreateNodeModal.tsx (1)

45-50: Consider adding Escape key support for better UX.

The Enter key handling is well implemented. Consider adding Escape key support to cancel the modal.

 this.titleInput.addEventListener("keydown", (e) => {
   if (e.key === "Enter" && !e.shiftKey) {
     e.preventDefault();
     this.handleConfirm();
+  } else if (e.key === "Escape") {
+    e.preventDefault();
+    this.close();
   }
 });
apps/obsidian/src/utils/registerCommands.ts (1)

21-28: Consider extracting the common callback logic.

The async callback is duplicated between both commands. Consider extracting it to a shared function for better maintainability.

+const createNodeCallback = (plugin: DiscourseGraphPlugin, editor: Editor) => 
+  async (nodeType: DiscourseNode, title: string) => {
+    await createDiscourseNode({
+      plugin,
+      nodeType,
+      text: title,
+      editor,
+    });
+  };

 // Then use it in both commands:
-onNodeCreate: async (nodeType, title) => {
-  await createDiscourseNode({
-    plugin,
-    nodeType,
-    text: title,
-    editor,
-  });
-},
+onNodeCreate: createNodeCallback(plugin, editor),

Also applies to: 41-48

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96db452 and a2378fb.

📒 Files selected for processing (5)
  • apps/obsidian/src/components/CreateNodeModal.tsx (1 hunks)
  • apps/obsidian/src/components/NodeTypeModal.tsx (1 hunks)
  • apps/obsidian/src/index.ts (1 hunks)
  • apps/obsidian/src/utils/createNode.ts (3 hunks)
  • apps/obsidian/src/utils/registerCommands.ts (1 hunks)
🔇 Additional comments (9)
apps/obsidian/src/components/NodeTypeModal.tsx (1)

3-3:

✅ Verification successful

LGTM! Verify the import path is correct.

The import path update aligns with the refactoring to separate text extraction from node creation logic.


🏁 Script executed:

#!/bin/bash
# Verify that the processTextToDiscourseNode function exists in the new location
ast-grep --pattern 'export function processTextToDiscourseNode($_) { $$$ }'

Length of output: 77


🏁 Script executed:

#!/bin/bash
# Search for the definition or export of processTextToDiscourseNode across the repository
rg -n 'processTextToDiscourseNode' -g '*.ts' -g '*.tsx' .

Length of output: 540


Confirmed: processTextToDiscourseNode export is present in utils/createNode.ts

I’ve verified that processTextToDiscourseNode is defined and exported in apps/obsidian/src/utils/createNode.ts (line 143), so the new import path is correct.

LGTM!

apps/obsidian/src/index.ts (1)

7-7: LGTM! Import path updated correctly.

Consistent with the refactoring pattern seen in other files.

apps/obsidian/src/components/CreateNodeModal.tsx (2)

113-134: Excellent error handling and validation.

The async error handling is comprehensive, including proper type checking and user feedback through notices.


101-101: Good practice using setTimeout for focus.

The setTimeout ensures the DOM is ready before focusing, which is a solid approach for modal components.

apps/obsidian/src/utils/registerCommands.ts (2)

13-32: Well-structured conditional logic for modal selection.

The command correctly handles both scenarios - opening NodeTypeModal for text selection and CreateNodeModal for direct creation.


5-5:

✅ Verification successful

Verify the createDiscourseNode function signature.

Ensure the new createDiscourseNode function accepts the parameters being passed and handles the editor parameter correctly when no text is selected.


🏁 Script executed:

#!/bin/bash
# Verify the createDiscourseNode function signature and implementation
ast-grep --pattern 'export function createDiscourseNode($params) { $$$ }'

Length of output: 75


Locating and inspecting the createNode implementation to verify the createDiscourseNode signature:


🏁 Script executed:

#!/bin/bash
# Find and display the start of the createNode source file
file=$(fd createNode.ts -t f | head -n1)
if [ -z "$file" ]; then
  echo "No createNode.ts file found"
  exit 1
fi
echo "Found file: $file"
sed -n '1,200p' "$file"

Length of output: 4311


Inspecting registerCommands.ts usage of createDiscourseNode:


🏁 Script executed:

#!/bin/bash
# Locate and display the top of registerCommands.ts to verify how createDiscourseNode is invoked
file=$(fd registerCommands.ts -t f | head -n1)
if [ -z "$file" ]; then
  echo "registerCommands.ts not found"
  exit 1
fi
echo "Found file: $file"
sed -n '1,200p' "$file"

Length of output: 2327


createDiscourseNode signature matches its usage
The function is defined as

export const createDiscourseNode = async ({
  plugin,
  nodeType,
  text,
  editor,
}: {
  plugin: DiscourseGraphPlugin;
  nodeType: DiscourseNode;
  text: string;
  editor?: Editor;
}) => 

and in registerCommands.ts it’s invoked with exactly those properties. The optional editor parameter is handled correctly (replaceSelection only runs when editor is passed). No changes required.

apps/obsidian/src/utils/createNode.ts (3)

9-12: LGTM! Good improvement to text normalization.

The parameter rename from selectedText to text is more generic and appropriate. The text normalization logic correctly handles multiline input by replacing newlines with spaces and trimming whitespace, which is essential for creating valid node names.


110-141: Excellent refactoring to separate concerns.

The function refactoring successfully separates text extraction from node creation logic:

  • Takes text directly instead of extracting from editor
  • Makes editor optional to support non-editor contexts (like modals)
  • Conditionally replaces selection only when both file creation succeeds and editor is provided

This design enables flexible node creation workflows while maintaining existing functionality.


143-160: Smart wrapper function maintains backward compatibility.

The new processTextToDiscourseNode function preserves the original API by extracting selected text from the editor and delegating to createDiscourseNode. This ensures existing code continues to work while enabling the new modal-based creation workflow.

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Nice. 🚀

Couple of small suggestions, then feel free to merge.

@trangdoan982 trangdoan982 force-pushed the eng-409-choose-folder branch from 343ec81 to 884e55b Compare June 10, 2025 21:37
Base automatically changed from eng-409-choose-folder to main June 10, 2025 22:09
@trangdoan982 trangdoan982 force-pushed the eng-410-node-dialog branch from c87ec4a to e5ffe26 Compare June 10, 2025 22:43
@trangdoan982 trangdoan982 merged commit 27049c6 into main Jun 10, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jun 10, 2025
@trangdoan982 trangdoan982 deleted the eng-410-node-dialog branch June 10, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants