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: add "Select all cards" to the column menu
Adorian Doranede9b5b45f4a
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 4643bb6cb0..bd0e03b452 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3585,7 +3585,8 @@"cards-selected_other": "{{count}} cards selected","select-column-cards": "Select every card in the column","reset-selection": "Reset the selection",- "expand-column": "Expand column"+ "expand-column": "Expand column",+ "select-all-cards": "Select all cards"},"dashboard_view": {"refresh-widget": "Refresh",diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 026143956e..da7550ef13 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -22,6 +22,7 @@ import { IconPickerButton } from "../../react/IconPicker";import { useIsOnScreen, useLingeringTrue, useStaticTooltip } from "../../react/hooks";import { useFlip } from "../../react/flip";import { useScrollFade } from "../../react/scroll_fade";+import { useSelection } from "../../react/selection";/** How long a field waits for the card it made, after which it is taken down regardless. */const HAND_OVER_MS = 2000;@@ -213,6 +214,8 @@ export default function Column({useContext(BoardActionsContext);const { branchIdToEdit, columnNameToEdit, draggedCard, draggedColumn } =useContext(BoardDragStateContext);+ // The store itself, for the menu entry that picks out the whole column.+ const selection = useSelection();// Every card on the move. The one under the pointer is taken out of the flow by the gesture// itself; the rest of a carried selection stay where they are drawn and are dimmed instead.const carriedNoteIds = draggedCard@@ -483,6 +486,7 @@ export default function Column({setColumnNameToEdit(await api.insertColumn(column, direction));},onSetLimit: () => setColumnLimitToEdit(column),+ onSelectAll: () => selection.selectAll(api.getColumnNoteIds(column)),onCollapse: collapse,onKeepCollapsed: (keep) => {setIsCollapsingByHand(keep);@@ -502,7 +506,7 @@ export default function Column({});}, [api, column, color, archived, collapsed, keepCollapsed, isCollapseVolatile, collapse,- isCollapsed, nested,+ isCollapsed, nested, selection,columns, columnIndex, setColumnNameToEdit, setColumnLimitToEdit, setActiveColumn,onMoveColumn, onFocusColumn]);diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.tsindex 16ac8c4b19..7e1ef519b8 100644--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts@@ -56,7 +56,8 @@ describe("Board column context menu", () => {onMoveColumn?: (toIndex: number) => void,onSetLimit?: () => void,onCollapse?: (collapsed: boolean) => void,- onKeepCollapsed?: (keepCollapsed: boolean) => void+ onKeepCollapsed?: (keepCollapsed: boolean) => void,+ onSelectAll?: () => void} = {}) {const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});@@ -71,6 +72,7 @@ describe("Board column context menu", () => {// by; a test answers only where that is what it is about.const withDefaults = Object.assign({getColumnTitle: (name: string) => name,+ getColumnNoteIds: () => [ "cardA", "cardB" ],getColumnSort: () => ({ orderBy: undefined, isDescending: false }),getEffectiveColumnSort: () => ({ orderBy: undefined, isDescending: false }),getPromotedAttributes: () => []@@ -88,7 +90,8 @@ describe("Board column context menu", () => {onMoveColumn: callbacks.onMoveColumn ?? (() => {}),onSetLimit: callbacks.onSetLimit ?? (() => {}),onCollapse: callbacks.onCollapse ?? (() => {}),- onKeepCollapsed: callbacks.onKeepCollapsed ?? (() => {})+ onKeepCollapsed: callbacks.onKeepCollapsed ?? (() => {}),+ onSelectAll: callbacks.onSelectAll ?? (() => {})});// The spy outlives one call, so it is the menu just opened that is read back.@@ -127,6 +130,22 @@ describe("Board column context menu", () => {expect(onEditTitle).toHaveBeenCalled();});+ it("picks out every card the column draws, and offers nothing for an empty one", () => {+ const onSelectAll = vi.fn();+ const entry = openMenu({} as BoardApi, {}, { onSelectAll }).find(item =>+ item && "uiIcon" in item && item.uiIcon === "bx bx-selection");+ if (!entry || !("handler" in entry)) throw new Error("expected a select-all entry");++ expect(entry.enabled).not.toBe(false);+ entry.handler?.(entry, {} as never);+ expect(onSelectAll).toHaveBeenCalled();++ const empty = openMenu({ getColumnNoteIds: () => [] } as unknown as BoardApi).find(item =>+ item && "uiIcon" in item && item.uiIcon === "bx bx-selection");+ if (!empty || !("enabled" in empty)) throw new Error("expected a select-all entry");+ expect(empty.enabled).toBe(false);+ });+it("offers to archive a column, and to bring back one already archived", () => {const api = { setColumnArchived: vi.fn() } as unknown as BoardApi;@@ -266,7 +285,8 @@ describe("Board column context menu", () => {"bx bx-collapse-horizontal", "bx bx-lock-alt", "bx bx-sort-alt-2","bx bx-tachometer","bx bx-horizontal-left",- "bx bx-archive", "bx bx-trash"+ "bx bx-archive", "bx bx-trash",+ "bx bx-selection"]);});diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex 94ccf59829..a6dc732c47 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -53,6 +53,8 @@ interface ColumnMenuTarget {onCollapse: (collapsed: boolean) => void;/** Sets whether the column collapses again once it has been opened. */onKeepCollapsed: (keepCollapsed: boolean) => void;+ /** Picks out every card the column draws, as Ctrl+A does. */+ onSelectAll: () => void;}export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: ColumnMenuTarget) {@@ -182,6 +184,14 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:handler: () => api.confirmAndRemoveColumn(column.value)},{ kind: "separator" },+ {+ title: t("board_view.select-all-cards"),+ uiIcon: "bx bx-selection",+ shortcut: "Ctrl+A",+ enabled: api.getColumnNoteIds(column.value).length > 0,+ handler: column.onSelectAll+ },+ { kind: "separator" },{kind: "custom",componentFn: () => ColumnColorPicker({ api, ...column })