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
client/bulk actions: add a flag to skip showing toast messages
Adorian Doranc00fe164e368
diff --git a/apps/client/src/services/bulk_action.spec.ts b/apps/client/src/services/bulk_action.spec.tsindex 6495adb1a6..bcc5d017e0 100644--- a/apps/client/src/services/bulk_action.spec.ts+++ b/apps/client/src/services/bulk_action.spec.ts@@ -146,7 +146,7 @@ describe("bulk_action service", () => {server.post = vi.fn(async () => ({})) as typeof server.post;vi.spyOn(toast, "showMessage").mockImplementation(() => {});- await executeBulkActions(["x"], [] as any, true);+ await executeBulkActions(["x"], [] as any, { includeDescendants: true });expect(server.post).toHaveBeenCalledWith("bulk-action/execute", {noteIds: ["x"],@@ -154,4 +154,15 @@ describe("bulk_action service", () => {actions: []});});++ it("executeBulkActions still applies the actions when told to stay silent", async () => {+ server.post = vi.fn(async () => ({})) as typeof server.post;+ const toastSpy = vi.spyOn(toast, "showMessage").mockImplementation(() => {});++ await executeBulkActions(["x"], [] as any, { silent: true });++ expect(server.post).toHaveBeenCalledTimes(1);+ expect(ws.waitForMaxKnownEntityChangeId).toHaveBeenCalledTimes(1);+ expect(toastSpy).not.toHaveBeenCalled();+ });});diff --git a/apps/client/src/services/bulk_action.ts b/apps/client/src/services/bulk_action.tsindex 194d1f8517..d079256810 100644--- a/apps/client/src/services/bulk_action.ts+++ b/apps/client/src/services/bulk_action.ts@@ -95,7 +95,21 @@ function parseActions(note: FNote) {.filter((action) => !!action);}-export async function executeBulkActions(targetNoteIds: string[], actions: BulkAction[], includeDescendants = false) {+export interface BulkActionOptions {+ /** Whether to apply the actions to every descendant of the given notes as well. */+ includeDescendants?: boolean;+ /**+ * Whether to skip the "bulk actions executed" toast, for a caller whose own UI already+ * shows the result of the change.+ */+ silent?: boolean;+}++export async function executeBulkActions(+ targetNoteIds: string[],+ actions: BulkAction[],+ { includeDescendants = false, silent = false }: BulkActionOptions = {}+) {await server.post("bulk-action/execute", {noteIds: targetNoteIds,includeDescendants,@@ -103,7 +117,10 @@ export async function executeBulkActions(targetNoteIds: string[], actions: BulkA});await ws.waitForMaxKnownEntityChangeId();- toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);++ if (!silent) {+ toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);+ }}export default {