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.

Unify panel actions to work across sidebar and developer panel (#7743)

Trevor Manzd19913231993
diff --git a/frontend/src/components/editor/chrome/state.ts b/frontend/src/components/editor/chrome/state.ts
index 4b9cd51899..41961367aa 100644
--- a/frontend/src/components/editor/chrome/state.ts
+++ b/frontend/src/components/editor/chrome/state.ts
@@ -3,10 +3,11 @@
import { useAtomValue } from "jotai";
import { atomWithStorage } from "jotai/utils";
import { z } from "zod";
+import { store } from "@/core/state/jotai";
import { createReducerAndAtoms } from "@/utils/createReducer";
import { jotaiJsonStorage } from "@/utils/storage/jotai";
import { ZodLocalStorage } from "@/utils/storage/typed";
-import type { PanelType } from "./types";
+import type { PanelSection, PanelType } from "./types";
import { isPanelHidden, PANELS } from "./types";
export interface ChromeState {
@@ -41,6 +42,20 @@ export const panelLayoutAtom = atomWithStorage<PanelLayout>(
{ getOnInit: true },
);
+/**
+ * Resolve which section a panel belongs to based on current layout.
+ */
+function resolvePanelLocation(panelType: PanelType): PanelSection | null {
+ const layout = store.get(panelLayoutAtom);
+ if (layout.sidebar.includes(panelType)) {
+ return "sidebar";
+ }
+ if (layout.developerPanel.includes(panelType)) {
+ return "developer-panel";
+ }
+ return null;
+}
+
const KEY = "marimo:sidebar";
const storage = new ZodLocalStorage<ChromeState>(
z.object({
@@ -76,20 +91,52 @@ const {
} = createReducerAndAtoms(
() => storage.get(KEY),
{
- openApplication: (state, selectedPanel: PanelType) => ({
- ...state,
- selectedPanel,
- isSidebarOpen: true,
- }),
- toggleApplication: (state, selectedPanel: PanelType) => ({
- ...state,
- selectedPanel,
- // If it was closed, open it
- // If it was open, keep it open unless it was the same application
- isSidebarOpen: state.isSidebarOpen
- ? state.selectedPanel !== selectedPanel
- : true,
- }),
+ openApplication: (state, selectedPanel: PanelType) => {
+ const location = resolvePanelLocation(selectedPanel);
+ if (location === "sidebar") {
+ return {
+ ...state,
+ selectedPanel,
+ isSidebarOpen: true,
+ };
+ }
+ if (location === "developer-panel") {
+ return {
+ ...state,
+ selectedDeveloperPanelTab: selectedPanel,
+ isDeveloperPanelOpen: true,
+ };
+ }
+ // Panel not found in layout, no-op
+ return state;
+ },
+ toggleApplication: (state, selectedPanel: PanelType) => {
+ const location = resolvePanelLocation(selectedPanel);
+ if (location === "sidebar") {
+ return {
+ ...state,
+ selectedPanel,
+ // If it was closed, open it
+ // If it was open, keep it open unless it was the same application
+ isSidebarOpen: state.isSidebarOpen
+ ? state.selectedPanel !== selectedPanel
+ : true,
+ };
+ }
+ if (location === "developer-panel") {
+ return {
+ ...state,
+ selectedDeveloperPanelTab: selectedPanel,
+ // If it was closed, open it
+ // If it was open, keep it open unless it was the same tab
+ isDeveloperPanelOpen: state.isDeveloperPanelOpen
+ ? state.selectedDeveloperPanelTab !== selectedPanel
+ : true,
+ };
+ }
+ // Panel not found in layout, no-op
+ return state;
+ },
toggleSidebarPanel: (state) => ({
...state,
isSidebarOpen: !state.isSidebarOpen,
@@ -106,15 +153,6 @@ const {
...state,
isDeveloperPanelOpen: isOpen,
}),
- setSelectedDeveloperPanelTab: (state, tab: PanelType) => ({
- ...state,
- selectedDeveloperPanelTab: tab,
- }),
- openDeveloperPanelTab: (state, tab: PanelType) => ({
- ...state,
- isDeveloperPanelOpen: true,
- selectedDeveloperPanelTab: tab,
- }),
},
[(_prevState, newState) => storage.set(KEY, newState)],
);
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index fef85862d8..6037c90829 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -75,12 +75,8 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
selectedPanel,
selectedDeveloperPanelTab,
} = useChromeState();
- const {
- setIsSidebarOpen,
- setIsDeveloperPanelOpen,
- setSelectedDeveloperPanelTab,
- openApplication,
- } = useChromeActions();
+ const { setIsSidebarOpen, setIsDeveloperPanelOpen, openApplication } =
+ useChromeActions();
const sidebarRef = React.useRef<ImperativePanelHandle>(null);
const developerPanelRef = React.useRef<ImperativePanelHandle>(null);
const { aiPanelTab, setAiPanelTab } = useAiPanelTab();
@@ -123,7 +119,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
}
// Select the dropped item in developer panel
- setSelectedDeveloperPanelTab(item.type);
+ openApplication(item.type);
};
// Get panels available for developer panel context menu
@@ -412,7 +408,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
ariaLabel="Developer panel tabs"
className="flex flex-row gap-1"
minItems={0}
- onAction={(panel) => setSelectedDeveloperPanelTab(panel.type)}
+ onAction={(panel) => openApplication(panel.type)}
renderItem={(panel) => (
<div
className={cn(
diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx
index f724367792..4d349910b7 100644
--- a/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/backend-status.tsx
@@ -125,7 +125,7 @@ export const BackendConnectionStatus: React.FC = () => {
if (isAppNotStarted(connection)) {
void connectToRuntime();
} else {
- void refetch();
+ refetch();
}
};
diff --git a/frontend/src/components/editor/chrome/wrapper/footer.tsx b/frontend/src/components/editor/chrome/wrapper/footer.tsx
index 84eef9fee6..f6fa96c8f1 100644
--- a/frontend/src/components/editor/chrome/wrapper/footer.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/footer.tsx
@@ -23,10 +23,8 @@ import { RuntimeSettings } from "./footer-items/runtime-settings";
import { useSetDependencyPanelTab } from "./useDependencyPanelTab";
export const Footer: React.FC = () => {
- const { isDeveloperPanelOpen, isSidebarOpen, selectedPanel } =
- useChromeState();
- const { toggleDeveloperPanel, openApplication, setIsSidebarOpen } =
- useChromeActions();
+ const { isDeveloperPanelOpen } = useChromeState();
+ const { toggleDeveloperPanel, toggleApplication } = useChromeActions();
const setDependencyPanelTab = useSetDependencyPanelTab();
const errorCount = useAtomValue(cellErrorCount);
@@ -42,7 +40,7 @@ export const Footer: React.FC = () => {
const warningCount = 0;
useHotkey("global.toggleTerminal", () => {
- toggleDeveloperPanel();
+ toggleApplication("terminal");
});
useHotkey("global.togglePanel", () => {
@@ -50,14 +48,8 @@ export const Footer: React.FC = () => {
});
useHotkey("global.toggleMinimap", () => {
- // If already on dependencies panel with minimap tab, close the sidebar
- if (isSidebarOpen && selectedPanel === "dependencies") {
- setIsSidebarOpen(false);
- } else {
- // Open sidebar with dependencies panel and switch to minimap tab
- openApplication("dependencies");
- setDependencyPanelTab("minimap");
- }
+ toggleApplication("dependencies");
+ setDependencyPanelTab("minimap");
});
return (
diff --git a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx b/frontend/src/components/editor/chrome/wrapper/sidebar.tsx
index b4da4676d2..d881f05bf7 100644
--- a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/sidebar.tsx
@@ -20,8 +20,7 @@ import {
export const Sidebar: React.FC = () => {
const { selectedPanel, selectedDeveloperPanelTab } = useChromeState();
- const { toggleApplication, setSelectedDeveloperPanelTab } =
- useChromeActions();
+ const { toggleApplication, openApplication } = useChromeActions();
const [panelLayout, setPanelLayout] = useAtom(panelLayoutAtom);
const renderIcon = ({ Icon }: PanelDescriptor, className?: string) => {
@@ -73,7 +72,7 @@ export const Sidebar: React.FC = () => {
(id) => id !== item.type,
);
if (remainingDevPanels.length > 0) {
- setSelectedDeveloperPanelTab(remainingDevPanels[0]);
+ openApplication(remainingDevPanels[0]);
}
}
}
diff --git a/frontend/src/components/editor/output/MarimoErrorOutput.tsx b/frontend/src/components/editor/output/MarimoErrorOutput.tsx
index a9e9028887..0637918c51 100644
--- a/frontend/src/components/editor/output/MarimoErrorOutput.tsx
+++ b/frontend/src/components/editor/output/MarimoErrorOutput.tsx
@@ -142,7 +142,7 @@ export const MarimoErrorOutput = ({
);
const openScratchpad = () => {
- chromeActions.openDeveloperPanelTab("scratchpad");
+ chromeActions.openApplication("scratchpad");
};
const renderMessages = () => {
@@ -186,7 +186,7 @@ export const MarimoErrorOutput = ({
size="xs"
variant="outline"
className="mt-2 font-normal"
- onClick={() => chromeActions.openDeveloperPanelTab("terminal")}
+ onClick={() => chromeActions.openApplication("terminal")}
>
<TerminalIcon className="h-3.5 w-3.5 mr-1.5" />
<span>Open terminal</span>
diff --git a/frontend/src/components/terminal/hooks.ts b/frontend/src/components/terminal/hooks.ts
index 8f3aa9e1d0..179deb81fc 100644
--- a/frontend/src/components/terminal/hooks.ts
+++ b/frontend/src/components/terminal/hooks.ts
@@ -25,11 +25,11 @@ import { useTerminalActions } from "./state";
*/
export function useTerminalCommands() {
const { addCommand } = useTerminalActions();
- const { openDeveloperPanelTab } = useChromeActions();
+ const { openApplication } = useChromeActions();
const sendCommand = (text: string) => {
// First, ensure the terminal is open
- openDeveloperPanelTab("terminal");
+ openApplication("terminal");
// Add the command to the queue
addCommand(text);