Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doran5de157fb014f
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 838845d033..a4bfe44f99 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -59,7 +59,8 @@ function createApi(
const board = parentNote ?? buildNote({ title: "Board" });
const saved: BoardViewData[] = [];
const editing: (string | undefined)[] = [];
- const pending: PendingColumnWrites = { renames: new Map(), claims: new Map() };
+ const pending: PendingColumnWrites =
+ { renames: new Map(), claims: new Map(), inFlight: 0 };
const api = new BoardApi(
byColumn,
columns,
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 8875b51cd3..56563ca1e3 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -42,6 +42,14 @@ interface ColumnClaim {
export interface PendingColumnWrites {
renames: Map<string, string | undefined>;
claims: Map<string, ColumnClaim[]>;
+ /**
+ * How many writes are running on the board right now.
+ *
+ * Counted apart from the records because a record outlives its write: it is given up only once
+ * no source names the old value, and a definition the board cannot write keeps naming it for
+ * good. What must not be put on disk is an answer no write has given yet, which is this.
+ */
+ inFlight: number;
}
/** Drops the record of a column the board now reads the same way from every source. */
@@ -74,7 +82,7 @@ export function getPendingWrites(board: string) {
return existing;
}
- const writes: PendingColumnWrites = { renames: new Map(), claims: new Map() };
+ const writes: PendingColumnWrites = { renames: new Map(), claims: new Map(), inFlight: 0 };
pendingWritesByBoard.set(board, writes);
return writes;
}
@@ -94,7 +102,8 @@ export default class BoardApi {
private viewConfig: BoardViewData,
private saveConfig: (newConfig: BoardViewData) => void,
private setBranchIdToEdit: (branchId: string | undefined) => void,
- private pending: PendingColumnWrites = { renames: new Map(), claims: new Map() },
+ private pending: PendingColumnWrites =
+ { renames: new Map(), claims: new Map(), inFlight: 0 },
private statusDefinition?: BoardStatusDefinition
) {
this.isRelationMode = statusAttribute.startsWith("~");
@@ -390,12 +399,15 @@ export default class BoardApi {
oldValue: string, newValue: string | undefined, write: () => Promise<T>
) {
const undoRetirement = this.retireColumn(oldValue, newValue);
+ this.pending.inFlight++;
try {
return await write();
} catch (e) {
undoRetirement();
throw e;
+ } finally {
+ this.pending.inFlight--;
}
}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 53866b7f53..3179cf21b2 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -248,15 +248,17 @@ describe("Board column rename", () => {
}
/**
- * What a second tab on the same board sees. The record is shared, so the column being
- * deleted is resolved away here too; persisting that answer would put a deletion on disk
- * the notes have not given yet, and the tab making the write persists it once it lands.
+ * What a second tab on the same board sees while the first is writing. The record is shared, so
+ * the column being carried is resolved away here too; putting that on disk would commit an
+ * answer the notes have not given, and the tab making the write persists it once it lands.
*/
- it("leaves the stored columns alone while a write on the board is still settling", async () => {
+ it("leaves the stored columns alone while a write on the board is running", async () => {
const { note } = await setup();
saved.length = 0;
- getPendingWrites(`${note.noteId}|status`).renames.set("Done", undefined);
+ const writes = getPendingWrites(`${note.noteId}|status`);
+ writes.renames.set("Done", undefined);
+ writes.inFlight = 1;
const second = document.createElement("div");
document.body.appendChild(second);
@@ -278,6 +280,38 @@ describe("Board column rename", () => {
second.remove();
});
+ /**
+ * A record outlasts the write that made it wherever the definition keeps naming the old value,
+ * which a board that cannot write its own definition does for good. The board still has to
+ * bring what it can reach into line, so only a running write holds persistence back.
+ */
+ it("persists again once the write has landed, even with its record left standing", async () => {
+ const { note } = await setup();
+ saved.length = 0;
+
+ // The record stands, and no write is running.
+ getPendingWrites(`${note.noteId}|status`).renames.set("Done", undefined);
+
+ const second = document.createElement("div");
+ document.body.appendChild(second);
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <Harness
+ note={note}
+ noteIds={[ ...note.getChildNoteIds() ]}
+ initialConfig={DEFAULT_CONFIG}
+ />
+ </ParentComponent.Provider>,
+ second
+ );
+ });
+ await act(async () => { await flush(); });
+
+ expect(saved.at(-1)?.columns?.map(column => column.value)).toEqual([ "To Do", "Doing" ]);
+ second.remove();
+ });
+
it("offers its keys as contextual shortcut hints", async () => {
const host = new Component();
const note = buildNote({
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 3848038aa9..43d3e1bae7 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -178,7 +178,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// instances to cover a rename (see BoardApi#retireColumn). Mutating it must not re-render.
const pendingRenamesRef = useRef<{ board: string, writes: PendingColumnWrites }>({
board: "",
- writes: { renames: new Map(), claims: new Map() }
+ writes: { renames: new Map(), claims: new Map(), inFlight: 0 }
});
/** Names each refresh, so one the board has moved on from is discarded rather than applied. */
const refreshSeqRef = useRef(0);
@@ -263,10 +263,11 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
setIsRelationMode(isInRelationMode);
setColumns(columns);
- // A column a write is still settling has already been taken out of `columns`, and
- // the two writes below would put that answer on disk before the notes have given
- // it. The write that made the record persists the outcome itself once it lands.
- if (pendingRenamesRef.current.writes.renames.size) {
+ // A column a write is carrying has already been taken out of `columns`, and the
+ // two writes below would put that answer on disk before the notes have given it.
+ // Only while the write runs: its record can outlast it, and the board still has to
+ // bring the definition into line afterwards.
+ if (pendingRenamesRef.current.writes.inFlight) {
return;
}
diff --git a/apps/client/src/widgets/note_wrapper.spec.ts b/apps/client/src/widgets/note_wrapper.spec.ts
index 431af0e684..2283286047 100644
--- a/apps/client/src/widgets/note_wrapper.spec.ts
+++ b/apps/client/src/widgets/note_wrapper.spec.ts
@@ -32,6 +32,9 @@ describe("NoteWrapperWidget", () => {
expect(hasBackgroundEffects(audio)).toBe(true);
expect(hasBackgroundEffects(buildNote({ title: "Grid", type: "book", "#viewType": "grid" }))).toBe(true);
+ // The board lays its columns on a bare surface, the way the grid lays its cards.
+ expect(hasBackgroundEffects(
+ buildNote({ title: "Board", type: "book", "#viewType": "board" }))).toBe(true);
// Notes whose content paints its own background stay opaque.
expect(hasBackgroundEffects(buildNote({ title: "Plain", type: "text" }))).toBe(false);
diff --git a/apps/client/src/widgets/note_wrapper.ts b/apps/client/src/widgets/note_wrapper.ts
index 861319cb1a..b7d55287ca 100644
--- a/apps/client/src/widgets/note_wrapper.ts
+++ b/apps/client/src/widgets/note_wrapper.ts
@@ -93,8 +93,9 @@ const CONTAINER_OWNED_CLASSES = [ "active", "last-visible" ];
/**
* Whether the split should be translucent (`bgfx`), letting the window background effect show through.
- * This suits notes that render their content on a bare background (media, option pages, grid/list
- * collections); notes that paint their own background stay opaque. Exported as a pure function for
+ * This suits notes that render their content on a bare background (media, option pages, and the
+ * collections whose own surface is only what they lay out on it); notes that paint their own
+ * background stay opaque. Exported as a pure function for
* unit testing.
*/
export function hasBackgroundEffects(note: FNote): boolean {
@@ -104,7 +105,8 @@ export function hasBackgroundEffects(note: FNote): boolean {
const COLLECTIONS_WITH_BACKGROUND_EFFECTS = [
"grid",
- "list"
+ "list",
+ "board"
];
if (note.isOptions()) {