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
style(autocomplete): address review nits
Elian Dorandff088a69fd3
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.tsindex 4bc2396566..948e08eb6c 100644--- a/apps/client/src/services/note_autocomplete.spec.ts+++ b/apps/client/src/services/note_autocomplete.spec.ts@@ -3,14 +3,19 @@ import $ from "jquery";// --- Mocks (hoisted above imports) ----const { triggerCommand, getActiveContextNoteId, getActiveContext, chooseNoteType, createNote, getInboxNotePath, getInboxTarget, translate, getAllCommands, searchCommands } = vi.hoisted(() => ({+const {+ triggerCommand, getActiveContextNoteId, getActiveContext, chooseNoteType, createNote,+ getInboxNotePath, getInboxTarget, translate, getAllCommands, searchCommands+} = vi.hoisted(() => ({triggerCommand: vi.fn(),getActiveContextNoteId: vi.fn<() => string | null>(() => "activeNote"),getActiveContext: vi.fn<() => any>(() => ({ hoistedNoteId: "hoisted" })),chooseNoteType: vi.fn(),createNote: vi.fn(),getInboxNotePath: vi.fn<() => Promise<string | undefined>>(async () => "root/inbox"),- getInboxTarget: vi.fn<() => Promise<unknown>>(async () => ({ kind: "inbox", noteId: "inb", title: "Inbox" })),+ getInboxTarget: vi.fn<() => Promise<unknown>>(+ async () => ({ kind: "inbox", noteId: "inb", title: "Inbox" })+ ),// i18next is never initialised here, so the real `t` returns undefined. Echoing the key// keeps the label assertions about which string is chosen rather than about its English.translate: vi.fn((key: string, _opts?: Record<string, unknown>) => key),@@ -148,8 +153,8 @@ describe("note_autocomplete", () => {// only the synthetic creation rows remain; they have no notePathTitle.const createRow = result.find((r) => r.action === "create-note");expect(createRow).toBeDefined();- expect(createRow!.name).toBe("");- expect(createRow!.id).toBe("@undefined");+ expect(createRow?.name).toBe("");+ expect(createRow?.id).toBe("@undefined");});});});diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.tsindex 7a17e8ce72..21cc919b13 100644--- a/apps/client/src/services/note_autocomplete.ts+++ b/apps/client/src/services/note_autocomplete.ts@@ -32,8 +32,7 @@ async function getInboxTarget() {try {return await dateNoteService.getInboxTarget();} catch (e) {- // A destination that cannot be named is not worth failing the dropdown over: the- // entry falls back to a label without one.+ // The entry falls back to a label with no destination rather than failing the dropdown.logError(`Unable to resolve the inbox target: ${e}`);return null;}@@ -166,8 +165,7 @@ async function autocompleteSource(term: string, cb: (rows: Suggestion[]) => voidconst activeNoteId = appContext.tabManager.getActiveContextNoteId();const length = term.trim().length;- // Started before the search rather than after it, so naming the destination costs a request- // but no extra wait.+ // Runs concurrently with the search, so naming the destination costs a request but no wait.const pendingInboxTarget = length >= 1 && options.allowCreatingNotes ? getInboxTarget() : null;let results = await server.get<Suggestion[]>(`autocomplete?query=${encodeURIComponent(term)}&activeNoteId=${activeNoteId}&fastSearch=${fastSearch}`);diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 85ee9530ec..4d39246c34 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -794,8 +794,8 @@ export type SimilarNoteResponse = SimilarNote[];export type SaveSearchNoteResponse = CloneResponse;/**- * Which rule decided where a quickly captured note goes. `dayNote` is the only one that- * names no note, because the day note is created when the capture happens.+ * Which rule decided where a quickly captured note goes. `dayNote` carries no note ID, because+ * the day note is created at capture time.*/export type InboxTargetKind = "inbox" | "workspaceInbox" | "workspaceRoot" | "dayNote" | "root";diff --git a/packages/trilium-core/src/services/special_notes.ts b/packages/trilium-core/src/services/special_notes.tsindex 8bbcb12f4a..f0b3d7f610 100644--- a/packages/trilium-core/src/services/special_notes.ts+++ b/packages/trilium-core/src/services/special_notes.ts@@ -10,7 +10,10 @@ import SearchContext from "./search/search_context.js";import { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } from "./hidden_subtree.js";import { t } from "i18next";import BNote from '../becca/entities/bnote.js';-import { InboxTargetKind, InboxTargetResponse, SaveLlmChatResponse, SaveSearchNoteResponse, SaveSqlConsoleResponse } from "@triliumnext/commons";+import {+ InboxTargetKind, InboxTargetResponse, SaveLlmChatResponse, SaveSearchNoteResponse,+ SaveSqlConsoleResponse+} from "@triliumnext/commons";function getInboxNote(date: string) {const { note } = resolveInboxTarget();@@ -19,9 +22,8 @@ function getInboxNote(date: string) {}/**- * Decides where a quickly captured note goes, without creating anything. `getInboxNote()`- * creates the day note it falls back to, so callers that only want to name the destination —- * the note autocomplete labels its creation entry with it — go through this instead.+ * Decides where a quickly captured note goes. Creates nothing, unlike `getInboxNote()`, which+ * creates the day note it falls back to. Use this to name the destination without capturing.*/function resolveInboxTarget(): { kind: InboxTargetKind; note?: BNote } {const workspaceNote = hoistedNoteService.getWorkspaceNote();