Skip to content

cf234 [Grida Canvas] Hierarchy Renaming - #349

Merged
softmarshmallow merged 6 commits into
mainfrom
canary
May 21, 2025
Merged

softmarshmallow merged 6 commits into
mainfrom
canary

Conversation

@softmarshmallow

@softmarshmallow softmarshmallow commented May 21, 2025 •

Copy link
Copy Markdown
Member

Introduces new Tree UI w/@headless-tree/react

Added inline renaming feature

day-234-grida-canvas-hierarchy-renaming.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a fully interactive, accessible tree view for organizational hierarchies with multi-select and drag-and-drop reordering.
    • Sidebar node hierarchy list now supports hierarchical display, selection, expansion, drag-and-drop, and integrated renaming with improved accessibility and keyboard navigation.
    • Added flexible and styled tree components with configurable indentation and drag indicators for enhanced UI consistency.
  • UI Improvements

    • Updated sidebar label from "Layers" to "Blocks" for clearer terminology.
    • Enhanced spacing for icons in dropdown menus for improved visual alignment.
  • Bug Fixes

    • Ensured consistent styling for icons across the interface.
  • Chores

    • Added new dependencies to support advanced tree functionality.

@codesandbox

codesandbox Bot commented May 21, 2025

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@vercel

vercel Bot commented May 21, 2025 •

Copy link
Copy Markdown

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

Name Status Preview Comments Updated (UTC)
grida ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 4:10pm
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
code ⬜️ Ignored (Inspect) May 21, 2025 4:10pm
legacy ⬜️ Ignored (Inspect) May 21, 2025 4:10pm
backgrounds ⬜️ Skipped (Inspect) May 21, 2025 4:10pm
blog ⬜️ Skipped (Inspect) May 21, 2025 4:10pm
docs ⬜️ Skipped (Inspect) May 21, 2025 4:10pm
viewer ⬜️ Skipped (Inspect) May 21, 2025 4:10pm

@coderabbitai

coderabbitai Bot commented May 21, 2025 •

Copy link
Copy Markdown

Walkthrough

A hierarchical, interactive tree component with drag-and-drop and multi-select was introduced and integrated into the editor, including a new UI for node hierarchy management with renaming and accessibility features. Supporting utilities and dependencies for tree management were added, and related types and UI elements were refactored for clarity and consistency.

Changes

File(s) Change Summary
editor/app/(dev)/ui/comp/comp-569.tsx Added a new default-exported React component OriginComp569 implementing a fully interactive, accessible tree view with drag-and-drop and multi-select.
editor/app/(dev)/ui/page.tsx Imported and rendered the new OriginComp569 component in the AllComponentsPage after a horizontal rule.
editor/components/ui-editor/tree.tsx Introduced a new tree UI component library: Tree, TreeItem, TreeItemLabel, and TreeDragLine, supporting context, styling, and ARIA attributes.
editor/grida-react-canvas-starter-kit/starterkit-icons/node-type-icon.tsx Updated icon components for flex layouts to accept and use the className prop for consistent styling.
editor/grida-react-canvas/action.ts Refactored editor action types: split and renamed order/path actions, added new move action, and updated the main action union for clarity and granularity.
editor/package.json Added @headless-tree/core and @headless-tree/react as new dependencies.
editor/scaffolds/playground-canvas/playground.tsx Added margin-end class (me-2) to two icon components in dropdown menu triggers for improved spacing.
editor/scaffolds/sidebar/sidebar-mode-design-form.tsx Changed sidebar group label from "Layers" to "Blocks".
editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx Rewrote the node hierarchy list to use a fully-featured tree component with hierarchical data, drag-and-drop, renaming, and accessibility. Updated related context menu and group components.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Sidebar
    participant TreeComponent
    participant DocumentState

    User->>Sidebar: Opens sidebar (Node Hierarchy)
    Sidebar->>TreeComponent: Initializes tree with scene root
    TreeComponent->>DocumentState: Loads children for root
    DocumentState-->>TreeComponent: Returns node hierarchy
    TreeComponent-->>User: Renders interactive tree (expand, select, drag, rename)
    User->>TreeComponent: Drags or renames node
    TreeComponent->>DocumentState: Updates hierarchy or node name
    DocumentState-->>TreeComponent: Confirms update
    TreeComponent-->>User: Updates tree display
