Skip to content

Commit 673a070

Browse files
committed
refactor: Improve notebook renaming logic in DeepnoteExplorerView
Signed-off-by: Tomas Kislan <[email protected]>
1 parent 2760a51 commit 673a070

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/notebooks/deepnote/deepnoteExplorerView.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -789,33 +789,13 @@ export class DeepnoteExplorerView {
789789
return;
790790
}
791791

792-
const notebook = treeItem.data as DeepnoteNotebook;
793-
const currentName = notebook.name;
794-
795-
const newName = await window.showInputBox({
796-
prompt: l10n.t('Enter new notebook name'),
797-
value: currentName,
798-
validateInput: (value) => {
799-
if (!value || value.trim().length === 0) {
800-
return l10n.t('Notebook name cannot be empty');
801-
}
802-
return null;
803-
}
804-
});
805-
806-
if (!newName || newName === currentName) {
807-
return;
808-
}
809-
810792
try {
811793
const fileUri = Uri.file(treeItem.context.filePath);
812794
const projectData = await this.readDeepnoteProjectFile(fileUri);
813-
814795
if (!projectData?.project?.notebooks) {
815796
await window.showErrorMessage(l10n.t('Invalid Deepnote file format'));
816797
return;
817798
}
818-
819799
const targetNotebook = projectData.project.notebooks.find(
820800
(nb: DeepnoteNotebook) => nb.id === treeItem.context.notebookId
821801
);
@@ -825,6 +805,34 @@ export class DeepnoteExplorerView {
825805
return;
826806
}
827807

808+
const itemNotebook = treeItem.data as DeepnoteNotebook;
809+
const currentName = itemNotebook.name;
810+
811+
if (targetNotebook.id !== itemNotebook.id) {
812+
await window.showErrorMessage(l10n.t('Selected notebook is not the target notebook'));
813+
return;
814+
}
815+
816+
const existingNames = new Set(projectData.project.notebooks.map((nb: DeepnoteNotebook) => nb.name));
817+
818+
const newName = await window.showInputBox({
819+
prompt: l10n.t('Enter new notebook name'),
820+
value: currentName,
821+
validateInput: (value) => {
822+
if (!value || value.trim().length === 0) {
823+
return l10n.t('Notebook name cannot be empty');
824+
}
825+
if (existingNames.has(value)) {
826+
return l10n.t('A notebook with this name already exists');
827+
}
828+
return null;
829+
}
830+
});
831+
832+
if (!newName || newName === currentName) {
833+
return;
834+
}
835+
828836
targetNotebook.name = newName;
829837

830838
if (!projectData.metadata) {

0 commit comments

Comments
 (0)