Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: allow renaming for inbox columns

Adorian Dorane5f5d191726a
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 9d29832fb6..5273a51765 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -1102,3 +1102,44 @@ describe("the icon the inbox column wears", () => {
expect(api.getColumnIcon("")).toBe("bx bx-star");
});
});
+
+describe("renaming a column that names itself", () => {
+ /** The inbox stands for the cards carrying no value, so its name is its own, not theirs. */
+ it("writes the inbox a name of its own and leaves its cards alone", async () => {
+ const { api, saved } = createApi(
+ { columns: [ { value: "", icon: "bx bxs-inbox" }, { value: "To Do" } ] },
+ [ "", "To Do" ]
+ );
+ vi.mocked(executeBulkActions).mockClear();
+
+ await api.setColumnTitle("", "Unsorted");
+
+ expect(saved.at(-1)?.columns).toEqual([
+ { value: "", icon: "bx bxs-inbox", displayName: "Unsorted" },
+ { value: "To Do" }
+ ]);
+ expect(api.getColumnTitle("")).toBe("Unsorted");
+ // Its cards carry no value, so there is none to write across them.
+ expect(executeBulkActions).not.toHaveBeenCalled();
+ });
+
+ it("renames any other column by the value its cards carry", async () => {
+ const { api } = createApi(
+ { columns: [ { value: "" }, { value: "To Do" } ] }, [ "", "To Do" ]);
+ vi.mocked(executeBulkActions).mockClear();
+
+ await api.setColumnTitle("To Do", "Doing");
+
+ expect(executeBulkActions).toHaveBeenCalled();
+ });
+
+ it("leaves either kind alone when given nothing", async () => {
+ const { api, saved } = createApi({ columns: [ { value: "" } ] }, [ "" ]);
+ vi.mocked(executeBulkActions).mockClear();
+
+ await api.setColumnTitle("", " ");
+
+ expect(saved).toEqual([]);
+ expect(api.getColumnTitle("")).toBe("board_view.inbox");
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 0798158e45..55ad88c6ec 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -306,7 +306,25 @@ export default class BoardApi {
* inbox: that one stands for the cards carrying no value, so it has a name of its own.
*/
getColumnTitle(column: string) {
- return column === INBOX_COLUMN ? t("board_view.inbox") : column;
+ const named = this.viewConfig?.columns?.find(col => col.value === column)?.displayName;
+ return named || (column === INBOX_COLUMN ? t("board_view.inbox") : column);
+ }
+
+ /**
+ * Renames a column however that column is named.
+ *
+ * A column is ordinarily known by the value its cards carry, so renaming it writes that value
+ * across them. The inbox stands for the cards carrying none, so it holds a name of its own
+ * instead and the cards are left alone.
+ */
+ async setColumnTitle(column: string, title: string) {
+ if (!title.trim()) {
+ return;
+ }
+
+ return column === INBOX_COLUMN
+ ? this.updateColumn(column, { displayName: title.trim() })
+ : this.renameColumn(column, title);
}
/**
@@ -388,6 +406,7 @@ export default class BoardApi {
if (!updated.icon) delete updated.icon;
if (!updated.color) delete updated.color;
if (!updated.archived) delete updated.archived;
+ if (!updated.displayName) delete updated.displayName;
return updated;
};
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index d9a95d11f7..84622e0084 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -113,7 +113,7 @@ export default function Column({
}, [ color ]);
const handleTitleKeyDown = useCallback((e: KeyboardEvent) => {
- if (e.key === "F2" && column !== INBOX_COLUMN) {
+ if (e.key === "F2") {
setColumnNameToEdit(column);
}
}, [ column ]);
@@ -188,7 +188,7 @@ export default function Column({
className="title"
// In relation mode the title is a link to the note the column stands
// for, and the first of the two clicks has already followed it.
- onDblClick={isInRelationMode || column === INBOX_COLUMN
+ onDblClick={isInRelationMode
? undefined
: () => setColumnNameToEdit(column)}
>
@@ -212,10 +212,12 @@ export default function Column({
</>
) : (
<TitleEditor
- currentValue={column}
- save={newTitle => api.renameColumn(column, newTitle)}
+ currentValue={api.getColumnTitle(column)}
+ save={newTitle => api.setColumnTitle(column, newTitle)}
dismiss={() => setColumnNameToEdit(undefined)}
- mode={isInRelationMode ? "relation" : "normal"}
+ // The inbox is named in words even on a board grouped by a relation, where
+ // every other column is named by the note it stands for.
+ mode={isInRelationMode && column !== INBOX_COLUMN ? "relation" : "normal"}
/>
)}
</h3>
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index e36138778e..0bc4c5f902 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -115,10 +115,10 @@ describe("Board column context menu", () => {
});
/**
- * The inbox stands for the cards carrying no value, so it has no name to rename and nothing to
- * archive; it is put away by the board's own setting instead.
+ * The inbox holds a name of its own, so it is renamed like any other column; what it has not is
+ * anything to archive, and it is put away by the board's own setting instead.
*/
- it("offers the inbox neither a rename nor an archive, and puts it away instead", () => {
+ it("offers the inbox no archive, and puts it away instead", () => {
const api = {
getColumnIcon: () => DEFAULT_COLUMN_ICON,
getColumnColorClass: () => "",
@@ -131,7 +131,7 @@ describe("Board column context menu", () => {
const icons = items.filter(item => item && "uiIcon" in item)
.map(item => "uiIcon" in item ? item.uiIcon : undefined);
- expect(icons).not.toContain("bx bx-edit-alt");
+ expect(icons).toContain("bx bx-edit-alt");
expect(icons).not.toContain("bx bx-archive");
const remove = items.find(item =>
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index d7cf09f664..7847a84b15 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -45,12 +45,12 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:
x: event.pageX,
y: event.pageY,
items: [
- ...(isInbox ? [] : [ {
+ {
title: t("board_view.rename-column"),
uiIcon: "bx bx-edit-alt",
shortcut: "F2",
handler: column.onEditTitle
- } ]),
+ },
...(isInbox ? [ {
title: t("board_view.inbox-nested"),
uiIcon: "bx bx-subdirectory-right",
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 8e03d89455..eb2f66d714 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -45,6 +45,11 @@ export interface BoardColumnData {
* any other column, which stands for a value a note carries wherever it stands.
*/
nested?: boolean;
+ /**
+ * What the column is called, for one that is not named by the value its cards carry. Renaming
+ * any other column writes the value itself, so it needs none.
+ */
+ displayName?: string;
}
interface CardDrag {