Loading
sequenceDiagram
    participant User
    participant AllComponentsPage
    participant OriginComp569

    User->>AllComponentsPage: Navigates to dev UI page
    AllComponentsPage->>OriginComp569: Renders tree demo
    OriginComp569-->>User: Displays interactive tree with drag-and-drop and multi-select
Loading

Poem

In the editor’s warren, a tree has grown tall,
With drag, drop, and rename—now it does all!
Blocks not layers, a sidebar anew,
Icons aligned, and actions in view.
Rabbits rejoice, for the forest is bright—
Hierarchies flourish in digital light!
🐇🌳✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@vercel
vercel Bot temporarily deployed to Preview – viewer May 21, 2025 09:39 Inactive
@vercel
vercel Bot temporarily deployed to Preview – docs May 21, 2025 09:39 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 21, 2025 09:39 Inactive
@vercel
vercel Bot temporarily deployed to Preview – blog May 21, 2025 09:39 Inactive
@vercel
vercel Bot temporarily deployed to Preview – blog May 21, 2025 11:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – viewer May 21, 2025 11:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – docs May 21, 2025 11:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 21, 2025 11:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – viewer May 21, 2025 11:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – blog May 21, 2025 11:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – docs May 21, 2025 11:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 21, 2025 11:26 Inactive
@softmarshmallow softmarshmallow changed the title [Grida Canvas] Tree UI [Grida Canvas] Hierarchy Renaming May 21, 2025
@softmarshmallow softmarshmallow changed the title [Grida Canvas] Hierarchy Renaming cf234 [Grida Canvas] Hierarchy Renaming May 21, 2025
@softmarshmallow
softmarshmallow marked this pull request as ready for review May 21, 2025 16:01

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (4)
editor/app/(dev)/ui/comp/comp-569.tsx (1)

123-123: Fix typo in accessibility text

There's a small typo in the accessibility text.

-Tee with multi-select and drag and drop ∙{" "}
+Tree with multi-select and drag and drop ∙{" "}
editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (3)

293-298: onDrop handler only logs – consider implementing or gating feature

Drag-and-drop is enabled (dragAndDropFeature, keyboardDragAndDropFeature) yet the callback currently just prints to the console.
If left as-is, users can drag layers with no visible effect, creating confusion.

Options:

-    onDrop(items, target) {
-      const ids = items.map((item) => item.getId());
-      const target_id = target.item.getId();
-      const index = "insertionIndex" in target ? target.insertionIndex : 0;
-      console.log("drop", ids, target_id, index);
-    },
+    async onDrop(items, target) {
+      const ids = items.map((i) => i.getId());
+      const parentId = target.item.getId();
+      const index   = "insertionIndex" in target ? target.insertionIndex : 0;
+
+      // TODO: call document.moveNodes(ids, parentId, index);
+      // await persistChange();
+      // tree.rebuildTree();
+    },

or temporarily disable DnD until implemented.


341-346: Avoid arbitrary 200 ms timeout when starting rename

Using setTimeout(..., 200) introduces race conditions (slow machines, differing context-menu close times).

If the issue is focus loss while the context-menu unmounts, prefer queueMicrotask / requestAnimationFrame or the library’s onOpenChange callback:

-onStartRenaming={() => {
-  // prevent from input blurring caused by the context menu closing
-  setTimeout(() => {
-    item.startRenaming();
-  }, 200);
-}}
+onStartRenaming={() => {
+  // run after the menu closes on the next frame
+  requestAnimationFrame(() => item.startRenaming());
+}}

This guarantees minimal delay and removes the magic number.


395-418: Add accessible labels for lock / visibility buttons

Icon-only controls should expose an aria-label so screen-reader users understand their purpose.

-<button
+<button
+  aria-label={node.locked ? "Unlock layer" : "Lock layer"}
 …
-<button
+<button
+  aria-label={node.active ? "Hide layer" : "Show layer"}

Consider adding title attributes for non-assistive hover hints as well.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b0c9a21 and 1a6d27f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • editor/app/(dev)/ui/comp/comp-569.tsx (1 hunks)
  • editor/app/(dev)/ui/page.tsx (2 hunks)
  • editor/components/ui-editor/tree.tsx (1 hunks)
  • editor/grida-react-canvas-starter-kit/starterkit-icons/node-type-icon.tsx (1 hunks)
  • editor/grida-react-canvas/action.ts (2 hunks)
  • editor/package.json (1 hunks)
  • editor/scaffolds/playground-canvas/playground.tsx (2 hunks)
  • editor/scaffolds/sidebar/sidebar-mode-design-form.tsx (1 hunks)
  • editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
