Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(client): send the note map's entry points to the sidebar and the popup
Elian Doranc5855e0d2d84
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex ec018e8ff3..95ad3d8cc1 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -150,6 +150,8 @@ export type CommandMappings = {openInWindow: NoteCommandData;/** Opens a note in the quick-edit popup. A `viewScope` carrying an `attachmentId` opens that attachment instead of the note itself. */openInPopup: CommandData & { noteIdOrPath: string; viewScope?: ViewScope; };+ /** Dismisses the quick-edit popup, for something within it that has sent the reader elsewhere. Does nothing if it isn't open. */+ closePopupEditor: CommandData;openInTreePopup: CommandData & { noteIdOrPath: string; hoistedNoteId: string; };openNoteInNewTab: CommandData;openNoteInNewSplit: CommandData;diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.tsindex 9d8b4e9303..7f341b22f4 100644--- a/apps/client/src/components/root_command_executor.ts+++ b/apps/client/src/components/root_command_executor.ts@@ -5,7 +5,7 @@ import options from "../services/options.js";import protectedSessionService from "../services/protected_session.js";import { collectShortcutHints } from "../services/shortcut_hints.js";import treeService from "../services/tree.js";-import utils, { openInReusableSplit } from "../services/utils.js";+import utils from "../services/utils.js";import appContext, { type CommandListenerData } from "./app_context.js";import Component from "./component.js";@@ -203,9 +203,16 @@ export default class RootCommandExecutor extends Component {return;}- const activeContext = appContext.tabManager.getActiveContext();- if (!activeContext?.notePath) return;- openInReusableSplit(activeContext.notePath, "note-map");+ // The sidebar's map is the note map of the new layout: it is the one that follows the note being+ // read, so the menu points at it rather than opening a second copy beside it that would then go+ // stale. Peeked rather than docked, as the connection badges of the status bar are: a press for+ // the tab already docked would otherwise close the pane out from under the card it is meant to+ // expand (see reduceTabSelection).+ void appContext.triggerEvent("selectRightPaneTab", {+ tabId: "connections",+ peek: true,+ expandWidgetId: "noteMap"+ });}firstTabCommand() {diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsxindex 8af61a7deb..68ffb590a7 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx@@ -119,6 +119,8 @@ import { ParentComponent } from "../react/react_utils";import PopupEditor from "./PopupEditor";const ATTACHMENT_SCOPE: ViewScope = { viewMode: "attachments", attachmentId: "att-1" };+/** A view mode of the note itself, as the sidebar's note map card expands into the popup with. */+const NOTE_MAP_SCOPE: ViewScope = { viewMode: "note-map" };function fakeNote(labels: string[] = [], isOptions = false) {return {@@ -278,7 +280,7 @@ describe("PopupEditor", () => {expect(modal()?.dataset.shown).toBe("false");});- it("maximizes into a tab, carrying the attachment along when one is in view", async () => {+ it("maximizes into a tab, carrying along whatever is in view instead of the note itself", async () => {await openPopup({ noteIdOrPath: "root/n1" });await act(async () => container.querySelector<HTMLElement>(".maximize-stub")?.click());@@ -294,6 +296,27 @@ describe("PopupEditor", () => {viewScope: expect.objectContaining(ATTACHMENT_SCOPE),activate: true});++ // Likewise for a view mode of the note itself: the last rung of the map's expand ladder is the+ // popup's own maximize, which would otherwise land on the note and leave the map behind.+ await openPopup({ noteIdOrPath: "root/n1", viewScope: NOTE_MAP_SCOPE });+ await act(async () => container.querySelector<HTMLElement>(".maximize-stub")?.click());++ expect(mocks.openContextWithNote).toHaveBeenLastCalledWith("n1", {+ hoistedNoteId: "root",+ viewScope: expect.objectContaining(NOTE_MAP_SCOPE),+ activate: true+ });+ });++ it("stands aside when something within it has sent the reader elsewhere", async () => {+ await openPopup({ noteIdOrPath: "root/n1" });+ expect(modal()?.dataset.shown).toBe("true");++ // What a press on a node of the note map amounts to: the map navigates the pane behind the+ // popup, so the popup would otherwise be left covering the note it has just gone to.+ await act(async () => { await parent.handleEvent("closePopupEditor", {} as never); });+ expect(modal()?.dataset.shown).toBe("false");});it("stays put when there is no note to maximize", async () => {diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex 65fd9f5d8e..2879222d0f 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx@@ -73,6 +73,11 @@ export default function PopupEditor() {setShown(true);});+ // Asked to stand aside by something within it that has sent the reader elsewhere — the note map,+ // whose nodes navigate the pane behind rather than the popup, which would otherwise be left covering+ // the note it has just gone to with a map of the note it came from.+ useTriliumEvent("closePopupEditor", () => setShown(false));+// Keep navigation that follows internal links inside the popup, rather than letting the global// link handler open the target in the background tab. Settings links open the options dialog.useContainedLinkNavigation(modalRef, useCallback((notePath, viewScope) => {@@ -114,8 +119,10 @@ export default function PopupEditor() {onClick: async () => {if (!noteContext.noteId) return;const { noteId, hoistedNoteId, viewScope } = noteContext;- if (viewScope?.attachmentId) {- // Keep showing the attachment rather than falling back to its owning note.+ if (viewScope?.attachmentId || (viewScope?.viewMode && viewScope.viewMode !== "default")) {+ // Whatever is on show that isn't the note itself — an attachment, or a view+ // mode such as the note map — is carried over, or the tab would open on the+ // note and drop what was being looked at.await appContext.tabManager.openContextWithNote(noteId, { hoistedNoteId, viewScope, activate: true });} else {await appContext.tabManager.openInNewTab(noteId, hoistedNoteId, true);diff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsxindex 67b7cd052e..730ef80781 100644--- a/apps/client/src/widgets/note_map/NoteMap.tsx+++ b/apps/client/src/widgets/note_map/NoteMap.tsx@@ -125,7 +125,7 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {// map shown in the quick-edit popup has to dismiss it, or it would be left covering the// note it has just gone to. Raised whatever the host: a map anywhere else is behind the// popup's backdrop while that is open, and so cannot be the one being pressed.- void appContext.triggerCommand("closePopupEditor");+ void appContext.triggerEvent("closePopupEditor", {});}).onNodeRightClick((node, e) => {if (!node.id) return;