Skip to content

refactor(ui/tree-view): rename and create new items using context menu#276

Merged
NTGNguyen merged 2 commits into
mainfrom
refactor/rename-workspace-items
Jun 2, 2026
Merged

refactor(ui/tree-view): rename and create new items using context menu#276
NTGNguyen merged 2 commits into
mainfrom
refactor/rename-workspace-items

Conversation

@NTGNguyen
Copy link
Copy Markdown
Contributor

@NTGNguyen NTGNguyen commented Jun 2, 2026

Summary by CodeRabbit

Release Notes

  • Style

    • Refined typography and spacing across landing page components
    • Updated hero section visual styling
  • Refactor

    • Improved tree view item creation and navigation workflow
    • Enhanced context menu organisation with visual separators
    • Streamlined item selection and expansion behaviour

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Four components receive updates: three landing page files consolidate Tailwind spacing and typography utilities; tree-view refactors item creation to accept explicit target IDs, moves create actions from toolbar to context menu, adds a custom render path for renaming, and updates cache invalidation to refresh the full workspace tree.

Changes

Landing Page Styling Updates

Layer / File(s) Summary
Landing page Tailwind utilities
packages/ui/src/components/landing-footer.tsx, packages/ui/src/components/landing-hero.tsx, packages/ui/src/components/landing-navigation-bar.tsx
Footer padding consolidates from px-6 py-6 to p-6; hero heading and paragraph switch from standard sizing to text-4xl/tight and text-base/relaxed; "Visualize Your Knowledge" background changes from bg-gradient-to-br to bg-linear-to-br; GitHub icon uses size-4 instead of h-4 w-4.

Tree View Item Creation Refactor

Layer / File(s) Summary
Item creation API and target parent resolution
packages/ui/src/components/tree-view.tsx
getTargetParentId accepts targetId parameter and determines parent folder by scanning items state; handleCreateItem accepts (targetId, isFolder) and expands the computed parent folder in viewState before invoking mutations.
Context menu create actions and separator
packages/ui/src/components/tree-view.tsx
ContextMenuSeparator imported and used; context menu adds "New Note" and "New Folder" items that call handleCreateItem with the selected tree item as target, with separator between create actions and remaining options.
Item rendering for renaming and focus management
packages/ui/src/components/tree-view.tsx
Custom render branch for context.isRenaming returns tailored list-item layout; toolbar header buttons for "New Note"/"New Folder" removed; focusTree() called when handling item focus.
Cache invalidation strategy update
packages/ui/src/components/tree-view.tsx
Rename-note mutation success handler changes cache invalidation from single note query to workspace tree query.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the primary change across the pull request: refactoring the tree-view component to enable renaming and creating items via context menu.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/rename-workspace-items

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
Copy Markdown
Member

@KevinNitroG KevinNitroG left a comment

Choose a reason for hiding this comment

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

Loki Grafana Tempo Mimir

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the tree view in the UI package so that creating new items (notes/folders) is initiated from the per-item context menu rather than from dedicated buttons in the toolbar, and adjusts the rename UX. It also adds a small render branch to show a different layout while an item is being renamed, ensures the parent folder is auto-expanded when creating a child item, and invalidates the workspace tree cache after rename mutations so the tree reflects the new name. Some unrelated Tailwind class adjustments are also bundled in landing-page components.

Changes:

  • Replace toolbar "New Note"/"New Folder" buttons with ContextMenuItem entries (plus a separator before "Move to Trash"); handleCreateItem now takes an explicit targetId, getTargetParentId is rewritten to derive the parent from a target id, and the parent is auto-expanded on creation.
  • Add an isRenaming branch in renderItem and invalidate the workspace tree query after a successful rename so the UI updates; also call tree.current?.focusTree() on focus.
  • Unrelated stylistic refactors of Tailwind utility classes in landing-hero.tsx, landing-footer.tsx, and landing-navigation-bar.tsx (e.g., h-x w-xsize-x, bg-gradient-to-brbg-linear-to-br, leading-relaxedtext-*/relaxed), with some stray double/trailing spaces introduced in className strings.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/ui/src/components/tree-view.tsx Move create-item actions into the context menu, refactor getTargetParentId/handleCreateItem to take a target id, auto-expand parent on create, invalidate tree on rename, render renaming state, and focus tree on focus events.
