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: fix some issues
Adorian Doranc8463265faf7
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex 41289ac739..468a25f5b7 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -86,7 +86,7 @@ export default class BoardApi {const action: BulkAction = this.isRelationMode? { name: "deleteRelation", relationName: this.statusAttribute }: { name: "deleteLabel", labelName: this.statusAttribute };- await executeBulkActions(noteIds, [ action ]);+ await executeBulkActions(noteIds, [ action ], { silent: true });this.storeColumns((this.viewConfig?.columns ?? []).filter(col => col.value !== column));}@@ -99,7 +99,7 @@ export default class BoardApi {const action: BulkAction = this.isRelationMode? { name: "updateRelationTarget", relationName: this.statusAttribute, targetNoteId: newValue }: { name: "updateLabelValue", labelName: this.statusAttribute, labelValue: newValue };- await executeBulkActions(noteIds, [ action ]);+ await executeBulkActions(noteIds, [ action ], { silent: true });// Rename the column in the persisted data.this.storeColumns((this.viewConfig?.columns ?? [])diff --git a/apps/client/src/widgets/collections/board/data.spec.ts b/apps/client/src/widgets/collections/board/data.spec.tsindex 21a05aafe2..f2abee437b 100644--- a/apps/client/src/widgets/collections/board/data.spec.ts+++ b/apps/client/src/widgets/collections/board/data.spec.ts@@ -32,7 +32,7 @@ describe("Board data", () => {});/*** The notes, the view config and the definition are written one at a time, so a refresh in- * between reads a source that still offers the old value. Resolution being additive, anything it+ * between reads a source that still offers the old value. Resolution being additive, what it* picks up there is persisted and can never be dropped again, leaving an empty column behind.*/describe("a column being renamed or deleted", () => {@@ -76,7 +76,8 @@ describe("Board data", () => {);expect(data.columns).toEqual([ "To Do", "Shipped" ]);- expect(data.newPersistedData?.columns?.map(c => c.value)).toEqual([ "To Do", "Shipped" ]);+ expect(data.newPersistedData?.columns?.map(c => c.value))+ .toEqual([ "To Do", "Shipped" ]);});it("keeps the renamed column where the old name stood", async () => {@@ -124,7 +125,27 @@ describe("Board data", () => {.toEqual([ "First", "Second" ]);});- it("is forgotten once every source has caught up, so the name can be used again", async () => {+ it("does not fold the cards of a deleted column into another one", async () => {+ const board = buildNote({+ title: "Board",+ "#collection": "",+ "#viewType": "board",+ children: [+ { title: "First", "#status": "Shipped" },+ { title: "Second", "#status": "Done" }+ ]+ });++ const data = await getBoardData(+ board, "status", { columns: [ { value: "Shipped" } ] }, false, [],+ new Map([ [ "Done", undefined ] ])+ );++ expect(data.columns).toEqual([ "Shipped" ]);+ expect(data.byColumn.get("Shipped")?.map(item => item.note.title)).toEqual([ "First" ]);+ });++ it("is forgotten once every source has caught up, freeing the name", async () => {const pending = new Map([ [ "Done", "Shipped" ] ]);await getBoardData(buildBoard(),diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 16990ef8c5..3c8e7d1431 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -3,7 +3,7 @@* view is re-entered, and a subsequent column reorder then deletes it again.*/import { render } from "preact";-import { useCallback, useState } from "preact/hooks";+import { useCallback, useEffect, useState } from "preact/hooks";import { act } from "preact/test-utils";import { afterEach, describe, expect, it, vi } from "vitest";@@ -16,7 +16,10 @@ import BoardView, { BoardViewData } from ".";// Stands in for the server: by the time the bulk action resolves, the notes carry the new value,// which is what makes the old column empty rather than merely renamed.vi.mock("../../../services/bulk_action", () => ({- executeBulkActions: vi.fn(async (noteIds: string[], actions: { name: string, labelName?: string, labelValue?: string }[]) => {+ executeBulkActions: vi.fn(async (+ noteIds: string[],+ actions: { name: string, labelName?: string, labelValue?: string }[]+ ) => {for (const noteId of noteIds) {for (const attribute of froca.getNoteFromCache(noteId)?.getAttributes() ?? []) {for (const action of actions) {@@ -48,6 +51,12 @@ function Harness({ note, noteIds, initialConfig }: { note: ReturnType<typeof buisetState({ config });}, []);+ // `useViewModeConfig` restores the config of whichever note it is handed, so a board shown+ // after another starts from its own. The board itself is not remounted, which is the point.+ useEffect(() => {+ setState({ config: initialConfig });+ }, [ note ]);+return (<BoardViewnote={note}@@ -223,6 +232,45 @@ describe("Board column rename", () => {.toEqual([ "To Do", "In Progress", "Done" ]);});+ /**+ * `NoteList` renders the view unkeyed, so the board the user moves to is the same component+ * instance. A rename still pending on the one they left must not rewrite a column here that+ * happens to carry the old name.+ */+ it("does not carry a pending rename over to the next board", async () => {+ const { container } = await setup();+ await renameSecondColumn(container, "In Progress");++ const other = buildNote({+ title: "Other board",+ "#collection": "",+ "#viewType": "board",+ "#label:status(inheritable)":+ "promoted,alias=Status,single,select,options=Doing;Shipped",+ children: [+ { id: "ocard1", title: "Fourth", "#status": "Doing" },+ { id: "ocard2", title: "Fifth", "#status": "Shipped" }+ ]+ });++ await act(async () => {+ render(+ <ParentComponent.Provider value={new Component()}>+ <Harness+ note={other}+ noteIds={[ "ocard1", "ocard2" ]}+ initialConfig={{ columns: [ { value: "Doing" }, { value: "Shipped" } ] }}+ />+ </ParentComponent.Provider>,+ container+ );+ await flush();+ });+ await act(async () => { await flush(); });++ expect(columnTitles(container)).toEqual([ "Doing", "Shipped" ]);+ });+it("keeps the cards of the renamed column under it", async () => {const { container } = await setup();diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 345a602d35..f18a7295d2 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -168,6 +168,14 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC});}+ // A pending rename belongs to the board and the grouping it was made on. `NoteList` renders the+ // view unkeyed, so moving to another board reuses this instance and the ref would otherwise+ // carry the rename over and rewrite a column of the same name there. Declared ahead of the+ // refresh below, which is what makes it run first when both fire on the same change.+ useEffect(() => {+ pendingRenamesRef.current.clear();+ }, [ parentNote, statusAttributeWithPrefix ]);+useEffect(refresh, [ parentNote, noteIds, viewConfig, statusAttributeWithPrefix, statusDefinition ]);const handleColumnDrop = useCallback((fromIndex: number, toIndex: number) => {