Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: extend the board context menu

Adorian Doran6a22f13f1e79
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 2881e618b1..902c3b47db 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3417,6 +3417,8 @@
"keep-column-collapsed": "Keep the column collapsed",
"collapse-all-columns": "Collapse all columns",
"expand-all-columns": "Expand all columns",
+ "show-inbox-column": "Show inbox column",
+ "show-archived-notes": "Show archived notes",
"collapse-hint": "Double click to collapse",
"set-limit": "Set limit...",
"set-limit-ok": "Set limit",
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 6a19f3e8e5..1a58fb4ab8 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -508,11 +508,22 @@ export default class BoardApi {
}
/**
- * Hides the inbox column by turning off the board's setting. The stored entry is kept, so
- * its icon, colour and position are restored when it is switched back on.
+ * Whether the board keeps an inbox column. The stored entry outlives being switched off, so
+ * its icon, colour and position come back with it.
*/
+ async setInboxEnabled(enabled: boolean) {
+ await attributes.setBooleanWithInheritance(
+ this.parentNote, "enableInboxColumn", enabled);
+ }
+
+ /** Hides the inbox column, which is what its own menu offers. */
async disableInbox() {
- await attributes.setBooleanWithInheritance(this.parentNote, "enableInboxColumn", false);
+ await this.setInboxEnabled(false);
+ }
+
+ /** Whether the board draws the notes filed as archived, cards and columns alike. */
+ async setArchivedShown(shown: boolean) {
+ await attributes.setBooleanWithInheritance(this.parentNote, "includeArchived", shown);
}
/** The note limit set for a column, absent if disabled. */
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 8081022467..7d341c3574 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -12,7 +12,7 @@ import { t } from "../../../services/i18n";
import { escapeHtml } from "../../../services/utils";
import ColorPicker from "../../react/ColorPicker";
import Api from "./api";
-import { INBOX_COLUMN } from "./columns";
+import { INBOX_COLUMN, INBOX_COLUMN_ICON } from "./columns";
/** What the column menu is opened for: the column itself, and what it can be asked to do. */
interface ColumnMenuTarget {
@@ -168,11 +168,22 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:
/** How many columns a card's menu lists before the rest go behind an entry of their own. */
const LISTED_COLUMNS = 7;
+/** What the board is, and what it can be asked to do, for a press on the ground its columns stand on. */
+interface BoardMenuTarget {
+ /** Whether the board keeps an inbox column, which the entry reports and toggles. */
+ inboxShown: boolean;
+ /** Whether the board draws the notes filed as archived. */
+ archivedShown: boolean;
+ /** Opens the editor a column is named in, the same one the button at the end opens. */
+ onAddColumn: () => void;
+ onCollapseAll: () => void;
+ onExpandAll: () => void;
+ onShowInbox: (shown: boolean) => void;
+ onShowArchived: (shown: boolean) => void;
+}
+
/** What the board itself offers, for a press on the ground the columns stand on. */
-export function openBoardContextMenu(
- event: ContextMenuEvent,
- board: { onCollapseAll: () => void, onExpandAll: () => void }
-) {
+export function openBoardContextMenu(event: ContextMenuEvent, board: BoardMenuTarget) {
event.preventDefault();
event.stopPropagation();
@@ -180,6 +191,12 @@ export function openBoardContextMenu(
x: event.pageX,
y: event.pageY,
items: [
+ {
+ title: t("board_view.add-new-column"),
+ uiIcon: "bx bx-columns",
+ handler: board.onAddColumn
+ },
+ { kind: "separator" },
{
title: t("board_view.collapse-all-columns"),
uiIcon: "bx bx-collapse-alt",
@@ -189,6 +206,19 @@ export function openBoardContextMenu(
title: t("board_view.expand-all-columns"),
uiIcon: "bx bx-expand-alt",
handler: board.onExpandAll
+ },
+ { kind: "separator" },
+ {
+ title: t("board_view.show-inbox-column"),
+ uiIcon: INBOX_COLUMN_ICON,
+ trailingIcon: board.inboxShown ? "bx bx-check" : undefined,
+ handler: () => board.onShowInbox(!board.inboxShown)
+ },
+ {
+ title: t("board_view.show-archived-notes"),
+ uiIcon: "bx bx-archive",
+ trailingIcon: board.archivedShown ? "bx bx-check" : undefined,
+ handler: () => board.onShowArchived(!board.archivedShown)
}
],
selectMenuItemHandler() {}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 32a7bc64e8..6f8e69df81 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -23,7 +23,7 @@ import BoardView, { BoardViewData } from ".";
import { collectShortcutHints } from "../../../services/shortcut_hints";
import { FLIP_SETTLE_MS } from "../../react/flip";
import BoardApi, { getPendingWrites } from "./api";
-import { DEFAULT_COLUMN_ICON } from "./columns";
+import { DEFAULT_COLUMN_ICON, INBOX_COLUMN_ICON } from "./columns";
// Stands in for the server: by the time the bulk action resolves, the notes carry the new value,
// which is what makes the old column empty rather than merely renamed.
@@ -477,11 +477,14 @@ describe("Collapsed board columns", () => {
item && "uiIcon" in item && "handler" in item
? [ { icon: item.uiIcon, handler: item.handler } ]
: []);
- expect(entries.map(entry => entry.icon))
- .toEqual([ "bx bx-collapse-alt", "bx bx-expand-alt" ]);
+ expect(entries.map(entry => entry.icon)).toEqual([
+ "bx bx-columns", "bx bx-collapse-alt", "bx bx-expand-alt",
+ INBOX_COLUMN_ICON, "bx bx-archive"
+ ]);
+ const entry = (icon: string) => entries.find(item => item.icon === icon)?.handler;
await act(async () => {
- entries[0]?.handler?.({} as never, {} as never);
+ entry("bx bx-collapse-alt")?.({} as never, {} as never);
await flush();
});
expect(isCollapsed(mountPoint, 0)).toBe(true);
@@ -489,7 +492,7 @@ describe("Collapsed board columns", () => {
expect(saved.at(-1)?.columns?.map(column => column.collapsed)).toEqual([ true, true ]);
await act(async () => {
- entries[1]?.handler?.({} as never, {} as never);
+ entry("bx bx-expand-alt")?.({} as never, {} as never);
await flush();
});
expect(isCollapsed(mountPoint, 0)).toBe(false);
@@ -505,6 +508,47 @@ describe("Collapsed board columns", () => {
show.mockRestore();
});
+ /**
+ * The board's own menu offers what the board is as well as what it does: an editor for a new
+ * column, and the two settings that decide which columns and cards it draws at all.
+ */
+ it("opens the column editor and toggles what the board shows, from its menu", async () => {
+ const { mountPoint } = await setup();
+ const board = mountPoint.querySelector<HTMLElement>(".board-view-container");
+ const inbox = vi.spyOn(BoardApi.prototype, "setInboxEnabled").mockResolvedValue(undefined);
+ const archived = vi.spyOn(BoardApi.prototype, "setArchivedShown")
+ .mockResolvedValue(undefined);
+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
+
+ board?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
+ const items = show.mock.calls.at(-1)?.[0].items ?? [];
+ const entry = (icon: string) => {
+ const found = items.find(item => item && "uiIcon" in item && item.uiIcon === icon);
+ if (!found || !("handler" in found)) throw new Error(`expected a ${icon} entry`);
+ return found;
+ };
+
+ // Neither is on, so neither is ticked, and pressing them asks for them.
+ expect("trailingIcon" in entry(INBOX_COLUMN_ICON) && entry(INBOX_COLUMN_ICON).trailingIcon)
+ .toBeUndefined();
+ entry(INBOX_COLUMN_ICON).handler?.(entry(INBOX_COLUMN_ICON), {} as never);
+ entry("bx bx-archive").handler?.(entry("bx bx-archive"), {} as never);
+ expect(inbox).toHaveBeenCalledWith(true);
+ expect(archived).toHaveBeenCalledWith(true);
+
+ // The same editor the slot at the end of the board opens.
+ expect(mountPoint.querySelector(".board-add-column input")).toBeNull();
+ await act(async () => {
+ entry("bx bx-columns").handler?.(entry("bx bx-columns"), {} as never);
+ await flush();
+ });
+ expect(mountPoint.querySelector(".board-add-column input")).toBeTruthy();
+
+ show.mockRestore();
+ inbox.mockRestore();
+ archived.mockRestore();
+ });
+
/** A column and a card answer for their own presses, and the board does not speak over them. */
it("leaves a press inside a column to the column", async () => {
const { mountPoint } = await setup();
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index ccdf290c3b..f151736091 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -242,6 +242,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
* is a column being selected or focused.
*/
const [ isPeekingAll, setIsPeekingAll ] = useState(false);
+ /** Whether the editor a column is named in is open, which the board's own menu also opens. */
+ const [ isCreatingColumn, setIsCreatingColumn ] = useState(false);
const selectColumn = useCallback<Dispatch<StateUpdater<string | undefined>>>((column) => {
setIsPeekingAll(false);
setActiveColumn(column);
@@ -311,6 +313,11 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
}
openBoardContextMenu(event, {
+ inboxShown: inboxEnabled,
+ archivedShown: includeArchived,
+ onAddColumn: () => setIsCreatingColumn(true),
+ onShowInbox: (shown) => api.setInboxEnabled(shown),
+ onShowArchived: (shown) => api.setArchivedShown(shown),
onCollapseAll: () => {
// The open column is closed with the rest: it holds the peek that would otherwise
// keep it open against what is being written for it.
@@ -325,7 +332,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
api.setAllColumnsCollapsed(false);
}
});
- }, [ api, selectColumn ]);
+ }, [ api, selectColumn, inboxEnabled, includeArchived ]);
const boardActions = useMemo<BoardActions>(() => ({
setBranchIdToEdit,
@@ -709,6 +716,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
isInRelationMode={isInRelationMode}
columnCount={shownColumns.length}
onCreated={setCreatedColumn}
+ isCreating={isCreatingColumn}
+ setIsCreating={setIsCreatingColumn}
/>
{/* Where what is being carried is put. Preact draws the layer and never
its contents, so the copy is not among the children it places. */}
@@ -773,15 +782,21 @@ export function findRefreshReason(loadResults: LoadResults, statusAttribute: str
return null;
}
-function AddNewColumn({ api, isInRelationMode, columnCount, onCreated }: {
+function AddNewColumn({
+ api, isInRelationMode, columnCount, onCreated, isCreating, setIsCreating
+}: {
api: BoardApi,
isInRelationMode: boolean,
/** How many columns stand before this, which is what carries it past the board's edge. */
columnCount: number,
/** Names the column just made, which the board reveals as it draws it. */
- onCreated: (column: string) => void
+ onCreated: (column: string) => void,
+ /** Whether the editor is open. The board's own menu opens the same one this slot opens. */
+ isCreating: boolean,
+ setIsCreating: (isCreating: boolean) => void
}) {
- const [ isCreatingNewColumn, setIsCreatingNewColumn ] = useState(false);
+ const isCreatingNewColumn = isCreating;
+ const setIsCreatingNewColumn = setIsCreating;
// Kept between columns, as the card editor keeps its own: a run of columns is often a run of
// the same kind of column.
const [ icon, setIcon ] = useState(DEFAULT_COLUMN_ICON);