Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doran903b4fe06ccc
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index ef50594a06..7e4a097204 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -1059,3 +1059,28 @@ describe("renaming a column to nothing", () => {
expect(saved).toEqual([]);
});
});
+
+describe("reordering columns the board is not showing all of", () => {
+ /**
+ * A column the board keeps but does not show, an inbox switched off among them, is in the
+ * config and not in the list the reorder counts in. It keeps the place it holds rather than
+ * being herded to the end.
+ */
+ it("leaves a stored column the render list does not carry where it stands", () => {
+ const { api, saved } = createApi(
+ { columns: [
+ { value: "", icon: "bx bx-inbox" }, { value: "To Do" }, { value: "Done" }
+ ] },
+ [ "To Do", "Done" ]
+ );
+
+ // "Done" before "To Do", counted among the two the board shows.
+ api.reorderColumn(1, 0);
+
+ expect(saved.at(-1)?.columns).toEqual([
+ { value: "", icon: "bx bx-inbox" },
+ { value: "Done" },
+ { value: "To Do" }
+ ]);
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 11a33944bc..85c9098290 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -407,18 +407,23 @@ export default class BoardApi {
newColumns.splice(adjustedToIndex, 0, movedColumn);
- // `columns` is derived render state and can lag behind the persisted config (it is rebuilt
- // only once the view re-renders), so anything it hasn't caught up with yet is kept at the
- // end instead of being dropped from the config.
- const storedColumns = new Map(
- (this.viewConfig?.columns ?? []).map(col => [ col.value, col ]));
- const missingColumns = (this.viewConfig?.columns ?? []).filter(col => !newColumns.includes(col.value));
- this.storeColumns([
- // Reordering moves the entries, so each keeps the icon it holds rather than being
- // rebuilt from its name.
- ...newColumns.map(value => storedColumns.get(value) ?? { value }),
- ...missingColumns
- ]);
+ // `columns` is derived render state and carries neither what it has yet to catch up with
+ // nor what the board is not showing, an inbox switched off among it. Each of those keeps
+ // the place it holds in the config rather than being herded to the end or dropped.
+ const stored = this.viewConfig?.columns ?? [];
+ const storedColumns = new Map(stored.map(col => [ col.value, col ]));
+ // Reordering moves the entries, so each keeps the icon it holds rather than being rebuilt
+ // from its name.
+ const reordered: BoardColumnData[] =
+ newColumns.map(value => storedColumns.get(value) ?? { value });
+
+ for (const [ index, column ] of stored.entries()) {
+ if (!newColumns.includes(column.value)) {
+ reordered.splice(index, 0, column);
+ }
+ }
+
+ this.storeColumns(reordered);
return newColumns;
}
@@ -665,7 +670,8 @@ export default class BoardApi {
// A relation points at a note, so there is no empty one to cover an inherited value
// with the way a label is covered below. Where the card takes its column from a
// template or an ancestor, that is the only place it can be changed.
- if (this.isInherited(note, "relation")) {
+ if (!note.getOwnedAttributes("relation", this.statusAttribute).length
+ && this.isInherited(note, "relation")) {
toast.showMessage(t("board_view.inherited-column"), 3000);
return;
}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index eb7351a02c..8e03d89455 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -310,7 +310,9 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// landed among them all once some are archived and hidden. Translated here so a reorder leaves
// every hidden column where it was rather than herding them to the end.
const handleColumnDrop = useCallback((fromIndex: number, toIndex: number) => {
- const allColumns = columns ?? [];
+ // The list the api holds, which is the one it reorders: a column the board is not showing
+ // at all is in neither, so counting in `columns` would leave the two a place apart.
+ const allColumns = api.columns;
const dropBefore = shownColumns[toIndex];
const newColumns = api.reorderColumn(
allColumns.indexOf(shownColumns[fromIndex]),
@@ -322,7 +324,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
setDraggedColumn(null);
setDraggedCard(null);
setColumnDropPosition(null);
- }, [ api, columns, shownColumns ]);
+ }, [ api, shownColumns ]);
const { onKeyDown: handleKeyDown, focusColumn, focusCard } = useBoardKeyboard({
containerRef,