-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create notebook copies (#2227)
* wip: Create a notebook copy * test: Add unit test * fix: Revert home page, create notebook action * chore: Lint, typecheck, format * fix: Open new notebook copy after create * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: Error handling * fix: Typecheck * fix: Make change requests --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e2e7796
commit 4d6b93f
Showing
18 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
frontend/src/components/editor/actions/useCopyNotebook.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { useImperativeModal } from "@/components/modal/ImperativeModal"; | ||
import { toast } from "@/components/ui/use-toast"; | ||
import { sendCopy } from "@/core/network/requests"; | ||
import { PathBuilder, Paths } from "@/utils/paths"; | ||
|
||
export function useCopyNotebook(source: string | null) { | ||
const { openPrompt, closeModal } = useImperativeModal(); | ||
|
||
return () => { | ||
if (!source) { | ||
return null; | ||
} | ||
const pathBuilder = PathBuilder.guessDeliminator(source); | ||
const filename = Paths.basename(source); | ||
|
||
openPrompt({ | ||
title: "Copy notebook", | ||
description: "Enter a new filename for the notebook copy.", | ||
defaultValue: `_${filename}`, | ||
confirmText: "Copy notebook", | ||
spellCheck: false, | ||
onConfirm: (destination: string) => { | ||
sendCopy({ | ||
source: source, | ||
destination: pathBuilder.join(Paths.dirname(source), destination), | ||
}).then(() => { | ||
closeModal(); | ||
toast({ | ||
title: "Notebook copied", | ||
description: "A copy of the notebook has been created.", | ||
}); | ||
window.open(`/?file=${destination}`, "_blank"); | ||
}); | ||
}, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ export const { | |
sendRestart, | ||
syncCellIds, | ||
sendSave, | ||
sendCopy, | ||
sendStdin, | ||
sendFormat, | ||
sendInterrupt, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.