Repository navigation
refactor(studio): split SQL editor navigation - #48392
Hardik180704 wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
@Hardik180704 is attempting to deploy a commit to the Supabase Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for contributing to Supabase! ❤️ Our team will review your PR. A few tips for a smoother review process:
|
📝 WalkthroughWalkthroughThe 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. ChangesSQL editor navigation refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsx (2)
34-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNo test file for this new orchestration component.
SnippetCollectionSection.test.tsxwas added alongside its component, butSnippetActionModals.tsxhas 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 tradeoffConsider modeling modal/selection state as a discriminated union.
selectedSnippetToRename/Download/Share/Unshare,selectedFolderToDelete, andshowRenameModal/showMoveModal/showDeleteModalare 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 inSQLEditorNav.tsxas 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
📒 Files selected for processing (4)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorNav.tsxapps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.tsxapps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.test.tsxapps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.tsx
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsx (1)
153-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid 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
ascasts.”🤖 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
📒 Files selected for processing (2)
apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetActionModals.test.tsxapps/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
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Refactor and tests.
What is the current behavior?
SQLEditorNavowns 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:
SnippetCollectionSectionrenders the Shared and Favorites collections, including loading and empty states, pagination, active/open/preview state, and snippet actions.SnippetActionModalsowns the rename, move, download, share, unshare, snippet deletion, and folder deletion modal cluster.SQLEditorNavremains 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:
Verification
pnpm --filter studio exec vitest --run components/layouts/SQLEditorLayout/SQLEditorNavV2/SnippetCollectionSection.test.tsxpnpm --filter studio typecheckgit diff --checkAdditional 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
Bug Fixes
Tests