label update should trigger parent resort, fixes #3366

This commit is contained in:
zadam
2022-12-14 23:44:26 +01:00
parent c4b0c44919
commit 31b3af4129
4 changed files with 45 additions and 12 deletions

View File

@@ -46,6 +46,8 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE
if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst'].includes(entity.name)) {
handleSortedAttribute(entity);
} else if (entity.type === 'label') {
handleMaybeSortingLabel(entity);
}
}
else if (entityName === 'notes') {
@@ -94,6 +96,9 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) =>
else if (entity.type === 'label' && entity.name === 'sorted') {
handleSortedAttribute(entity);
}
else if (entity.type === 'label') {
handleMaybeSortingLabel(entity);
}
}
else if (entityName === 'branches') {
runAttachedRelations(entity.getNote(), 'runOnBranchCreation', entity);
@@ -138,6 +143,27 @@ function handleSortedAttribute(entity) {
}
}
function handleMaybeSortingLabel(entity) {
// check if this label is used for sorting, if yes force re-sort
const note = becca.notes[entity.noteId];
// this will not work on deleted notes, but in that case we don't really need to re-sort
if (note) {
for (const parentNote of note.getParentNotes()) {
console.log("PAR", parentNote.noteId);
const sorted = parentNote.getLabelValue("sorted");
console.log("sorted", sorted);
if (sorted?.includes(entity.name)) { // hacky check if the sorting is affected by this label
console.log("RESIRT!");
treeService.sortNotesIfNeeded(parentNote.noteId);
}
}
}
}
eventService.subscribe(eventService.ENTITY_CHANGED, ({ entityName, entity }) => {
processInverseRelations(entityName, entity, (definition, note, targetNote) => {
// we need to make sure that also target's inverse attribute exists and if not, then create it