Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: add cell data-attributes in read/present (#3538)

Myles Scolnick698e06797263
diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsx
index 4ef325a49c..d9996f3b8b 100644
--- a/frontend/src/components/editor/Cell.tsx
+++ b/frontend/src/components/editor/Cell.tsx
@@ -540,7 +540,14 @@ const CellComponent = (
return null;
}
return (
- <div tabIndex={-1} id={HTMLId} ref={cellRef} className={className}>
+ <div
+ tabIndex={-1}
+ id={HTMLId}
+ ref={cellRef}
+ className={className}
+ data-cell-id={cellId}
+ data-cell-name={name}
+ >
{outputArea}
</div>
);
diff --git a/frontend/src/components/editor/__tests__/data-attributes.test.tsx b/frontend/src/components/editor/__tests__/data-attributes.test.tsx
index bd516677de..be0eb009f8 100644
--- a/frontend/src/components/editor/__tests__/data-attributes.test.tsx
+++ b/frontend/src/components/editor/__tests__/data-attributes.test.tsx
@@ -8,6 +8,7 @@ import type { OutputMessage } from "@/core/kernel/messages";
import { Functions } from "@/utils/functions";
import type { UserConfig } from "@/core/config/config-schema";
import { TooltipProvider } from "@/components/ui/tooltip";
+import type { AppMode } from "@/core/mode";
beforeAll(() => {
global.ResizeObserver = class ResizeObserver {
@@ -27,95 +28,98 @@ beforeAll(() => {
});
describe("Cell data attributes", () => {
- it("should render cell with data-cell-id and data-cell-name", () => {
- const cellId = "test" as CellId;
- const cellName = "test_cell";
+ it.each(["edit", "read", "present"])(
+ "should render cell with data-cell-id and data-cell-name in %s mode",
+ (mode) => {
+ const cellId = "test" as CellId;
+ const cellName = "test_cell";
- const userConfig: UserConfig = {
- display: {
- cell_output: "below",
- code_editor_font_size: 14,
- dataframes: "rich",
- default_width: "normal",
- theme: "light",
- },
- keymap: { preset: "default" },
- completion: {
- activate_on_typing: true,
- copilot: false,
- },
- formatting: { line_length: 88 },
- package_management: { manager: "pip" },
- runtime: {
- auto_instantiate: false,
- auto_reload: "off",
- on_cell_change: "lazy",
- },
- server: {
- browser: "default",
- follow_symlink: false,
- },
- save: { autosave: "off", autosave_delay: 1000, format_on_save: false },
- ai: {},
- };
+ const userConfig: UserConfig = {
+ display: {
+ cell_output: "below",
+ code_editor_font_size: 14,
+ dataframes: "rich",
+ default_width: "normal",
+ theme: "light",
+ },
+ keymap: { preset: "default" },
+ completion: {
+ activate_on_typing: true,
+ copilot: false,
+ },
+ formatting: { line_length: 88 },
+ package_management: { manager: "pip" },
+ runtime: {
+ auto_instantiate: false,
+ auto_reload: "off",
+ on_cell_change: "lazy",
+ },
+ server: {
+ browser: "default",
+ follow_symlink: false,
+ },
+ save: { autosave: "off", autosave_delay: 1000, format_on_save: false },
+ ai: {},
+ };
- const { container } = render(
- <TooltipProvider>
- <Cell
- id={cellId}
- name={cellName}
- code=""
- output={null}
- consoleOutputs={[]}
- status="idle"
- edited={false}
- interrupted={false}
- errored={false}
- stopped={false}
- staleInputs={false}
- runStartTimestamp={null}
- lastRunStartTimestamp={null}
- runElapsedTimeMs={null}
- serializedEditorState={null}
- mode="edit"
- debuggerActive={false}
- appClosed={false}
- canDelete={true}
- updateCellCode={Functions.NOOP}
- prepareForRun={Functions.NOOP}
- createNewCell={Functions.NOOP}
- deleteCell={Functions.NOOP}
- focusCell={Functions.NOOP}
- moveCell={Functions.NOOP}
- setStdinResponse={Functions.NOOP}
- moveToNextCell={Functions.NOOP}
- updateCellConfig={Functions.NOOP}
- clearSerializedEditorState={Functions.NOOP}
- sendToBottom={Functions.NOOP}
- sendToTop={Functions.NOOP}
- collapseCell={Functions.NOOP}
- expandCell={Functions.NOOP}
- userConfig={userConfig}
- outline={null}
- isCollapsed={false}
- collapseCount={0}
- config={{
- disabled: false,
- hide_code: false,
- column: null,
- }}
- canMoveX={false}
- theme="light"
- showPlaceholder={false}
- allowFocus={true}
- />
- </TooltipProvider>,
- );
+ const { container } = render(
+ <TooltipProvider>
+ <Cell
+ id={cellId}
+ name={cellName}
+ code=""
+ output={null}
+ consoleOutputs={[]}
+ status="idle"
+ edited={false}
+ interrupted={false}
+ errored={false}
+ stopped={false}
+ staleInputs={false}
+ runStartTimestamp={null}
+ lastRunStartTimestamp={null}
+ runElapsedTimeMs={null}
+ serializedEditorState={null}
+ mode={mode as AppMode}
+ debuggerActive={false}
+ appClosed={false}
+ canDelete={true}
+ updateCellCode={Functions.NOOP}
+ prepareForRun={Functions.NOOP}
+ createNewCell={Functions.NOOP}
+ deleteCell={Functions.NOOP}
+ focusCell={Functions.NOOP}
+ moveCell={Functions.NOOP}
+ setStdinResponse={Functions.NOOP}
+ moveToNextCell={Functions.NOOP}
+ updateCellConfig={Functions.NOOP}
+ clearSerializedEditorState={Functions.NOOP}
+ sendToBottom={Functions.NOOP}
+ sendToTop={Functions.NOOP}
+ collapseCell={Functions.NOOP}
+ expandCell={Functions.NOOP}
+ userConfig={userConfig}
+ outline={null}
+ isCollapsed={false}
+ collapseCount={0}
+ config={{
+ disabled: false,
+ hide_code: false,
+ column: null,
+ }}
+ canMoveX={false}
+ theme="light"
+ showPlaceholder={false}
+ allowFocus={true}
+ />
+ </TooltipProvider>,
+ );
- const cellElement = container.querySelector(`[data-cell-id="${cellId}"]`);
- expect(cellElement).toBeTruthy();
- expect(cellElement?.getAttribute("data-cell-name")).toBe(cellName);
- });
+ const cellElement = container.querySelector(`[data-cell-id="${cellId}"]`);
+ expect(cellElement).toBeTruthy();
+ expect(cellElement?.getAttribute("data-cell-name")).toBe(cellName);
+ },
+ );
});
describe("Output data attributes", () => {
diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
index 4fdccbad67..cb05f92caa 100644
--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx
@@ -324,7 +324,14 @@ const VerticalCell = memo(
const isCodeEmpty = code.trim() === "";
return (
- <div tabIndex={-1} id={HTMLId} ref={cellRef} className={className}>
+ <div
+ tabIndex={-1}
+ id={HTMLId}
+ ref={cellRef}
+ className={className}
+ data-cell-id={cellId}
+ data-cell-name={name}
+ >
{cellOutputArea === "above" && outputArea}
{/* Hide code if it's empty or pure markdown */}
{!isPureMarkdown && !isCodeEmpty && (
@@ -355,7 +362,14 @@ const VerticalCell = memo(
}
return (
- <div tabIndex={-1} id={HTMLId} ref={cellRef} className={className}>
+ <div
+ tabIndex={-1}
+ id={HTMLId}
+ ref={cellRef}
+ className={className}
+ data-cell-id={cellId}
+ data-cell-name={name}
+ >
<OutputArea
allowExpand={mode === "edit"}
output={output}