Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: prevent a column being renamed to an empty string

Adorian Dorandba364cc39dc
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index a4bfe44f99..96892b8726 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -994,3 +994,24 @@ describe("what the board calls the field it groups by", () => {
expect(createApi({}, [], empty).api.getStatusLabel()).toBe("board_view.status-header");
});
});
+
+describe("renaming a column to nothing", () => {
+ /**
+ * The value a column carries is what its cards are grouped by, so an empty name would write an
+ * empty label over all of them and take the column with it.
+ */
+ it("leaves the column and its cards alone", async () => {
+ const { api, saved } = createApi(
+ { columns: [ { value: "To Do" }, { value: "Done" } ] },
+ [ "To Do", "Done" ]
+ );
+ // A module mock outlives a test, so what earlier ones asked for is cleared first.
+ vi.mocked(executeBulkActions).mockClear();
+
+ await api.renameColumn("Done", "");
+ await api.renameColumn("Done", " ");
+
+ expect(executeBulkActions).not.toHaveBeenCalled();
+ expect(saved).toEqual([]);
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 56563ca1e3..e4cf65f5e4 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -263,6 +263,13 @@ export default class BoardApi {
}
async renameColumn(oldValue: string, newValue: string) {
+ // A column is known by the value its cards carry, so a blank name is not a name: it would
+ // write an empty label over every card in the column and leave nothing to group them by.
+ // The editor is simply left as it was.
+ if (!newValue.trim()) {
+ return;
+ }
+
const noteIds = this.byColumn?.get(oldValue)?.map(item => item.note.noteId) || [];
// Change the value in the notes.