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.

improvement: redesign disconnected state (#2865)

Myles Scolnick36b2223fce8d
diff --git a/frontend/src/components/editor/Disconnected.tsx b/frontend/src/components/editor/Disconnected.tsx
index bbb976da39..1caac09d91 100644
--- a/frontend/src/components/editor/Disconnected.tsx
+++ b/frontend/src/components/editor/Disconnected.tsx
@@ -4,6 +4,8 @@ import { Button } from "../ui/button";
import { toast } from "../ui/use-toast";
import { prettyError } from "@/utils/errors";
import { reloadSafe } from "@/utils/reload-safe";
+import { ArrowRightSquareIcon } from "lucide-react";
+import { Banner } from "@/plugins/impl/common/error-banner";
interface DisconnectedProps {
reason: string;
@@ -30,14 +32,40 @@ export const Disconnected = ({
}
};
+ if (canTakeover) {
+ return (
+ <div className="flex justify-center">
+ <Banner
+ kind="info"
+ className="mt-10 flex flex-col rounded p-3 max-w-[800px] mx-4"
+ >
+ <div className="flex justify-between">
+ <span className="font-bold text-xl flex items-center mb-2">
+ Notebook already connected
+ </span>
+ </div>
+ <div className="flex justify-between items-end text-base gap-20">
+ <span>{reason}</span>
+ {canTakeover && (
+ <Button
+ onClick={handleTakeover}
+ variant="outline"
+ data-testid="takeover-button"
+ className="flex-shrink-0"
+ >
+ <ArrowRightSquareIcon className="w-4 h-4 mr-2" />
+ Take over session
+ </Button>
+ )}
+ </div>
+ </Banner>
+ </div>
+ );
+ }
+
return (
- <div id="Disconnected">
+ <div className="font-mono text-center text-base text-[var(--red-11)]">
<p>{reason}</p>
- {canTakeover && (
- <Button onClick={handleTakeover} variant="secondary" className="mt-2">
- Take over session
- </Button>
- )}
</div>
);
};
diff --git a/frontend/src/components/editor/app-container.tsx b/frontend/src/components/editor/app-container.tsx
index d3415ca4b5..fd51682c19 100644
--- a/frontend/src/components/editor/app-container.tsx
+++ b/frontend/src/components/editor/app-container.tsx
@@ -1,5 +1,5 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import { WebSocketState } from "@/core/websocket/types";
+import { type ConnectionStatus, WebSocketState } from "@/core/websocket/types";
import { cn } from "@/utils/cn";
import type React from "react";
import type { PropsWithChildren } from "react";
@@ -10,21 +10,23 @@ import { PyodideLoader } from "@/core/wasm/PyodideLoader";
import { DynamicFavicon } from "./dynamic-favicon";
interface Props {
- connectionState: WebSocketState;
+ connection: ConnectionStatus;
isRunning: boolean;
width: AppConfig["width"];
}
export const AppContainer: React.FC<PropsWithChildren<Props>> = ({
width,
- connectionState,
+ connection,
isRunning,
children,
}) => {
+ const connectionState = connection.state;
+
return (
<>
<DynamicFavicon isRunning={isRunning} />
- <StatusOverlay state={connectionState} isRunning={isRunning} />
+ <StatusOverlay connection={connection} isRunning={isRunning} />
<PyodideLoader>
<WrappedWithSidebar>
<div
diff --git a/frontend/src/components/editor/controls/keyboard-shortcuts.tsx b/frontend/src/components/editor/controls/keyboard-shortcuts.tsx
index 6e20c3b8ca..f3e97b2225 100644
--- a/frontend/src/components/editor/controls/keyboard-shortcuts.tsx
+++ b/frontend/src/components/editor/controls/keyboard-shortcuts.tsx
@@ -233,7 +233,7 @@ export const KeyboardShortcuts: React.FC = () => {
const renderGroup = (group: HotkeyGroup) => {
const items = groups[group];
return (
- <div className="keyboard-shortcut-group gap-2 flex flex-col">
+ <div className="mb-[40px] gap-2 flex flex-col">
<h3 className="text-lg font-medium">{group}</h3>
{items.map((item) => renderItem(item))}
diff --git a/frontend/src/components/editor/header/status.tsx b/frontend/src/components/editor/header/status.tsx
index e064ab56a8..650c8bb270 100644
--- a/frontend/src/components/editor/header/status.tsx
+++ b/frontend/src/components/editor/header/status.tsx
@@ -1,19 +1,24 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { Tooltip } from "@/components/ui/tooltip";
import { notebookScrollToRunning } from "@/core/cells/actions";
-import { WebSocketState } from "@/core/websocket/types";
-import { UnlinkIcon, HourglassIcon } from "lucide-react";
+import { type ConnectionStatus, WebSocketState } from "@/core/websocket/types";
+import { UnlinkIcon, HourglassIcon, LockIcon } from "lucide-react";
import React from "react";
export const StatusOverlay: React.FC<{
- state: WebSocketState;
+ connection: ConnectionStatus;
isRunning: boolean;
-}> = ({ state, isRunning }) => {
+}> = ({ connection, isRunning }) => {
return (
<>
- {state === WebSocketState.OPEN && isRunning && <RunningIcon />}
- {state === WebSocketState.CLOSED && <NoiseBackground />}
- {state === WebSocketState.CLOSED && <DisconnectedIcon />}
+ {connection.state === WebSocketState.OPEN && isRunning && <RunningIcon />}
+ {connection.state === WebSocketState.CLOSED &&
+ !connection.canTakeover && <NoiseBackground />}
+ {connection.state === WebSocketState.CLOSED &&
+ !connection.canTakeover && <DisconnectedIcon />}
+ {connection.state === WebSocketState.CLOSED && connection.canTakeover && (
+ <LockedIcon />
+ )}
</>
);
};
@@ -24,7 +29,15 @@ const topLeftStatus =
const DisconnectedIcon = () => (
<Tooltip content="App disconnected">
<div className={topLeftStatus}>
- <UnlinkIcon className="closed-app-icon" />
+ <UnlinkIcon className="w-[25px] h-[25px] text-[var(--red-11)]" />
+ </div>
+ </Tooltip>
+);
+
+const LockedIcon = () => (
+ <Tooltip content="Notebook locked">
+ <div className={topLeftStatus}>
+ <LockIcon className="w-[25px] h-[25px] text-[var(--blue-11)]" />
</div>
</Tooltip>
);
diff --git a/frontend/src/core/edit-app.tsx b/frontend/src/core/edit-app.tsx
index 547eecd6d6..10e6cb3716 100644
--- a/frontend/src/core/edit-app.tsx
+++ b/frontend/src/core/edit-app.tsx
@@ -301,7 +301,7 @@ export const EditApp: React.FC<AppProps> = ({ userConfig, appConfig }) => {
return (
<>
<AppContainer
- connectionState={connection.state}
+ connection={connection}
isRunning={isRunning}
width={appConfig.width}
>
diff --git a/frontend/src/core/run-app.tsx b/frontend/src/core/run-app.tsx
index 65717ef1d4..baa051a066 100644
--- a/frontend/src/core/run-app.tsx
+++ b/frontend/src/core/run-app.tsx
@@ -38,7 +38,7 @@ export const RunApp: React.FC<AppProps> = ({ appConfig }) => {
return (
<AppContainer
- connectionState={connection.state}
+ connection={connection}
isRunning={isRunning}
width={appConfig.width}
>
diff --git a/frontend/src/css/app/Header.css b/frontend/src/css/app/Header.css
index 73fdf186e2..0777dca25e 100644
--- a/frontend/src/css/app/Header.css
+++ b/frontend/src/css/app/Header.css
@@ -1,11 +1,3 @@
-#Disconnected {
- font-family: var(--monospace-font);
- text-align: center;
- font-size: 1rem;
- font-weight: 400;
- color: var(--red-11);
-}
-
@keyframes running-app-animation {
0% {
transform: rotate(0turn);
@@ -31,13 +23,3 @@
animation-iteration-count: infinite;
animation-delay: 1000ms;
}
-
-.closed-app-icon {
- width: 25px;
- height: 25px;
- color: var(--red-11);
-}
-
-.keyboard-shortcut-group {
- margin-bottom: 40px;
-}
diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.py
index 9337590216..2db0b80be3 100644
--- a/marimo/_server/sessions.py
+++ b/marimo/_server/sessions.py
@@ -760,7 +760,10 @@ class SessionManager:
self, file_key: MarimoFileKey
) -> Optional[Session]:
for session in self.sessions.values():
- if session.initialization_id == file_key:
+ if (
+ session.initialization_id == file_key
+ or session.app_file_manager.path == os.path.abspath(file_key)
+ ):
return session
return None
@@ -833,15 +836,6 @@ class SessionManager:
return True
return False
- def get_session_for_key(self, key: MarimoFileKey) -> Optional[Session]:
- for session in self.sessions.values():
- if (
- session.app_file_manager.path == os.path.abspath(key)
- or session.initialization_id == key
- ) and session.connection_state() == ConnectionState.OPEN:
- return session
- return None
-
async def start_lsp_server(self) -> None:
"""Starts the lsp server if it is not already started.