Skip to content

Commit 03d5944

Browse files
mscolnicksebbeutler
authored andcommitted
fix: opening a notebook from the sidebar when in a subpath (marimo-team#5561)
Fixes marimo-team#5239 This removes the leading `/` when opening notebooks in a few places, and consolidates the logic.
1 parent bd9ec71 commit 03d5944

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

frontend/src/components/editor/actions/useCopyNotebook.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useImperativeModal } from "@/components/modal/ImperativeModal";
33
import { toast } from "@/components/ui/use-toast";
44
import { sendCopy } from "@/core/network/requests";
5+
import { openNotebook } from "@/utils/links";
56
import { PathBuilder, Paths } from "@/utils/paths";
67

78
export function useCopyNotebook(source: string | null) {
@@ -31,7 +32,7 @@ export function useCopyNotebook(source: string | null) {
3132
title: "Notebook copied",
3233
description: "A copy of the notebook has been created.",
3334
});
34-
window.open(`/?file=${destination}`, "_blank");
35+
openNotebook(destination);
3536
});
3637
},
3738
});

frontend/src/components/editor/file-tree/file-explorer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { ErrorBanner } from "@/plugins/impl/common/error-banner";
5757
import { cn } from "@/utils/cn";
5858
import { copyToClipboard } from "@/utils/copy";
5959
import { downloadBlob } from "@/utils/download";
60+
import { openNotebook } from "@/utils/links";
6061
import type { FilePath } from "@/utils/paths";
6162
import { fileSplit } from "@/utils/pathUtils";
6263
import { FileViewer } from "./file-viewer";
@@ -675,5 +676,5 @@ function openMarimoNotebook(
675676
) {
676677
event.stopPropagation();
677678
event.preventDefault();
678-
window.open(`/?file=${path}`, "_blank");
679+
openNotebook(path);
679680
}

frontend/src/components/home/components.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import {
3030
import { Constants } from "@/core/constants";
3131
import { openTutorial } from "@/core/network/requests";
3232
import type { TutorialId } from "@/core/network/types";
33+
import { openNotebook } from "@/utils/links";
3334
import { Objects } from "@/utils/objects";
34-
import { asURL } from "@/utils/url";
3535

3636
const TUTORIALS: Record<
3737
TutorialId,
@@ -89,7 +89,7 @@ export const OpenTutorialDropDown: React.FC = () => {
8989
if (!file) {
9090
return;
9191
}
92-
window.open(asURL(`?file=${file.path}`).toString(), "_blank");
92+
openNotebook(file.path);
9393
}}
9494
>
9595
<Icon

frontend/src/utils/links.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Copyright 2024 Marimo. All rights reserved. */
2+
import { asURL } from "./url";
3+
4+
/**
5+
* Open a notebook in a new tab.
6+
* @param path - The path to the notebook.
7+
*/
8+
export function openNotebook(path: string) {
9+
// There is no leading `/` in the path in order to work when marimo is at a subpath.
10+
window.open(asURL(`?file=${path}`).toString(), "_blank");
11+
}

0 commit comments

Comments
 (0)