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/collections/board/switchable card grouping: ensure the inbox column is always first
Adorian Doran4a1ed7de1107
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.tsindex ad471239e0..771a9e25cc 100644--- a/apps/client/src/widgets/collections/board/api.spec.ts+++ b/apps/client/src/widgets/collections/board/api.spec.ts@@ -1637,6 +1637,39 @@ describe("collapsing a column", () => {});});+describe("reordering around the inbox", () => {+ /** The inbox leads whatever the board groups by, so a reorder cannot take it off the front. */+ function boardWithInbox() {+ return createApi(+ { columns: [ { value: "" }, { value: "To Do" }, { value: "Done" } ] },+ [ "", "To Do", "Done" ]+ );+ }++ it("refuses to carry the inbox off the front", () => {+ const { api, saved } = boardWithInbox();++ expect(api.reorderColumn(0, 2)).toBeUndefined();+ expect(saved).toEqual([]);+ });++ it("refuses to place another column in front of it", () => {+ const { api, saved } = boardWithInbox();++ expect(api.reorderColumn(2, 0)).toBeUndefined();+ expect(saved).toEqual([]);+ });++ it("leaves the columns behind it free to move among themselves", () => {+ const { api, saved } = boardWithInbox();++ api.reorderColumn(2, 1);++ expect(saved.at(-1)?.columns)+ .toEqual([ { value: "" }, { value: "Done" }, { value: "To Do" } ]);+ });+});+describe("reordering columns the board is not showing all of", () => {/*** A column the config keeps but the board does not show, such as a disabled inbox, is missingdiff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex c0e9dea7ae..81c09fc3ea 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -936,6 +936,14 @@ export default class BoardApi {reorderColumn(fromIndex: number, toIndex: number) {if (!this.columns || fromIndex === toIndex) return;+ // The inbox leads whatever the board groups by, so neither carrying it off the front nor+ // placing a column before it can stand. Refused here rather than at each gesture: the+ // drag, the keyboard and the menu all reorder through this.+ const leadsWithInbox = this.columns[0] === INBOX_COLUMN;+ if (this.columns[fromIndex] === INBOX_COLUMN || (leadsWithInbox && toIndex === 0)) {+ return;+ }+const newColumns = [...this.columns];const [movedColumn] = newColumns.splice(fromIndex, 1);diff --git a/apps/client/src/widgets/collections/board/columns.spec.ts b/apps/client/src/widgets/collections/board/columns.spec.tsindex 784b0c847c..6936796a2a 100644--- a/apps/client/src/widgets/collections/board/columns.spec.ts+++ b/apps/client/src/widgets/collections/board/columns.spec.ts@@ -183,6 +183,20 @@ describe("the inbox column", () => {.toEqual([ "To Do", "Done" ]);});+ /**+ * Only the board's own list can name the inbox, and that list is read after the definition's+ * options, so a grouping the definition leads would put the inbox behind every one of them.+ */+ it("leads even where the definition leads on the order", () => {+ expect(resolveBoardColumns([ "High", "Low" ], [ "" ], [ "High", "Low" ]))+ .toEqual([ "", "High", "Low" ]);+ });++ it("leads a list the board arranged itself, wherever that list carries it", () => {+ expect(resolveBoardColumns([ "To Do", "Done" ], [ "To Do", "", "Done" ], []))+ .toEqual([ "", "To Do", "Done" ]);+ });+/** Deleting is recorded as `undefined`, which the inbox's own name must not be taken for. */it("is told apart from a column being deleted", () => {const pending = new Map([ [ "Done", undefined ] ]);diff --git a/apps/client/src/widgets/collections/board/columns.ts b/apps/client/src/widgets/collections/board/columns.tsindex 04032f0413..3604ed442f 100644--- a/apps/client/src/widgets/collections/board/columns.ts+++ b/apps/client/src/widgets/collections/board/columns.ts@@ -164,7 +164,17 @@ export function resolveBoardColumns(// list holds every one of them: that list is the arrangement made here, which a definition// shared with other notes cannot express, and which it lags by a round trip after every insert// and reorder. Equal lengths are enough to tell, the attachment being one of the sources above.- return persisted.length === columns.length ? persisted : columns;+ const ordered = persisted.length === columns.length ? persisted : columns;++ // The inbox leads whatever the board groups by. It collects the cards carrying no value, which+ // is a different set under every grouping, and only the board's own list can name it: a+ // definition cannot, so the columns it leads with would otherwise push the inbox to the end.+ const inbox = ordered.indexOf(INBOX_COLUMN);+ if (inbox > 0) {+ ordered.unshift(...ordered.splice(inbox, 1));+ }++ return ordered;}/** Whether a value identifies a column of its own, rather than the absence of one. */diff --git a/apps/client/src/widgets/collections/board/data.spec.ts b/apps/client/src/widgets/collections/board/data.spec.tsindex ca4b9176bd..df746fdde2 100644--- a/apps/client/src/widgets/collections/board/data.spec.ts+++ b/apps/client/src/widgets/collections/board/data.spec.ts@@ -7,6 +7,7 @@ import type { EntityChange } from "../../../server_types";import { buildNote } from "../../../test/easy-froca";import type { PromotedAttribute } from "../promoted_attributes";import type { SortContext, SortKey } from "../sorting";+import { INBOX_COLUMN } from "./columns";import {affectsSortOrder, applyCardMove, type ColumnMap, type ColumnSort, filterColumnMap,getBoardData, resolveColumnSorts, resolveSortWatch, sortColumnMap, unfilteredCardIndex@@ -696,6 +697,31 @@ describe("getBoardData column storage", () => {expect(newPersistedData?.priorityViewColumns).toEqual(config.priorityViewColumns);});+ /**+ * The inbox collects the cards carrying no value, which is a different set under every+ * grouping. Only the board's own list can name it, so a grouping the definition leads would+ * put it behind every option that definition offers.+ */+ it("puts the inbox first under a grouping the board has never been on", async () => {+ const board = buildNote({+ title: "Board",+ "#collection": "",+ "#viewType": "board",+ "#label:priority(inheritable)": "promoted,single,select,options=High;Low",+ children: [+ { title: "First", "#priority": "High" },+ { title: "Unassigned" }+ ]+ });++ const { columns, byColumn } = await getBoardData(+ board, "priority", {}, false, [ "High", "Low" ], new Map(), true);++ expect(columns).toEqual([ INBOX_COLUMN, "High", "Low" ]);+ expect((byColumn.get(INBOX_COLUMN) ?? []).map(({ note }) => note.title))+ .toEqual([ "Unassigned" ]);+ });+it("keeps a column's icon across a rewrite of its own grouping", async () => {const board = twoGroupings();