Repository navigation
feat(studio): notebook content at the API boundary - #48815
Conversation
Introduce Zod schemas for notebook content type, the first in a series of PRs implementing Notebooks — a new SQL Editor content combining SQL, markdown, and log cells. Key additions: - notebook-schema.ts: Zod schemas mirroring RFC-defined shape (schema_version, cells discriminated by _tag). Maintains separation between wire schema (id required, plain sql) and domain schema (id required, sql branded as unchecked_sql for security). Agent-writable schema for create operations omits ids (backend-generated); update operations (later PR) will require them. - iso-datetime.ts: Moved IsoDateTimeString/validator from querySource.ts to lib layer (data/ shouldn't import from components/). Needed by notebook time_range fields. querySource imports updated. - content-query.ts: Workaround for unpublished platform API notebook type — locally widened ContentBase type to include 'notebook' (TODO for removal when api:codegen catches up; does not touch generated packages/api-types). - types/userContent.ts: Notebooks namespace re-exporting Zod-inferred types. All types are z.infer'd from schemas (no hand-written parallel interfaces), ensuring runtime validation and compile-time types can't drift.
Teach content-remap.ts's wire<->domain dispatcher about the notebook content type (branding each cell's sql per _tag via the notebook schemas from 1.2), and add notebook to the Content union in content-query.ts so type: 'notebook' is valid wherever Content already flows. Fixes the resulting narrowing fallout at call sites that assumed Content only ever meant sql/report/log_sql.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe content model now includes notebooks and a ChangesContent typing and notebook support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ContentAPI
participant remapSqlContentField
participant notebookDomainSchema
participant unmapSqlContentField
ContentAPI->>remapSqlContentField: provide notebook content
remapSqlContentField->>notebookDomainSchema: validate and brand SQL cells
notebookDomainSchema-->>remapSqlContentField: return notebook domain content
unmapSqlContentField->>ContentAPI: submit notebook with sql fields
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx (1)
61-61: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest the content discriminant before narrowing to
ContentOfType.The current cast and predicates narrow by ID only. A mixed response can then be treated as incompatible report or log SQL content. Test
typein each lookup.
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx#L61-L61: replace the index assertion with afindpredicate that testsitem.type === 'report'.apps/studio/components/interfaces/Reports/Reports.tsx#L76-L78: addreport.type === 'report'to the type predicate.apps/studio/pages/project/[ref]/logs/explorer/index.tsx#L153-L153: addx.type === 'log_sql'to the type predicate.🤖 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/interfaces/ProjectHome/CustomReportSection.tsx` at line 61, Validate content discriminants before narrowing lookup results: in apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx:61, replace the first-item assertion with a find predicate requiring item.type === 'report'; in apps/studio/components/interfaces/Reports/Reports.tsx:76-78, require report.type === 'report' alongside the existing predicate; and in apps/studio/pages/project/[ref]/logs/explorer/index.tsx:153, require x.type === 'log_sql' alongside the existing predicate.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/data/content/content-query.ts`:
- Around line 66-71: Update the OpenAPI source/schema and regenerate the client
types so the generated content request type includes “notebook” in ContentType.
Then remove the narrow type assertions from the request calls in
apps/studio/data/content/content-query.ts lines 66-71 and
apps/studio/data/content/content-infinite-query.ts lines 30-33, passing type
directly at both sites.
---
Nitpick comments:
In `@apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx`:
- Line 61: Validate content discriminants before narrowing lookup results: in
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsx:61,
replace the first-item assertion with a find predicate requiring item.type ===
'report'; in apps/studio/components/interfaces/Reports/Reports.tsx:76-78,
require report.type === 'report' alongside the existing predicate; and in
apps/studio/pages/project/[ref]/logs/explorer/index.tsx:153, require x.type ===
'log_sql' alongside the existing predicate.
🪄 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: 5f48c00f-f2fe-40ac-a0fe-817da2938f52
📒 Files selected for processing (9)
apps/studio/components/interfaces/ProjectHome/CustomReportSection.tsxapps/studio/components/interfaces/Reports/Reports.tsxapps/studio/components/interfaces/Reports/UpdateModal.tsxapps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.tsxapps/studio/data/content/content-infinite-query.tsapps/studio/data/content/content-query.tsapps/studio/data/content/content-remap.test.tsapps/studio/data/content/content-remap.tsapps/studio/pages/project/[ref]/logs/explorer/index.tsx
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › can join and leave a channel Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
…#48905) ## Summary - Joshen's `state/notebooks/types.ts` (Explorer/notebook editor UI) redefined its own `TimeRange`, cell union, and `NotebookContent` shapes, duplicating the canonical schema from `data/content/notebooks/notebook-schema.ts` (#48813, #48815). - Points `Notebook.content` and `notebooksState.updateCells` at the canonical `Notebooks.Content` / `Notebooks.Cell` types (via `@/types`) instead, and fixes the handful of call sites that constructed notebook content by hand to match the real wire shape: `schema_version: 1` (not `'1.0'`) and `_tag`-discriminated cells (e.g. `{ _tag: 'markdown_cell', id, text }` instead of `{ type: 'markdown', content }`). - No behavioral changes — Joshen's state management, editor component, and hooks are untouched aside from the type-level fixes needed to compile against the canonical schema. ## Test plan - [x] `pnpm exec tsc --noEmit` — no new errors - [x] `pnpm exec vitest run state/notebooks/notebooks-state.test.ts components/interfaces/Explorer/__tests__/NotebookEditor.test.tsx` — 8/8 passing - [x] `pnpm exec eslint` on changed files — clean - [x] `pnpm exec prettier --check` on changed files — clean <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Updated notebook content handling to use the current schema version format. * Improved compatibility for markdown cells, including their identifiers and text. * Standardized notebook content and cell updates for more consistent behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Stacked on #48813 (1.2: notebook content schema). Part of FE-4109 — see that issue for the rest of the notebooks data-model stack.
content-remap.ts's wire↔domain dispatcher about thenotebookcontent type, branding each cell'ssqlper_tagvia the notebook schemas added in 1.2 (parses throughnotebookDomainSchemaon the way in, unbrands per cell on the way out).{ type: 'notebook'; content: Notebooks.Content }to theContentunion incontent-query.ts, plus aContentOfType<T>helper for narrowing it.Contentonly ever meantsql/report/log_sql: two generated-query-param casts, and four report/logs call sites now narrowed viaContentOfType<'report'>/ContentOfType<'log_sql'>.Test plan
pnpm --filter studio vitest run data/content/— 35 tests pass, including new notebook coverage incontent-remap.test.ts(per-cell brand separation, missing-field throw, remap↔unmap round-trip)pnpm typecheck— clean (pre-existing unrelatedui-patternserror aside)pnpm --filter studio lint— no new warnings/errors on changed filespnpm format— cleanSummary by CodeRabbit
New Features
Bug Fixes