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
Update cell state to track elapsed run time and display it in cell status tooltip (#277)
Myles Scolnick15e6f854ce61
diff --git a/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap b/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snapindex 358486662d..ecb24f97fe 100644--- a/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap+++ b/frontend/src/core/state/__tests__/__snapshots__/cells.test.ts.snap@@ -523,7 +523,7 @@ import numpy","ref": {"current": null,},- "runElapsedTimeMs": null,+ "runElapsedTimeMs": 11000,"runStartTimestamp": null,"serializedEditorState": null,"status": "idle",diff --git a/frontend/src/core/state/__tests__/cells.test.ts b/frontend/src/core/state/__tests__/cells.test.tsindex 561f44c9b6..7ea1538946 100644--- a/frontend/src/core/state/__tests__/cells.test.ts+++ b/frontend/src/core/state/__tests__/cells.test.ts@@ -409,7 +409,7 @@ describe("cell reducer", () => {expect(cell.status).toBe("idle");expect(cell.lastCodeRun).toBe("import marimo as mo\nimport numpy");expect(cell.edited).toBe(false);- expect(cell.runElapsedTimeMs).toBe(null);+ expect(cell.runElapsedTimeMs).toBe(11_000);expect(cell.runStartTimestamp).toBe(null);expect(cell).toMatchSnapshot(); // snapshot everything as a catch alldiff --git a/frontend/src/core/state/cell.ts b/frontend/src/core/state/cell.tsindex 0ba1dc3d63..6fff1f191c 100644--- a/frontend/src/core/state/cell.ts+++ b/frontend/src/core/state/cell.ts@@ -68,11 +68,18 @@ export function transitionCell(// The cell didn't run, but it was intentional, so don't count as// errored.nextCell.stopped = true;- nextCell.runElapsedTimeMs = null;+ // Update elapsed time, since it is still useful to know how long before+ // the cell was stopped.+ nextCell.runElapsedTimeMs = cell.runStartTimestamp+ ? (message.timestamp - cell.runStartTimestamp) * 1000+ : null;} else {nextCell.errored = true;- // The cell didn't actually run.- nextCell.runElapsedTimeMs = null;+ // Update elapsed time, since it is still useful to know how long before+ // the cell was stopped.+ nextCell.runElapsedTimeMs = cell.runStartTimestamp+ ? (message.timestamp - cell.runStartTimestamp) * 1000+ : null;}}diff --git a/frontend/src/editor/cell/CellStatus.tsx b/frontend/src/editor/cell/CellStatus.tsxindex 787270e259..98038d3563 100644--- a/frontend/src/editor/cell/CellStatus.tsx+++ b/frontend/src/editor/cell/CellStatus.tsx@@ -151,19 +151,36 @@ export const CellStatusComponent: React.FC<CellStatusComponentProps> = ({// outdatedif (edited || interrupted) {+ const elapsedTimeStr = formatElapsedTime(elapsedTime);const title = interrupted? "This cell was interrupted when it was last run": "This cell has been modified since it was last run";+ const timerTitle = interrupted+ ? `This cell ran for ${elapsedTimeStr} before being interrupted`+ : `This cell took ${elapsedTimeStr} to run`;return (- <Tooltip content={title} usePortal={false}>- <div- className="cell-status-icon cell-status-stale"- data-testid="cell-status"- data-status="outdated"- >- <RefreshCwIcon className="h-5 w-5" strokeWidth={1.5} />- </div>- </Tooltip>+ <div className="cell-status-icon flex items-center gap-2">+ <Tooltip content={title} usePortal={false}>+ <div+ className="cell-status-stale"+ data-testid="cell-status"+ data-status="outdated"+ >+ <RefreshCwIcon className="h-5 w-5" strokeWidth={1.5} />+ </div>+ </Tooltip>+ {elapsedTimeStr && (+ <Tooltip content={timerTitle} usePortal={false}>+ <div+ className={"elapsed-time hover-action"}+ data-testid="cell-status"+ data-status="outdated"+ >+ <span>{elapsedTimeStr}</span>+ </div>+ </Tooltip>+ )}+ </div>);}