Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): show a saved search's results once the tree loads them

Elian Doranf8dbf6e4db6c
diff --git a/apps/client/src/services/froca.spec.ts b/apps/client/src/services/froca.spec.ts
index a359b760b0..5078fb65a1 100644
--- a/apps/client/src/services/froca.spec.ts
+++ b/apps/client/src/services/froca.spec.ts
@@ -307,6 +307,7 @@ describe("loadSearchNote", () => {
expect(search.highlightedTokenInfos).toEqual([{ token: "token", type: "plain" }]);
expect(search.children).toContain(result.noteId);
expect(search.children).not.toContain("stale");
+ expect(appContext.triggerEvent).toHaveBeenCalledWith("notesReloaded", { noteIds: [ search.noteId ] });
});
it("stores the server's structured highlightedTokenInfos as-is when present", async () => {
diff --git a/apps/client/src/services/froca.ts b/apps/client/src/services/froca.ts
index 307b764808..3be6204f53 100644
--- a/apps/client/src/services/froca.ts
+++ b/apps/client/src/services/froca.ts
@@ -242,6 +242,9 @@ class FrocaImpl implements Froca {
froca.notes[note.noteId].highlightedTokenInfos = highlightedTokenInfos
?? highlightedTokens.map((token) => ({ token, type: "plain" as const }));
+ // The tree and embedded collections also load search notes, so `SearchResult` needs telling.
+ appContext.triggerEvent("notesReloaded", { noteIds: [ note.noteId ] });
+
return { error };
}
diff --git a/apps/client/src/widgets/search_result.spec.tsx b/apps/client/src/widgets/search_result.spec.tsx
index 3957c886de..729c79d1b7 100644
--- a/apps/client/src/widgets/search_result.spec.tsx
+++ b/apps/client/src/widgets/search_result.spec.tsx
@@ -25,6 +25,7 @@ vi.mock("./react/hooks", async (importOriginal) => {
};
});
+import appContext from "../components/app_context";
import Component from "../components/component";
import froca from "../services/froca";
import server from "../services/server";
@@ -99,6 +100,22 @@ describe("SearchResult", () => {
expect(container.querySelector("button")).toBeNull();
});
+ it("shows the results of a saved search loaded elsewhere, such as by expanding it in the tree", async () => {
+ const savedSearch = buildNote({ id: "treeSearch", title: "Tree search", type: "search", "#searchString": "#book" });
+ const result = buildNote({ id: "treeResult", title: "Result" });
+ vi.spyOn(server, "get").mockResolvedValue({ searchResultNoteIds: [ result.noteId ], highlightedTokens: [], error: null });
+ vi.spyOn(appContext, "triggerEvent").mockImplementation(async (name, data) => parent.handleEvent(name, data));
+
+ shownNote.current = savedSearch;
+ await mount();
+ expect(container.querySelector(".no-items .bx-file-find")).not.toBeNull();
+
+ await settle(() => { void froca.loadSearchNote(savedSearch.noteId); });
+
+ expect(container.querySelector(".no-items")).toBeNull();
+ expect(container.textContent).toContain("Result");
+ });
+
it("reports an error from the saved search as a toast", async () => {
const savedSearch = buildNote({ id: "badSearch", title: "Bad search", type: "search", "#searchString": "#" });
vi.spyOn(froca, "loadSearchNote").mockResolvedValue({ error: "Invalid saved search" });