Skip to content

refactor(studio): split SQL editor navigation - #48392

Open
Hardik180704 wants to merge 3 commits into
supabase:masterfrom
Hardik180704:fix/issue-48194-sql-editor-nav
Open

Hardik180704 wants to merge 3 commits into
supabase:masterfrom
Hardik180704:fix/issue-48194-sql-editor-nav

Conversation

@Hardik180704

@Hardik180704 Hardik180704 commented Jul 28, 2026 •

Copy link
Copy Markdown

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Refactor and tests.

What is the current behavior?

SQLEditorNav owns the data orchestration, repeated Shared/Favorites tree rendering, item interaction state, and every snippet action modal in one large component.

Fixes #48194.

What is the new behavior?

This change keeps the existing SQL editor navigation behavior while extracting two cohesive responsibilities:

  • SnippetCollectionSection renders the Shared and Favorites collections, including loading and empty states, pagination, active/open/preview state, and snippet actions.
  • SnippetActionModals owns the rename, move, download, share, unshare, snippet deletion, and folder deletion modal cluster.

SQLEditorNav remains responsible for data fetching, mutations, routing, and state orchestration. The component is reduced from 829 to 715 lines without changing its user-facing behavior.

Focused tests cover:

  • loading and empty states
  • active, opened, and preview snippet state
  • making preview tabs permanent on double-click
  • forwarding delete, rename, download, share, and unshare actions

Verification

  • pnpm --filter studio exec vitest --run components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.test.tsx
  • pnpm --filter studio typecheck
  • targeted ESLint for all changed files (zero errors)
  • git diff --check

Additional context

This is intentionally a behavior-preserving refactor. It does not change data fetching, mutations, routing, styling, or SQL editor functionality.

Summary by CodeRabbit

  • New Features

    • Added expandable SQL snippet collections (Shared and Favorites) with loading, empty states, selection, pagination, and per-snippet actions.
    • Consolidated snippet and folder dialogs into a single actions modal experience (rename, move, download, share/unshare, delete).
  • Bug Fixes

    • Improved snippet tab behavior, including correct preview/active/opened state handling and double-click to make a preview tab permanent.
  • Tests

    • Added unit tests for snippet collection rendering, interactions, and action wiring (including modal behavior).

@Hardik180704
Hardik180704 requested a review from a team as a code owner July 28, 2026 14:48
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview Aug 28, 2026 8:28pm
studio-staging Ready Ready Preview Aug 28, 2026 8:28pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 28, 2026 8:28pm
design-system Skipped Skipped Aug 28, 2026 8:28pm
docs Skipped Skipped Aug 28, 2026 8:28pm
ui-library Skipped Skipped Aug 28, 2026 8:28pm
zone-www-dot-com Skipped Skipped Aug 28, 2026 8:28pm

Request Review

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Hardik180704 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The SQL editor navigation now delegates snippet collection rendering and snippet action modal orchestration to dedicated components. New tests cover collection states, tab-derived item behavior, action forwarding, modal visibility, loading state, and deletion callbacks.

Changes

SQL editor navigation refactor

Layer / File(s) Summary
Snippet collection rendering
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx, apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.test.tsx
Extracts expandable snippet collection rendering, tab-derived item state, pagination, loading and empty states, item actions, and related tests.
Snippet action modal orchestration
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx, apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx
Consolidates snippet and folder deletion modals behind a single component with shared state, callbacks, confirmation content, and tests.
Navigation integration
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorNav.tsx
Uses the extracted collection and modal components while preserving section visibility, selection, pagination, and action handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: splitting SQL editor navigation into smaller pieces.
Description check ✅ Passed The description follows the template sections and includes behavior, issue link, and additional context.
Linked Issues check ✅ Passed The PR fulfills #48194 by splitting SQLEditorNav into smaller components while preserving behavior.
Out of Scope Changes check ✅ Passed The changes stay focused on the navigation refactor and related tests, with no obvious unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx (2)

34-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No test file for this new orchestration component.

SnippetCollectionSection.test.tsx was added alongside its component, but SnippetActionModals.tsx has no corresponding test, despite containing conditional visibility/loading wiring (e.g., visible={selectedFolderToDelete !== undefined}, loading={isDeletingFolder}) worth covering.

