Repository navigation
refactor(studio): static tab kind registry and tab id codec (PR 1/9) - #48718
Conversation
First step of decoupling SQL editor tabs from snippets: a leaf-safe TAB_KINDS descriptor table plus a typed createTabId/parseTabId/ toUrlSegment/parseUrlSegment codec, so a new tab kind eventually costs one registry entry instead of touching id-prefix checks scattered across the tab strip, bulk-close, and pruning logic. EntityTypeIcon becomes a thin wrapper delegating to the new state/tabs/kinds.icons leaf module, preserving its existing prop API and all current consumers. No other call sites change in this PR.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughChangesThe change centralizes tab-kind metadata and icons. It adds validated tab ID and URL segment utilities with surface-aware parsing. Tab kind routing and icons
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 4
🧹 Nitpick comments (2)
apps/studio/state/tabs/tab-id.test.ts (1)
6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the type assertion.
Use the existing
isTabKindpredicate to narrow the keys instead of assertingArray<TabKind>.-import { kindsOnSurface, TAB_KINDS, type TabKind } from './kinds' +import { isTabKind, kindsOnSurface, TAB_KINDS } from './kinds' -const ALL_KINDS = Object.keys(TAB_KINDS) as Array<TabKind> +const ALL_KINDS = Object.keys(TAB_KINDS).filter(isTabKind)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/state/tabs/tab-id.test.ts` at line 6, Update the ALL_KINDS initialization to remove the Array<TabKind> type assertion, and use the existing isTabKind predicate to filter or narrow Object.keys(TAB_KINDS) into valid TabKind values.Source: Coding guidelines
apps/studio/state/tabs/tab-id.ts (1)
39-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename the ambiguity flag.
Rename
bareKindIsAmbiguoustoisBareKindAmbiguous. Boolean names in Studio TypeScript files must begin withis,has,can, orshould.As per coding guidelines, “Use boolean names beginning with
is,has,can, orshould.”🤖 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/state/tabs/tab-id.ts` around lines 39 - 45, Rename the boolean variable bareKindIsAmbiguous to isBareKindAmbiguous throughout the surrounding tab-kind resolution logic, including its declaration and every read or assignment, without changing behavior.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/ui/EntityTypeIcon.tsx`:
- Line 7: Update all importers of LogsSnippetIcon to import it directly from
"`@/state/tabs/kinds.icons`", then remove the LogsSnippetIcon re-export from
EntityTypeIcon.tsx.
In `@apps/studio/state/tabs/kinds.ts`:
- Around line 81-88: Update isTabKind to check whether the value is an own
property of TAB_KINDS rather than using the prototype-traversing in operator,
rejecting inherited names such as "constructor". Replace the
Object.keys(TAB_KINDS) as Array<TabKind> assertion in TAB_KIND_LIST with an
approach that derives the typed keys without an as cast.
In `@apps/studio/state/tabs/tab-id.ts`:
- Around line 25-56: Update toUrlSegment and parseUrlSegment so bare SQL content
IDs beginning with reserved prefixes such as “notebook-” or “chat-” cannot be
interpreted as another tab kind, using an escaping/disambiguation rule that
round-trips reliably. Preserve existing serialization for non-colliding IDs and
prefixed kinds, and add round-trip coverage for both SQL collision cases.
- Around line 9-10: Update createTabId to reject an empty contentId before
constructing the tab ID, while preserving the existing `${kind}-${contentId}`
format for non-empty values. Ensure the rejection prevents IDs such as `sql-`
that parseTabId cannot decode.
---
Nitpick comments:
In `@apps/studio/state/tabs/tab-id.test.ts`:
- Line 6: Update the ALL_KINDS initialization to remove the Array<TabKind> type
assertion, and use the existing isTabKind predicate to filter or narrow
Object.keys(TAB_KINDS) into valid TabKind values.
In `@apps/studio/state/tabs/tab-id.ts`:
- Around line 39-45: Rename the boolean variable bareKindIsAmbiguous to
isBareKindAmbiguous throughout the surrounding tab-kind resolution logic,
including its declaration and every read or assignment, without changing
behavior.
🪄 Autofix
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: bcb80796-0435-4dce-89c6-ea1fc9be7f48
📒 Files selected for processing (5)
apps/studio/components/ui/EntityTypeIcon.tsxapps/studio/state/tabs/kinds.icons.tsxapps/studio/state/tabs/kinds.tsapps/studio/state/tabs/tab-id.test.tsapps/studio/state/tabs/tab-id.ts
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › queue-table-operations.spec.ts › Queue Table Operations › pending changes persist when switching between tables Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
- Remove EntityTypeIcon's LogsSnippetIcon re-export shim; SQLEditorTreeViewItem
now imports it directly from state/tabs/kinds.icons.
- isTabKind uses hasOwnProperty instead of `in`, so an inherited Object
property name (e.g. "constructor") can't pass as a valid kind; drops the
`as Array<TabKind>` cast on TAB_KIND_LIST in favor of filtering by the guard.
- createTabId throws on an empty contentId, matching parseTabId's rejection of
a trailing-dash id (previously createTabId('sql', '') and parseTabId('sql-')
disagreed on validity).
A thrown exception from a codec helper is a crash risk for any call site that doesn't wrap it — return null instead, consistent with how parseTabId and parseUrlSegment already signal failure. toUrlSegment now accepts a null tabId and passes it through, so it composes directly with createTabId's result without every caller needing its own null check first.
joshenlim
left a comment
There was a problem hiding this comment.
Did a quick check on staging preview icons on SQL and Table Editor - LGTM!
Braintrust eval report
|
Summary
First PR in the tab/snippet decoupling stack. Purely additive: no existing call sites change behavior except the
EntityTypeIconrewire, which preserves its API exactly.state/tabs/kinds.ts— staticTAB_KINDSdescriptor table (TabKind,TabSurface,surfaceOf,kindsOnSurface,isTabKind). Leaf-safe: its only reference to the domainTabtype is a type-only import, so it stays importable at module scope (needed later for the valtio store and the persistence migration reader) without creating a runtime cycle.state/tabs/kinds.icons.tsx— per-kind icon leaf module (ui+lucide-react+TabKindtype only), plus the preservedLogsSnippetIcon.state/tabs/tab-id.ts—createTabId/parseTabId/toUrlSegment/parseUrlSegment(segment, surface)codec.parseUrlSegmentis surface-scoped: a bare segment only resolves to a kind when the surface has exactly one bare kind (true forsql). The table surface has five bare kinds (r/v/m/f/p) with no URL disambiguator between them, matching/editor/[id], which learns kind from the fetched entity rather than the URL — so a bare table segment correctly resolves to nothing.components/ui/EntityTypeIcon.tsx— rewired to a thin wrapper delegating tokinds.icons.tsx, preserving its exact prop API (type,size,strokeWidth,isActive,sqlSource) for all existing consumers.state/tabs/tab-id.test.ts— codec round-trips per kind, bare-vs-prefixed URL segments, thetemplates/examples/newsentinels, and surface scoping (including the table-surface ambiguity above).Full plan:
apps/studio/TABS_DECOUPLING_PLAN.md(not included in this PR).Test plan
pnpm typecheckpnpm lint --filter=studio(0 errors)pnpm --filter studio run lint:ratchet(warning counts did not increase)pnpm test:studio(full suite green, including 50 new/updated tests instate/tabs/)pnpm format(no-op)Summary by CodeRabbit
New Features
Bug Fixes
Tests