From 351bb760ae468b93371c4cb4a4a6e72f4dbae794 Mon Sep 17 00:00:00 2001 From: Philipp Oeschger Date: Mon, 27 Mar 2023 01:42:50 +0200 Subject: [PATCH 1/4] change downdown border to light border --- src/public/stylesheets/style.css | 1 + src/public/stylesheets/theme-dark.css | 1 + src/public/stylesheets/theme-light.css | 1 + 3 files changed, 3 insertions(+) diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 90970b2c0..3353f5e86 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -181,6 +181,7 @@ div.ui-tooltip { } .dropdown-menu { + border: 1px solid var(--dropdown-border-color); color: var(--menu-text-color) !important; background-color: var(--menu-background-color) !important; } diff --git a/src/public/stylesheets/theme-dark.css b/src/public/stylesheets/theme-dark.css index 535282c30..c44690e41 100644 --- a/src/public/stylesheets/theme-dark.css +++ b/src/public/stylesheets/theme-dark.css @@ -16,6 +16,7 @@ --main-background-color: #333; --main-text-color: #ccc; --main-border-color: #aaa; + --dropdown-border-color: #555; --accented-background-color: #555; --more-accented-background-color: #777; diff --git a/src/public/stylesheets/theme-light.css b/src/public/stylesheets/theme-light.css index 2eeb8b408..1bf4bb509 100644 --- a/src/public/stylesheets/theme-light.css +++ b/src/public/stylesheets/theme-light.css @@ -20,6 +20,7 @@ html { --main-background-color: white; --main-text-color: black; --main-border-color: #ccc; + --dropdown-border-color: #ccc; --accented-background-color: #f5f5f5; --more-accented-background-color: #ddd; From 89681977b5fe96643dc2671685ec3f9f51ef9ce8 Mon Sep 17 00:00:00 2001 From: baiyongjie <407221377@qq.com> Date: Sun, 23 Apr 2023 15:36:34 +0800 Subject: [PATCH 2/4] perf: improve descendant count performance --- src/routes/api/note_map.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index b8487e6ce..9f33960d2 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -3,9 +3,12 @@ const becca = require("../../becca/becca"); const { JSDOM } = require("jsdom"); const NotFoundError = require("../../errors/not_found_error"); +function buildDescendantCountMap(noteIdsToCount) { + if (!Array.isArray(noteIdsToCount)) { + throw new Error('noteIdsToCount: type error'); + } -function buildDescendantCountMap() { - const noteIdToCountMap = {}; + const noteIdToCountMap = Object.create(null); function getCount(noteId) { if (!(noteId in noteIdToCountMap)) { @@ -24,12 +27,12 @@ function buildDescendantCountMap() { return noteIdToCountMap[noteId]; } - - getCount('root'); + noteIdsToCount.forEach((nodeId) => { + getCount(nodeId); + }); return noteIdToCountMap; } - /** * @param {BNote} note * @param {int} depth @@ -119,7 +122,9 @@ function getLinkMap(req) { noteIds.add(noteId); } - const notes = Array.from(noteIds).map(noteId => { + const noteIdsArray = Array.from(noteIds) + + const notes = noteIdsArray.map(noteId => { const note = becca.getNote(noteId); return [ @@ -155,7 +160,7 @@ function getLinkMap(req) { return { notes: notes, - noteIdToDescendantCountMap: buildDescendantCountMap(), + noteIdToDescendantCountMap: buildDescendantCountMap(noteIdsArray), links: links }; } @@ -209,7 +214,7 @@ function getTreeMap(req) { }); } - const noteIdToDescendantCountMap = buildDescendantCountMap(); + const noteIdToDescendantCountMap = buildDescendantCountMap(Array.from(noteIds)); updateDescendantCountMapForSearch(noteIdToDescendantCountMap, subtree.relationships); From e007aba06702a3630549c9892b157651014141e2 Mon Sep 17 00:00:00 2001 From: Castor <407221377@qq.com> Date: Mon, 24 Apr 2023 13:43:19 +0800 Subject: [PATCH 3/4] Update note_map.js --- src/routes/api/note_map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index 9f33960d2..11fc9a3e6 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -27,8 +27,8 @@ function buildDescendantCountMap(noteIdsToCount) { return noteIdToCountMap[noteId]; } - noteIdsToCount.forEach((nodeId) => { - getCount(nodeId); + noteIdsToCount.forEach((noteId) => { + getCount(noteId); }); return noteIdToCountMap; From 53c87f3d250d5bcbedae05fe96d8e2856a20ee37 Mon Sep 17 00:00:00 2001 From: Kara Date: Mon, 1 May 2023 12:41:22 -0500 Subject: [PATCH 4/4] Return created/existing branch in `EnsureNoteIsPresentInParent` --- src/services/backend_script_api.js | 4 ++-- src/services/cloning.js | 8 ++++---- src/services/tree.js | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 526617d44..d2906df91 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -137,13 +137,13 @@ function BackendScriptApi(currentNote, apiParams) { this.getNoteWithLabel = attributeService.getNoteWithLabel; /** - * If there's no branch between note and parent note, create one. Otherwise, do nothing. + * If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch. * * @method * @param {string} noteId * @param {string} parentNoteId * @param {string} prefix - if branch will be created between note and parent note, set this prefix - * @returns {void} + * @returns {{branch: BBranch|null}} */ this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent; diff --git a/src/services/cloning.js b/src/services/cloning.js index f62b8724b..30235fbc1 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -61,15 +61,15 @@ function cloneNoteToBranch(noteId, parentBranchId, prefix) { function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) { if (isNoteDeleted(noteId)) { - return { success: false, message: `Note '${noteId}' is deleted.` }; + return { branch: null, success: false, message: `Note '${noteId}' is deleted.` }; } else if (isNoteDeleted(parentNoteId)) { - return { success: false, message: `Note '${parentNoteId}' is deleted.` }; + return { branch: null, success: false, message: `Note '${parentNoteId}' is deleted.` }; } const parentNote = becca.getNote(parentNoteId); if (parentNote.type === 'search') { - return { success: false, message: "Can't clone into a search note" }; + return { branch: null, success: false, message: "Can't clone into a search note" }; } const validationResult = treeService.validateParentChild(parentNoteId, noteId); @@ -87,7 +87,7 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) { log.info(`Ensured note '${noteId}' is in parent note '${parentNoteId}' with prefix '${branch.prefix}'`); - return { success: true }; + return { branch: branch, success: true }; } function ensureNoteIsAbsentFromParent(noteId, parentNoteId) { diff --git a/src/services/tree.js b/src/services/tree.js index 1038e8772..fd3c034c0 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -31,12 +31,12 @@ function getNotes(noteIds) { function validateParentChild(parentNoteId, childNoteId, branchId = null) { if (['root', '_hidden', '_share', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(childNoteId)) { - return { success: false, message: `Cannot change this note's location.`}; + return { branch: null, success: false, message: `Cannot change this note's location.`}; } if (parentNoteId === 'none') { // this shouldn't happen - return { success: false, message: `Cannot move anything into 'none' parent.` }; + return { branch: null, success: false, message: `Cannot move anything into 'none' parent.` }; } const existing = getExistingBranch(parentNoteId, childNoteId); @@ -46,6 +46,7 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) { const childNote = becca.getNote(childNoteId); return { + branch: existing, success: false, message: `Note "${childNote.title}" note already exists in the "${parentNote.title}".` }; @@ -53,6 +54,7 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) { if (!checkTreeCycle(parentNoteId, childNoteId)) { return { + branch: null, success: false, message: 'Moving/cloning note here would create cycle.' }; @@ -60,12 +62,13 @@ function validateParentChild(parentNoteId, childNoteId, branchId = null) { if (parentNoteId !== '_lbBookmarks' && becca.getNote(parentNoteId).type === 'launcher') { return { + branch: null, success: false, message: 'Launcher note cannot have any children.' }; } - return { success: true }; + return { branch: null, success: true }; } function getExistingBranch(parentNoteId, childNoteId) {