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: fix an issue
Adorian Dorane09f1b019375
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.tsindex 596601e329..4e36eeb274 100644--- a/apps/client/src/widgets/collections/board/api.spec.ts+++ b/apps/client/src/widgets/collections/board/api.spec.ts@@ -16,7 +16,7 @@ import { buildNote } from "../../../test/easy-froca";import { BoardViewData } from ".";import BoardApi, { getPendingWrites, PendingColumnWrites } from "./api";import { ColumnMap } from "./data";-import { BOARD_TEMPLATE_ID, DEFAULT_COLUMN_ICON, getStatusDefinition } from "./columns";+import { BOARD_TEMPLATE_ID, DEFAULT_COLUMN_ICON, getStatusDefinition, INBOX_COLUMN } from "./columns";vi.mock("../../../services/bulk_action", () => ({executeBulkActions: vi.fn(async () => {})@@ -1189,6 +1189,30 @@ describe("collapsing a column", () => {expect(saved.at(-1)?.columns).toEqual([ { value: "To Do" } ]);});+ /**+ * The inbox is drawn at the head of the board without ever having been written, so the first+ * thing picked for it is also the first entry it gets. Appended, that entry would send the+ * column to the end of the board, the stored order being what the board reads first.+ */+ it("writes a column with no entry yet where the board draws it", async () => {+ const { api, saved } = createApi(+ { columns: [ { value: "To Do" }, { value: "Done" } ] },+ [ INBOX_COLUMN, "To Do", "Done" ]);++ await api.setColumnCollapsed(INBOX_COLUMN, true);+ expect(saved.at(-1)?.columns).toEqual([+ { value: INBOX_COLUMN, collapsed: true }, { value: "To Do" }, { value: "Done" }+ ]);++ // One drawn between two stored columns lands between them.+ const middle = createApi(+ { columns: [ { value: "To Do" }, { value: "Done" } ] },+ [ "To Do", "Doing", "Done" ]);+ await middle.api.setColumnCollapsed("Doing", true);+ expect(middle.saved.at(-1)?.columns?.map(column => column.value))+ .toEqual([ "To Do", "Doing", "Done" ]);+ });+/** The icon goes in with the column, rather than as a second write and a second refresh. */it("stores a new column with the icon picked for it", 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.tsindex 1a58fb4ab8..a3ee5f8105 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -637,9 +637,26 @@ export default class BoardApi {return updated;};- this.storeColumns(columns.some(col => col.value === column)- ? columns.map(col => col.value === column ? patched(col) : col)- : [ ...columns, patched({ value: column }) ]);+ if (columns.some(col => col.value === column)) {+ this.storeColumns(columns.map(col => col.value === column ? patched(col) : col));+ return;+ }++ // A column with no entry yet is written where the board draws it, after the last column+ // before it that has one. Appended, it would move to the end of the board the moment+ // anything was picked for it: the stored order is what the board reads first, and a column+ // with no entry keeps a place of its own only until it has one. The inbox is drawn at the+ // head without ever having been written, so collapsing it used to send it to the back.+ const drawn = this.columns.indexOf(column);+ const previous = drawn < 0 ? undefined : this.columns.slice(0, drawn).reverse()+ .find(value => columns.some(col => col.value === value));+ const at = drawn < 0+ ? columns.length+ : previous ? columns.findIndex(col => col.value === previous) + 1 : 0;++ const placed = [ ...columns ];+ placed.splice(at, 0, patched({ value: column }));+ this.storeColumns(placed);}reorderColumn(fromIndex: number, toIndex: number) {