fixes for undefined parent note #3066

This commit is contained in:
zadam 2022-08-16 23:46:56 +02:00
parent 78bca2477d
commit 8abcf571e8
4 changed files with 7 additions and 5 deletions

View File

@ -105,7 +105,7 @@ class Branch extends AbstractEntity {
return this.childNote; return this.childNote;
} }
/** @returns {Note} */ /** @returns {Note|undefined} - root branch will have undefined parent, all other branches have to have a parent note */
get parentNote() { get parentNote() {
if (!(this.parentNoteId in this.becca.notes) && this.parentNoteId !== 'none') { if (!(this.parentNoteId in this.becca.notes) && this.parentNoteId !== 'none') {
// entities can come out of order in sync/import, create skeleton which will be filled later // entities can come out of order in sync/import, create skeleton which will be filled later

View File

@ -699,9 +699,11 @@ class Note extends AbstractEntity {
sortParents() { sortParents() {
this.parentBranches.sort((a, b) => this.parentBranches.sort((a, b) =>
a.branchId.startsWith('virt-') a.branchId.startsWith('virt-')
|| a.parentNote.hasInheritableOwnedArchivedLabel() ? 1 : -1); || a.parentNote?.hasInheritableOwnedArchivedLabel() ? 1 : -1);
this.parents = this.parentBranches.map(branch => branch.parentNote); this.parents = this.parentBranches
.map(branch => branch.parentNote)
.filter(note => !!note);
} }
/** /**

View File

@ -281,7 +281,7 @@ async function findSimilarNotes(noteId) {
} }
function gatherAncestorRewards(note) { function gatherAncestorRewards(note) {
if (ancestorNoteIds.has(note.noteId)) { if (!note || ancestorNoteIds.has(note.noteId)) {
return 0; return 0;
} }

View File

@ -10,7 +10,7 @@ function getNotesAndBranchesAndAttributes(noteIds) {
const collectedBranchIds = new Set(); const collectedBranchIds = new Set();
function collectEntityIds(note) { function collectEntityIds(note) {
if (collectedNoteIds.has(note.noteId)) { if (!note || collectedNoteIds.has(note.noteId)) {
return; return;
} }