Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Aug 24, 2025

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

  • Introduced DiscourseGraphPanel component to manage node and relation tools.
  • Added onEnter cursor behavior for DiscourseGraphTool and relation tools.
  • Updated Tldraw component to include the new DiscourseGraphTool.
  • Enhanced UI with new styles for the Discourse Graph tool button.
  • Refactored UI components to integrate the DiscourseGraphPanel for better tool management.

Summary by CodeRabbit

  • New Features

    • Introduced a Discourse Graph tool with a dedicated toolbar button and localized label.
    • Added a contextual panel to browse and select discourse nodes and relations; reflects current tool and enables quick switching.
    • Simplified toolbar to focus on the Discourse Graph tool.
    • Tools now show a crosshair cursor when activated for clearer placement feedback.
  • Style

    • Added a custom icon for the Discourse Graph tool in the toolbar.
  • Chores

    • Exposed a SharePanel that embeds the new Discourse Graph panel.

- Introduced DiscourseGraphPanel component to manage node and relation tools.
- Added onEnter cursor behavior for DiscourseGraphTool and relation tools.
- Updated Tldraw component to include the new DiscourseGraphTool.
- Enhanced UI with new styles for the Discourse Graph tool button.
- Refactored UI components to integrate the DiscourseGraphPanel for better tool management.
@linear
Copy link

linear bot commented Aug 24, 2025

@supabase
Copy link

supabase bot commented Aug 24, 2025

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

@mdroidian
Copy link
Contributor Author

@CodeRabbit Full Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

📝 Walkthrough

Walkthrough

Introduces a new “discourse-tool” StateNode and integrates it into Tldraw and the toolbar; adds a DiscourseGraphPanel for selecting nodes/relations via a SharePanel; updates tool entry behavior to set crosshair cursors; and adds styling for the new tool’s icon. No exported signatures changed except new panel props/component.

Changes

Cohort / File(s) Summary
Tool cursor behavior updates
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx, apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx
Add onEnter handlers to set editor cursor to cross (NodeUtil uses rotation: 45). Update Idle onEnter to set cross cursor. No other tool logic changes.
New DiscourseGraph tool registration and styling
apps/roam/src/components/canvas/Tldraw.tsx, apps/roam/src/components/canvas/tldrawStyles.ts
Define/register StateNode tool "discourse-tool" with initial state "idle". Add CSS to render an icon for button[data-value="discourse-tool"].
DiscourseGraphPanel component
apps/roam/src/components/canvas/DiscourseToolPanel.tsx
Add DiscourseGraphPanel (default export) and DiscourseGraphPanelProps. Renders contextual node/relation rows; updates editor tool based on selection; deduplicates relations and colors icons.
UI overrides and toolbar integration
apps/roam/src/components/canvas/uiOverrides.tsx
Add SharePanel that renders DiscourseGraphPanel with nodes and combined relations. Expose "discourse-tool" in UI and toolbar (single item). Add translation key tool.discourse-tool. Comment out prior node/relation tool buttons.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant TB as Toolbar
  participant UI as SharePanel / DiscourseGraphPanel
  participant ED as Editor (tldraw)
  participant DT as DiscourseGraphTool
  participant NT as Node/Relation Tools

  U->>TB: Click "Discourse Graph" tool
  TB->>ED: setCurrentTool("discourse-tool")
  ED->>DT: enter()
  note right of DT: Tool state = idle

  U->>UI: Open panel / select Node or Relation
  UI->>ED: setCurrentTool("<node|relation>")
  ED->>NT: enter()
  NT->>ED: setCursor({ type: "cross"[ , rotation: 45 ]})
  note over NT,ED: Cursor switches to crosshair on enter
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ENG-62 - Upgrade Tldraw #235 — Modifies cursor-on-enter for DiscourseNodeTool/ReferencedNodeTool/RelationShapeTool in the same tool classes touched here, indicating overlapping cursor handling changes.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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

🧹 Nitpick comments (14)
apps/roam/src/components/canvas/Tldraw.tsx (1)

321-325: Add basic onEnter cleanup for DiscourseGraphTool

All occurrences of "discourse-tool" across the codebase refer to the same tool ID (no drift detected in tldrawStyles.ts, Tldraw.tsx, uiOverrides.tsx, DiscourseToolPanel.tsx).

Apply this diff in apps/roam/src/components/canvas/Tldraw.tsx:

   const discourseGraphTool = class DiscourseGraphTool extends StateNode {
     static override id = "discourse-tool";
     static override initial = "idle";
+    override onEnter = () => {
+      // Neutral cursor; this is a palette tool, not a drawing tool.
+      this.editor.setCursor({ type: "default" });
+      this.editor.setSelectedShapes([]);
+      this.editor.setEditingShape(null);
+    };
   };
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (1)

