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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: added expandAllCells in cells.ts (#4791)
Joaquin Coromina93f16a953ce6
diff --git a/frontend/src/core/cells/__tests__/cells.test.ts b/frontend/src/core/cells/__tests__/cells.test.tsindex 3a4a6c08d0..d3d0fac615 100644--- a/frontend/src/core/cells/__tests__/cells.test.ts+++ b/frontend/src/core/cells/__tests__/cells.test.ts@@ -48,6 +48,7 @@ vi.mock("../scrollCellIntoView", async (importOriginal) => {});const FIRST_COLUMN = 0;+const SECOND_COLUMN = 1;const { initialNotebookState, reducer, createActions } = exportedForTesting;@@ -1446,6 +1447,127 @@ describe("cell reducer", () => {expect(state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(id)).toBe(false);});+ it("can expand all cells in multiple columns", () => {+ actions.createNewCell({ cellId: firstCellId, before: false });+ actions.createNewCell({+ cellId: "1" as CellId,+ before: false,+ code: "# First Column Header",+ });+ actions.createNewCell({+ cellId: "2" as CellId,+ before: false,+ code: "## First Column Subheader",+ });++ actions.addColumnBreakpoint({ cellId: "2" as CellId });++ actions.createNewCell({+ cellId: "3" as CellId,+ before: false,+ code: "# Second Column Header",+ });+ actions.createNewCell({+ cellId: "4" as CellId,+ before: false,+ code: "## Second Column Subheader",+ });++ const firstColumnHeaderId = state.cellIds+ .atOrThrow(FIRST_COLUMN)+ .atOrThrow(1);+ state.cellRuntime[firstColumnHeaderId] = {+ ...state.cellRuntime[firstColumnHeaderId],+ outline: {+ items: [+ { name: "First Column Header", level: 1, by: { id: "header" } },+ ],+ },+ };++ const secondColumnHeaderId = state.cellIds+ .atOrThrow(SECOND_COLUMN)+ .atOrThrow(0);+ state.cellRuntime[secondColumnHeaderId] = {+ ...state.cellRuntime[secondColumnHeaderId],+ outline: {+ items: [+ { name: "Second Column Header", level: 1, by: { id: "header" } },+ ],+ },+ };++ actions.collapseCell({ cellId: firstColumnHeaderId });+ expect(+ state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(firstColumnHeaderId),+ ).toBe(true);++ actions.collapseCell({ cellId: secondColumnHeaderId });+ expect(+ state.cellIds.atOrThrow(SECOND_COLUMN).isCollapsed(secondColumnHeaderId),+ ).toBe(true);++ actions.expandAllCells();+ expect(+ state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(firstColumnHeaderId),+ ).toBe(false);+ expect(+ state.cellIds.atOrThrow(SECOND_COLUMN).isCollapsed(secondColumnHeaderId),+ ).toBe(false);+ });++ it("can expand nested cells in one call", () => {+ actions.createNewCell({ cellId: firstCellId, before: false });+ actions.createNewCell({+ cellId: "1" as CellId,+ before: false,+ code: "# Header",+ });+ actions.createNewCell({+ cellId: "2" as CellId,+ before: false,+ code: "## Subheader",+ });+ actions.createNewCell({+ cellId: "3" as CellId,+ before: false,+ code: "### Subsubheader",+ });++ const headerId = state.cellIds.atOrThrow(FIRST_COLUMN).atOrThrow(1);+ state.cellRuntime[headerId] = {+ ...state.cellRuntime[headerId],+ outline: {+ items: [{ name: "Header", level: 1, by: { id: "header" } }],+ },+ };++ const subheaderId = state.cellIds.atOrThrow(FIRST_COLUMN).atOrThrow(2);+ state.cellRuntime[subheaderId] = {+ ...state.cellRuntime[subheaderId],+ outline: {+ items: [{ name: "Subheader", level: 2, by: { id: "subheader" } }],+ },+ };++ actions.collapseCell({ cellId: subheaderId });+ expect(state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(subheaderId)).toBe(+ true,+ );+ actions.collapseCell({ cellId: headerId });+ expect(state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(headerId)).toBe(+ true,+ );++ actions.expandAllCells();+ expect(state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(headerId)).toBe(+ false,+ );+ expect(state.cellIds.atOrThrow(FIRST_COLUMN).isCollapsed(subheaderId)).toBe(+ false,+ );+ });+it("can show hidden cells", () => {actions.createNewCell({ cellId: firstCellId, before: false });actions.createNewCell({ cellId: "1" as CellId, before: false });diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.tsindex db665e66cd..e714a6d1cb 100644--- a/frontend/src/core/cells/cells.ts+++ b/frontend/src/core/cells/cells.ts@@ -1076,6 +1076,12 @@ const {scrollKey: cellId,};},+ expandAllCells: (state) => {+ return {+ ...state,+ cellIds: state.cellIds.transformAll((column) => column.expandAll()),+ };+ },showCellIfHidden: (state, action: { cellId: CellId }) => {const { cellId } = action;const column = state.cellIds.findWithId(cellId);