Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Dec 1, 2025

Before
image

After
image

Summary by CodeRabbit

  • Bug Fixes

    • Relations are no longer draggable; only nodes can be dragged.
    • Dropped items now center correctly on the canvas.
  • Improvements

    • Drag previews now scale intelligently with zoom level for improved visibility.
    • Enhanced color consistency in drag-and-drop UI elements.

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

…or logic with getDiscourseNodeColors utility function for improved maintainability and clarity.
…oved color handling, adjust drag behavior for relations, and refine drag preview styling based on zoom level.
…dependent offsets, adjust padding in drag preview, and enhance color retrieval logic in getDiscourseNodeColors for improved palette handling.
@linear
Copy link

linear bot commented Dec 1, 2025

… are only clickable, preventing pointermove listener from being added for relation items.
@mdroidian mdroidian closed this Dec 1, 2025
@mdroidian mdroidian deleted the eng-1107-update-drag-and-drop-image-for-nodes-in-discourse-toolbar branch December 1, 2025 20:08
@mdroidian mdroidian restored the eng-1107-update-drag-and-drop-image-for-nodes-in-discourse-toolbar branch December 1, 2025 20:08
@mdroidian mdroidian reopened this Dec 1, 2025
@supabase
Copy link

supabase bot commented Dec 1, 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 mdroidian changed the title ENG-1107 make tool-lock work for discourse-tool in roam ENG-1107 Update drag and drop image for nodes in discourse toolbar Dec 1, 2025
@mdroidian
Copy link
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

📝 Walkthrough

Walkthrough

This PR refactors discourse node color computation by extracting it into a dedicated utility function, exports sizing and dimension constants for reuse, and enhances the drag-and-drop panel with color properties, zoom-aware preview rendering, and relation-specific handling.

Changes

Cohort / File(s) Summary
Color Utility Extraction
apps/roam/src/utils/getDiscourseNodeColors.ts
New utility function that centralizes color computation for discourse nodes by accepting nodeType and discourseNodes, computing backgroundColor and textColor via palette selection and getPleasingColors.
DiscourseNodeUtil Refactoring
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
Delegates color computation to getDiscourseNodeColors utility; removes inline colord/palette logic; exports FONT_SIZES constant for public consumption.
Tldraw Constants Export
apps/roam/src/components/canvas/Tldraw.tsx
Exports DEFAULT_WIDTH and DEFAULT_HEIGHT constants for reuse by other modules.
DiscourseToolPanel Enhancements
apps/roam/src/components/canvas/DiscourseToolPanel.tsx
Adds backgroundColor and textColor properties to drag state items; implements zoom-aware drag preview sizing; prevents relations from being draggable; applies coordinate offsetting on drop; updates panel item rendering with computed colors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • DiscourseToolPanel.tsx contains significant changes across drag state structure, preview rendering logic, and conditional handling for relations vs nodes—review the guard conditions for relation exclusion and zoom calculation correctness.
  • Verify getDiscourseNodeColors correctly computes palette indices and fallback color logic.
  • Ensure drag preview zoom scaling and coordinate offsetting align with editor expectations.

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main objective of updating drag and drop visuals for nodes in the discourse toolbar, which is reflected in DiscourseToolPanel.tsx changes including zoom-aware drag preview styling and color properties.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

🧹 Nitpick comments (3)
apps/roam/src/utils/getDiscourseNodeColors.ts (1)

21-22: Remove redundant nullish coalescing operator.

Array.findIndex() returns -1 when no match is found, never null or undefined. The ?? -1 fallback is unreachable.

-  const discourseNodeIndex =
-    discourseNodes.findIndex((node) => node.type === nodeType) ?? -1;
+  const discourseNodeIndex = discourseNodes.findIndex(
+    (node) => node.type === nodeType,
+  );
apps/roam/src/components/canvas/DiscourseToolPanel.tsx (2)

82-111: Minor inconsistency: relation colors use tldraw color names, not hex values.

