Skip to content

Build your personal knowledge base with Trilium Notes

client: fix some issues

Adorian Doranba673a6ef5d1
diff --git a/apps/client/src/menus/context_menu_utils.ts b/apps/client/src/menus/context_menu_utils.ts
index 14b6fd9afc..82dee190a7 100644
--- a/apps/client/src/menus/context_menu_utils.ts
+++ b/apps/client/src/menus/context_menu_utils.ts
@@ -46,16 +46,16 @@ export async function notePathMenuItem<T>(
notePath: string,
handler: () => void
): Promise<MenuCommandItem<T>> {
- const titles = await tree.getNotePathTitleComponents(notePath)
- const title = titles.pop() ?? ""
- const noteId = notePath.split("/").at(-1) ?? ""
+ const titles = await tree.getNotePathTitleComponents(notePath);
+ const title = titles.pop() ?? "";
+ const noteId = notePath.split("/").at(-1) ?? "";
return {
title: escapeHtml(title),
trailingText: titles.join(NOTE_PATH_TITLE_SEPARATOR) || undefined,
uiIcon: froca.getNoteFromCache(noteId)?.getIcon(),
handler
- }
+ };
}
/** A row that opens `items` as a submenu, enabled while any of their commands is. */
diff --git a/apps/client/src/menus/recent_changes_menu_items.spec.ts b/apps/client/src/menus/recent_changes_menu_items.spec.ts
index bda882905b..ff70a1fb91 100644
--- a/apps/client/src/menus/recent_changes_menu_items.spec.ts
+++ b/apps/client/src/menus/recent_changes_menu_items.spec.ts
@@ -96,19 +96,29 @@ describe("getRecentChangesMenuItems", () => {
]);
});
- it("keeps only the dialog entry when no note qualifies", async () => {
+ it("keeps only the dialog entry when no note qualifies or the request fails", async () => {
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
+ const onlyShowAll = [
+ { kind: "header", title: "tab_row.recently_changed_notes" },
+ SHOW_ALL
+ ];
+
mocks.noteContexts = [ { noteId: "html" } ];
mocks.get.mockResolvedValueOnce([ "html" ]);
+ expect(await getRecentChangesMenuItems()).toEqual(onlyShowAll);
- expect(await getRecentChangesMenuItems()).toEqual([
- { kind: "header", title: "tab_row.recently_changed_notes" },
- SHOW_ALL
- ]);
+ const error = new Error("Offline");
+ mocks.get.mockRejectedValueOnce(error);
+ expect(await getRecentChangesMenuItems()).toEqual(onlyShowAll);
+ expect(consoleError).toHaveBeenCalledWith(expect.any(String), error);
+ consoleError.mockRestore();
});
});
describe("getRecentlyChangedNotesMenuItems", () => {
it("lists the heading and the notes without the dialog entry, or nothing", async () => {
+ const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
+
mocks.get.mockResolvedValueOnce([ "plan3" ]);
expect((await getRecentlyChangedNotesMenuItems()).map(describeItem)).toEqual([
[ "header", "tab_row.recently_changed_notes" ],
@@ -117,6 +127,10 @@ describe("getRecentlyChangedNotesMenuItems", () => {
mocks.get.mockResolvedValueOnce([]);
expect(await getRecentlyChangedNotesMenuItems()).toEqual([]);
+
+ mocks.get.mockRejectedValueOnce(new Error("Offline"));
+ expect(await getRecentlyChangedNotesMenuItems()).toEqual([]);
+ consoleError.mockRestore();
});
});
diff --git a/apps/client/src/menus/recent_changes_menu_items.ts b/apps/client/src/menus/recent_changes_menu_items.ts
index 794602364b..52dedb6d9b 100644
--- a/apps/client/src/menus/recent_changes_menu_items.ts
+++ b/apps/client/src/menus/recent_changes_menu_items.ts
@@ -42,7 +42,17 @@ export async function getRecentlyChangedNotesMenuItems(): Promise<MenuItem<Comma
return [ { kind: "header", title: t("tab_row.recently_changed_notes") }, ...noteItems ];
}
+/** Returns the recently changed notes as menu rows, or no rows when they cannot be loaded. */
async function getRecentlyChangedNoteItems(): Promise<MenuCommandItem<CommandNames>[]> {
+ try {
+ return await loadRecentlyChangedNoteItems();
+ } catch (e) {
+ console.error("Failed to load the recently changed notes:", e);
+ return [];
+ }
+}
+
+async function loadRecentlyChangedNoteItems(): Promise<MenuCommandItem<CommandNames>[]> {
const hoistedNoteId = hoistedNoteService.getHoistedNoteId();
const openNoteIds = new Set<string>();
for (const noteContext of appContext.tabManager.getNoteContexts()) {