Skip to content

Conversation

@trangdoan982
Copy link
Collaborator

@trangdoan982 trangdoan982 commented May 16, 2025

Context:

  • The DG summoning menu. This PR is the final piece for our v0!!
  • Creates the custom trigger setting to open the node search menu.

Testing:

https://www.loom.com/share/9f23f6b7dab8401c97918f3fd2f5bd8b

Summary by CodeRabbit

  • New Features

    • Added the ability for users to customize the trigger string that opens the Node Search Menu, allowing for multi-character triggers.
    • Introduced a new settings section in personal settings where users can configure the Node Search Menu trigger.
  • Refactor

    • Improved detection logic for the Node Search Menu trigger, supporting dynamic and multi-character triggers instead of a hardcoded "@".
  • Chores

    • Updated event handling to listen for input events instead of keydown events for better trigger detection.

@linear
Copy link

linear bot commented May 16, 2025

@vercel
Copy link

vercel bot commented May 16, 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) May 20, 2025 2:22am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 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

The changes introduce a configurable trigger string for the Node Search Menu, replacing the previously hardcoded "@" trigger. A new component enables users to set this trigger in the settings UI. The event listener logic and menu activation now dynamically use the user-defined trigger string, supporting multi-character triggers and updating relevant event dependencies.

Changes

File(s) Change Summary
apps/roam/src/components/DiscourseNodeSearchMenu.tsx Added a triggerText prop to NodeSearchMenu, replaced hardcoded trigger in regex, updated dependencies, and introduced NodeSearchMenuTriggerSetting for trigger configuration.
apps/roam/src/components/settings/HomePersonalSettings.tsx Added a new section to the settings UI for configuring the Node Search Menu trigger using the new NodeSearchMenuTriggerSetting component.
apps/roam/src/index.ts Changed the event listener for node search trigger from "keydown" to "input" events for more accurate detection.
apps/roam/src/utils/initializeObserversAndListeners.ts Refactored trigger detection logic to use a dynamic, user-configurable trigger string from settings, supporting multi-character triggers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsUI
    participant ExtensionAPI
    participant Listener
    participant NodeSearchMenu

    User->>SettingsUI: Enters new trigger string
    SettingsUI->>ExtensionAPI: Save trigger to settings
    Note over SettingsUI,ExtensionAPI: User refreshes page

    User->>Listener: Types in textarea
    Listener->>ExtensionAPI: Fetch trigger string
    Listener->>Listener: Detect trigger in textarea input
    alt Trigger detected
        Listener->>NodeSearchMenu: Open menu with triggerText
    end
Loading

Possibly related PRs

  • DiscourseGraphs/discourse-graph#138: Initial introduction of the NodeSearchMenu component and its fixed "@" trigger detection, which this PR extends by making the trigger configurable.

Suggested reviewers

  • mdroidian

Poem

A bunny hopped in, code in its paws,
Now triggers can change—oh, what applause!
No longer just "@", pick what you wish,
Type in a string, and grant your own swish.
Settings now sparkle, menus obey,
Custom triggers are here—hip hip hooray!
🐇✨


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 review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (1)
apps/roam/src/components/DiscourseNodeSearchMenu.tsx (1)

529-560: Well-implemented settings component.

The NodeSearchMenuTriggerSetting component:

  1. Correctly manages state and persists changes to extension settings
  2. Properly sanitizes input by escaping special characters and trimming whitespace
  3. Has appropriate validation with maxLength
  4. Uses a sensible default placeholder

One suggestion for improvement:

