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 collapse/expand all columns commands as overlay buttons
Adorian Doranabd97155e698
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.cssindex ed1fd42926..2b075c9f38 100644--- a/apps/client/src/widgets/collections/board/index.css+++ b/apps/client/src/widgets/collections/board/index.css@@ -1372,3 +1372,9 @@ body.mobile .column-drop-placeholder {text-overflow: ellipsis;white-space: nowrap;}++/* Below `.board-edit-backdrop` (z-index 50), so the controls dim with the board while a card is+ being named. */+.board-view .board-overlay-controls {+ z-index: 2;+}diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 59cc8fc148..7c9e4ffda4 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -573,6 +573,33 @@ describe("Collapsed board columns", () => {show.mockRestore();});+ /**+ * The same two actions on the overlay group in the foot corner, where the shortcut-hints button+ * stands last so that what the board does keeps the leading end.+ */+ it("collapses and expands every column from the overlay group", async () => {+ const { mountPoint } = await setup({ keepCollapsed: true });+ const group = mountPoint.querySelector<HTMLElement>(".board-overlay-controls");+ const buttons = [ ...(group?.querySelectorAll<HTMLButtonElement>("button") ?? []) ];+ expect(buttons.map(button => button.getAttribute("aria-label"))).toEqual([+ "board_view.collapse-all-columns", "board_view.expand-all-columns",+ "shortcut_hints.show_button"+ ]);++ await act(async () => {+ buttons[0]?.click();+ await flush();+ });+ expect(isCollapsed(mountPoint, 0)).toBe(true);+ expect(isCollapsed(mountPoint, 1)).toBe(true);++ await act(async () => {+ buttons[1]?.click();+ await flush();+ });+ expect(isCollapsed(mountPoint, 0)).toBe(false);+ expect(isCollapsed(mountPoint, 1)).toBe(false);+ });/*** A press on a card is focus arriving before it is a click, and while the whole board is peeked* every column reads as inactive. The column pressed in keeps its peek; the rest give theirs up.diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex fe7be63ae1..de97aa86a0 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -37,7 +37,8 @@ import {} from "../../react/hooks";import Icon from "../../react/Icon";import NoteAutocomplete from "../../react/NoteAutocomplete";-import ShortcutHintButton from "../../shortcut_hints/shortcut_hint_button";+import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";+import { ShortcutHintOverlayButton } from "../../shortcut_hints/shortcut_hint_button";import { onWheelHorizontalScroll } from "../../widget_utils";import ActionButton from "../../react/ActionButton";import { IconPickerButton } from "../../react/IconPicker";@@ -549,6 +550,17 @@ export default function BoardView({api.noteContext = noteContext;// Every member is one of useState's own setters, so this value is built once and never changes// identity -- a drag cannot reach anything that reads only this.+ const collapseAllColumns = useCallback(() => {+ // 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.+ selectColumn(undefined);+ api.setAllColumnsCollapsed(true);+ }, [ api, selectColumn ]);+ const expandAllColumns = useCallback(() => {+ // Opened for good where the column is not kept collapsed, and peeked where it is.+ setIsPeekingAll(true);+ api.setAllColumnsCollapsed(false);+ }, [ api ]);const openBoardMenu = useCallback((event: ContextMenuEvent) => {// Only the ground the columns stand on. A column and a card answer for their own presses,// and what they leave alone, such as the button that makes a card, is left alone here too.@@ -561,19 +573,10 @@ export default function BoardView({onAddColumn: () => setIsCreatingColumn(true),onShowArchived: (shown) => api.setArchivedShown(shown),onOpenProperties: () => setIsEditingProperties(true),- 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.- selectColumn(undefined);- api.setAllColumnsCollapsed(true);- },- onExpandAll: () => {- // Opened for good where the column is not kept collapsed, and peeked where it is.- setIsPeekingAll(true);- api.setAllColumnsCollapsed(false);- }+ onCollapseAll: collapseAllColumns,+ onExpandAll: expandAllColumns});- }, [ api, selectColumn, inboxEnabled, includeArchived ]);+ }, [ api, collapseAllColumns, expandAllColumns, inboxEnabled, includeArchived ]);// Read from the api rather than from the prop, since a pick moves the api's own copy ahead of// the board's; keyed on the prop so that a change from anywhere else is followed too.@@ -1363,10 +1366,22 @@ export default function BoardView({document.body)}{!isMobile() && (- <ShortcutHintButton- className="board-shortcut-hint-button"+ <OverlayControlGroup+ className="board-overlay-controls"placement="bottom-end"- />+ >+ <OverlayControlButton+ title={t("board_view.collapse-all-columns")}+ icon="bx-collapse-alt"+ onClick={collapseAllColumns}+ />+ <OverlayControlButton+ title={t("board_view.expand-all-columns")}+ icon="bx-expand-alt"+ onClick={expandAllColumns}+ />+ <ShortcutHintOverlayButton />+ </OverlayControlGroup>)}</div>}</SelectionContext.Provider>