For nodes, getDiscourseNodeColors returns hex colors (e.g., #4263eb), but for relations, getRelationColor returns tldraw color style names (e.g., "green", "red"). While this doesn't cause issues currently since relations aren't draggable and their preview is hidden, the asymmetry could cause confusion if relation dragging is enabled in the future.

Consider documenting this distinction or converting relation colors to hex for consistency.


261-264: Minor: zoomLevel is computed twice.

zoomLevel is derived at line 261-264 via useValue, then re-computed at line 295 inside useQuickReactor. The reactor recomputation is necessary for reactivity within that callback, but the outer zoomLevel (lines 261-264) is only used at line 432 for font sizing.

This is functionally correct but could be consolidated if the reactor's logic were restructured. Low priority.

Also applies to: 294-295

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83a18be and 9fa66a1.

📒 Files selected for processing (4)
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (3 hunks)
  • apps/roam/src/components/canvas/DiscourseToolPanel.tsx (10 hunks)
  • apps/roam/src/components/canvas/Tldraw.tsx (1 hunks)
  • apps/roam/src/utils/getDiscourseNodeColors.ts (1 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
Prefer type over interface in TypeScript
Use explicit return types for functions
Avoid any types 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/Tldraw.tsx
  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
  • apps/roam/src/components/canvas/DiscourseToolPanel.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/Tldraw.tsx
  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
  • apps/roam/src/components/canvas/DiscourseToolPanel.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/Tldraw.tsx
  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
  • apps/roam/src/components/canvas/DiscourseToolPanel.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/Tldraw.tsx
  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
  • apps/roam/src/components/canvas/DiscourseToolPanel.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/Tldraw.tsx
  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
  • apps/roam/src/components/canvas/DiscourseToolPanel.tsx
🧠 Learnings (5)
📚 Learning: 2025-06-17T23:37:45.289Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `type` serves as the unique identifier field, not a type classification field. The interface has no `uid` or `id` field, making `node.type` the correct field to use for UID-related operations.

Applied to files:

  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
📚 Learning: 2025-06-17T23:37:45.289Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `node.type` serves as the UID field rather than having a conventional `node.uid` field. This is an unusual naming convention where the type field actually contains the unique identifier.

Applied to files:

  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
📚 Learning: 2025-06-22T10:40:52.752Z
Learnt from: sid597
Repo: DiscourseGraphs/discourse-graph PR: 232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.

Applied to files:

  • apps/roam/src/utils/getDiscourseNodeColors.ts
  • apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
📚 Learning: 2025-06-22T10:40:21.679Z
Learnt from: sid597
Repo: DiscourseGraphs/discourse-graph PR: 232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:15-16
Timestamp: 2025-06-22T10:40:21.679Z
Learning: In the getAllDiscourseNodesSince function in apps/roam/src/utils/getAllDiscourseNodesSince.ts, date validation is performed before the function is called, so additional date validation within the function is not needed.

Applied to files:

  • apps/roam/src/utils/getDiscourseNodeColors.ts
📚 Learning: 2025-07-08T14:51:55.299Z
Learnt from: maparent
Repo: DiscourseGraphs/discourse-graph PR: 0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual `process.env` keys to avoid unnecessary coupling.

Applied to files:

  • apps/roam/src/components/canvas/DiscourseToolPanel.tsx
🧬 Code graph analysis (3)
apps/roam/src/utils/getDiscourseNodeColors.ts (2)
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (2)
  • COLOR_ARRAY (78-78)
  • COLOR_PALETTE (81-95)
packages/utils/src/getPleasingColors.ts (1)
  • getPleasingColors (118-188)
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (1)
apps/roam/src/utils/getDiscourseNodeColors.ts (1)
  • getDiscourseNodeColors (14-41)
apps/roam/src/components/canvas/DiscourseToolPanel.tsx (5)
apps/roam/src/utils/getDiscourseNodeColors.ts (1)
  • getDiscourseNodeColors (14-41)
apps/roam/src/components/settings/DiscourseNodeCanvasSettings.tsx (1)
  • formatHexColor (16-26)
apps/roam/src/components/canvas/DiscourseRelationShape/DiscourseRelationUtil.tsx (1)
  • getRelationColor (86-107)
apps/roam/src/components/canvas/Tldraw.tsx (2)
  • DEFAULT_WIDTH (117-117)
  • DEFAULT_HEIGHT (118-118)
apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (2)
  • DEFAULT_STYLE_PROPS (71-77)
  • FONT_SIZES (60-65)
🔇 Additional comments (11)
apps/roam/src/components/canvas/Tldraw.tsx (1)

117-118: LGTM!

Exporting DEFAULT_WIDTH and DEFAULT_HEIGHT enables consistent centering behavior across the codebase. The values are now shared with DiscourseToolPanel.tsx for drag-and-drop offset calculations.

apps/roam/src/utils/getDiscourseNodeColors.ts (1)

14-41: Good extraction of color computation logic.

The utility correctly encapsulates the color derivation logic, handles edge cases (missing node, missing color), and returns contrast-safe colors via getPleasingColors. The explicit return type and use of type align with the coding guidelines.

apps/roam/src/components/canvas/DiscourseNodeUtil.tsx (3)

48-48: LGTM!

Import added for the new centralized color utility.


60-65: LGTM!

Exporting FONT_SIZES enables consistent typography across canvas components. The Record<TLDefaultSizeStyle, number> type ensures type safety when accessing font sizes by tldraw's size style keys.


344-346: Good refactor to centralize color computation.

Delegating to getDiscourseNodeColors eliminates duplicate color logic and ensures consistency with DiscourseToolPanel.tsx.

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

9-18: LGTM!

Imports are well-organized, bringing in the necessary constants and utilities for consistent sizing, styling, and color computation.


37-38: LGTM!

Extending DragState with backgroundColor and textColor enables the drag preview to display accurate colors matching the node's canvas appearance.

Also applies to: 49-50


131-134: LGTM!

Good defensive guards ensuring relations are click-to-activate only, not draggable. The three locations (pointermove transition, listener attachment, and preview display) are consistently guarded.

Also applies to: 227-232, 282-286


180-181: LGTM!

Using DEFAULT_WIDTH / 2 and DEFAULT_HEIGHT / 2 as offsets ensures dropped shapes are centered at the cursor position, improving the drag-and-drop UX.

Also applies to: 188-189


294-321: Zoom-aware preview rendering looks good.

The preview correctly scales dimensions, border radius, and positioning based on zoom level, with a sensible 0.5 minimum to prevent overly small previews. The viewport-relative positioning ensures correct placement.


425-438: LGTM!

The drag preview text styling now uses shared constants (DEFAULT_STYLE_PROPS, FONT_FAMILIES, FONT_SIZES) for consistency with the actual rendered nodes. The zoom-scaled font size ensures the preview matches the expected canvas appearance.

@mdroidian mdroidian merged commit 64d41c6 into main Dec 1, 2025
6 checks passed
@mdroidian mdroidian deleted the eng-1107-update-drag-and-drop-image-for-nodes-in-discourse-toolbar branch December 1, 2025 20:17
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