Consider adding validation feedback when users enter invalid characters or empty strings. You could display a helper text that explains the restrictions and provides immediate feedback.

  return (
    <InputGroup
      value={nodeSearchTrigger}
      onChange={handleNodeSearchTriggerChange}
      placeholder="@"
      maxLength={5}
+     intent={nodeSearchTrigger ? "none" : "warning"}
+     helperText={!nodeSearchTrigger ? "Trigger cannot be empty" : undefined}
    />
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5b410c2 and 9e3dbc1.

📒 Files selected for processing (4)
  • apps/roam/src/components/DiscourseNodeSearchMenu.tsx (6 hunks)
  • apps/roam/src/components/settings/HomePersonalSettings.tsx (2 hunks)
  • apps/roam/src/index.ts (2 hunks)
  • apps/roam/src/utils/initializeObserversAndListeners.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/roam/src/utils/initializeObserversAndListeners.ts (1)
apps/roam/src/components/DiscourseNodeSearchMenu.tsx (1)
  • renderDiscourseNodeSearchMenu (508-527)
apps/roam/src/components/settings/HomePersonalSettings.tsx (1)
apps/roam/src/components/DiscourseNodeSearchMenu.tsx (1)
  • NodeSearchMenuTriggerSetting (529-560)
🔇 Additional comments (9)
apps/roam/src/utils/initializeObserversAndListeners.ts (1)

192-238: Well-implemented dynamic trigger detection logic.

The refactoring improves flexibility by replacing the hardcoded "@" trigger with a configurable setting. The implementation correctly handles:

  1. Checking if the trigger is at a valid position (start of line, after space, or after newline)
  2. Verifying the cursor position is immediately after the trigger
  3. Passing the appropriate positioning information to the search menu component

This approach enables multi-character triggers and improves user customization.

apps/roam/src/index.ts (2)

110-110: Correctly updated event listener type.

Changing from "keydown" to "input" aligns with the modified trigger detection logic that now responds to input changes rather than specific keystrokes.


141-141: Event cleanup properly updated.

The event removal correctly matches the new event type, ensuring proper cleanup on extension unload.

apps/roam/src/components/settings/HomePersonalSettings.tsx (2)

15-15: Import added for new component.

The import is correctly placed with related imports.


32-40: Well-integrated settings UI component.

The new trigger setting is logically placed near the related "Personal Node Menu Trigger" setting with appropriate labeling and description. The UI implementation follows the existing pattern for consistency.

apps/roam/src/components/DiscourseNodeSearchMenu.tsx (4)

15-15: Added required imports.

The additional imports for InputGroup and OnloadArgs support the new functionality.

Also applies to: 23-23


33-33: Props interface and component signature properly updated.

The triggerText prop has been added to both the Props interface and component parameters, maintaining type safety.

Also applies to: 57-57


243-245: Robust regex pattern construction.

The code now dynamically builds the regex pattern from the triggerText, properly escaping special characters to prevent regex syntax errors with custom triggers.


257-257: Updated dependency array in useCallback.

The dependency array correctly includes the new triggerText prop to ensure the callback is regenerated when the trigger changes.

@trangdoan982 trangdoan982 requested a review from mdroidian May 16, 2025 17:16
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.

Good stuff. A couple of quick fixes.

target.classList.contains("rm-block-input")
) {
const textarea = target as HTMLTextAreaElement;
const location = window.roamAlphaAPI.ui.getFocusedBlock();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure this is only called when customTrigger the evt.key. Right now this is being called on every keystroke.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think it needs to check every keystroke because we're trying to match a pattern (the key could be multiple chars, similar to smartblock) instead of listening to just 1 key.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you walk me through the reason we need to call window.roamAlphaAPI.ui.getFocusedBlock() on every keystroke?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh i see what you mean. yes good point. I moved getFocusedBlock() check to the last step right before rendering the search menu to optimize

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.

Couple nits, feel free to edit them now or defer.

@trangdoan982 trangdoan982 merged commit 59926c8 into eng-235-create-dg-summoning-menu May 20, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General May 20, 2025
@trangdoan982 trangdoan982 deleted the eng-299-trigger-key branch May 20, 2025 02:22
mdroidian pushed a commit that referenced this pull request May 27, 2025
* [ENG-259] Create Observer and UI pattern (#138)

* create event listener for @ key

* fix ui

* address PR comments

* cur progress

* current progress

* tested yayyy

* add the checkbox UI

* fix focus issue

* rm logs

* address PR comments

* address PR comments

* [ENG-261] Query function for DG summoning menu (#150)

* cur progress

* current progress

* rm logs

* address PR comments

* address PR comments

* query works

* address PR comments

* address PR comments

* sm change

* [ENG-299] Trigger setting for DG summoning menu (#162)

* setting menu done

* trigger works correctly

* clean up

* address PR comment

* optimize getFocusedBlock()

* address nit comments

* fix bug (#166)

* address PR comments
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