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 setup cell that has been deleted (#6916)

Shahmir Varqhab6d76da81f86
diff --git a/frontend/src/core/cells/__tests__/cells.test.ts b/frontend/src/core/cells/__tests__/cells.test.ts
index d9d7bab4dd..897826534d 100644
--- a/frontend/src/core/cells/__tests__/cells.test.ts
+++ b/frontend/src/core/cells/__tests__/cells.test.ts
@@ -2109,7 +2109,7 @@ describe("cell reducer", () => {
actions.addSetupCellIfDoesntExist({ code: "# Updated setup code" });
// Check that the same setup cell was updated, not duplicated
- expect(state.cellData[SETUP_CELL_ID].code).toBe("# Setup code");
+ expect(state.cellData[SETUP_CELL_ID].code).toBe("# Updated setup code");
expect(state.cellData[SETUP_CELL_ID].edited).toBe(true);
expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
});
@@ -2143,6 +2143,24 @@ describe("cell reducer", () => {
expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
});
+ it("can delete and then create a new setup cell", () => {
+ // Create the setup cell
+ actions.addSetupCellIfDoesntExist({ code: "# Setup code" });
+
+ // Delete the setup cell
+ actions.deleteCell({ cellId: SETUP_CELL_ID });
+
+ // Create a new setup cell
+ actions.addSetupCellIfDoesntExist({ code: "# New code" });
+
+ // Check that the new setup cell was created
+ expect(state.cellData[SETUP_CELL_ID].id).toBe(SETUP_CELL_ID);
+ expect(state.cellData[SETUP_CELL_ID].name).toBe("setup");
+ expect(state.cellData[SETUP_CELL_ID].code).toBe("# New code");
+ expect(state.cellData[SETUP_CELL_ID].edited).toBe(true);
+ expect(state.cellIds.inOrderIds).toContain(SETUP_CELL_ID);
+ });
+
it("can clear all outputs", () => {
// Add a cell and give it output
actions.createNewCell({
diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.ts
index c7519fdc60..7e1a0a0f64 100644
--- a/frontend/src/core/cells/cells.ts
+++ b/frontend/src/core/cells/cells.ts
@@ -1336,7 +1336,7 @@ const {
}
// First check if setup cell already exists
- if (SETUP_CELL_ID in state.cellData) {
+ if (SETUP_CELL_ID in state.cellIds) {
// Just focus on the existing setup cell
return {
...state,