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.

Add 'Run cell' action to cellActionButtons and update cell status in CellComponent (#279)

Myles Scolnick480b3badf201
diff --git a/frontend/src/editor/Cell.tsx b/frontend/src/editor/Cell.tsx
index 0e740354d5..14c73551aa 100644
--- a/frontend/src/editor/Cell.tsx
+++ b/frontend/src/editor/Cell.tsx
@@ -443,6 +443,7 @@ const CellComponent = (
<CellActionsContextMenu
cellId={cellId}
config={cellConfig}
+ status={status}
editorView={editorView.current}
hasOutput={!!output}
>
@@ -496,6 +497,7 @@ const CellComponent = (
/>
<CellActionsDropdown
cellId={cellId}
+ status={status}
editorView={editorView.current}
config={cellConfig}
hasOutput={!!output}
diff --git a/frontend/src/editor/actions/useCellActionButton.tsx b/frontend/src/editor/actions/useCellActionButton.tsx
index a225dd7c46..81013da53b 100644
--- a/frontend/src/editor/actions/useCellActionButton.tsx
+++ b/frontend/src/editor/actions/useCellActionButton.tsx
@@ -14,16 +14,19 @@ import {
ChevronsDownIcon,
Trash2Icon,
ZapOffIcon,
+ PlayIcon,
} from "lucide-react";
import { ActionButton } from "./types";
import { MultiIcon } from "@/components/icons/multi-icon";
-import { CellConfig } from "@/core/model/cells";
+import { CellConfig, CellStatus } from "@/core/model/cells";
import { CellId } from "@/core/model/ids";
import { saveCellConfig } from "@/core/network/requests";
import { EditorView } from "@codemirror/view";
+import { useRunCell } from "../cell/useRunCells";
export interface CellActionButtonProps {
cellId: CellId;
+ status: CellStatus;
config: CellConfig;
editorView: EditorView | null;
hasOutput: boolean;
@@ -34,6 +37,7 @@ export function useCellActionButtons({
config,
editorView,
hasOutput,
+ status,
}: CellActionButtonProps) {
const {
createNewCell: createCell,
@@ -44,6 +48,7 @@ export function useCellActionButtons({
sendToTop,
sendToBottom,
} = useCellActions();
+ const runCell = useRunCell(cellId);
const toggleDisabled = async () => {
if (config.disabled) {
await saveCellConfig({ configs: { [cellId]: { disabled: false } } });
@@ -57,6 +62,17 @@ export function useCellActionButtons({
// Actions
const actions: ActionButton[][] = [
[
+ {
+ icon: <PlayIcon size={13} strokeWidth={1.5} />,
+ label: "Run cell",
+ hotkey: "cell.run",
+ hidden:
+ status === "running" ||
+ status === "queued" ||
+ status === "disabled-transitively" ||
+ config.disabled === true,
+ handle: () => runCell(),
+ },
{
icon: <ImageIcon size={13} strokeWidth={1.5} />,
label: "Export to PNG",
diff --git a/frontend/src/editor/cell/cell-actions.tsx b/frontend/src/editor/cell/cell-actions.tsx
index 9282192429..73652fe025 100644
--- a/frontend/src/editor/cell/cell-actions.tsx
+++ b/frontend/src/editor/cell/cell-actions.tsx
@@ -25,16 +25,6 @@ import {
CellActionButtonProps,
useCellActionButtons,
} from "../actions/useCellActionButton";
-import { CellConfig } from "@/core/model/cells";
-import { CellId } from "@/core/model/ids";
-import { EditorView } from "@codemirror/view";
-
-interface Props {
- editorView: EditorView | null;
- hasOutput: boolean;
- cellId: CellId;
- config: CellConfig;
-}
interface Props extends CellActionButtonProps {
children: React.ReactNode;
diff --git a/frontend/src/editor/cell/useRunCells.ts b/frontend/src/editor/cell/useRunCells.ts
index 776fb4a31f..fdd8e3ca73 100644
--- a/frontend/src/editor/cell/useRunCells.ts
+++ b/frontend/src/editor/cell/useRunCells.ts
@@ -7,6 +7,9 @@ import { useCells } from "@/core/state/cells";
import { derefNotNull } from "@/utils/dereference";
import useEvent from "react-use-event-hook";
+/**
+ * Creates a function that runs all cells that have been edited or interrupted.
+ */
export function useRunStaleCells() {
const cells = useCells();
const runCells = useRunCells();
@@ -21,6 +24,26 @@ export function useRunStaleCells() {
return runStaleCells;
}
+/**
+ * Creates a function that runs the cell with the given id.
+ */
+export function useRunCell(cellId: CellId) {
+ const cells = useCells();
+ const runCells = useRunCells();
+
+ const runCell = useEvent(async () => {
+ const cell = cells.present.find((cell) => cell.key === cellId);
+ if (cell) {
+ await runCells([cell]);
+ }
+ });
+
+ return runCell;
+}
+
+/**
+ * Creates a function that runs the given cells.
+ */
export function useRunCells() {
const runCells = useEvent(async (cells: CellState[]) => {
if (cells.length === 0) {