Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doran2c6dbde1ad7d
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 69aea6f235..37a8647e4f 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -1249,6 +1249,17 @@ export default class BoardApi {
.some(attribute => attribute.noteId !== note.noteId);
}
+ /**
+ * Whether the board draws the inbox column, which holds the cards with no grouping value.
+ *
+ * {@link removeFromBoard} takes that value away, so with the inbox drawn a card has nowhere to
+ * go: it lands in the inbox instead of leaving, and one already there does not move at all.
+ * The menu and the Delete key leave the action out where this is true.
+ */
+ get isInboxEnabled() {
+ return !!this.parentNote?.isLabelTruthy("enableInboxColumn");
+ }
+
/**
* Takes cards off the board, which leaves the notes where they are and only takes the grouping
* value away. Written together, so a set does not leave a card at a time.
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index d25977ef81..e3820f3093 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -677,6 +677,29 @@ describe("Board item context menu", () => {
expect(deleteNotes).toHaveBeenCalledWith([ "branchId" ], false, false);
});
+ /**
+ * The inbox is the column a card with no grouping value stands in, so taking that value away
+ * leaves the card there instead of off the board. Deleting the note is what removes it.
+ */
+ it("offers no way off the board while the inbox column is drawn", () => {
+ const api = {
+ columns: [],
+ isColumnArchived: () => false,
+ getColumnIcon: () => DEFAULT_COLUMN_ICON,
+ getColumnColorClass: () => "",
+ isInboxEnabled: true,
+ removeFromBoard: vi.fn()
+ } as unknown as BoardApi;
+
+ const items = openItemMenu(api);
+
+ expect(items.find(item => item && "uiIcon" in item && item.uiIcon === "bx bx-task-x"))
+ .toBeUndefined();
+ // Deleting the note is still offered, since that does take it off the board.
+ expect(items.find(item => item && "uiIcon" in item && item.uiIcon === "bx bx-trash"))
+ .toBeTruthy();
+ });
+
/**
* A board can hold more columns than a menu has screen to stand in, so what does not fit goes
* behind one entry. The card's own column is listed whatever its place, since the check beside
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 469088c7de..e0ffad2cf3 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -544,12 +544,14 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, target: N
}),
{ kind: "separator" },
...getArchiveMenuItems<CommandNames>(notes),
- {
+ // Left out where the inbox is drawn: taking the grouping value away would leave the
+ // card in the inbox rather than off the board. Deleting the note is what removes it.
+ ...(api.isInboxEnabled ? [] : [ {
title: t("board_view.remove-from-board"),
uiIcon: "bx bx-task-x",
shortcut: "Delete",
handler: () => api.removeFromBoard(notes.map((selected) => selected.noteId))
- },
+ } ]),
{
title: t("board_view.delete-note"),
uiIcon: "bx bx-trash",
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index 546c90db5a..35fc5e5abf 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -286,6 +286,32 @@ describe("Board keyboard", () => {
expect(branches.deleteNotes).not.toHaveBeenCalled();
});
+ /**
+ * The inbox holds the cards with no grouping value, so stripping the label would leave the
+ * card there rather than off the board. The card's own menu leaves the entry out to match.
+ */
+ it("leaves Delete unanswered while the inbox column is drawn", async () => {
+ const board = await renderBoard(undefined, undefined, [], true);
+ const strip = vi.spyOn(attributes, "removeOwnedLabelByName").mockReturnValue(true);
+ // The inbox is seeded at the front, so the first card stands in the column after it.
+ focusCard(board, 1, 0);
+
+ press(board, "Delete");
+
+ expect(strip).not.toHaveBeenCalled();
+ expect(branches.deleteNotes).not.toHaveBeenCalled();
+ });
+
+ /** Deleting the note is what takes it off a board drawing the inbox, so Shift still works. */
+ it("still deletes the note with Shift and Delete while the inbox is drawn", async () => {
+ const board = await renderBoard(undefined, undefined, [], true);
+ focusCard(board, 1, 0);
+
+ press(board, "Delete", { shiftKey: true });
+
+ expect(branches.deleteNotes).toHaveBeenCalled();
+ });
+
it("deletes the note itself with Shift and Delete", async () => {
const board = await renderBoard();
const strip = vi.spyOn(attributes, "removeOwnedLabelByName").mockReturnValue(true);
@@ -1169,11 +1195,14 @@ describe("Board keyboard", () => {
* @param extra the cards to add beyond the three, each named by the column it stands in. Only
* the tests about moving a run of them need a column deep enough to hold one.
*/
- async function renderBoard(collapsed?: string, orderBy?: string, extra: string[] = []) {
+ async function renderBoard(
+ collapsed?: string, orderBy?: string, extra: string[] = [], inbox = false
+ ) {
boardNote = buildNote({
title: "Board",
"#collection": "",
"#viewType": "board",
+ ...(inbox ? { "#enableInboxColumn": "true" } : {}),
children: [
{ title: "First", "#status": "To Do" },
{ title: "Second", "#status": "To Do" },
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index 5c831f03f0..4830b58476 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -315,6 +315,9 @@ export function useBoardKeyboard({
if (e.key === "Delete" && spot.kind === "item") {
const item = itemAt(columns, byColumn, spot);
if (!item) return;
+ // Plain Delete takes the card off the board, which the inbox leaves nowhere to do: the
+ // card would land there instead. The menu leaves the entry out for the same reason.
+ if (!e.shiftKey && api.isInboxEnabled) return;
take(e);
// The whole selection while the focused card belongs to it, and that card alone