106-112: Reset cursor on exit to avoid crosshair persisting after switching tools

Nice touch setting a crosshair with 45° rotation on enter. Add an onExit to return to default when leaving the tool, so the cursor doesn’t persist when switching back to select/discourse-tool.

Add alongside onEnter (outside the shown range):

override onExit = () => {
  this.editor.setCursor({ type: "default" });
};
apps/roam/src/components/canvas/tldrawStyles.ts (1)

69-78: Make the icon theme-aware and better scoped (use mask + currentColor in the toolbar)

Using a background-image hardcodes black and may clash with themes. Prefer mask-image with currentColor so the icon picks up the button color, and scope to the TL toolbar to avoid accidental collisions.

Apply this diff:

-/* Discourse Graph ToolButton */
- button[data-value="discourse-tool"] div::before {
-  content: "";
-  display: inline-block;
-  width: 18px;
-  height: 18px;
-  background-image: url("data:image/svg+xml,%3Csvg width='256' height='264' viewBox='0 0 256 264' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M156.705 252.012C140.72 267.995 114.803 267.995 98.8183 252.012L11.9887 165.182C-3.99622 149.197 -3.99622 123.28 11.9886 107.296L55.4035 63.8807C63.3959 55.8881 76.3541 55.8881 84.3467 63.8807C92.3391 71.8731 92.3391 84.8313 84.3467 92.8239L69.8751 107.296C53.8901 123.28 53.8901 149.197 69.8751 165.182L113.29 208.596C121.282 216.589 134.241 216.589 142.233 208.596C150.225 200.604 150.225 187.646 142.233 179.653L127.761 165.182C111.777 149.197 111.777 123.28 127.761 107.296C143.746 91.3105 143.746 65.3939 127.761 49.4091L113.29 34.9375C105.297 26.9452 105.297 13.9868 113.29 5.99432C121.282 -1.99811 134.241 -1.99811 142.233 5.99434L243.533 107.296C259.519 123.28 259.519 149.197 243.533 165.182L156.705 252.012ZM200.119 121.767C192.127 113.775 179.168 113.775 171.176 121.767C163.184 129.76 163.184 142.718 171.176 150.71C179.168 158.703 192.127 158.703 200.119 150.71C208.112 142.718 208.112 129.76 200.119 121.767Z' fill='%23000000'/%3E%3C/svg%3E");
-  background-size: contain;
-  background-repeat: no-repeat;
-}
+/* Discourse Graph ToolButton (scoped to TL toolbar) */
+.tlui-toolbar button[data-value="discourse-tool"] .tlui-button__icon::before {
+  content: "";
+  display: inline-block;
+  width: 18px;
+  height: 18px;
+  /* theme-aware monochrome via mask + currentColor */
+  -webkit-mask-image: url("data:image/svg+xml,%3Csvg width='256' height='264' viewBox='0 0 256 264' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M156.705 252.012C140.72 267.995 114.803 267.995 98.8183 252.012L11.9887 165.182C-3.99622 149.197 -3.99622 123.28 11.9886 107.296L55.4035 63.8807C63.3959 55.8881 76.3541 55.8881 84.3467 63.8807C92.3391 71.8731 92.3391 84.8313 84.3467 92.8239L69.8751 107.296C53.8901 123.28 53.8901 149.197 69.8751 165.182L113.29 208.596C121.282 216.589 134.241 216.589 142.233 208.596C150.225 200.604 150.225 187.646 142.233 179.653L127.761 165.182C111.777 149.197 111.777 123.28 127.761 107.296C143.746 91.3105 143.746 65.3939 127.761 49.4091L113.29 34.9375C105.297 26.9452 105.297 13.9868 113.29 5.99432C121.282 -1.99811 134.241 -1.99811 142.233 5.99434L243.533 107.296C259.519 123.28 259.519 149.197 243.533 165.182L156.705 252.012ZM200.119 121.767C192.127 113.775 179.168 113.775 171.176 121.767C163.184 129.76 163.184 142.718 171.176 150.71C179.168 158.703 192.127 158.703 200.119 150.71C208.112 142.718 208.112 129.76 200.119 121.767Z' fill='%23000'/%3E%3C/svg%3E");
+  mask-image: url("data:image/svg+xml,%3Csvg width='256' height='264' viewBox='0 0 256 264' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M156.705 252.012C140.72 267.995 114.803 267.995 98.8183 252.012L11.9887 165.182C-3.99622 149.197 -3.99622 123.28 11.9886 107.296L55.4035 63.8807C63.3959 55.8881 76.3541 55.8881 84.3467 63.8807C92.3391 71.8731 92.3391 84.8313 84.3467 92.8239L69.8751 107.296C53.8901 123.28 53.8901 149.197 69.8751 165.182L113.29 208.596C121.282 216.589 134.241 216.589 142.233 208.596C150.225 200.604 150.225 187.646 142.233 179.653L127.761 165.182C111.777 149.197 111.777 123.28 127.761 107.296C143.746 91.3105 143.746 65.3939 127.761 49.4091L113.29 34.9375C105.297 26.9452 105.297 13.9868 113.29 5.99432C121.282 -1.99811 134.241 -1.99811 142.233 5.99434L243.533 107.296C259.519 123.28 259.519 149.197 243.533 165.182L156.705 252.012ZM200.119 121.767C192.127 113.775 179.168 113.775 171.176 121.767C163.184 129.76 163.184 142.718 171.176 150.71C179.168 158.703 192.127 158.703 200.119 150.71C208.112 142.718 208.112 129.76 200.119 121.767Z' fill='%23000'/%3E%3C/svg%3E");
+  -webkit-mask-repeat: no-repeat;
+  mask-repeat: no-repeat;
+  -webkit-mask-size: contain;
+  mask-size: contain;
+  background-color: currentColor;
+}
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx (1)

