-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Create notebook copies #2227
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
19e5df7
wip: Create a notebook copy
wasimsandhu fcbb8af
test: Add unit test
wasimsandhu 910c297
fix: Revert home page, create notebook action
wasimsandhu 99fd552
chore: Lint, typecheck, format
wasimsandhu 13a8de3
fix: Open new notebook copy after create
wasimsandhu ae1c7e6
Merge branch 'main' into ws/copy-notebook
wasimsandhu 0330f87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5a33dbe
fix: Error handling
wasimsandhu 281285a
Merge branch 'ws/copy-notebook' of https://github.com/marimo-team/mar…
wasimsandhu 2df9c99
fix: Typecheck
wasimsandhu fa12271
fix: Make change requests
wasimsandhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
/* 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 = new PathBuilder("/"); | ||
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.", | ||
}); | ||
const notebookCopy = window.location.href.replace( | ||
filename, | ||
destination, | ||
); | ||
window.open(notebookCopy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would just directly do:
|
||
}) | ||
.catch((error) => { | ||
toast({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we already toast from the request wrapper in |
||
title: "Failed to copy notebook", | ||
description: error.detail, | ||
variant: "danger", | ||
}); | ||
}); | ||
}, | ||
}); | ||
}; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const pathBuilder = PathBuilder.guessDeliminator(source)