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 some issues
Adorian Doran7feffe908291
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.tsindex 71a5feaa18..838845d033 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 server from "../../../services/server";import ws from "../../../services/ws";import { buildNote } from "../../../test/easy-froca";import { BoardViewData } from ".";-import BoardApi, { getPendingWrites, PendingColumnWrites, releasePendingWrites } from "./api";+import BoardApi, { getPendingWrites, PendingColumnWrites } from "./api";import { ColumnMap } from "./data";import { BOARD_TEMPLATE_ID, DEFAULT_COLUMN_ICON, getStatusDefinition } from "./columns";@@ -905,16 +905,16 @@ describe("pending writes shared between the views of a board", () => {expect(getPendingWrites("board2|status")).not.toBe(writes);});- it("keeps a board's record while a write is on it, and forgets it once none is", () => {+ /**+ * A view is handed the record once and holds it while it is mounted, so a record dropped for+ * being empty would leave the views that already have it talking to nobody.+ */+ it("keeps a board's record after the writes on it have all landed", () => {const writes = getPendingWrites("board3|status");writes.renames.set("Done", undefined);+ writes.renames.delete("Done");- releasePendingWrites("board3|status");expect(getPendingWrites("board3|status")).toBe(writes);-- writes.renames.delete("Done");- releasePendingWrites("board3|status");- expect(getPendingWrites("board3|status")).not.toBe(writes);});});diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex 8b3d850444..8875b51cd3 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -60,7 +60,14 @@ export function settleColumn(pending: PendingColumnWrites, column: string) {*/const pendingWritesByBoard = new Map<string, PendingColumnWrites>();-/** The record every view of one board writes into, made on first use. */+/**+ * The record every view of one board writes into, made on first use and kept for good.+ *+ * Never dropped, however empty: a view is handed the record once, when it first draws a board, and+ * holds that object for as long as it is mounted. Dropping an empty one would hand the next view a+ * different record, and the two would stop hearing about each other's writes. What is left behind+ * is one string and two empty maps per board opened.+ */export function getPendingWrites(board: string) {const existing = pendingWritesByBoard.get(board);if (existing) {@@ -72,19 +79,6 @@ export function getPendingWrites(board: string) {return writes;}-/**- * Forgets a board no write is left on, an empty record saying the same as none at all.- *- * Kept while anything is still claimed: a write in flight holds the record it made itself in, and- * one dropped here would leave its undo writing into an object nothing reads.- */-export function releasePendingWrites(board: string) {- const writes = pendingWritesByBoard.get(board);- if (writes && !writes.renames.size && !writes.claims.size) {- pendingWritesByBoard.delete(board);- }-}-export default class BoardApi {private isRelationMode: boolean;diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsxindex 46dfe86af6..5868239e7e 100644--- a/apps/client/src/widgets/collections/board/card.tsx+++ b/apps/client/src/widgets/collections/board/card.tsx@@ -91,9 +91,8 @@ function Card({const handleKeyDown = useCallback((e: KeyboardEvent) => {if (e.key === "Enter" && !e.ctrlKey) {- // Enter makes a card rather than opening one, the way a row is made in a spreadsheet;- // Space is what opens. Shift puts the new card above, the reversal Shift stands for- // wherever else it pairs with a key.+ // Enter adds a card the way it adds a row in a spreadsheet, and Space is what opens+ // one. Shift adds it above instead of below.e.preventDefault();api.insertRowAtPosition(column, branch.branchId, e.shiftKey ? "before" : "after");} else if (e.key === "F2") {diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex cd79f6039d..d03d4e5bd0 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -344,6 +344,52 @@ describe("Board column rename", () => {]);});+ /**+ * A view is handed its record when it first draws the board and holds it while it is mounted.+ * A record dropped for being empty would leave this view reading one nothing writes into, and+ * a column another tab is deleting would come back.+ */+ it("keeps a drawn view on the record later writes go into", async () => {+ const note = buildNote({+ title: "Board",+ "#collection": "",+ "#viewType": "board",+ "#label:status(inheritable)":+ "promoted,alias=Status,single,select,options=To Do;Doing;Done",+ children: [ { title: "First", "#status": "To Do" } ]+ });+ const host = new Component();+ const mountPoint = document.createElement("div");+ container = mountPoint;+ document.body.appendChild(mountPoint);++ // A fresh list each time, so the refresh the board hangs off runs again.+ const draw = async () => {+ await act(async () => {+ render(+ <ParentComponent.Provider value={host}>+ <Harness+ note={note}+ noteIds={[ ...note.getChildNoteIds() ]}+ initialConfig={DEFAULT_CONFIG}+ />+ </ParentComponent.Provider>,+ mountPoint+ );+ });+ await act(async () => { await flush(); });+ };++ await draw();+ expect(columnTitles(mountPoint)).toEqual([ "To Do", "Doing", "Done" ]);++ // What another tab deleting a column leaves behind, after this view has been drawing.+ getPendingWrites(`${note.noteId}|status`).renames.set("Done", undefined);+ await draw();++ expect(columnTitles(mountPoint)).toEqual([ "To Do", "Doing" ]);+ });+/** Renames the middle column, so a slot that is not the last one has to survive. */async function renameSecondColumn(container: HTMLElement, newName: string) {return renameColumnAt(container, 1, newName);diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex b152a703ac..3848038aa9 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -21,9 +21,7 @@ import NoteAutocomplete from "../../react/NoteAutocomplete";import ShortcutHintButton from "../../shortcut_hints/shortcut_hint_button";import { onWheelHorizontalScroll } from "../../widget_utils";import { ViewModeProps } from "../interface";-import Api, {- getPendingWrites, PendingColumnWrites, releasePendingWrites, settleColumn-} from "./api";+import Api, { getPendingWrites, PendingColumnWrites, settleColumn } from "./api";import BoardApi from "./api";import { DEFAULT_GROUP_BY, getStatusDefinition } from "./columns";import Column from "./column";@@ -260,7 +258,6 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveCfor (const settled of settledRenames) {settleColumn(pendingRenamesRef.current.writes, settled);}- releasePendingWrites(pendingRenamesRef.current.board);setByColumn(byColumn);setIsRelationMode(isInRelationMode);