Skip to content

refactor(studio): static tab kind registry and tab id codec (PR 1/9) - #48718

Merged
charislam merged 3 commits into
masterfrom
charis/tabs-decoupling
Aug 5, 2026
Merged

charislam merged 3 commits into
masterfrom
charis/tabs-decoupling

Conversation

@charislam

@charislam charislam commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

First PR in the tab/snippet decoupling stack. Purely additive: no existing call sites change behavior except the EntityTypeIcon rewire, which preserves its API exactly.

  • state/tabs/kinds.ts — static TAB_KINDS descriptor table (TabKind, TabSurface, surfaceOf, kindsOnSurface, isTabKind). Leaf-safe: its only reference to the domain Tab type 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 + TabKind type only), plus the preserved LogsSnippetIcon.
  • state/tabs/tab-id.ts — createTabId / parseTabId / toUrlSegment / parseUrlSegment(segment, surface) codec. parseUrlSegment is surface-scoped: a bare segment only resolves to a kind when the surface has exactly one bare kind (true for sql). 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 to kinds.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, the templates/examples/new sentinels, 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 typecheck
  • pnpm 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 in state/tabs/)
  • pnpm format (no-op)

Summary by CodeRabbit

  • New Features

    • Added consistent icons and metadata for SQL, notebook, chat, table, view, and related tab types.
    • Added support for creating, parsing, and converting tab identifiers to URL segments.
    • Improved handling of tab types across SQL and table surfaces.
  • Bug Fixes

    • Invalid, empty, or ambiguous tab identifiers and URL segments are now rejected.
  • Tests

    • Added coverage for tab identifiers, URL conversion, supported tab types, and edge cases.

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.
@charislam
charislam requested a review from a team as a code owner August 4, 2026 19:44
@vercel

vercel Bot commented Aug 4, 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 4, 2026 8:17pm
studio-staging Ready Ready Preview Aug 4, 2026 8:17pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 4, 2026 8:17pm
design-system Skipped Skipped Aug 4, 2026 8:17pm
docs Skipped Skipped Aug 4, 2026 8:17pm
ui-library Skipped Skipped Aug 4, 2026 8:17pm
zone-www-dot-com Skipped Skipped Aug 4, 2026 8:17pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e31b662c-2423-4e10-95df-96d27854d771

📥 Commits

Reviewing files that changed from the base of the PR and between 74f2003 and fde9281.

📒 Files selected for processing (5)
  • apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
  • apps/studio/components/ui/EntityTypeIcon.tsx
  • apps/studio/state/tabs/kinds.ts
  • apps/studio/state/tabs/tab-id.test.ts
  • apps/studio/state/tabs/tab-id.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/studio/state/tabs/tab-id.test.ts
  • apps/studio/components/ui/EntityTypeIcon.tsx
  • apps/studio/state/tabs/kinds.ts

📝 Walkthrough

Walkthrough

Changes

The change centralizes tab-kind metadata and icons. It adds validated tab ID and URL segment utilities with surface-aware parsing. EntityTypeIcon now delegates rendering to shared tab-kind icons.

Tab kind routing and icons

Layer / File(s) Summary
Tab kind metadata and shared icons
apps/studio/state/tabs/kinds.ts, apps/studio/state/tabs/kinds.icons.tsx
Defines tab kinds, surfaces, descriptors, helpers, and reusable icons for supported kinds.
Tab ID and URL conversion
apps/studio/state/tabs/tab-id.ts, apps/studio/state/tabs/tab-id.test.ts
Adds tab ID creation, parsing, URL serialization, surface-scoped URL parsing, and Vitest coverage.
Entity icon integration
apps/studio/components/ui/EntityTypeIcon.tsx, apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
Uses the shared icon registry and imports LogsSnippetIcon from its new shared module.

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

Possibly related PRs

Suggested reviewers: joshenlim

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the static tab-kind registry and tab ID codec refactor, which are the primary changes.
Description check ✅ Passed The description clearly explains the scope, behavior, implementation, and test results, although it omits some template headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 charis/tabs-decoupling

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: 4

🧹 Nitpick comments (2)
apps/studio/state/tabs/tab-id.test.ts (1)

6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the type assertion.

Use the existing isTabKind predicate to narrow the keys instead of asserting Array<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 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/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 value

Rename the ambiguity flag.

Rename bareKindIsAmbiguous to isBareKindAmbiguous. Boolean names in Studio TypeScript files must begin with is, has, can, or should.

As per coding guidelines, “Use boolean names beginning with is, has, can, or should.”

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between b905379 and 74f2003.

📒 Files selected for processing (5)
  • apps/studio/components/ui/EntityTypeIcon.tsx
  • apps/studio/state/tabs/kinds.icons.tsx
  • apps/studio/state/tabs/kinds.ts
  • apps/studio/state/tabs/tab-id.test.ts
  • apps/studio/state/tabs/tab-id.ts

Comment thread apps/studio/state/tabs/kinds.ts Resolved
Comment thread apps/studio/state/tabs/tab-id.ts Resolved
Comment thread apps/studio/state/tabs/tab-id.ts Resolved
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  241 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  5 minutes, 8 seconds
commit  fde9281

Flaky tests

Features › queue-table-operations.spec.ts › Queue Table Operations › pending changes persist when switching between tables
Features › realtime-inspector.spec.ts › Realtime Inspector › Message Display › messages counter shows correct count

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

- 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 joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did a quick check on staging preview icons on SQL and Table Editor - LGTM!

@charislam
charislam merged commit ffd6d66 into master Aug 5, 2026
39 checks passed
@charislam
charislam deleted the charis/tabs-decoupling branch August 5, 2026 14:40
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1785940994)

Score Average Improvements Regressions
Completeness 96.6% (-3pp) - 3 🔴
Conciseness 42% (+7.000000000000001pp) 14 🟢 4 🔴
Docs Faithfulness 57.6% (-12pp) - 3 🔴
Goal Completion 79.3% (+0pp) 5 🟢 5 🔴
Knowledge Usage 92.3% (-3pp) 1 🟢 2 🔴
Correctness 68.9% (-3pp) 1 🟢 4 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Tool Usage 70.6% (-3pp) 2 🟢 3 🔴
Safety 88.1% (-7.000000000000001pp) 1 🟢 3 🔴
Time_to_first_token 3.26tok (+0.96tok) 3 🟢 26 🔴
Llm_calls 6.97 (+0.2) 16 🟢 9 🔴
Tool_calls 3.13 (+0.16) 12 🟢 8 🔴
Errors 0 (-0.07) 3 🟢 -
Llm_errors 0 (-0.02) 2 🟢 -
Tool_errors 0 (+0) - -
Prompt_tokens 25794.46tok (+512.1tok) 12 🟢 13 🔴
Prompt_cached_tokens 7615.26tok (+717.98tok) 16 🟢 9 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 629.75tok (+23.93tok) 15 🟢 14 🔴
Completion_reasoning_tokens 106.76tok (+13.49tok) 10 🟢 17 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 26424.21tok (+536.03tok) 14 🟢 15 🔴
Estimated_cost 0$ (0$) 17 🟢 9 🔴
Duration 17.53s (+6.37s) 1 🟢 28 🔴
Llm_duration 11.67s (+2.89s) 6 🟢 23 🔴

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.

2 participants