36-41: Reset cursor on exit for ReferencedNodeTool

Good to set crosshair on enter. Add an onExit to return to default when leaving the tool to avoid the cursor persisting after switching.

Add alongside onEnter (outside the shown range):

override onExit = () => {
  this.editor.setCursor({ type: "default" });
};
apps/roam/src/components/canvas/DiscourseToolPanel.tsx (4)

3-3: Remove unused import

DiscourseRelation is imported but not used. This will trip the linter.

-import { DiscourseRelation } from "~/utils/getDiscourseRelations";

27-28: Memoize uniqueRelations to avoid recomputing on each render

Tiny optimization; prevents recreating a new Set/string array on any unrelated state change.

-  const uniqueRelations = [...new Set(relations)];
+  const uniqueRelations = React.useMemo(
+    () => [...new Set(relations)],
+    [relations],
+  );

If relations are not passed in a stable order, colors derived from getRelationColor(relation, index) may shift across renders. Confirm the prop maintains a stable order. If not, consider a deterministic sort or a persistent mapping keyed by relation id.


40-56: Use semantic buttons for clickable rows (accessibility + keyboard support)

These rows are interactive but use divs. Switch to button with type="button", role, and keyboard semantics for a11y (and to match TL UI styles).

Example diff for the first occurrence; apply the same pattern to the other three ranges:

-          <div
+          <button
             className="tlui-style-panel__row tlui-button tlui-button__icon flex h-5 cursor-pointer items-center gap-2 px-3"
             style={{
               justifyContent: "flex-start",
             }}
             onClick={() => editor.setCurrentTool("discourse-tool")}
-          >
+            type="button"
+            aria-label="Back to Discourse Graph tools"
+          >
             <span
               className="tlui-icon tlui-button__icon mr-2"
               style={{
                 mask: `url("https://cdn.tldraw.com/2.3.0/icons/icon/color.svg") center 100% / 100% no-repeat`,
                 backgroundColor:
                   formatHexColor(currentNodeTool.canvasSettings.color) ||
                   "black",
               }}
             />
             <span>{currentNodeTool.text}</span>
-          </div>
+          </button>

Optionally, consider extracting a small component to remove duplication.

Also applies to: 72-86, 98-116, 126-142


78-84: Prefer theme-driven coloring for icons (mask + currentColor)

For consistency with TL UI, prefer driving icon color via the color (currentColor) rather than mixing backgroundColor + mask. Set className to include tlui-button__icon and pass style={{ color }}; rely on TL’s CSS to color the masked icon.

Example for relations:

-            <div
+            <div
               className="tlui-icon tlui-button__icon mr-2"
               style={{
-                color,
-                mask: `url("https://cdn.tldraw.com/2.3.0/icons/icon/tool-arrow.svg") center 100% / 100% no-repeat`,
+                color, // TL CSS uses currentColor with masked icons
+                mask: `url("https://cdn.tldraw.com/2.3.0/icons/icon/tool-arrow.svg") center 100% / 100% no-repeat`,
               }}
             ></div>

For node color swatches, consider the same approach or keep backgroundColor if you intend the glyph to be filled rather than stroked.

Also applies to: 106-113, 134-139

apps/roam/src/components/canvas/uiOverrides.tsx (6)

228-233: Toolbar wiring for discourse-tool looks good; tiny readability nit

Hook usage is correct and outside loops. For readability, consider extracting the selection hook to a named const.

-          <TldrawUiMenuItem
-            key="discourse-tool"
-            {...tools["discourse-tool"]}
-            isSelected={useIsToolSelected(tools["discourse-tool"])}
-          />
+          <TldrawUiMenuItem
+            key="discourse-tool"
+            {...tools["discourse-tool"]}
+            isSelected={isDiscourseToolSelected}
+          />

And just above the return in this component:

