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.

Simplify cell menu (#7481)

Akshay Agrawal3e8a9de0fa08
diff --git a/frontend/src/components/editor/actions/types.ts b/frontend/src/components/editor/actions/types.ts
index e2d1dc5482..649d275ed0 100644
--- a/frontend/src/components/editor/actions/types.ts
+++ b/frontend/src/components/editor/actions/types.ts
@@ -3,7 +3,7 @@ import type { HotkeyAction } from "@/core/hotkeys/hotkeys";
/**
* Shared interface to render a user action in the editor.
- * This can be in a dropdown menu, context menu, or toolbar.
+ * This can be in a dropdown menu, context menu, toolbar, or command palette.
*/
export interface ActionButton {
label: string;
@@ -14,7 +14,10 @@ export interface ActionButton {
variant?: "danger" | "muted" | "disabled";
disableClick?: boolean;
icon?: React.ReactElement;
+ // whether the action is applicable
hidden?: boolean;
+ // whether to show the action in a menu
+ redundant?: boolean;
rightElement?: React.ReactNode;
hotkey?: HotkeyAction;
handle: (event?: Event) => void;
diff --git a/frontend/src/components/editor/actions/useCellActionButton.tsx b/frontend/src/components/editor/actions/useCellActionButton.tsx
index ff9a20a019..59c158e347 100644
--- a/frontend/src/components/editor/actions/useCellActionButton.tsx
+++ b/frontend/src/components/editor/actions/useCellActionButton.tsx
@@ -35,7 +35,6 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
-import { Switch } from "@/components/ui/switch";
import { toast } from "@/components/ui/use-toast";
import { aiCompletionCellAtom } from "@/core/ai/state";
import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
@@ -141,50 +140,6 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
// Actions
const actions: ActionButton[][] = [
[
- {
- icon: <TextCursorInputIcon size={13} strokeWidth={1.5} />,
- label: "Name",
- disableClick: true,
- handle: (evt) => {
- evt?.stopPropagation();
- evt?.preventDefault();
- },
- handleHeadless: () => {
- openModal(
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Rename cell</DialogTitle>
- </DialogHeader>
- <div className="flex items-center justify-between">
- <Label htmlFor="cell-name">Cell name</Label>
- <NameCellInput
- placeholder={"cell name"}
- value={name}
- onKeyDown={(e) => {
- if (e.key === "Enter") {
- e.preventDefault();
- e.stopPropagation();
- openModal(null);
- }
- }}
- onChange={(newName) =>
- updateCellName({ cellId, name: newName })
- }
- />
- </div>
- </DialogContent>,
- );
- },
- rightElement: (
- <NameCellInput
- placeholder={"cell name"}
- value={name}
- onChange={(newName) => updateCellName({ cellId, name: newName })}
- onEnterKey={() => closePopover?.()}
- />
- ),
- hidden: isSetupCell,
- },
{
icon: <PlayIcon size={13} strokeWidth={1.5} />,
label: "Run cell",
@@ -194,11 +149,12 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
status === "queued" ||
status === "disabled-transitively" ||
config.disabled,
+ redundant: true,
handle: () => runCell(),
},
{
icon: <SparklesIcon size={13} strokeWidth={1.5} />,
- label: "AI completion",
+ label: "Refactor with AI",
hidden: !aiEnabled,
handle: () => {
setAiCompletionCell((current) =>
@@ -209,19 +165,13 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
},
{
icon: <ScissorsIcon size={13} strokeWidth={1.5} />,
- label: "Split cell",
+ label: "Split",
hotkey: "cell.splitCell",
handle: () => splitCell({ cellId }),
},
- {
- icon: <ImageIcon size={13} strokeWidth={1.5} />,
- label: "Export output as PNG",
- hidden: !hasOutput,
- handle: () => downloadCellOutput(cellId),
- },
{
icon: <Code2Icon size={13} strokeWidth={1.5} />,
- label: "Format cell",
+ label: "Format",
hotkey: "cell.format",
handle: () => {
const editorView = getEditorView();
@@ -247,26 +197,10 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
) : (
<ZapIcon size={13} strokeWidth={1.5} />
),
- label: "Reactive execution",
- rightElement: (
- <Switch
- data-testid="cell-disable-switch"
- checked={!config.disabled}
- size="sm"
- onCheckedChange={toggleDisabled}
- />
- ),
+ label: config.disabled ? "Enable execution" : "Disable execution",
handle: toggleDisabled,
hidden: isSetupCell,
},
- {
- icon: <XCircleIcon size={13} strokeWidth={1.5} />,
- label: "Clear output",
- hidden: !(hasOutput || hasConsoleOutput),
- handle: () => {
- clearCellOutput({ cellId });
- },
- },
],
// View as
@@ -332,6 +266,7 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
hotkey: "cell.createAbove",
handle: () => createCell({ cellId, before: true }),
hidden: isSetupCell,
+ redundant: true,
},
{
icon: (
@@ -343,6 +278,7 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
label: "Create cell below",
hotkey: "cell.createBelow",
handle: () => createCell({ cellId, before: false }),
+ redundant: true,
},
{
icon: <ChevronUpIcon size={13} strokeWidth={1.5} />,
@@ -399,8 +335,70 @@ export function useCellActionButtons({ cell, closePopover }: Props) {
},
],
+ // Outputs
+ [
+ {
+ icon: <ImageIcon size={13} strokeWidth={1.5} />,
+ label: "Export output as PNG",
+ hidden: !hasOutput,
+ handle: () => downloadCellOutput(cellId),
+ },
+ {
+ icon: <XCircleIcon size={13} strokeWidth={1.5} />,
+ label: "Clear output",
+ hidden: !(hasOutput || hasConsoleOutput),
+ handle: () => {
+ clearCellOutput({ cellId });
+ },
+ },
+ ],
+
// Link to cell
[
+ {
+ icon: <TextCursorInputIcon size={13} strokeWidth={1.5} />,
+ label: "Name",
+ disableClick: true,
+ handle: (evt) => {
+ evt?.stopPropagation();
+ evt?.preventDefault();
+ },
+ handleHeadless: () => {
+ openModal(
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Rename cell</DialogTitle>
+ </DialogHeader>
+ <div className="flex items-center justify-between">
+ <Label htmlFor="cell-name">Cell name</Label>
+ <NameCellInput
+ placeholder={"cell name"}
+ value={name}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ e.stopPropagation();
+ openModal(null);
+ }
+ }}
+ onChange={(newName) =>
+ updateCellName({ cellId, name: newName })
+ }
+ />
+ </div>
+ </DialogContent>,
+ );
+ },
+ rightElement: (
+ <NameCellInput
+ placeholder={"cell name"}
+ value={name}
+ onChange={(newName) => updateCellName({ cellId, name: newName })}
+ onEnterKey={() => closePopover?.()}
+ />
+ ),
+ hidden: isSetupCell,
+ },
{
icon: <LinkIcon size={13} strokeWidth={1.5} />,
label: "Copy link to cell",
diff --git a/frontend/src/components/editor/cell/cell-actions.tsx b/frontend/src/components/editor/cell/cell-actions.tsx
index 269ca5261f..2f9750ace9 100644
--- a/frontend/src/components/editor/cell/cell-actions.tsx
+++ b/frontend/src/components/editor/cell/cell-actions.tsx
@@ -80,6 +80,9 @@ const CellActionsDropdownInternal = (
<Fragment key={i}>
<CommandGroup key={i}>
{group.map((action) => {
+ if (action.redundant) {
+ return null;
+ }
let body = (
<div className="flex items-center flex-1">
{action.icon && (
diff --git a/frontend/src/components/editor/cell/cell-context-menu.tsx b/frontend/src/components/editor/cell/cell-context-menu.tsx
index fbca79fdc5..9e1afd8b06 100644
--- a/frontend/src/components/editor/cell/cell-context-menu.tsx
+++ b/frontend/src/components/editor/cell/cell-context-menu.tsx
@@ -192,7 +192,7 @@ export const CellActionsContextMenu = ({
{allActions.map((group, i) => (
<Fragment key={i}>
{group.map((action) => {
- if (action.hidden) {
+ if (action.hidden || action.redundant) {
return null;
}