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
fix: disable controls when not connected (#5438)
Akshay Agrawal61656fd02540
diff --git a/frontend/src/components/app-config/app-config-button.tsx b/frontend/src/components/app-config/app-config-button.tsxindex 0009a2a6f5..aaf47ac673 100644--- a/frontend/src/components/app-config/app-config-button.tsx+++ b/frontend/src/components/app-config/app-config-button.tsx@@ -17,10 +17,17 @@ import { UserConfigForm } from "./user-config-form";interface Props {showAppConfig?: boolean;+ disabled?: boolean;+ tooltip?: string;}-export const ConfigButton: React.FC<Props> = ({ showAppConfig = true }) => {+export const ConfigButton: React.FC<Props> = ({+ showAppConfig = true,+ disabled = false,+ tooltip = "Settings",+}) => {const [settingDialog, setSettingDialog] = useAtom(settingDialogAtom);+const button = (<EditorButtonaria-label="Config"@@ -28,9 +35,10 @@ export const ConfigButton: React.FC<Props> = ({ showAppConfig = true }) => {shape="circle"size="small"className="h-[27px] w-[27px]"- color="hint-green"+ disabled={disabled}+ color={disabled ? "disabled" : "hint-green"}>- <Tooltip content="Settings">+ <Tooltip content={tooltip}><SettingsIcon strokeWidth={1.8} /></Tooltip></EditorButton>diff --git a/frontend/src/components/editor/controls/Controls.tsx b/frontend/src/components/editor/controls/Controls.tsxindex 78badc6ed8..47cebe8fb9 100644--- a/frontend/src/components/editor/controls/Controls.tsx+++ b/frontend/src/components/editor/controls/Controls.tsx@@ -17,6 +17,11 @@ import { FindReplace } from "@/components/find-replace/find-replace";import type { AppConfig } from "@/core/config/config-schema";import { isConnectedAtom } from "@/core/network/connection";import { SaveComponent } from "@/core/saving/save-component";+import {+ getConnectionTooltip,+ isAppInteractionDisabled,+} from "@/core/websocket/connection-utils";+import { WebSocketState } from "@/core/websocket/types";import { cn } from "@/utils/cn";import { Functions } from "@/utils/functions";import {@@ -37,7 +42,7 @@ interface ControlsProps {onTogglePresenting: () => void;onInterrupt: () => void;onRun: () => void;- closed: boolean;+ connectionState: WebSocketState;running: boolean;appConfig: AppConfig;}@@ -47,7 +52,7 @@ export const Controls = ({onTogglePresenting,onInterrupt,onRun,- closed,+ connectionState,running,appConfig,}: ControlsProps): JSX.Element => {@@ -55,6 +60,7 @@ export const Controls = ({const undoAvailable = useAtomValue(canUndoDeletesAtom);const needsRun = useAtomValue(needsRunAtom);const { undoDeleteCell } = useCellActions();+ const closed = connectionState === WebSocketState.CLOSED;let undoControl: JSX.Element | null = null;if (!closed && undoAvailable) {@@ -73,6 +79,10 @@ export const Controls = ({);}+ const disabled = isAppInteractionDisabled(connectionState);+ const connectionTooltip = disabled+ ? getConnectionTooltip(connectionState)+ : undefined;return (<>{!presenting && <FindReplace />}@@ -80,9 +90,16 @@ export const Controls = ({{!closed && (<div className={topRightControls}>{presenting && <LayoutSelect />}- <NotebookMenuDropdown />- <ConfigButton />- <ShutdownButton description="This will terminate the Python kernel. You'll lose all data that's in memory." />+ <NotebookMenuDropdown+ disabled={disabled}+ tooltip={connectionTooltip}+ />+ <ConfigButton disabled={disabled} tooltip={connectionTooltip} />+ <ShutdownButton+ description="This will terminate the Python kernel. You'll lose all data that's in memory."+ disabled={disabled}+ tooltip={connectionTooltip}+ /></div>)}diff --git a/frontend/src/components/editor/controls/notebook-menu-dropdown.tsx b/frontend/src/components/editor/controls/notebook-menu-dropdown.tsxindex be7016e21f..564ff11b88 100644--- a/frontend/src/components/editor/controls/notebook-menu-dropdown.tsx+++ b/frontend/src/components/editor/controls/notebook-menu-dropdown.tsx@@ -20,9 +20,16 @@ import { MinimalShortcut } from "../../shortcuts/renderShortcut";import type { ActionButton } from "../actions/types";import { useNotebookActions } from "../actions/useNotebookActions";-export const NotebookMenuDropdown: React.FC = () => {- const actions = useNotebookActions();+interface Props {+ disabled?: boolean;+ tooltip?: string;+}+export const NotebookMenuDropdown: React.FC<Props> = ({+ disabled = false,+ tooltip = "Actions",+}) => {+ const actions = useNotebookActions();const button = (<Buttonaria-label="Config"@@ -30,9 +37,12 @@ export const NotebookMenuDropdown: React.FC = () => {size="small"className="h-[27px] w-[27px]"data-testid="notebook-menu-dropdown"- color="hint-green"+ disabled={disabled}+ color={disabled ? "disabled" : "hint-green"}>- <MenuIcon strokeWidth={1.8} />+ <Tooltip content={tooltip}>+ <MenuIcon strokeWidth={1.8} />+ </Tooltip></Button>);@@ -80,7 +90,9 @@ export const NotebookMenuDropdown: React.FC = () => {return (<DropdownMenu modal={false}>- <DropdownMenuTrigger asChild={true}>{button}</DropdownMenuTrigger>+ <DropdownMenuTrigger asChild={true} disabled={disabled}>+ {button}+ </DropdownMenuTrigger><DropdownMenuContent align="end" className="no-print w-[240px]">{actions.map((action) => {if (action.hidden) {diff --git a/frontend/src/components/editor/controls/shutdown-button.tsx b/frontend/src/components/editor/controls/shutdown-button.tsxindex c68e8364f2..0f270da6be 100644--- a/frontend/src/components/editor/controls/shutdown-button.tsx+++ b/frontend/src/components/editor/controls/shutdown-button.tsx@@ -8,7 +8,17 @@ import { AlertDialogDestructiveAction } from "../../ui/alert-dialog";import { Tooltip } from "../../ui/tooltip";import { Button } from "../inputs/Inputs";-export const ShutdownButton: React.FC<{ description: string }> = (props) => {+interface Props {+ description: string;+ disabled?: boolean;+ tooltip?: string;+}++export const ShutdownButton: React.FC<Props> = ({+ description,+ disabled = false,+ tooltip = "Shutdown",+}) => {const { openConfirm, closeModal } = useImperativeModal();const handleShutdown = () => {sendShutdown();@@ -23,19 +33,20 @@ export const ShutdownButton: React.FC<{ description: string }> = (props) => {}return (- <Tooltip content="Shutdown">+ <Tooltip content={tooltip}><Buttonaria-label="Shutdown"data-testid="shutdown-button"shape="circle"size="small"- color="red"+ color={disabled ? "disabled" : "red"}className="h-[27px] w-[27px]"+ disabled={disabled}onClick={(e) => {e.stopPropagation();openConfirm({title: "Shutdown",- description: props.description,+ description: description,variant: "destructive",confirmAction: (<AlertDialogDestructiveActiondiff --git a/frontend/src/components/editor/inputs/Inputs.styles.ts b/frontend/src/components/editor/inputs/Inputs.styles.tsindex 17d9d73af7..199515bf4d 100644--- a/frontend/src/components/editor/inputs/Inputs.styles.ts+++ b/frontend/src/components/editor/inputs/Inputs.styles.ts@@ -18,7 +18,7 @@ export const button = cva(yellow: "mo-button yellow",// for actions that will change state but are not destructive"hint-green": "mo-button hint-green",- disabled: "mo-button disabled",+ disabled: "mo-button disabled active:shadow-xsSolid",},shape: {rectangle: "rounded",diff --git a/frontend/src/core/edit-app.tsx b/frontend/src/core/edit-app.tsxindex 6aaca170d9..0f1505fda7 100644--- a/frontend/src/core/edit-app.tsx+++ b/frontend/src/core/edit-app.tsx@@ -34,7 +34,6 @@ import { viewStateAtom } from "./mode";import { useFilename } from "./saving/filename";import { lastSavedNotebookAtom } from "./saving/state";import { useJotaiEffect } from "./state/jotai";-import { WebSocketState } from "./websocket/types";import { useMarimoWebSocket } from "./websocket/useMarimoWebSocket";interface AppProps {@@ -177,7 +176,7 @@ export const EditApp: React.FC<AppProps> = ({onTogglePresenting={togglePresenting}onInterrupt={sendInterrupt}onRun={runStaleCells}- closed={connection.state === WebSocketState.CLOSED}+ connectionState={connection.state}running={isRunning}appConfig={appConfig}/>