Skip to content

Build your personal knowledge base with Trilium Notes

feat(board): show the column icons in the card's "Move to" menu

Elian Doran0b310775e96e
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 2ae3927460..9a3e794209 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -14,7 +14,7 @@ import { buildNote } from "../../../test/easy-froca";
import { BoardViewData } from ".";
import BoardApi, { PendingColumnWrites } from "./api";
import { ColumnMap } from "./data";
-import { BOARD_TEMPLATE_ID, getStatusDefinition } from "./columns";
+import { BOARD_TEMPLATE_ID, DEFAULT_COLUMN_ICON, getStatusDefinition } from "./columns";
vi.mock("../../../services/bulk_action", () => ({
executeBulkActions: vi.fn(async () => {})
@@ -171,6 +171,24 @@ describe("BoardApi column mutations", () => {
expect(saved.at(-1)?.columns).toEqual([ { value: "To Do" } ]);
});
+ it("reads back the icon a column carries, falling back to the default", async () => {
+ const { api } = createApi(
+ { columns: [ { value: "To Do", icon: "bx bx-list-ul" }, { value: "Done" } ] },
+ [ "To Do", "Done", "Backlog" ]);
+
+ expect(api.getColumnIcon("To Do")).toBe("bx bx-list-ul");
+ expect(api.getColumnIcon("Done")).toBe(DEFAULT_COLUMN_ICON);
+ // Resolved from the definition, so it has no stored entry at all.
+ expect(api.getColumnIcon("Backlog")).toBe(DEFAULT_COLUMN_ICON);
+ });
+
+ it("reads a relation column's icon off the note the column is", async () => {
+ const column = buildNote({ title: "Done", "#iconClass": "bx bx-check" });
+ const { api } = createApi({ columns: [] }, [ column.noteId ], undefined, "~status");
+
+ expect(api.getColumnIcon(column.noteId)).toContain("bx bx-check");
+ });
+
it("stores a colour beside the icon, without either clearing the other", async () => {
const { api, saved } = createApi({ columns: [ { value: "To Do" } ] }, [ "To Do" ]);
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 0f0a0eb3b0..5e9b53729f 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -12,7 +12,7 @@ import note_create from "../../../services/note_create";
import server from "../../../services/server";
import toast from "../../../services/toast";
import { BoardColumnData, BoardViewData } from ".";
-import { type BoardStatusDefinition, canStoreColumnsInDefinition, DEFAULT_GROUP_BY } from "./columns";
+import { type BoardStatusDefinition, canStoreColumnsInDefinition, DEFAULT_COLUMN_ICON, DEFAULT_GROUP_BY } from "./columns";
import { ColumnMap } from "./data";
/** One write's claim on a column, held until that write lands or is taken back. */
@@ -223,6 +223,21 @@ export default class BoardApi {
this.updateColumn(column, { color: color ?? undefined });
}
+ /**
+ * The icon a column heading shows, for anything else that stands in for the column.
+ *
+ * In relation mode the column is a note, so the icon is that note's own — the same one
+ * `NoteLink` puts in the heading — and `setColumnIcon` is not offered there.
+ */
+ getColumnIcon(column: string) {
+ if (this.isRelationMode) {
+ return froca.getNoteFromCache(column)?.getIcon();
+ }
+
+ return this.viewConfig?.columns?.find(col => col.value === column)?.icon
+ ?? DEFAULT_COLUMN_ICON;
+ }
+
/** Whether a column is archived, which the board shows only while archived notes are shown. */
isColumnArchived(column: string) {
return !!this.viewConfig?.columns?.find(col => col.value === column)?.archived;
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 6d2c512cec..21dff4cefb 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -8,6 +8,7 @@ import dialog from "../../../services/dialog";
import FNote from "../../../entities/fnote";
import { buildNote } from "../../../test/easy-froca";
import BoardApi from "./api";
+import { DEFAULT_COLUMN_ICON } from "./columns";
import { openColumnContextMenu, openNoteContextMenu } from "./context_menu";
// The card menu opens with the shared link items, which reach for the active note context.
@@ -228,6 +229,7 @@ describe("Board item context menu", () => {
const api = {
columns: [ "To Do", "Done" ],
isColumnArchived: () => false,
+ getColumnIcon: () => DEFAULT_COLUMN_ICON,
changeColumn: vi.fn(async () => {})
} as unknown as BoardApi;
@@ -281,7 +283,8 @@ describe("Board item context menu", () => {
it("marks the archived columns it offers to move a card to", () => {
const api = {
columns: [ "To Do", "Done" ],
- isColumnArchived: (column: string) => column === "Done"
+ isColumnArchived: (column: string) => column === "Done",
+ getColumnIcon: () => DEFAULT_COLUMN_ICON
} as unknown as BoardApi;
const moveTo = openItemMenu(api).find(item =>
@@ -294,4 +297,20 @@ describe("Board item context menu", () => {
.map(item => !!(item && "badges" in item && item.badges?.length)))
.toEqual([ false, true ]);
});
+
+ it("shows each column it offers to move a card to with the icon that column carries", () => {
+ const api = {
+ columns: [ "To Do", "Done" ],
+ isColumnArchived: () => false,
+ getColumnIcon: (column: string) =>
+ column === "Done" ? "bx bx-check-circle" : DEFAULT_COLUMN_ICON
+ } as unknown as BoardApi;
+
+ const moveTo = openItemMenu(api).find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-transfer");
+ if (!moveTo || !("items" in moveTo)) throw new Error("expected a move-to entry");
+
+ expect((moveTo.items ?? []).map(item => item && "uiIcon" in item ? item.uiIcon : undefined))
+ .toEqual([ DEFAULT_COLUMN_ICON, "bx bx-check-circle" ]);
+ });
});
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 582e8d3e23..1bdfa667f5 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -149,6 +149,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
// fair thing to want; the badge is there so it is not a surprise when it goes.
items: api.columns.map(columnToMoveTo => ({
title: columnToMoveTo,
+ uiIcon: api.getColumnIcon(columnToMoveTo),
enabled: columnToMoveTo !== column,
badges: api.isColumnArchived(columnToMoveTo)
? [ { title: t("board_view.archived-badge") } ]