Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 10 additions & 21 deletions src/notebooks/deepnote/deepnoteSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,18 @@ export class DeepnoteNotebookSerializer implements NotebookSerializer {
* @returns
*/
private findDefaultNotebook(file: DeepnoteFile): DeepnoteNotebook | undefined {
const sortedNotebooks = file.project.notebooks.slice().sort((a, b) => {
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();

// If there's an Init notebook, we don't want to open it by default unless it's the only one.
if (file.project.initNotebookId && a.id === file.project.initNotebookId) {
return 1;
}

if (file.project.initNotebookId && b.id === file.project.initNotebookId) {
return -1;
}

if (nameA < nameB) {
return -1;
}
if (file.project.notebooks.length === 0) {
return undefined;
}

if (nameA > nameB) {
return 1;
}
const sortedNotebooks = file.project.notebooks.slice().sort((a, b) => a.name.localeCompare(b.name));
const sortedNotebooksWithoutInit = file.project.initNotebookId
? sortedNotebooks.filter((nb) => nb.id !== file.project.initNotebookId)
: sortedNotebooks;

return 0;
});
if (sortedNotebooksWithoutInit.length > 0) {
return sortedNotebooksWithoutInit[0];
}

return sortedNotebooks[0];
}
Expand Down
Loading