From 43e12fbea257c37155c8848ab73151c59de97214 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 3 May 2020 13:52:12 +0200 Subject: [PATCH] small fixes for collapse/expand --- src/public/app/services/tree_cache.js | 2 +- src/public/app/services/tree_context_menu.js | 2 +- src/public/app/widgets/note_tree.js | 4 +++- src/routes/api/branches.js | 11 ++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js index 3f92901e6..baf7350b3 100644 --- a/src/public/app/services/tree_cache.js +++ b/src/public/app/services/tree_cache.js @@ -231,7 +231,7 @@ class TreeCache { /** @return {Promise} */ async getNote(noteId, silentNotFoundError = false) { if (noteId === 'none') { - console.log(`No 'none' note.`); + console.trace(`No 'none' note.`); return null; } else if (!noteId) { diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.js index dd0b9a6bd..0478a05ff 100644 --- a/src/public/app/services/tree_context_menu.js +++ b/src/public/app/services/tree_context_menu.js @@ -40,9 +40,9 @@ class TreeContextMenu { async getMenuItems() { const note = await treeCache.getNote(this.node.data.noteId); const branch = treeCache.getBranch(this.node.data.branchId); - const parentNote = await treeCache.getNote(branch.parentNoteId); const isNotRoot = note.noteId !== 'root'; const isHoisted = note.noteId === hoistedNoteService.getHoistedNoteId(); + const parentNote = isNotRoot ? await treeCache.getNote(branch.parentNoteId) : null; // some actions don't support multi-note so they are disabled when notes are selected // the only exception is when the only selected note is the one that was right-clicked, then diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 0959dafdd..11b80f8fc 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -606,7 +606,9 @@ export default class NoteTreeWidget extends TabAwareWidget { await this.batchUpdate(async () => { await node.load(true); - await node.setExpanded(isExpanded, {noEvents: true}); + if (node.data.noteId !== 'root') { // root is always expanded + await node.setExpanded(isExpanded, {noEvents: true}); + } }); } diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 7bceaa4cc..b0cfe0578 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -114,14 +114,16 @@ async function moveBranchAfterNote(req) { async function setExpanded(req) { const {branchId, expanded} = req.params; - await sql.execute("UPDATE branches SET isExpanded = ? WHERE branchId = ?", [expanded, branchId]); - // we don't sync expanded label + if (branchId !== 'root') { + await sql.execute("UPDATE branches SET isExpanded = ? WHERE branchId = ?", [expanded, branchId]); + // we don't sync expanded label + } } async function setExpandedForSubtree(req) { const {branchId, expanded} = req.params; - const branchIds = await sql.getColumn(` + let branchIds = await sql.getColumn(` WITH RECURSIVE tree(branchId, noteId) AS ( SELECT branchId, noteId FROM branches WHERE branchId = ? @@ -132,6 +134,9 @@ async function setExpandedForSubtree(req) { ) SELECT branchId FROM tree`, [branchId]); + // root is always expanded + branchIds = branchIds.filter(branchId => branchId !== 'root'); + await sql.executeMany(`UPDATE branches SET isExpanded = ${expanded} WHERE branchId IN (???)`, branchIds); return {