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 an issue
Adorian Doran29917bb3ce58
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex bd533d3901..127b68f1b2 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3379,6 +3379,7 @@"unarchive-column": "Unarchive column","archived-badge": "Archived","inbox": "Inbox",+ "inherited-column": "This card takes its column from a template or a parent note, which is where it can be changed.","inbox-nested": "Include nested notes","inbox-remove": "Remove inbox column","card-count_one": "{{count}} item",diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.tsindex 0789597f01..ef50594a06 100644--- a/apps/client/src/widgets/collections/board/api.spec.ts+++ b/apps/client/src/widgets/collections/board/api.spec.ts@@ -566,6 +566,27 @@ describe("BoardApi card operations", () => {expect(removeRelation).toHaveBeenCalledWith(expect.anything(), "status");});+ /**+ * A relation points at a note, so there is no empty one to cover an inherited value with. The+ * card cannot leave its column here, and saying so beats appearing to do nothing.+ */+ it("says why a card cannot leave a column it takes from elsewhere", async () => {+ const board = buildNote({+ title: "Board",+ "~status(inheritable)": "root",+ children: [ { title: "Card" } ]+ });+ const { api } = createApi({}, [], board, "~status");+ const removeRelation = vi.spyOn(attributes, "removeOwnedRelationByName")+ .mockReturnValue(true);+ const message = vi.spyOn(toast, "showMessage").mockReturnValue(undefined);++ await api.removeFromBoard(board.getChildNoteIds()[0]);++ expect(message).toHaveBeenCalledWith("board_view.inherited-column", 3000);+ expect(removeRelation).not.toHaveBeenCalled();+ });+it("trims the title it renames a card to", async () => {const { api, items } = createBoardWithCards();const put = vi.spyOn(server, "put").mockResolvedValue(undefined);diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.tsindex d3027c28b4..11a33944bc 100644--- a/apps/client/src/widgets/collections/board/api.ts+++ b/apps/client/src/widgets/collections/board/api.ts@@ -652,19 +652,31 @@ export default class BoardApi {await branches.moveAfterBranch([ branch.branchId ], branchId);}+ /** Whether the value the card is grouped by stands on another note: a template or a parent. */+ private isInherited(note: FNote, type: "label" | "relation") {+ return note.getAttributes(type, this.statusAttribute)+ .some(attribute => attribute.noteId !== note.noteId);+ }+removeFromBoard(noteId: string) {const note = froca.getNoteFromCache(noteId);if (!note) return;if (this.isRelationMode) {+ // 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")) {+ toast.showMessage(t("board_view.inherited-column"), 3000);+ return;+ }+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) {+ if (this.isInherited(note, "label")) {return attributes.setLabel(noteId, this.statusAttribute, "");}