const isDiscourseToolSelected = useIsToolSelected(tools["discourse-tool"]);

234-257: Remove or feature-flag the large commented toolbar block

Leaving a large commented section adds noise and risks drift. Either remove it or guard the old toolbar with a feature flag for easy rollback.

-          {/* {allNodes.map((n) => (
-            <TldrawUiMenuItem
-              key={n.type}
-              {...tools[n.type]}
-              // eslint-disable-next-line react-hooks/rules-of-hooks
-              isSelected={useIsToolSelected(tools[n.type])}
-            />
-          ))}
-          {allRelationNames.map((name) => (
-            <TldrawUiMenuItem
-              key={name}
-              {...tools[name]}
-              // eslint-disable-next-line react-hooks/rules-of-hooks
-              isSelected={useIsToolSelected(tools[name])}
-            />
-          ))}
-          {allAddReferencedNodeActions.map((action) => (
-            <TldrawUiMenuItem
-              key={action}
-              {...tools[action]}
-              // eslint-disable-next-line react-hooks/rules-of-hooks
-              isSelected={useIsToolSelected(tools[action])}
-            />
-          ))} */}

302-308: De-duplicate relations before passing to DiscourseGraphPanel

If any names overlap between relation tools and add-referenced actions, the panel could show duplicates. De-duplicate when composing the list.

-    SharePanel: () => {
-      const allRelations = [
-        ...allRelationNames,
-        ...allAddReferencedNodeActions,
-      ];
-      return <DiscourseGraphPanel nodes={allNodes} relations={allRelations} />;
-    },
+    SharePanel: () => {
+      const allRelations = Array.from(
+        new Set([...allRelationNames, ...allAddReferencedNodeActions])
+      );
+      return <DiscourseGraphPanel nodes={allNodes} relations={allRelations} />;
+    },

459-459: i18n key added — ensure parity across locales if applicable

English entry looks right. If you maintain other locales, mirror this key there to avoid fallback English strings in non-en locales.


47-47: Default export and props verified; consider renaming file

The import of DiscourseGraphPanel from ./DiscourseToolPanel is correct—DiscourseToolPanel.tsx declares

export type DiscourseGraphPanelProps = {
  nodes: DiscourseNode[];
  relations: string[];
};

export default DiscourseGraphPanel;

and the default export matches the imported component.

• Optional refactor: rename
– apps/roam/src/components/canvas/DiscourseToolPanel.tsx → DiscourseGraphPanel.tsx
for clearer discoverability and consistency with the component name.


329-338: Add a “D” shortcut for the discourse tool and include it in the shortcuts dialog

Based on the existing keybindings scan, no tool is currently using “D” as its kbd value, so it’s safe to assign it here.

• In apps/roam/src/components/canvas/uiOverrides.tsx (around line 333), update the discourse-tool registration:

     tools["discourse-tool"] = {
       id: "discourse-tool",
       icon: "none",
       label: "tool.discourse-tool" as TLUiTranslationKey,
-      kbd: "",
+      kbd: "D",
       readonlyOk: true,
       onSelect: () => {
         editor.setCurrentTool("discourse-tool");
       },
     };

• In the same file, within the <KeyboardShortcutsDialog> JSX (near line 266), add the new menu item so it appears in the shortcuts list:

const tools = useTools();

<TldrawUiMenuItem key="discourse-tool" {...tools["discourse-tool"]} />

These optional UX enhancements will give users a quick “D” hotkey to switch to the custom discourse tool and surface it in the built-in keyboard shortcuts dialog for discoverability.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7cb2e08 and 3993076.

📒 Files selected for processing (6)
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (1 hunks)
  • apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx (3 hunks)
  • apps/roam/src/components/canvas/DiscourseToolPanel.tsx (1 hunks)
  • apps/roam/src/components/canvas/Tldraw.tsx (3 hunks)
  • apps/roam/src/components/canvas/tldrawStyles.ts (1 hunks)
  • apps/roam/src/components/canvas/uiOverrides.tsx (6 hunks)
🔇 Additional comments (3)
apps/roam/src/components/canvas/Tldraw.tsx (2)

43-44: LGTM: importing StateNode to enable a custom tool is correct

Import looks right for defining a no-op palette tool (DiscourseGraphTool).


332-336: LGTM: tool registration order is fine

Registering DiscourseGraphTool ahead of shape tools is consistent with showing it as the primary toolbar entry.

apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationTool.tsx (1)

276-278: LGTM: Idle state cursor for referenced-node tools

Idle showing a crosshair matches drawing semantics and is consistent with node tools.

@mdroidian mdroidian merged commit 0673532 into main Aug 24, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 24, 2025
@mdroidian mdroidian deleted the eng-772-add-new-discourse-tool branch August 26, 2025 06:45
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.

2 participants