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
improvement: split run and stop buttons (#2119)
Akshay Agrawal576a0d32d828
diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsxindex 9b5b5498f2..9027832dc8 100644--- a/frontend/src/components/editor/Cell.tsx+++ b/frontend/src/components/editor/Cell.tsx@@ -47,6 +47,7 @@ import { useSetAtom } from "jotai";import { aiCompletionCellAtom } from "@/core/ai/state";import { CollapsedCellBanner, CollapseToggle } from "./cell/collapse";import { canCollapseOutline } from "@/core/dom/outline";+import { StopButton } from "@/components/editor/cell/StopButton";/*** Imperative interface of the cell.@@ -503,7 +504,7 @@ const CellComponent = (runStartTimestamp={runStartTimestamp}uninstantiated={uninstantiated}/>- <div className="flex align-bottom">+ <div className="flex gap-2 align-bottom"><RunButtonedited={edited}onClick={appClosed ? Functions.NOOP : handleRun}@@ -512,6 +513,7 @@ const CellComponent = (config={cellConfig}needsRun={needsRun}/>+ <StopButton status={status} appClosed={appClosed} /><CellActionsDropdownref={cellActionDropdownRef}cellId={cellId}diff --git a/frontend/src/components/editor/SortableCell.tsx b/frontend/src/components/editor/SortableCell.tsxindex 68f82eedd5..eb0051f6ab 100644--- a/frontend/src/components/editor/SortableCell.tsx+++ b/frontend/src/components/editor/SortableCell.tsx@@ -56,7 +56,7 @@ const SortableCellInternal = React.forwardRef({...attributes}{...listeners}data-testid="drag-button"- className="py-[1px] mx-2 cursor-grab opacity-50 hover:opacity-100 hover-action hover:bg-muted rounded border border-transparent hover:border-border active:bg-accent"+ className="py-[1px] cursor-grab opacity-50 hover:opacity-100 hover-action hover:bg-muted rounded border border-transparent hover:border-border active:bg-accent"><GripVerticalIcon strokeWidth={1} size={20} /></div>diff --git a/frontend/src/components/editor/cell/RunButton.tsx b/frontend/src/components/editor/cell/RunButton.tsxindex b029083d5c..896466f4e6 100644--- a/frontend/src/components/editor/cell/RunButton.tsx+++ b/frontend/src/components/editor/cell/RunButton.tsx@@ -1,11 +1,9 @@/* Copyright 2024 Marimo. All rights reserved. */-import { HardDriveDownloadIcon, PlayIcon, SquareIcon } from "lucide-react";+import { HardDriveDownloadIcon, PlayIcon } from "lucide-react";import { Button } from "@/components/editor/inputs/Inputs";import { Tooltip } from "../../ui/tooltip";import { renderShortcut } from "../../shortcuts/renderShortcut";import { cn } from "../../../utils/cn";-import { sendInterrupt } from "@/core/network/requests";-import { useShouldShowInterrupt } from "./useShouldShowInterrupt";import type { RuntimeState, CellConfig } from "@/core/network/types";function computeColor(@@ -41,10 +39,6 @@ export const RunButton = (props: {const inactive =appClosed || loading || (!config.disabled && blockedStatus && !edited);const color = computeColor(appClosed, needsRun, loading, inactive);- const running = status === "running";-- // Show the interrupt button after 200ms to avoid flickering.- const showInterrupt = useShouldShowInterrupt(running);if (config.disabled) {return (@@ -88,28 +82,13 @@ export const RunButton = (props: {);}- if (showInterrupt) {- return (- <Tooltip content={renderShortcut("global.interrupt")} usePortal={false}>- <Button- className={cn(appClosed && "inactive-button")}- onClick={sendInterrupt}- color="yellow"- shape="circle"- size="small"- data-testid="run-button"- >- <SquareIcon strokeWidth={1.5} />- </Button>- </Tooltip>- );- }-let tooltipMsg: React.ReactNode = "";if (appClosed) {tooltipMsg = "App disconnected";} else if (status === "queued") {tooltipMsg = "This cell is already queued to run";+ } else if (status === "running") {+ tooltipMsg = "This cell is already running.";} else {tooltipMsg = renderShortcut("cell.run");}@@ -118,7 +97,7 @@ export const RunButton = (props: {<Tooltip content={tooltipMsg} usePortal={false}><ButtonclassName={cn(- !needsRun && "hover-action",+ !needsRun && status !== "running" && "hover-action",inactive && "inactive-button",)}onClick={onClick}diff --git a/frontend/src/components/editor/cell/StopButton.tsx b/frontend/src/components/editor/cell/StopButton.tsxnew file mode 100644index 0000000000..bc33642471--- /dev/null+++ b/frontend/src/components/editor/cell/StopButton.tsx@@ -0,0 +1,41 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { SquareIcon } from "lucide-react";+import { Button } from "@/components/editor/inputs/Inputs";+import { Tooltip } from "../../ui/tooltip";+import { renderShortcut } from "../../shortcuts/renderShortcut";+import { cn } from "../../../utils/cn";+import { sendInterrupt } from "@/core/network/requests";+import { useShouldShowInterrupt } from "./useShouldShowInterrupt";+import type { RuntimeState } from "@/core/network/types";+import { Functions } from "@/utils/functions";++export const StopButton = (props: {+ status: RuntimeState;+ appClosed: boolean;+}): JSX.Element => {+ const { appClosed, status } = props;++ const running = status === "running";++ // Show the interrupt button after 200ms to avoid flickering.+ const showInterrupt = useShouldShowInterrupt(running);++ return (+ <Tooltip content={renderShortcut("global.interrupt")} usePortal={false}>+ <Button+ className={cn(+ !showInterrupt && "hover-action",+ (appClosed || !showInterrupt) &&+ "inactive-button active:shadow-xsSolid",+ )}+ onClick={showInterrupt ? sendInterrupt : Functions.NOOP}+ color={showInterrupt ? "yellow" : "disabled"}+ shape="circle"+ size="small"+ data-testid="run-button"+ >+ <SquareIcon strokeWidth={1.5} />+ </Button>+ </Tooltip>+ );+};diff --git a/frontend/src/components/editor/controls/Controls.tsx b/frontend/src/components/editor/controls/Controls.tsxindex 1f0409ebdf..b9bbcf3ea9 100644--- a/frontend/src/components/editor/controls/Controls.tsx+++ b/frontend/src/components/editor/controls/Controls.tsx@@ -25,6 +25,7 @@ import { useShouldShowInterrupt } from "../cell/useShouldShowInterrupt";import { CommandPaletteButton } from "./command-palette-button";import { cn } from "@/utils/cn";import { HideInKioskMode } from "../kiosk-mode";+import { Functions } from "@/utils/functions";interface ControlsProps {filename: string | null;@@ -148,13 +149,9 @@ export const Controls = ({<div className="flex flex-col gap-2 items-center">{undoControl}{!closed && (- <RunControlButton- running={running}- needsRun={needsRun}- onRun={onRun}- onInterrupt={onInterrupt}- />+ <StopControlButton running={running} onInterrupt={onInterrupt} />)}+ {!closed && <RunControlButton needsRun={needsRun} onRun={onRun} />}</div></HideInKioskMode></div>@@ -163,34 +160,12 @@ export const Controls = ({};const RunControlButton = ({- running,needsRun,onRun,- onInterrupt,}: {- running: boolean;needsRun: boolean;onRun: () => void;- onInterrupt: () => void;}) => {- // Show the interrupt button after 200ms to avoid flickering.- const showInterrupt = useShouldShowInterrupt(running);-- if (showInterrupt) {- return (- <Tooltip content={renderShortcut("global.interrupt")}>- <Button- data-testid="interrupt-button"- size="medium"- color="yellow"- shape="circle"- onClick={onInterrupt}- >- <SquareIcon strokeWidth={1.5} size={16} />- </Button>- </Tooltip>- );- }if (needsRun) {return (<Tooltip content={renderShortcut("global.runStale")}>@@ -222,6 +197,34 @@ const RunControlButton = ({);};+const StopControlButton = ({+ running,+ onInterrupt,+}: {+ running: boolean;+ onInterrupt: () => void;+}) => {+ // Show the interrupt button after 200ms to avoid flickering.+ const showInterrupt = useShouldShowInterrupt(running);++ return (+ <Tooltip content={renderShortcut("global.interrupt")}>+ <Button+ className={cn(+ !showInterrupt && "inactive-button active:shadow-xsSolid",+ )}+ data-testid="interrupt-button"+ size="medium"+ color={showInterrupt ? "yellow" : "disabled"}+ shape="circle"+ onClick={showInterrupt ? onInterrupt : Functions.NOOP}+ >+ <SquareIcon strokeWidth={1.5} size={16} />+ </Button>+ </Tooltip>+ );+};+const topRightControls ="absolute top-3 right-5 m-0 flex items-center space-x-3 min-h-[28px] no-print pointer-events-auto z-30 print:hidden";diff --git a/frontend/src/core/hotkeys/hotkeys.ts b/frontend/src/core/hotkeys/hotkeys.tsindex b90ff1b460..cd3b679d35 100644--- a/frontend/src/core/hotkeys/hotkeys.ts+++ b/frontend/src/core/hotkeys/hotkeys.ts@@ -265,7 +265,7 @@ const DEFAULT_HOT_KEY = {key: "Mod-k",},"global.runStale": {- name: "Run all modified cells",+ name: "Run all stale cells",group: "Running Cells",key: "Mod-Shift-r",},