Skip to content

Build your personal knowledge base with Trilium Notes

fix(bulk_actions): keep saving an action whose removal failed

Elian Doran91b17d83cfda
diff --git a/apps/client/src/widgets/bulk_actions/abstract_bulk_action.ts b/apps/client/src/widgets/bulk_actions/abstract_bulk_action.ts
index 3bed970b3b..f598ba0988 100644
--- a/apps/client/src/widgets/bulk_actions/abstract_bulk_action.ts
+++ b/apps/client/src/widgets/bulk_actions/abstract_bulk_action.ts
@@ -81,7 +81,13 @@ export default abstract class AbstractBulkAction {
async deleteAction() {
this.deleted = true;
- await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
+ try {
+ await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
+ } catch {
+ // `server.remove()` has already shown the error; the row stays, so its edits save again.
+ this.deleted = false;
+ return;
+ }
await ws.waitForMaxKnownEntityChangeId();
}
}
diff --git a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
index 5e0444ab76..1f52b9d1c1 100644
--- a/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
+++ b/apps/client/src/widgets/dialogs/bulk_actions.spec.tsx
@@ -328,6 +328,35 @@ describe("BulkActionsDialog", () => {
}
});
+ it("keeps saving an action whose removal failed", async () => {
+ vi.useFakeTimers();
+ try {
+ buildNote({ id: "_bulkAction", title: "Bulk action", "#action": JSON.stringify({ name: "deleteLabel", labelName: "a" }) });
+ const [ attributeId ] = actionAttributeIds();
+ await open([ "n1" ]);
+
+ server.remove.mockRejectedValueOnce(new Error("offline"));
+ await act(async () => container.querySelector<HTMLElement>(".bulk-existing-action-list .search-option-del")?.click());
+ expect(server.remove).toHaveBeenCalledOnce();
+
+ const [ input ] = labelNameInputs();
+ expect(input).toBeDefined();
+ await act(async () => {
+ input.value = "ab";
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(2000);
+ });
+ expect(server.put).toHaveBeenCalledWith("notes/_bulkAction/attribute", expect.objectContaining({
+ attributeId,
+ value: JSON.stringify({ name: "deleteLabel", labelName: "ab" })
+ }));
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("keeps each row's fields with its own action when an earlier one is removed", async () => {
buildNote({
id: "_bulkAction",