Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Dorancd8b0f318c28
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 96892b8726..0789597f01 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -443,6 +443,8 @@ describe("BoardApi column mutations", () => {
*/
describe("BoardApi card operations", () => {
beforeEach(() => {
+ // Spies outlive a test otherwise, and one standing in for a write is read by the next.
+ vi.restoreAllMocks();
vi.mocked(branches.moveBeforeBranch).mockClear();
vi.mocked(branches.moveAfterBranch).mockClear();
vi.mocked(note_create.createNote).mockClear();
@@ -533,6 +535,27 @@ describe("BoardApi card operations", () => {
expect(removeLabel).toHaveBeenCalledTimes(1);
});
+ /**
+ * A value the card takes from an ancestor is not the card's to remove, and the board reads the
+ * value it ends up with rather than the one it owns.
+ */
+ it("covers a value the card inherits rather than uncovering it", async () => {
+ const board = buildNote({
+ title: "Board",
+ "#status(inheritable)": "Done",
+ children: [ { title: "Card" } ]
+ });
+ const [ cardId ] = [ ...board.getChildNoteIds() ];
+ const { api } = createApi({}, [], board);
+ const removeLabel = vi.spyOn(attributes, "removeOwnedLabelByName").mockReturnValue(true);
+ const setLabel = vi.spyOn(attributes, "setLabel").mockResolvedValue(undefined as never);
+
+ await api.removeFromBoard(cardId);
+
+ expect(setLabel).toHaveBeenCalledWith(cardId, "status", "");
+ expect(removeLabel).not.toHaveBeenCalled();
+ });
+
it("takes a card off a relation board by removing that relation", async () => {
const board = buildNote({ title: "Board", children: [ { title: "Card" } ] });
const { api } = createApi({}, [], board, "~status");
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index a94e508be6..d3027c28b4 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -303,8 +303,7 @@ export default class BoardApi {
/**
* What a column is called on screen, which is the value its cards carry everywhere but the
- * inbox: that one stands for the cards carrying no value, so it has a name of its own and
- * cannot be renamed.
+ * inbox: that one stands for the cards carrying no value, so it has a name of its own.
*/
getColumnTitle(column: string) {
return column === INBOX_COLUMN ? t("board_view.inbox") : column;
@@ -659,6 +658,16 @@ export default class BoardApi {
if (this.isRelationMode) {
return attributes.removeOwnedRelationByName(note, this.statusAttribute);
}
+
+ // A value the card takes from a template or an ancestor is not the card's to remove, and
+ // taking away the one it owns would only uncover what that was covering. An empty value of
+ // its own covers it instead, which reads as carrying none.
+ const inherited = note.getAttributes("label", this.statusAttribute)
+ .some(attribute => attribute.noteId !== noteId);
+ if (inherited) {
+ return attributes.setLabel(noteId, this.statusAttribute, "");
+ }
+
return attributes.removeOwnedLabelByName(note, this.statusAttribute);
}
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 82f19c717e..e94a98860a 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -113,7 +113,6 @@ export default function Column({
}, [ color ]);
const handleTitleKeyDown = useCallback((e: KeyboardEvent) => {
- // The inbox has no name of its own to edit, its cards being the ones carrying none.
if (e.key === "F2" && column !== INBOX_COLUMN) {
setColumnNameToEdit(column);
}
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index f86ec7b5f8..d7cf09f664 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -36,8 +36,6 @@ interface ColumnMenuTarget {
}
export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: ColumnMenuTarget) {
- // The inbox stands for the cards carrying no value, so it has no name to rename and nothing to
- // archive: it is put away by its own setting instead, which is what its delete entry does.
const isInbox = column.value === INBOX_COLUMN;
event.preventDefault();