The mocking approach from SnippetCollectionSection.test.tsx (mocking each child modal) can be reused here. Want me to draft a test file following that same pattern?
As per path instructions, apps/studio/**/*.{test,spec}.{ts,tsx}: "Include relevant tests by default... A decision to add no tests should be deliberate."

🤖 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
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx`
around lines 34 - 111, Add a dedicated SnippetActionModals test using the
child-modal mocking pattern from SnippetCollectionSection.test.tsx. Cover
rendering and prop wiring for each modal, especially folder-delete visibility
based on selectedFolderToDelete and loading based on isDeletingFolder, plus the
relevant close, confirm, and success callbacks.

Source: Path instructions


11-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Consider modeling modal/selection state as a discriminated union.

selectedSnippetToRename/Download/Share/Unshare, selectedFolderToDelete, and showRenameModal/showMoveModal/showDeleteModal are independent optional/boolean fields representing mutually-related "which action is active" state. Nothing currently prevents inconsistent combinations (e.g., a modal flag true while its paired entity is undefined).

Modeling this as a single discriminated union (e.g., { type: 'rename', snippet } | { type: 'delete', snippets } | ...) would remove the possibility of inconsistent flag/entity combinations, but doing so requires reworking the owning state in SQLEditorNav.tsx as well, beyond this component alone.
As per coding guidelines, "model multi-state values as discriminated unions instead of independent boolean flags."

🤖 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
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx`
around lines 11 - 32, Refactor the modal and selection state represented by
SnippetActionModalsProps into a discriminated union keyed by the active action,
so each modal state carries its required snippet, folder, or selected snippets
together. Update the owning state and handlers in SQLEditorNav.tsx, along with
SnippetActionModals, to consume this union and eliminate the independent
showRenameModal/showMoveModal/showDeleteModal flags and optional selected-entity
combinations.

Source: Coding guidelines

🤖 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.

Inline comments:
In
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx`:
- Around line 65-114: Replace the nested loading/empty/success ternary inside
InnerSideMenuCollapsibleContent with flat mutually exclusive rendering guards.
Preserve the existing priority and output: render SQLEditorLoadingSnippets while
isLoading, emptyState when loading is false and snippets is empty, and TreeView
otherwise.

---

Nitpick comments:
In
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx`:
- Around line 34-111: Add a dedicated SnippetActionModals test using the
child-modal mocking pattern from SnippetCollectionSection.test.tsx. Cover
rendering and prop wiring for each modal, especially folder-delete visibility
based on selectedFolderToDelete and loading based on isDeletingFolder, plus the
relevant close, confirm, and success callbacks.
- Around line 11-32: Refactor the modal and selection state represented by
SnippetActionModalsProps into a discriminated union keyed by the active action,
so each modal state carries its required snippet, folder, or selected snippets
together. Update the owning state and handlers in SQLEditorNav.tsx, along with
SnippetActionModals, to consume this union and eliminate the independent
showRenameModal/showMoveModal/showDeleteModal flags and optional selected-entity
combinations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 11a58b1a-9da6-40f7-8514-aa45a8c7a7d1

📥 Commits

Reviewing files that changed from the base of the PR and between 7743fee and 2c15125.

📒 Files selected for processing (4)
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorNav.tsx
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.test.tsx
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx (1)

153-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid assertions for API-model fixtures.

Build these fixtures through a typed factory or the relevant schema so required-field changes cannot be silently bypassed. As per coding guidelines, “Avoid TypeScript as casts.”

🤖 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
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx`
around lines 153 - 154, Replace the `as Snippet` and `as SnippetFolder` casts in
the test fixtures with typed construction using the project’s existing factory
or relevant schema, supplying all required API-model fields. Keep the fixture
values and test behavior unchanged while ensuring future required-field changes
produce type errors.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In
`@apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx`:
- Around line 153-154: Replace the `as Snippet` and `as SnippetFolder` casts in
the test fixtures with typed construction using the project’s existing factory
or relevant schema, supplying all required API-model fields. Keep the fixture
values and test behavior unchanged while ensuring future required-field changes
produce type errors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 38b45b3b-b7bf-46c5-9534-db717ad850c0

📥 Commits

Reviewing files that changed from the base of the PR and between 2c15125 and d89f339.

📒 Files selected for processing (2)
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx

This branch has not been deployed

No deployments
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.

Consider splitting up SQLEditorNav (780 lines, complexity 229)

1 participant