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 panel section context for orientation-aware layouts (#7724)

Trevor Manz0afb90fa85d3
diff --git a/frontend/src/components/editor/chrome/panels/panel-context.tsx b/frontend/src/components/editor/chrome/panels/panel-context.tsx
new file mode 100644
index 0000000000..eaafdf4477
--- /dev/null
+++ b/frontend/src/components/editor/chrome/panels/panel-context.tsx
@@ -0,0 +1,34 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { createContext, useContext } from "react";
+import { invariant } from "@/utils/invariant";
+
+export type PanelSection = "sidebar" | "developer-panel";
+
+const PanelSectionContext = createContext<PanelSection | null>(null);
+
+export const PanelSectionProvider = PanelSectionContext.Provider;
+
+/**
+ * Hook to get the current panel section context.
+ * Returns "sidebar" or "developer-panel" depending on where the panel is rendered.
+ * Throws if used outside of a panel context.
+ */
+export function usePanelSection(): PanelSection {
+ const section = useContext(PanelSectionContext);
+ invariant(
+ section !== null,
+ "usePanelSection must be used within a PanelSectionProvider",
+ );
+ return section;
+}
+
+/**
+ * Hook to get the preferred orientation based on the panel section.
+ * - Sidebar panels should use vertical layouts (stacked)
+ * - Developer panel should use horizontal layouts (side-by-side)
+ */
+export function usePanelOrientation(): "horizontal" | "vertical" {
+ const section = usePanelSection();
+ return section === "sidebar" ? "vertical" : "horizontal";
+}
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index 24f951b6f1..354bc35e14 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -26,6 +26,7 @@ import { getFeatureFlag } from "@/core/config/feature-flag";
import { cn } from "@/utils/cn";
import { ErrorBoundary } from "../../boundary/ErrorBoundary";
import { ContextAwarePanel } from "../panels/context-aware-panel/context-aware-panel";
+import { PanelSectionProvider } from "../panels/panel-context";
import { panelLayoutAtom, useChromeActions, useChromeState } from "../state";
import { PANEL_MAP, PANELS, type PanelDescriptor } from "../types";
import { BackendConnectionStatus } from "./footer-items/backend-status";
@@ -222,72 +223,74 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
const helpPaneBody = (
<ErrorBoundary>
- <div className="flex flex-col h-full flex-1 overflow-hidden mr-[-4px]">
- <div className="p-3 border-b flex justify-between items-center">
- {selectedPanel === "ai" && agentsEnabled ? (
- <Tabs
- value={aiPanelTab}
- onValueChange={(value) => {
- if (value === "chat" || value === "agents") {
- setAiPanelTab(value);
- }
- }}
+ <PanelSectionProvider value="sidebar">
+ <div className="flex flex-col h-full flex-1 overflow-hidden mr-[-4px]">
+ <div className="p-3 border-b flex justify-between items-center">
+ {selectedPanel === "ai" && agentsEnabled ? (
+ <Tabs
+ value={aiPanelTab}
+ onValueChange={(value) => {
+ if (value === "chat" || value === "agents") {
+ setAiPanelTab(value);
+ }
+ }}
+ >
+ <TabsList>
+ <TabsTrigger
+ value="chat"
+ className="py-0.5 text-xs uppercase tracking-wide font-bold"
+ >
+ Chat
+ </TabsTrigger>
+ <TabsTrigger
+ value="agents"
+ className="py-0.5 text-xs uppercase tracking-wide font-bold"
+ >
+ Agents
+ </TabsTrigger>
+ </TabsList>
+ </Tabs>
+ ) : (
+ <span className="text-sm text-(--slate-11) uppercase tracking-wide font-semibold flex-1">
+ {selectedPanel}
+ </span>
+ )}
+ <Button
+ data-testid="close-helper-pane"
+ className="m-0"
+ size="xs"
+ variant="text"
+ onClick={() => setIsSidebarOpen(false)}
>
- <TabsList>
- <TabsTrigger
- value="chat"
- className="py-0.5 text-xs uppercase tracking-wide font-bold"
- >
- Chat
- </TabsTrigger>
- <TabsTrigger
- value="agents"
- className="py-0.5 text-xs uppercase tracking-wide font-bold"
- >
- Agents
- </TabsTrigger>
- </TabsList>
- </Tabs>
- ) : (
- <span className="text-sm text-(--slate-11) uppercase tracking-wide font-semibold flex-1">
- {selectedPanel}
- </span>
- )}
- <Button
- data-testid="close-helper-pane"
- className="m-0"
- size="xs"
- variant="text"
- onClick={() => setIsSidebarOpen(false)}
- >
- <XIcon className="w-4 h-4" />
- </Button>
+ <XIcon className="w-4 h-4" />
+ </Button>
+ </div>
+ <Suspense>
+ <TooltipProvider>
+ {selectedPanel === "files" && <LazyFileExplorerPanel />}
+ {selectedPanel === "variables" && <LazySessionPanel />}
+ {selectedPanel === "dependencies" && <LazyDependencyGraphPanel />}
+ {selectedPanel === "packages" && <LazyPackagesPanel />}
+ {selectedPanel === "outline" && <LazyOutlinePanel />}
+ {selectedPanel === "documentation" && <LazyDocumentationPanel />}
+ {selectedPanel === "snippets" && <LazySnippetsPanel />}
+ {selectedPanel === "ai" && renderAiPanel()}
+ {selectedPanel === "errors" && <LazyErrorsPanel />}
+ {selectedPanel === "scratchpad" && <LazyScratchpadPanel />}
+ {selectedPanel === "tracing" && <LazyTracingPanel />}
+ {selectedPanel === "secrets" && <LazySecretsPanel />}
+ {selectedPanel === "logs" && <LazyLogsPanel />}
+ {selectedPanel === "terminal" && (
+ <LazyTerminal
+ visible={isSidebarOpen}
+ onClose={() => setIsSidebarOpen(false)}
+ />
+ )}
+ {selectedPanel === "cache" && <LazyCachePanel />}
+ </TooltipProvider>
+ </Suspense>
</div>
- <Suspense>
- <TooltipProvider>
- {selectedPanel === "files" && <LazyFileExplorerPanel />}
- {selectedPanel === "variables" && <LazySessionPanel />}
- {selectedPanel === "dependencies" && <LazyDependencyGraphPanel />}
- {selectedPanel === "packages" && <LazyPackagesPanel />}
- {selectedPanel === "outline" && <LazyOutlinePanel />}
- {selectedPanel === "documentation" && <LazyDocumentationPanel />}
- {selectedPanel === "snippets" && <LazySnippetsPanel />}
- {selectedPanel === "ai" && renderAiPanel()}
- {selectedPanel === "errors" && <LazyErrorsPanel />}
- {selectedPanel === "scratchpad" && <LazyScratchpadPanel />}
- {selectedPanel === "tracing" && <LazyTracingPanel />}
- {selectedPanel === "secrets" && <LazySecretsPanel />}
- {selectedPanel === "logs" && <LazyLogsPanel />}
- {selectedPanel === "terminal" && (
- <LazyTerminal
- visible={isSidebarOpen}
- onClose={() => setIsSidebarOpen(false)}
- />
- )}
- {selectedPanel === "cache" && <LazyCachePanel />}
- </TooltipProvider>
- </Suspense>
- </div>
+ </PanelSectionProvider>
</ErrorBoundary>
);
@@ -409,37 +412,47 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
</div>
{/* Panel content */}
<Suspense fallback={<div />}>
- <div className="flex-1 overflow-hidden">
- {selectedDeveloperPanelTab === "files" && <LazyFileExplorerPanel />}
- {selectedDeveloperPanelTab === "variables" && <LazySessionPanel />}
- {selectedDeveloperPanelTab === "dependencies" && (
- <LazyDependencyGraphPanel />
- )}
- {selectedDeveloperPanelTab === "packages" && <LazyPackagesPanel />}
- {selectedDeveloperPanelTab === "outline" && <LazyOutlinePanel />}
- {selectedDeveloperPanelTab === "documentation" && (
- <LazyDocumentationPanel />
- )}
- {selectedDeveloperPanelTab === "snippets" && <LazySnippetsPanel />}
- {selectedDeveloperPanelTab === "ai" && renderAiPanel()}
- {selectedDeveloperPanelTab === "errors" && <LazyErrorsPanel />}
- {selectedDeveloperPanelTab === "scratchpad" && (
- <LazyScratchpadPanel />
- )}
- {selectedDeveloperPanelTab === "tracing" && <LazyTracingPanel />}
- {selectedDeveloperPanelTab === "secrets" && <LazySecretsPanel />}
- {selectedDeveloperPanelTab === "logs" && <LazyLogsPanel />}
- {/* LazyMount needed for Terminal to avoid spurious connection */}
- {selectedDeveloperPanelTab === "terminal" && (
- <LazyMount isOpen={isDeveloperPanelOpen}>
- <LazyTerminal
- visible={isDeveloperPanelOpen}
- onClose={() => setIsDeveloperPanelOpen(false)}
- />
- </LazyMount>
- )}
- {selectedDeveloperPanelTab === "cache" && <LazyCachePanel />}
- </div>
+ <PanelSectionProvider value="developer-panel">
+ <div className="flex-1 overflow-hidden">
+ {selectedDeveloperPanelTab === "files" && (
+ <LazyFileExplorerPanel />
+ )}
+ {selectedDeveloperPanelTab === "variables" && (
+ <LazySessionPanel />
+ )}
+ {selectedDeveloperPanelTab === "dependencies" && (
+ <LazyDependencyGraphPanel />
+ )}
+ {selectedDeveloperPanelTab === "packages" && (
+ <LazyPackagesPanel />
+ )}
+ {selectedDeveloperPanelTab === "outline" && <LazyOutlinePanel />}
+ {selectedDeveloperPanelTab === "documentation" && (
+ <LazyDocumentationPanel />
+ )}
+ {selectedDeveloperPanelTab === "snippets" && (
+ <LazySnippetsPanel />
+ )}
+ {selectedDeveloperPanelTab === "ai" && renderAiPanel()}
+ {selectedDeveloperPanelTab === "errors" && <LazyErrorsPanel />}
+ {selectedDeveloperPanelTab === "scratchpad" && (
+ <LazyScratchpadPanel />
+ )}
+ {selectedDeveloperPanelTab === "tracing" && <LazyTracingPanel />}
+ {selectedDeveloperPanelTab === "secrets" && <LazySecretsPanel />}
+ {selectedDeveloperPanelTab === "logs" && <LazyLogsPanel />}
+ {/* LazyMount needed for Terminal to avoid spurious connection */}
+ {selectedDeveloperPanelTab === "terminal" && (
+ <LazyMount isOpen={isDeveloperPanelOpen}>
+ <LazyTerminal
+ visible={isDeveloperPanelOpen}
+ onClose={() => setIsDeveloperPanelOpen(false)}
+ />
+ </LazyMount>
+ )}
+ {selectedDeveloperPanelTab === "cache" && <LazyCachePanel />}
+ </div>
+ </PanelSectionProvider>
</Suspense>
</div>
</Panel>
diff --git a/frontend/src/components/scratchpad/scratchpad.tsx b/frontend/src/components/scratchpad/scratchpad.tsx
index 0ecea3638a..25bb59ce80 100644
--- a/frontend/src/components/scratchpad/scratchpad.tsx
+++ b/frontend/src/components/scratchpad/scratchpad.tsx
@@ -27,6 +27,10 @@ import { useTheme } from "@/theme/useTheme";
import { cn } from "@/utils/cn";
import { Functions } from "@/utils/functions";
import { CellEditor } from "../editor/cell/code/cell-editor";
+import {
+ usePanelOrientation,
+ usePanelSection,
+} from "../editor/chrome/panels/panel-context";
import { HideInKioskMode } from "../editor/kiosk-mode";
import { OutputArea } from "../editor/Output";
import { ConsoleOutput } from "../editor/output/console/ConsoleOutput";
@@ -53,6 +57,8 @@ export const ScratchPad: React.FC = () => {
const lastFocusedCellId = useLastFocusedCellId();
const { createNewCell, updateCellCode } = useCellActions();
const { sendRunScratchpad } = useRequestClient();
+ const orientation = usePanelOrientation();
+ const section = usePanelSection();
const cellId = SCRATCH_CELL_ID;
const cellRuntime = notebookState.cellRuntime[cellId];
@@ -223,13 +229,15 @@ export const ScratchPad: React.FC = () => {
</div>
);
+ const isVertical = orientation === "vertical";
+
return (
<div
className="flex flex-col h-full overflow-hidden"
id={HTMLCellId.create(cellId)}
>
- <PanelGroup direction="horizontal" className="h-full">
- {/* Left side: toolbar + editor */}
+ <PanelGroup key={section} direction={orientation} className="h-full">
+ {/* Editor panel */}
<Panel defaultSize={40} minSize={20} maxSize={70}>
<div className="h-full flex flex-col overflow-hidden relative">
{renderToolbar()}
@@ -257,8 +265,13 @@ export const ScratchPad: React.FC = () => {
{renderHistory()}
</div>
</Panel>
- <PanelResizeHandle className="w-1 bg-border hover:bg-primary/50 transition-colors" />
- {/* Right side: outputs */}
+ <PanelResizeHandle
+ className={cn(
+ "bg-border hover:bg-primary/50 transition-colors",
+ isVertical ? "h-1" : "w-1",
+ )}
+ />
+ {/* Output panel */}
<Panel defaultSize={60} minSize={20}>
<div className="h-full flex flex-col divide-y overflow-hidden">
<div className="flex-1 overflow-auto">