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.

enhancement: add a signifier for the create cell context menu (#5489)

Akshay Agrawalc67572942df6
diff --git a/frontend/src/components/editor/cell/CreateCellButton.tsx b/frontend/src/components/editor/cell/CreateCellButton.tsx
index 1d2cd7f1ef..4df3c34d6f 100644
--- a/frontend/src/components/editor/cell/CreateCellButton.tsx
+++ b/frontend/src/components/editor/cell/CreateCellButton.tsx
@@ -7,6 +7,8 @@ import {
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
+import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
+import { useCellActions } from "@/core/cells/cells";
import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
import { SQLLanguageAdapter } from "@/core/codemirror/language/languages/sql";
import {
@@ -28,8 +30,18 @@ export const CreateCellButton = ({
tooltipContent: React.ReactNode;
onClick: ((opts: { code: string }) => void) | undefined;
}) => {
- const finalTooltipContent =
+ const baseTooltipContent =
getConnectionTooltip(connectionState) || tooltipContent;
+ const finalTooltipContent = isAppInteractionDisabled(connectionState) ? (
+ baseTooltipContent
+ ) : (
+ <div className="flex flex-col gap-4">
+ <div>{baseTooltipContent}</div>
+ <div className="text-xs text-muted-foreground font-medium pt-1 -mt-2 border-t border-border">
+ Right-click for cell types
+ </div>
+ </div>
+ );
return (
<CreateCellButtonContextMenu onClick={onClick}>
@@ -58,11 +70,16 @@ const CreateCellButtonContextMenu = (props: {
children: React.ReactNode;
}) => {
const { children, onClick } = props;
+ const { createNewCell } = useCellActions();
if (!onClick) {
return children;
}
+ // NB: When adding the marimo import for markdown and SQL, we run it
+ // automatically regardless of whether autoinstantiate or lazy execution is
+ // enabled; the user experience is confusing otherwise (how does the user
+ // know they need to run import marimo as mo. first?).
return (
<ContextMenu>
<ContextMenuTrigger>{children}</ContextMenuTrigger>
@@ -84,6 +101,7 @@ const CreateCellButtonContextMenu = (props: {
key="markdown"
onSelect={(evt) => {
evt.stopPropagation();
+ maybeAddMarimoImport(true, createNewCell);
onClick({ code: new MarkdownLanguageAdapter().defaultCode });
}}
>
@@ -96,6 +114,7 @@ const CreateCellButtonContextMenu = (props: {
key="sql"
onSelect={(evt) => {
evt.stopPropagation();
+ maybeAddMarimoImport(true, createNewCell);
onClick({ code: new SQLLanguageAdapter().defaultCode });
}}
>
diff --git a/frontend/src/components/editor/renderers/CellArray.tsx b/frontend/src/components/editor/renderers/CellArray.tsx
index 6861308980..2553456027 100644
--- a/frontend/src/components/editor/renderers/CellArray.tsx
+++ b/frontend/src/components/editor/renderers/CellArray.tsx
@@ -22,7 +22,7 @@ import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
import type { CellId } from "@/core/cells/ids";
import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
import { SQLLanguageAdapter } from "@/core/codemirror/language/languages/sql";
-import { aiEnabledAtom, autoInstantiateAtom } from "@/core/config/config";
+import { aiEnabledAtom } from "@/core/config/config";
import { isConnectedAtom } from "@/core/network/connection";
import { useBoolean } from "@/hooks/useBoolean";
import { cn } from "@/utils/cn";
@@ -290,7 +290,6 @@ const AddCellButtons: React.FC<{
className?: string;
}> = ({ columnId, className }) => {
const { createNewCell } = useCellActions();
- const autoInstantiate = useAtomValue(autoInstantiateAtom);
const [isAiButtonOpen, isAiButtonOpenActions] = useBoolean(false);
const aiEnabled = useAtomValue(aiEnabledAtom);
const isConnected = useAtomValue(isConnectedAtom);
@@ -328,7 +327,7 @@ const AddCellButtons: React.FC<{
size="sm"
disabled={!isConnected}
onClick={() => {
- maybeAddMarimoImport(autoInstantiate, createNewCell);
+ maybeAddMarimoImport(true, createNewCell);
createNewCell({
cellId: { type: "__end__", columnId },
@@ -346,7 +345,7 @@ const AddCellButtons: React.FC<{
size="sm"
disabled={!isConnected}
onClick={() => {
- maybeAddMarimoImport(autoInstantiate, createNewCell);
+ maybeAddMarimoImport(true, createNewCell);
createNewCell({
cellId: { type: "__end__", columnId },