Repository navigation
feat: Add table state to Code and SQL blocks. - #34
Conversation
📝 WalkthroughWalkthrough
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Dev
participant TS as Block renderer (TS)
participant DF as createDataFrameConfig
participant PY as Python runtime
participant GS as Global state
Dev->>TS: Render CodeBlock
TS->>DF: build prelude from deepnote_table_state
DF-->>TS: dedented Python prelude
rect rgba(200,220,255,0.25)
note over PY,GS: Guarded prelude injected before user code
TS->>PY: if '_dntk' in globals(): _dntk.dataframe_utils.configure_dataframe_formatter(JSON)
TS->>GS: else: _deepnote_current_table_attrs = JSON
end
TS->>PY: Execute user code content
sequenceDiagram
autonumber
actor Dev as Dev
participant TS as Block renderer (TS)
participant DF as createDataFrameConfig
participant PY as Python runtime
participant GS as Global state
Dev->>TS: Render SqlBlock
TS->>DF: build prelude from deepnote_table_state
DF-->>TS: dedented Python prelude
rect rgba(200,220,255,0.25)
note over PY,GS: Guarded prelude injected before SQL execution
TS->>PY: if '_dntk' in globals(): configure_dataframe_formatter(JSON)
TS->>GS: else: _deepnote_current_table_attrs = JSON
end
alt variable assigned
TS->>PY: var = _dntk.execute_sql(...)
else direct execution
TS->>PY: _dntk.execute_sql(...)
end
Possibly related PRs
Suggested reviewers
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
==========================================
+ Coverage 93.59% 93.80% +0.20%
==========================================
Files 19 21 +2
Lines 593 613 +20
Branches 120 182 +62
==========================================
+ Hits 555 575 +20
Misses 38 38 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
CLAUDE.md(1 hunks)packages/blocks/src/blocks.ts(1 hunks)packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/data-frame.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/python-code.test.ts(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/blocks/src/blocks/code-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(6-16)
packages/blocks/src/blocks/data-frame.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(6-16)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/python-code.test.ts (4)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/index.ts (1)
createPythonCode(4-4)packages/blocks/src/python-code.ts (1)
createPythonCode(27-81)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/data-frame.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)packages/blocks/src/blocks/python-utils.ts (1)
escapePythonString(1-7)
🔇 Additional comments (9)
packages/blocks/src/blocks.ts (1)
39-40: LGTM!The index signature enables flexible metadata storage for table state and other dynamic properties. Comment appropriately documents the rationale.
packages/blocks/src/blocks/data-frame.ts (1)
6-16: LGTM!The function correctly extracts table state, serializes to JSON, and emits conditional Python boilerplate. The use of
escapePythonStringensures safe embedding of JSON in Python strings.CLAUDE.md (1)
1-184: LGTM!Comprehensive development guide that aligns well with the PR's changes. Clear workflow documentation and package-specific guidance.
packages/blocks/src/blocks/code-blocks.ts (1)
14-22: LGTM!The function now correctly prepends the dataframe configuration before block content. The dedent usage ensures clean formatting.
packages/blocks/src/blocks/sql-blocks.ts (1)
50-62: LGTM!The dataframe configuration is correctly injected in both the undefined-variable and defined-variable paths, ensuring consistent behavior.
packages/blocks/src/blocks/data-frame.test.ts (1)
8-214: LGTM!Comprehensive test coverage including edge cases (empty state, missing metadata, special characters, complex state). Tests verify both code and SQL block scenarios.
packages/blocks/src/python-code.test.ts (3)
169-282: LGTM!Tests correctly validate the augmented output structure with dataframe configuration preface. Good coverage of various table state scenarios (empty, with state, custom page size, hidden columns).
590-735: LGTM!SQL block tests appropriately updated to include dataframe configuration. Tests cover all execution paths (with/without variable, different return types, special characters).
737-823: LGTM!New tests for SQL blocks with table state provide comprehensive validation of the configuration injection and JSON serialization.
f8336f7 to
624d676
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
CLAUDE.md(1 hunks)packages/blocks/src/blocks.ts(1 hunks)packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/data-frame.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/python-code.test.ts(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
packages/blocks/src/python-code.test.ts (4)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/python-code.ts (1)
createPythonCode(27-81)packages/blocks/src/index.ts (1)
createPythonCode(4-4)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/sql-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(6-16)
packages/blocks/src/blocks/data-frame.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(6-16)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/code-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(6-16)
packages/blocks/src/blocks/data-frame.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(8-12)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)packages/blocks/src/blocks/python-utils.ts (1)
escapePythonString(1-7)
🔇 Additional comments (10)
packages/blocks/src/blocks/code-blocks.ts (1)
15-21: LGTM: DF config prelude before user codeThe dedent wrapper + injected
dataFrameConfigis clean and consistent with SQL blocks.packages/blocks/src/blocks/sql-blocks.ts (3)
41-49: Good fix: wrapexecute_sqlcall withdedentThis resolves unintended indentation/whitespace. Injection of
dataFrameConfigabove it is correct.
52-56: Undefined-variable path handled correctlyReturning a dedented block with
dataFrameConfigthen the call is consistent with the assignment path.
60-64: Assignment path looks right
dataFrameConfigprecedes assignment and expression echo; formatting is consistent.CLAUDE.md (1)
173-173: Build Tool “tsdown” is correct
Referenced in package.json and used in build scripts for blocks and hello-world; no doc change needed.packages/blocks/src/blocks/data-frame.test.ts (1)
1-215: Excellent test coverage.Comprehensive suite covering empty state, populated state, SQL blocks, missing metadata, special character escaping, and complex scenarios. The escaping test (lines 144-168) is particularly thorough, correctly validating that
escapePythonStringhandles both single quotes (\') and backslashes in JSON-encoded strings.packages/blocks/src/python-code.test.ts (4)
169-176: Consistent boilerplate addition.Correctly updated to expect the dataframe config boilerplate before the user code. Defaults to
'{}'whendeepnote_table_stateis absent from metadata.
179-225: Good coverage of table state scenarios.Validates full JSON serialization of table state fields (pageSize, pageIndex, columnOrder, etc.) and confirms the boilerplate is properly prepended to user code.
590-604: Consistent SQL block updates.All SQL block tests properly updated to include the dataframe config boilerplate before
_dntk.execute_sqlcalls. Good consistency across assignment and non-assignment paths.Also applies to: 622-635, 655-669, 687-701, 720-734
737-792: Comprehensive SQL block with table state.Validates the full flow: table state JSON serialization → boilerplate → execute_sql call. Expected output correctly includes pageSize/pageIndex and column configuration.
624d676 to
2caee5f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (5)
packages/blocks/src/blocks/code-blocks.ts (1)
1-2: LGTM!Named import consistent with project-wide standardization.
packages/blocks/src/blocks.ts (1)
39-40: LGTM!Index signature with
unknownenables arbitrary metadata (e.g.,deepnote_table_state) while preserving type safety.packages/blocks/src/blocks/data-frame.ts (1)
1-1: LGTM!Named import aligns with project standards.
packages/blocks/src/blocks/sql-blocks.ts (2)
1-1: LGTM!Import standardization consistent with other files.
41-49: LGTM!
dedentproperly formats the SQL execution call.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (10)
CLAUDE.md(1 hunks)packages/blocks/src/blocks.ts(1 hunks)packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/data-frame.ts(1 hunks)packages/blocks/src/blocks/input-blocks.test.ts(1 hunks)packages/blocks/src/blocks/input-blocks.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/python-code.test.ts(8 hunks)packages/blocks/src/python-snippets.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
packages/blocks/src/python-code.test.ts (4)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(9-13)packages/blocks/src/index.ts (1)
createPythonCode(4-4)packages/blocks/src/python-code.ts (1)
createPythonCode(27-81)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/data-frame.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(9-13)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)packages/blocks/src/blocks/python-utils.ts (1)
escapePythonString(1-7)
packages/blocks/src/blocks/sql-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-18)
packages/blocks/src/blocks/code-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-18)
🔇 Additional comments (27)
packages/blocks/src/blocks/input-blocks.ts (1)
1-1: LGTM!Named import aligns with
ts-dedentpackage structure.Based on learnings
packages/blocks/src/blocks/input-blocks.test.ts (1)
1-1: LGTM!Import style consistent with source file changes.
CLAUDE.md (1)
1-184: LGTM!Comprehensive guide covering repo structure, workflow, and quality standards. Content aligns with modern TypeScript monorepo practices.
packages/blocks/src/python-snippets.ts (1)
1-1: LGTM!Import change consistent across codebase.
packages/blocks/src/blocks/code-blocks.ts (1)
15-23: LGTM!DataFrame config correctly prepended before user code. The blank line separation ensures clean output.
packages/blocks/src/blocks/sql-blocks.ts (3)
39-39: LGTM!DataFrame config generation correctly placed before execution paths.
52-56: LGTM!Config correctly prepended in undefined-variable path.
59-64: LGTM!Config correctly prepended in defined-variable path. Both execution paths now include DataFrame configuration.
packages/blocks/src/blocks/data-frame.test.ts (7)
1-6: LGTM!Named import from ts-dedent aligns with best practices.
9-29: LGTM!Validates guard structure and empty state serialization.
31-75: LGTM!Comprehensive validation of full table state serialization.
77-122: LGTM!Validates SQL block support.
124-142: LGTM!Validates fallback for missing table state.
144-168: LGTM!Correctly validates double-escaping for JSON in Python strings. The comment explaining the escaping logic is helpful.
170-214: LGTM!Comprehensive coverage of complex table state scenarios.
packages/blocks/src/python-code.test.ts (12)
1-1: LGTM!Import change aligns with ts-dedent best practices.
169-177: LGTM!Correctly validates boilerplate injection before user code.
179-225: LGTM!Validates full table state serialization in code block output.
227-254: LGTM!Validates custom pagination parameters in serialized state.
256-282: LGTM!Validates hidden column IDs in serialized state.
590-605: LGTM!Correctly validates boilerplate before execute_sql with variable assignment.
622-636: LGTM!Validates boilerplate before execute_sql without variable assignment.
655-670: LGTM!Validates boilerplate with query_preview return type.
687-702: LGTM!Validates boilerplate with fallback integration ID.
720-735: LGTM!Validates boilerplate before execute_sql with special characters in SQL.
737-792: LGTM!Comprehensive validation of SQL block with full table state serialization.
794-823: LGTM!Validates custom pagination in SQL block output.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (10)
CLAUDE.md(1 hunks)packages/blocks/src/blocks.ts(1 hunks)packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/data-frame.ts(1 hunks)packages/blocks/src/blocks/input-blocks.test.ts(1 hunks)packages/blocks/src/blocks/input-blocks.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/python-code.test.ts(8 hunks)packages/blocks/src/python-snippets.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
packages/blocks/src/blocks/code-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-18)
packages/blocks/src/blocks/data-frame.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(9-13)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-18)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/data-frame.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(9-13)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)packages/blocks/src/blocks/python-utils.ts (1)
escapePythonString(1-7)
packages/blocks/src/python-code.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(9-13)packages/blocks/src/python-code.ts (1)
createPythonCode(27-81)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(19-23)
packages/blocks/src/blocks/sql-blocks.ts (1)
packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-18)
🔇 Additional comments (21)
packages/blocks/src/blocks/input-blocks.ts (1)
1-1: LGTM!Named import aligns with ts-dedent 2.2.0+ and project standards.
packages/blocks/src/blocks/input-blocks.test.ts (1)
1-1: LGTM!Matches project-wide import standardization.
packages/blocks/src/python-snippets.ts (1)
1-1: LGTM!Consistent import style across the codebase.
packages/blocks/src/blocks.ts (1)
39-40: LGTM!Index signature with
unknownallows dynamic metadata while preserving type safety. Supports the table state feature properly.CLAUDE.md (1)
1-184: LGTM!Comprehensive developer guide with accurate tooling references and clear guidelines. Well-structured for both AI assistants and human developers.
packages/blocks/src/blocks/code-blocks.ts (3)
1-1: LGTM!Named import aligns with project standards.
5-5: LGTM!Clean integration with the data-frame module.
15-23: LGTM!Cleanly injects table state config before user code. The dedent template handles indentation properly.
packages/blocks/src/blocks/data-frame.ts (1)
1-1: LGTM!Named import matches project standards.
packages/blocks/src/blocks/sql-blocks.ts (5)
1-1: LGTM!Matches project-wide import standardization.
5-5: LGTM!Clean integration with data-frame module.
39-49: LGTM!Table config setup and dedented SQL call template are clean.
51-57: LGTM!Properly injects table config for undefined-variable path.
59-65: LGTM!Properly injects table config for defined-variable path. Pattern is consistent across both code and SQL blocks.
packages/blocks/src/blocks/data-frame.test.ts (4)
1-1: Named import aligns with best practice.Based on learnings, the named export form is preferred for TypeScript/ESM projects.
9-75: LGTM!Tests validate both empty and populated table state scenarios correctly, including the conditional
_dntkcheck and fallback assignment.
144-168: LGTM!Escaping test correctly validates multi-layer escaping (JSON → Python string). The nested quotes are handled properly by the combination of
JSON.stringifyandescapePythonString.
170-214: LGTM!Comprehensive test validates complex table state with sorting, filtering, pagination, hidden columns, and formatting rules.
packages/blocks/src/python-code.test.ts (3)
1-1: Named import aligns with best practice.Consistent with ts-dedent conventions and other test files in this PR.
156-282: LGTM!Code block tests correctly validate that the dataframe config boilerplate is prepended in all scenarios (empty state, full state, custom pagination, hidden columns). The boilerplate defaulting to
{}for blocks without table state is intentional.
571-823: LGTM!SQL block tests comprehensively validate the integration of dataframe config across various scenarios: with/without variable names, different return types, missing integration IDs, special character escaping, and table state configurations.
saltenasl
left a comment
There was a problem hiding this comment.
The only blocking thing is to test that the SQL query code is escaped.
The fact that the escape utility doesn't have tests can be addressed in a separate PR
| export function createPythonCodeForCodeBlock(block: CodeBlock): string { | ||
| return block.content | ||
| const dataFrameConfig = createDataFrameConfig(block) | ||
|
|
||
| return dedent` | ||
| ${dataFrameConfig} | ||
|
|
||
| ${block.content} | ||
| ` | ||
| } |
There was a problem hiding this comment.
Nit - i can't do a code suggestion but along the lines of:
export const createPythonCodeForCodeBlock = (block: CodeBlock): string => dedent`
${createDataFrameConfig(block)}
${block.content}
`
| `) | ||
| }) | ||
|
|
||
| it('escapes special characters in JSON string', () => { |
There was a problem hiding this comment.
This should be tested in the utility function instead, otherwise, if we end up removing the data-frame.ts file we will remove the tests for the utility.
There was a problem hiding this comment.
OK, I've thought about this further and think we need the test in both places:
- The utility function should be tested inclusive of all edge cases
- This function needs to be tested that it is indeed using the utility to escape (because removal of it should break tests as it will break user code).
There was a problem hiding this comment.
I added the test to the python-code tests as well
|
|
||
| expect(result).toContain('"hiddenColumnIds":["secret"]') | ||
| }) | ||
| }) |
There was a problem hiding this comment.
lets please add a test that the query code is escaped
| | MarkdownCellMetadata | ||
|
|
||
| export interface ExecutableBlockMetadata { | ||
| [key: string]: unknown |
There was a problem hiding this comment.
Is the purpose of this adding the data table related fields? If so, can we list them explicitly? Allowing any key here may be unnecessarily permissive.
There was a problem hiding this comment.
I've added the real types.
| import type { SqlBlock } from './sql-blocks' | ||
|
|
||
| export function createDataFrameConfig(block: CodeBlock | SqlBlock): string { | ||
| const rawTableState = 'deepnote_table_state' in block.metadata ? block.metadata.deepnote_table_state : {} |
There was a problem hiding this comment.
Why is the key presence check needed? Wouldn't it be enough to do block.metadata.deepnote_table_state ?? {}?
There was a problem hiding this comment.
It's not needed now that we have the explicit types. Updated!
| export function createDataFrameConfig(block: CodeBlock | SqlBlock): string { | ||
| const rawTableState = 'deepnote_table_state' in block.metadata ? block.metadata.deepnote_table_state : {} | ||
| const tableState = rawTableState ?? {} | ||
| const tableStateAsJson = JSON.stringify(tableState) ?? '{}' |
There was a problem hiding this comment.
Why is this fallback needed? Shouldn't this always be at least {} before the stringifying?
(may seem like a nitpick but any fallback like this makes the reader wonder whether there is some random edge case that this is covering)
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/python-code.test.ts(8 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-03T15:02:01.006Z
Learnt from: jankuca
PR: deepnote/deepnote#17463
File: apps/webapp-client/src/features/drag-n-drop/CellDropTarget.tsx:63-67
Timestamp: 2025-09-03T15:02:01.006Z
Learning: In the Deepnote codebase, follow Google casing rules for compound words in camelCase - prefer "Sql" over "SQL", so useInsertEmptyDataframeSqlBlock is preferred over useInsertEmptyDataframeSQLBlock.
Applied to files:
packages/blocks/src/blocks/sql-blocks.ts
🧬 Code graph analysis (2)
packages/blocks/src/blocks/data-frame.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(16-20)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(25-29)packages/blocks/src/blocks/python-utils.ts (1)
escapePythonString(1-7)
packages/blocks/src/blocks/code-blocks.ts (2)
packages/blocks/src/blocks.ts (1)
ExecutableBlockMetadata(38-48)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)
🪛 GitHub Check: Typecheck
packages/blocks/src/python-code.test.ts
[failure] 237-237:
Object literal may only specify known properties, and 'filters' does not exist in type '{ columnOrder: string[]; pageIndex: number; pageSize: number; sortBy: { id: string; type: string; }[]; }'.
[failure] 189-189:
Object literal may only specify known properties, and 'filters' does not exist in type '{ columnOrder: string[]; pageIndex: number; pageSize: number; sortBy: { id: string; type: string; }[]; }'.
🔇 Additional comments (4)
packages/blocks/src/blocks/data-frame.ts (1)
7-17: LGTM!Clean implementation. Nullish coalescing handles missing table state, and the conditional Python logic routes to
_dntkor fallback variable as needed.packages/blocks/src/blocks/sql-blocks.ts (1)
45-70: Clean integration of dataFrameConfig.The dedented template properly prefixes SQL execution with table state configuration. Logic correctly handles both variable assignment and direct return paths.
packages/blocks/src/blocks/code-blocks.ts (1)
22-30: LGTM!Straightforward integration—dataFrameConfig prepended to block content via dedent.
packages/blocks/src/python-code.test.ts (1)
169-177: Test coverage looks solid.Guarded boilerplate generation, empty vs. populated table states, special character escaping, and various SQL scenarios are all covered.
Also applies to: 217-225, 618-633, 650-664, 683-698, 715-730, 748-763, 805-819
| deepnote_table_state: { | ||
| columnOrder: string[] | ||
| pageIndex: number | ||
| pageSize: number | ||
| sortBy: { id: string; type: string }[] | ||
| } |
There was a problem hiding this comment.
Type definition incomplete—compilation will fail.
The type defines 4 properties but tests use at least 10: filters, hiddenColumnIds, columnDisplayNames, conditionalFilters, cellFormattingRules, wrappedTextColumnIds are missing.
Apply this diff to align with test expectations:
export interface SqlBlockMetadata extends ExecutableBlockMetadata {
deepnote_return_variable_type?: SqlBlockVariableType
deepnote_table_state: {
columnOrder: string[]
+ columnDisplayNames: string[]
+ hiddenColumnIds: string[]
+ wrappedTextColumnIds: string[]
pageIndex: number
pageSize: number
sortBy: { id: string; type: string }[]
+ filters: unknown[]
+ conditionalFilters: unknown[]
+ cellFormattingRules: unknown[]
}
deepnote_variable_name?: string
function_export_name?: string
is_compiled_sql_query_visible?: boolean
sql_integration_id?: string
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| deepnote_table_state: { | |
| columnOrder: string[] | |
| pageIndex: number | |
| pageSize: number | |
| sortBy: { id: string; type: string }[] | |
| } | |
| deepnote_table_state: { | |
| columnOrder: string[] | |
| columnDisplayNames: string[] | |
| hiddenColumnIds: string[] | |
| wrappedTextColumnIds: string[] | |
| pageIndex: number | |
| pageSize: number | |
| sortBy: { id: string; type: string }[] | |
| filters: unknown[] | |
| conditionalFilters: unknown[] | |
| cellFormattingRules: unknown[] | |
| } |
🤖 Prompt for AI Agents
In packages/blocks/src/blocks/sql-blocks.ts around lines 13 to 18, the
deepnote_table_state type only lists columnOrder, pageIndex, pageSize and sortBy
but tests expect additional properties causing compilation failures; update the
type to include the missing properties used by tests — add filters (array),
hiddenColumnIds (string[]), columnDisplayNames (Record<string,string>),
conditionalFilters (array), cellFormattingRules (array), and
wrappedTextColumnIds (string[]), using appropriate specific types if known (or
unknown/any for complex shapes) and make them required to match test usage.
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
packages/blocks/src/python-code.test.ts (1)
749-753: SQL string escaping test — addresses prior feedbackCovers single quotes and newlines; matches expected escaping.
packages/blocks/src/blocks/code-blocks.ts (1)
21-25: Minor style nit: inline as one-liner arrow (optional)Could be simplified per prior suggestion to a one-liner template. No behavior change.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (6)
packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/blocks/table-state.ts(1 hunks)packages/blocks/src/index.ts(1 hunks)packages/blocks/src/python-code.test.ts(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/blocks/src/blocks/data-frame.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(12-16)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(21-25)
packages/blocks/src/blocks/code-blocks.ts (3)
packages/blocks/src/blocks.ts (1)
ExecutableBlockMetadata(38-48)packages/blocks/src/blocks/table-state.ts (1)
TableState(1-12)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)
packages/blocks/src/blocks/sql-blocks.ts (3)
packages/blocks/src/blocks.ts (1)
ExecutableBlockMetadata(38-48)packages/blocks/src/blocks/table-state.ts (1)
TableState(1-12)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)
🔇 Additional comments (21)
packages/blocks/src/blocks/table-state.ts (1)
1-12: TableState shape matches usages/testsCovers all fields referenced in tests and other modules. Looks good.
packages/blocks/src/python-code.test.ts (12)
1-1: Consistent dedent importNamed import adopted. Good move.
169-177: Code block prelude (no table state) — OKAsserts the guarded dataframe config with empty JSON.
179-225: Code block prelude with table state — OKValidates proper JSON injection and placement before content.
227-254: Custom page size/index in code block — OKAssertions are precise and robust.
256-283: Hidden columns in code block — OKCoverage for hiddenColumnIds present.
284-310: Escaping within table state JSON — OKBackslashes and quotes correctly escaped end-to-end.
619-623: SQL prelude (no table state) — OKCorrectly emits guarded formatter config.
651-655: SQL without variable name — OKPrelude present; execution call formatted as expected.
684-688: SQL query_preview path — OKPrelude included; return type handled.
716-720: SQL without integration id — OKFalls back to SQL_ALCHEMY_JSON_ENV_VAR correctly, with prelude.
765-820: SQL block with table state — OKValidates JSON passthrough and prelude placement before execute_sql.
822-851: Custom page size/index in SQL block — OKAssertions confirm correct serialization.
packages/blocks/src/index.ts (1)
1-1: Publicly exporting TableState — OKKeeps API surface coherent with new metadata usage.
packages/blocks/src/blocks/sql-blocks.ts (2)
14-15: SqlBlockMetadata extended with deepnote_table_state — OKType aligned with TableState and tests.
41-51: Always prepend dataframe config — OKdataFrameConfig is injected in both branches; execute_sql call stays clean and dedented. Escaped query usage is correct.
Also applies to: 54-58, 62-63
packages/blocks/src/blocks/code-blocks.ts (1)
8-10: CodeBlockMetadata extended with deepnote_table_state — OKType addition matches consumers.
packages/blocks/src/blocks/data-frame.test.ts (4)
9-29: LGTM!Correctly validates empty table state produces
'{}'in Python output.
124-142: LGTM!Correctly validates the
?? {}fallback whendeepnote_table_stateis missing.
144-168: LGTM!Escaping test correctly validates:
- Single quotes:
'→\'(Python string)- Double quotes:
"→\"(JSON) →\\"(Python string)The multi-layer escaping in the string literal is accurate.
1-1: ts-dedent import is correct All imports use nameddedentconsistently across the codebase; no further action needed.
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
packages/blocks/src/blocks/code-blocks.ts (1)
19-25: Inline and simplify templateMinor nit: avoid the temporary and inline for readability.
-export function createPythonCodeForCodeBlock(block: CodeBlock): string { - const dataFrameConfig = createDataFrameConfig(block) - - return dedent` - ${dataFrameConfig} - - ${block.content} - ` -} +export function createPythonCodeForCodeBlock(block: CodeBlock): string { + return dedent` + ${createDataFrameConfig(block)} + + ${block.content} + ` +}packages/blocks/src/python-code.test.ts (1)
732-763: SQL query escaping test added—thanks.Correctly escapes quotes and newlines; resolves earlier feedback.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (6)
packages/blocks/src/blocks/code-blocks.ts(2 hunks)packages/blocks/src/blocks/data-frame.test.ts(1 hunks)packages/blocks/src/blocks/sql-blocks.ts(2 hunks)packages/blocks/src/blocks/table-state.ts(1 hunks)packages/blocks/src/index.ts(1 hunks)packages/blocks/src/python-code.test.ts(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/blocks/src/blocks/code-blocks.ts (3)
packages/blocks/src/blocks.ts (1)
ExecutableBlockMetadata(38-48)packages/blocks/src/blocks/table-state.ts (1)
TableState(1-12)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)
packages/blocks/src/blocks/data-frame.test.ts (3)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(12-16)packages/blocks/src/blocks/data-frame.ts (1)
createDataFrameConfig(7-17)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(21-25)
packages/blocks/src/python-code.test.ts (4)
packages/blocks/src/blocks/code-blocks.ts (1)
CodeBlock(12-16)packages/blocks/src/index.ts (1)
createPythonCode(5-5)packages/blocks/src/python-code.ts (1)
createPythonCode(27-81)packages/blocks/src/blocks/sql-blocks.ts (1)
SqlBlock(21-25)
🔇 Additional comments (10)
packages/blocks/src/index.ts (1)
1-1: Public type export LGTMClean, type-only re-export; no runtime impact.
packages/blocks/src/blocks/sql-blocks.ts (1)
41-66: DataFrame config injection looks correctGood use of dedent and consistent injection in both return paths; assignment with multiline call is valid Python.
packages/blocks/src/blocks/data-frame.test.ts (1)
144-168: Great coverage for escaping edge casesThe explicit assertion for mixed quotes and backslashes is spot-on and guards regressions in escapePythonString.
packages/blocks/src/python-code.test.ts (7)
1-1: Named import for ts-dedent—good.Consistent with best practices and current package API. Based on learnings
227-254: Custom pagination for Code blocks—ok.Asserts pageSize/pageIndex appear in payload.
256-282: Hidden columns propagation—ok.Presence of hiddenColumnIds verified.
284-310: JSON and Python string escaping—good coverage.Backslashes and quotes handled correctly.
765-820: SQL table state JSON injection—ok.End-to-end expectation (including ID normalization) looks right.
822-851: Custom pagination for SQL blocks—ok.pageSize/pageIndex correctly present.
187-198: TableState covers all required deepnote_table_state fields
TableState defines sortBy, filters, pageSize, pageIndex, columnOrder, hiddenColumnIds, columnDisplayNames (with columnName/displayName), conditionalFilters, cellFormattingRules, and wrappedTextColumnIds; both CodeBlockMetadata and SqlBlockMetadata reference deepnote_table_state?: TableState.
Summary by CodeRabbit