editor/scaffolds/sidebar/sidebar-mode-design-form.tsx (1)
editor/components/ui/sidebar.tsx (1)
  • SidebarGroupLabel (708-708)
editor/components/ui-editor/tree.tsx (1)
editor/components/lib/utils/index.ts (1)
  • cn (4-6)
editor/grida-react-canvas/action.ts (1)
packages/grida-canvas-schema/grida.ts (2)
  • NodeID (806-806)
  • NodeID (2109-2109)
🔇 Additional comments (19)
editor/scaffolds/playground-canvas/playground.tsx (2)

340-340: Clean UI spacing improvement.

Adding margin-end to the icon improves the visual spacing between the icon and the "Tools" label.


384-384: Consistent UI spacing enhancement.

Added margin-end to maintain consistent spacing between the icon and the "Examples" label, matching the pattern used with other menu items.

editor/grida-react-canvas/action.ts (3)

223-240: Excellent refactoring of hierarchy action types.

The introduction of EditorHierarchyAction with its specific subtypes provides better type organization and control for hierarchy operations. The new EditorHierarchyMoveAction interface with source and target properties enables precise node movement, which is essential for the drag-and-drop functionality described in the PR objectives.

This refactoring creates a clean separation of concerns between ordering nodes and moving nodes within the hierarchy, making the code more maintainable and the actions more semantically clear.


45-46: Improved type naming for better code readability.

The updated type names in DocumentAction provide clearer semantics about their purposes:

  • EditorHierarchyOrderAction explicitly indicates hierarchy ordering
  • EditorVectorPathAction clarifies that these actions relate to vector paths

This naming improvement helps distinguish between different action categories.


243-243: Better naming for vector path actions.

Renaming from EditorPathAction to EditorVectorPathAction adds clarity by explicitly indicating these actions relate to vector paths rather than general paths or hierarchical paths.

editor/grida-react-canvas-starter-kit/starterkit-icons/node-type-icon.tsx (1)

39-41: LGTM: Improved consistency in className prop usage

The addition of the className prop to ViewVerticalIcon and ViewHorizontalIcon components makes the code more consistent, as all other icon components in this file already had the className prop applied. This ensures uniform styling capabilities across all icons.

editor/app/(dev)/ui/page.tsx (3)

2-2: LGTM: Consolidated React imports

Good cleanup by consolidating the React imports into a single statement.


9-9: LGTM: New tree component import

Proper import of the new tree UI component that will be showcased on this page.


27-28: LGTM: Added new component with proper separation

The new tree component is properly added to the components showcase with an appropriate divider.

editor/app/(dev)/ui/comp/comp-569.tsx (5)

3-20: LGTM: Well-structured imports for tree functionality

The imports are organized in logical groups - React core, headless tree functionality, UI icons, and custom tree components. This organization makes the dependencies clear and maintainable.


22-55: LGTM: Clear data model structure

The Item interface and initial data structure are well-defined, providing a good hierarchical structure for demonstrating the tree functionality. The nested departments and teams effectively showcase the component's capabilities for handling multi-level hierarchies.


62-92: LGTM: Comprehensive tree configuration

The tree hook configuration is thorough, with proper initial state setup, item handlers, and comprehensive feature enablement. The reordering implementation using state updates is clean and efficient.


94-116: LGTM: Well-structured tree rendering

The component renders the tree with appropriate accessibility features and visual indicators for folder states. The mapping over tree items is clean and each item is properly keyed.


118-132: LGTM: Good accessibility implementation

The component includes appropriate ARIA attributes and explanatory text with a link to documentation, enhancing usability for all users.

editor/components/ui-editor/tree.tsx (5)

9-23: LGTM: Well-structured context setup

The TreeContext is properly set up with reasonable defaults and a strongly-typed hook for accessing context values.


30-56: LGTM: Flexible Tree component implementation

The Tree component has a clean implementation that:

  • Properly merges props from tree controller if available
  • Sets up custom CSS variables for indentation
  • Provides the context to child components
  • Uses appropriate data attributes for styling

64-128: LGTM: Comprehensive TreeItem implementation

The TreeItem component handles all necessary state and styling concerns:

  • Dynamic padding based on item level and indent size
  • Data attributes for various item states (focused, folder, selected, etc.)
  • Appropriate ARIA attributes for accessibility
  • Proper context propagation

135-165: LGTM: Flexible TreeItemLabel with fallbacks

