Skip to content

Fix notebook rename. #262

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

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions examples/1/notebook_20240709183641.ipynb

This file was deleted.

32 changes: 0 additions & 32 deletions examples/66.ipynb

This file was deleted.

32 changes: 0 additions & 32 deletions examples/666.ipynb

This file was deleted.

32 changes: 0 additions & 32 deletions examples/notebook_test.ipynb

This file was deleted.

2 changes: 2 additions & 0 deletions server/app/services/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def rename_notebook_by_path(notebook_path: str = None, new_notebook_name: str =
parent_path = '/'.join(notebook_path.split('/')[:-1])
new_path = f"{parent_path}/{new_notebook_name}"

logger.info(f"Renaming notebook with path: {notebook_path} to {new_path}")

response = requests.patch(
path,
json={"path": new_path}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/notebook/Notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Notebook({
path: 'work/' + currentName,
}
});
NotebookModel.renameNotebook(baseUrl, notebook.path, currentName).then((data) => {
NotebookModel.renameNotebook(notebook.path, currentName).then((data) => {
console.log('Notebook name saved:', data);
}).catch((error) => {
console.error('Failed to save notebook name:', error);
Expand Down
8 changes: 6 additions & 2 deletions webapp/src/components/sidebar/workspace/item/MoreButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CgMoreVerticalAlt } from "react-icons/cg";
import { Menu, MenuItem } from '@mui/material';
import config from '../../../../config';
import DirectoryModel from '../../../../models/DirectoryModel';
import NotebookModel from '../../../../models/NotebookModel';
import DeleteDialog from './DeleteDialog';
import RenameDialog from './RenameDialog';

Expand Down Expand Up @@ -38,7 +39,11 @@ const MoreButton = ({

const handleRename = async (file, newName) => {
try {
await DirectoryModel.renameItem(currentPath + '/' + file.name, currentPath + '/' + newName);
if (file.type === 'notebook') {
await NotebookModel.renameNotebook(currentPath + '/' + file.name, newName);
} else {
await DirectoryModel.renameDirectory(currentPath + '/' + file.name, currentPath + '/' + newName);
}
} catch (error) {
console.error('Failed to rename item:', error);
}
Expand Down Expand Up @@ -98,7 +103,6 @@ const MoreButton = ({
Rename
</MenuItem>
<RenameDialog
baseUrl={baseUrl}
file={file}
renameDialogOpen={renameDialogOpen}
setRenameDialogOpen={setRenameDialogOpen}
Expand Down
5 changes: 2 additions & 3 deletions webapp/src/components/sidebar/workspace/item/RenameDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { useState } from 'react';
import NotebookModel from '../../../../models/NotebookModel';

const RenameDialog = ({
baseUrl,
file,
renameDialogOpen,
setRenameDialogOpen,
handleMoreClose,
handleRename
}) => {

const [newName, setNewName] = useState(file.name);
const [newName, setNewName] = useState(NotebookModel.getNameWithoutExtension(file.name));

const handleInputChange = (event) => {
setNewName(event.target.value);
Expand Down Expand Up @@ -68,7 +67,7 @@ const RenameDialog = ({
</Button>
<Button
style={{ color: 'lightgrey' }}
onClick={(event) => {
onClick={() => {
setRenameDialogOpen(false);
handleMoreClose();
file.type === 'directory' ?
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/models/DirectoryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DirectoryModel {
}
};

static async renameItem(oldPath='', newPath='') {
static async renameDirectory(oldPath='', newPath='') {
console.log("Renaming item at path:", oldPath, "to", newPath);
const response = await fetch("http://localhost:5002/directory/" + oldPath, {
method: 'PATCH',
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/models/NotebookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class NotebookModel {
});

if (!response.ok) {
throw new Error('Failed to create notebook');
throw new Error('Failed to delete notebook');
} else {
const data = await response.json();
return data;
Expand Down Expand Up @@ -194,8 +194,8 @@ class NotebookModel {
return data;
};

static async renameNotebook(basePath = '', path = '', newName = '') {
console.log("Renaming notebook at path:", basePath + '/' + path, "to:", newName);
static async renameNotebook(path = '', newName = '') {
console.log("Renaming notebook at path:", path, "to:", newName);

const response = await fetch("http://localhost:5002/notebook/" + path, {
method: 'PATCH',
Expand Down
Loading