packages/ui/src/components/landing-hero.tsx Tailwind class refactors (size utilities, leading shorthands, bg-linear-to-br); introduces some extra whitespace in class strings.
packages/ui/src/components/landing-footer.tsx Replace px-6 py-6 with p-6 (with a stray double space).
packages/ui/src/components/landing-navigation-bar.tsx Replace h-4 w-4 with size-4 (with a trailing space).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

<div className="flex flex-1 flex-col justify-center gap-6">
<div className="flex flex-col gap-3">
<h1 className="text-foreground text-4xl leading-tight font-semibold tracking-tight sm:text-5xl lg:text-[52px]">
<h1 className="text-foreground text-4xl/tight font-semibold tracking-tight sm:text-5xl lg:text-[52px]">
<div className="flex shrink-0 items-center gap-2">
<Button variant="outline" size="icon" className="rounded-lg" aria-label="GitHub">
<Icons.Github className="h-4 w-4" />
<Icons.Github className="size-4 " />
Comment on lines 23 to +54
@@ -48,10 +48,10 @@ export default function LandingHero() {
</div>
</div>

<div className="from-muted to-muted/40 flex flex-1 flex-col items-center justify-center gap-6 rounded-2xl bg-gradient-to-br p-10">
<div className="from-muted to-muted/40 flex flex-1 flex-col items-center justify-center gap-6 rounded-2xl bg-linear-to-br p-10">
<div className="flex flex-col gap-3 text-center">
<h2 className="text-foreground text-2xl font-semibold">Visualize Your Knowledge</h2>
<p className="text-muted-foreground text-sm leading-relaxed">
<p className="text-muted-foreground text-sm/relaxed ">
return (
<footer className="border-t">
<div className="mx-auto flex max-w-6xl flex-col items-center justify-between gap-4 px-6 py-6 md:flex-row">
<div className="mx-auto flex max-w-6xl flex-col items-center justify-between gap-4 p-6 md:flex-row">
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ui/src/components/tree-view.tsx (1)

240-268: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Refresh the controlled tree after folder renames as well.

Line 245 fixes note renames, but folder renames still never update items, so the folder title can stay stale until some unrelated refetch happens. This component renders labels from the controlled items map, so useRenameFolderMutation needs the same success-path refresh or a local setItems update.

Proposed fix
   const { mutate: renameFolder } = useRenameFolderMutation({
+    onSuccess: () => {
+      queryClient.invalidateQueries({
+        queryKey: getWorkspaceTreeOptions({
+          path: { workspaceId: currentWorkspaceId },
+        }).queryKey,
+      });
+    },
     onError: (error) => {
       showAlert({
         type: 'error',
         title: 'Rename Folder Failed',
         message: `${error instanceof Error ? error.message : 'Unknown error'}`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/components/tree-view.tsx` around lines 240 - 268, The folder
rename path doesn't refresh the controlled tree items so folder labels stay
stale; update the useRenameFolderMutation success path (renameFolder) to mirror
renameNote by invalidating the workspace-tree query (getWorkspaceTreeOptions
with path: { workspaceId: currentWorkspaceId }) or alternatively call the
component's setItems to update the single renamed entry; modify the mutate
options for renameFolder to add an onSuccess handler that invalidates the same
queryKey used for the tree refresh (getWorkspaceTreeOptions) so the controlled
items map is updated after a folder rename.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/ui/src/components/tree-view.tsx`:
- Around line 240-268: The folder rename path doesn't refresh the controlled
tree items so folder labels stay stale; update the useRenameFolderMutation
success path (renameFolder) to mirror renameNote by invalidating the
workspace-tree query (getWorkspaceTreeOptions with path: { workspaceId:
currentWorkspaceId }) or alternatively call the component's setItems to update
the single renamed entry; modify the mutate options for renameFolder to add an
onSuccess handler that invalidates the same queryKey used for the tree refresh
(getWorkspaceTreeOptions) so the controlled items map is updated after a folder
rename.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f3ba660f-8464-4747-8e56-e299b0fcbebd

📥 Commits

Reviewing files that changed from the base of the PR and between 54c16b6 and 49f7bae.

📒 Files selected for processing (4)
  • packages/ui/src/components/landing-footer.tsx
  • packages/ui/src/components/landing-hero.tsx
  • packages/ui/src/components/landing-navigation-bar.tsx
  • packages/ui/src/components/tree-view.tsx

@NTGNguyen NTGNguyen merged commit 00aea81 into main Jun 2, 2026
4 of 5 checks passed
@NTGNguyen NTGNguyen deleted the refactor/rename-workspace-items branch June 2, 2026 07:15
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.

3 participants