The TreeItemLabel component is well-implemented with:

  • Support for items from either props or context
  • Proper error handling when no item is provided
  • Conditional rendering of folder indicator
  • Flexible content rendering (children or item name)

167-191: LGTM: Robust TreeDragLine implementation

The TreeDragLine component:

  • Properly handles the case when tree or required methods are missing
  • Applies styles from the tree controller
  • Uses appropriate styling for visual feedback during drag operations

Comment thread editor/package.json
Comment on lines +46 to +47
"@headless-tree/core": "^1.0.1",
"@headless-tree/react": "^1.0.1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM! Appropriate dependencies for implementing tree UI components.

Adding these tree-related packages aligns well with the PR objectives of introducing a new Tree UI component with hierarchical management capabilities. The versioning looks good with stable 1.x releases.


🌐 Web query:

What is the latest version of @headless-tree/react?

💡 Result:

The latest version of @headless-tree/react is 1.0.0, which was published 13 days ago as of May 21, 2025[1]. This is the current stable release version available on npm. The package is part of the headless-tree project by Lukas Bach, which provides tree component functionality for React applications[3].

The package can be installed via npm using the command npm i @headless-tree/react[1]. It's designed to work alongside @headless-tree/core, which provides the core functionality for the tree components[3][4].

The headless-tree project is aimed at providing super-easy integration of complex tree components into React applications, with support for ordered and unordered drag-and-drop, extensive keybindings, search, renaming, and more features[3]. The latest release was published to GitHub as well, where both @headless-tree/react and @headless-tree/core received version 1.0.0 releases[7].

Citations:


Update Headless-Tree dependency versions

The specified versions (^1.0.1) aren’t available on npm—the latest stable release for both packages is 1.0.0. Please adjust your editor/package.json accordingly:

  • File: editor/package.json
  • Lines: 46–47
- "@headless-tree/core": "^1.0.1",
- "@headless-tree/react": "^1.0.1",
+ "@headless-tree/core": "^1.0.0",
+ "@headless-tree/react": "^1.0.0",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"@headless-tree/core": "^1.0.1",
"@headless-tree/react": "^1.0.1",
"@headless-tree/core": "^1.0.0",
"@headless-tree/react": "^1.0.0",
🤖 Prompt for AI Agents
In editor/package.json at lines 46 to 47, the versions specified for
@headless-tree/core and @headless-tree/react are ^1.0.1, which do not exist on
npm. Update both dependency versions to the latest stable release, which is
1.0.0, to ensure the packages can be correctly resolved and installed.


<SidebarGroup>
<SidebarGroupLabel>Layers</SidebarGroupLabel>
<SidebarGroupLabel>Blocks</SidebarGroupLabel>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Terminology update from "Layers" to "Blocks".

This label change reflects a conceptual shift in how hierarchy items are presented to users. The term "Blocks" better aligns with the component-based structure being implemented with the new tree UI components.

To ensure consistency, let's verify that this terminology is used consistently across the application:


🏁 Script executed:

#!/bin/bash
# Check for occurrences of both "Layers" and "Blocks" in the codebase to ensure consistency
echo "Searching for 'Layers' references that might need updating:"
rg -i "layers" --glob="*.{tsx,ts,js,jsx}" | grep -v "node_modules" | grep -i "label\|title\|heading"

echo -e "\nSearching for 'Blocks' terminology usage:"
rg -i "blocks" --glob="*.{tsx,ts,js,jsx}" | grep -v "node_modules" | grep -i "label\|title\|heading"

Length of output: 1422


Ensure consistent “Blocks” terminology across sidebar labels

The update in sidebar-mode-design-form.tsx replaces “Layers” with “Blocks”, but there are two remaining instances that should also be updated for consistency:

  • editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx

    - <SidebarGroupLabel>Layers</SidebarGroupLabel>
    + <SidebarGroupLabel>Blocks</SidebarGroupLabel>
  • editor/components/formfield/grida-canvas/index.tsx

    - <SidebarSectionHeaderLabel>Layers</SidebarSectionHeaderLabel>
    + <SidebarSectionHeaderLabel>Blocks</SidebarSectionHeaderLabel>

Please make these changes so users encounter a uniform “Blocks” label throughout the UI.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In editor/scaffolds/sidebar/sidebar-mode-design-form.tsx at line 47, the label
"Layers" has been updated to "Blocks" but two other files still use "Layers" in
their sidebar labels: editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx
and editor/components/formfield/grida-canvas/index.tsx. Locate the label or
heading text in these files that still say "Layers" and update them to "Blocks"
to maintain consistent terminology across the UI.

