Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doran7fc7a42d8580
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 5273a51765..5c4feae5d9 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -1143,3 +1143,43 @@ describe("renaming a column that names itself", () => {
expect(api.getColumnTitle("")).toBe("board_view.inbox");
});
});
+
+describe("filing a card under the inbox", () => {
+ /**
+ * Landing in the inbox means carrying no value at all. A relation the card takes from elsewhere
+ * would still point somewhere once the owned one goes, so the card would arrive in that column
+ * rather than the inbox: it is refused and said so, instead of moved somewhere unasked.
+ */
+ it("refuses a relation card that would still point somewhere", async () => {
+ const board = buildNote({
+ title: "Board",
+ "~status(inheritable)": "root",
+ children: [ { title: "Card", "~status": "root" } ]
+ });
+ const { api } = createApi({}, [], board, "~status");
+ const removeRelation = vi.spyOn(attributes, "removeOwnedRelationByName")
+ .mockReturnValue(true);
+ const message = vi.spyOn(toast, "showMessage").mockReturnValue(undefined);
+
+ await api.changeColumn(board.getChildNoteIds()[0], "");
+
+ expect(message).toHaveBeenCalledWith("board_view.inherited-column", 3000);
+ expect(removeRelation).not.toHaveBeenCalled();
+ });
+
+ /** Taking the card off the board is a lesser thing to ask, and still takes what it owns. */
+ it("still removes what such a card owns when it is taken off the board", async () => {
+ const board = buildNote({
+ title: "Board",
+ "~status(inheritable)": "root",
+ children: [ { title: "Card", "~status": "root" } ]
+ });
+ const { api } = createApi({}, [], board, "~status");
+ const removeRelation = vi.spyOn(attributes, "removeOwnedRelationByName")
+ .mockReturnValue(true);
+
+ await api.removeFromBoard(board.getChildNoteIds()[0]);
+
+ expect(removeRelation).toHaveBeenCalled();
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 55ad88c6ec..5f4d2ae7b1 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -167,11 +167,8 @@ export default class BoardApi {
}
async changeColumn(noteId: string, newColumn: string) {
- // The inbox is where the cards carrying no value stand, so filing one there takes its value
- // away rather than writing an empty one. Every path comes through here: the drag, the
- // keyboard, and the menu.
if (newColumn === INBOX_COLUMN) {
- return this.removeFromBoard(noteId);
+ return this.moveToInbox(noteId);
}
if (this.isRelationMode) {
@@ -181,6 +178,26 @@ export default class BoardApi {
}
}
+ /**
+ * Files a card under the inbox, which is to say leaves it carrying no value at all.
+ *
+ * Told apart from {@link removeFromBoard}, which takes away what the card owns and is content
+ * to uncover whatever that was covering. Landing in the inbox is a stronger thing to ask: a
+ * relation the card takes from elsewhere would still be pointing somewhere afterwards, and the
+ * card would arrive in that column instead of the one it was aimed at.
+ */
+ private moveToInbox(noteId: string) {
+ const note = froca.getNoteFromCache(noteId);
+ if (!note) return;
+
+ if (this.isRelationMode && this.isInherited(note, "relation")) {
+ toast.showMessage(t("board_view.inherited-column"), 3000);
+ return;
+ }
+
+ return this.removeFromBoard(noteId);
+ }
+
async addNewColumn(columnName: string) {
if (!columnName.trim()) {
return;