Comment on lines +484 to +491
(e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter" || e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
onValueCommit?.(value);
ref.current?.blur();
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

NameInput commits twice – duplicate callbacks on Enter

onKeyDown commits (onValueCommit) and triggers blur(), then the capture-phase listener (lines 506-514) commits again when the same event bubbles. This results in two rename events.

Simplify by relying on one handler (React’s onKeyDown) and drop the manual addEventListener:

-// Set up capture-phase event listener …
-useEffect(() => {
-  const handleKeyDown = (e: KeyboardEvent) => {
-    if (e.key === "Enter" || e.keyCode === 13) {
-      …
-    }
-  };
-  const input = ref.current;
-  if (input) {
-    input.addEventListener("keydown", handleKeyDown, true);
-  }
-  return () => {
-    if (input) input.removeEventListener("keydown", handleKeyDown, true);
-  };
-}, [ref.current, initialValue, onValueCommit, value]);
+// (effect removed – onKeyDown already prevents propagation & commits)

This avoids duplicate dispatches and simplifies cleanup.

Also applies to: 506-514

🤖 Prompt for AI Agents
In editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx around lines 484 to
491 and 506 to 514, the onValueCommit callback is triggered twice on Enter key
press due to both React's onKeyDown handler and a manual capture-phase event
listener committing the value. To fix this, remove the manual addEventListener
code (lines 506-514) and rely solely on the React onKeyDown handler to commit
the value and blur the input, preventing duplicate rename events and simplifying
event handling and cleanup.

Comment on lines +265 to +267
return children.filter(
(id) => (document.nodes[id] as grida.program.nodes.UnknwonNode).expanded
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in generic cast – current spelling breaks type-checking and compilation

grida.program.nodes.UnknwonNode is misspelled.
The incorrect reference will cause a TypeScript error and block the build.

-      (id) => (document.nodes[id] as grida.program.nodes.UnknwonNode).expanded
+      (id) => (document.nodes[id] as grida.program.nodes.UnknownNode /* or more specific */).expanded

Double-check the actual exported name in @grida/schema; if no such alias exists, fall back to Node or a local interface.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return children.filter(
(id) => (document.nodes[id] as grida.program.nodes.UnknwonNode).expanded
);
return children.filter(
(id) => (document.nodes[id] as grida.program.nodes.UnknownNode /* or more specific */).expanded
);
🤖 Prompt for AI Agents
In editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx around lines 265 to
267, fix the typo in the type cast from grida.program.nodes.UnknwonNode to the
correct spelling, likely grida.program.nodes.UnknownNode. Verify the exact
exported type name from @grida/schema and update the cast accordingly to restore
proper type-checking and compilation.

@vercel
vercel Bot temporarily deployed to Preview – blog May 21, 2025 16:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – backgrounds May 21, 2025 16:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – viewer May 21, 2025 16:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – docs May 21, 2025 16:06 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (2)

265-267: Fix the typo in type cast: "UnknwonNode" → "UnknownNode"

This typo will cause TypeScript errors and block the build.

-      (id) => (document.nodes[id] as grida.program.nodes.UnknwonNode).expanded
+      (id) => (document.nodes[id] as grida.program.nodes.UnknownNode).expanded

506-527: NameInput commits twice – remove duplicate enter key handler

The current implementation has both React's onKeyDown handler and a manual capture-phase event listener that trigger the same action, resulting in duplicate commits on Enter key press.

-// Set up capture-phase event listener to intercept events before they reach other handlers
-useEffect(() => {
-  const handleKeyDown = (e: KeyboardEvent) => {
-    if (e.key === "Enter" || e.keyCode === 13) {
-      e.preventDefault();
-      e.stopPropagation();
-      onValueCommit?.(value);
-      ref.current?.blur();
-    }
-  };
-
-  const input = ref.current;
-  if (input) {
-    // Using capture phase (true) to intercept events before they reach other handlers
-    input.addEventListener("keydown", handleKeyDown, true);
-  }
-
-  return () => {
-    if (input) {
-      input.removeEventListener("keydown", handleKeyDown, true);
-    }
-  };
-}, [ref.current, initialValue, onValueCommit, value]);
🧹 Nitpick comments (2)
editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (2)

400-406: Add aria-label to lock/unlock button for better accessibility

The button currently lacks an accessible label that explains its purpose.

 <button
+  aria-label={node.locked ? "Unlock node" : "Lock node"}
   onClick={(e) => {
     e.stopPropagation();
     toggleNodeLocked(node.id);
   }}
 >

412-418: Add aria-label to visibility toggle button for better accessibility

The button currently lacks an accessible label that explains its purpose.

 <button
+  aria-label={node.active ? "Hide node" : "Show node"}
   onClick={(e) => {
     e.stopPropagation();
     toggleNodeActive(node.id);
   }}
 >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a6d27f and 0baaece.

📒 Files selected for processing (1)
  • editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx (5 hunks)

Comment on lines +293 to +298
onDrop(items, target) {
const ids = items.map((item) => item.getId());
const target_id = target.item.getId();
const index = "insertionIndex" in target ? target.insertionIndex : 0;
console.log("drop", ids, target_id, index);
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement the onDrop handler function

The onDrop function currently only logs the drop operation but doesn't actually handle updating the document structure. This will make the drag-and-drop feature non-functional.

 onDrop(items, target) {
   const ids = items.map((item) => item.getId());
   const target_id = target.item.getId();
   const index = "insertionIndex" in target ? target.insertionIndex : 0;
-  console.log("drop", ids, target_id, index);
+  // Handle actual node reparenting/reordering logic
+  if (target_id === "<scene-root>") {
+    // Move nodes to scene root at specified index
+  } else {
+    // Move nodes to be children of target node at specified index
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onDrop(items, target) {
const ids = items.map((item) => item.getId());
const target_id = target.item.getId();
const index = "insertionIndex" in target ? target.insertionIndex : 0;
console.log("drop", ids, target_id, index);
},
onDrop(items, target) {
const ids = items.map((item) => item.getId());
const target_id = target.item.getId();
const index = "insertionIndex" in target ? target.insertionIndex : 0;
// Handle actual node reparenting/reordering logic
if (target_id === "<scene-root>") {
// Move nodes to scene root at specified index
} else {
// Move nodes to be children of target node at specified index
}
},
🤖 Prompt for AI Agents
In editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx around lines 293 to
298, the onDrop handler only logs the drop event without updating the document
structure. To fix this, implement logic inside onDrop to update the underlying
data model by moving the dragged items to the new target location at the
specified insertion index. Ensure the document state is updated accordingly to
reflect the changes in the UI and persist the new hierarchy.

Comment on lines +529 to +536
useEffect(() => {
const input = ref.current;
if (input && !isInitiallyFocused.current) {
input.focus();
input.select();
isInitiallyFocused.current = true;
}
}, [ref.current]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix dependency array in useEffect for input focus

The current implementation incorrectly uses ref.current in the dependency array, which doesn't trigger re-renders when it changes. Also, the effect doesn't include all dependencies it uses.

 useEffect(() => {
   const input = ref.current;
   if (input && !isInitiallyFocused.current) {
     input.focus();
     input.select();
     isInitiallyFocused.current = true;
   }
-}, [ref.current]);
+}, []);  // Run only once when component mounts
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
const input = ref.current;
if (input && !isInitiallyFocused.current) {
input.focus();
input.select();
isInitiallyFocused.current = true;
}
}, [ref.current]);
useEffect(() => {
const input = ref.current;
if (input && !isInitiallyFocused.current) {
input.focus();
input.select();
isInitiallyFocused.current = true;
}
}, []); // Run only once when component mounts
🤖 Prompt for AI Agents
In editor/scaffolds/sidebar/sidebar-node-hierarchy-list.tsx around lines 529 to
536, the useEffect hook incorrectly lists ref.current in its dependency array,
which does not properly trigger the effect when the ref changes. Update the
dependency array to include the ref object itself or other relevant stable
dependencies instead of ref.current, and ensure all variables used inside the
effect, such as isInitiallyFocused, are included as dependencies if necessary.
This will ensure the effect runs correctly when the input element becomes
available.

This branch was successfully deployed

1 active and 4 inactive deployments
Preview – grida — 0baaece9 Deployed May 21, 2025 by vercel[bot]
Preview – docs — 0baaece9 Deployed May 21, 2025 by vercel[bot]
Preview – viewer — 0baaece9 Deployed May 21, 2025 by vercel[bot]
Preview – backgrounds — 0baaece9 Deployed May 21, 2025 by vercel[bot]
Preview – blog — 0baaece9 Deployed May 21, 2025 by vercel[bot]
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.

1 participant