Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: add a menu button for columns

Adorian Doranabb468189728
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index fa3884f191..1c5c72af8d 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3352,8 +3352,9 @@
"add-column": "Add Column",
"add-column-placeholder": "Enter column name...",
"edit-note-title": "Click to edit note title",
- "edit-column-title": "Click to edit column title",
+ "edit-column-title": "Edit column title",
"change-column-icon": "Change column icon",
+ "column-menu": "Column menu",
"column-already-exists": "This column already exists on the board.",
"column-definition-save-error": "The columns were saved on the board, but could not be saved to the status attribute.",
"status-alias": "Status"
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index f99e6d3321..a6e017b6ca 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -11,6 +11,7 @@ import { getHue, parseColor } from "../../../services/css_class_manager";
import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
import { DragData, TREE_CLIPBOARD_TYPE } from "../../note_tree";
+import ActionButton from "../../react/ActionButton";
import Icon from "../../react/Icon";
import { IconPickerButton } from "../../react/IconPicker";
import NoteLink from "../../react/NoteLink";
@@ -60,13 +61,13 @@ export default function Column({
column, columnIndex, columnItems, isEditing, api, parentNote
});
- const handleEdit = useCallback(() => {
- setColumnNameToEdit(column);
- }, [column]);
-
- const handleContextMenu = useCallback((e: ContextMenuEvent) => {
- openColumnContextMenu(api, e, column, color);
- }, [ api, column, color ]);
+ const openMenu = useCallback((e: ContextMenuEvent) => {
+ openColumnContextMenu(api, e, {
+ value: column,
+ color,
+ onEditTitle: () => setColumnNameToEdit(column)
+ });
+ }, [ api, column, color, setColumnNameToEdit ]);
// A fully desaturated colour has no hue to tint with, and leaves the column plain.
const hue = useMemo(() => {
@@ -126,7 +127,7 @@ export default function Column({
draggable
onDragStart={handleColumnDragStart}
onDragEnd={handleColumnDragEnd}
- onContextMenu={handleContextMenu}
+ onContextMenu={openMenu}
onKeyDown={handleTitleKeyDown}
tabIndex={300}
>
@@ -151,10 +152,16 @@ export default function Column({
</span>
<span className="counter-badge">{columnItems?.length ?? 0}</span>
<div className="spacer" />
- <span
- className="edit-icon icon bx bx-edit-alt"
- title={t("board_view.edit-column-title")}
- onClick={handleEdit}
+ <ActionButton
+ className="column-menu"
+ icon="bx bx-dots-vertical-rounded"
+ text={t("board_view.column-menu")}
+ onClick={(e) => {
+ // The header is the column's drag handle and opens this same menu
+ // on a right click; neither should also fire from the button.
+ e.stopPropagation();
+ openMenu(e);
+ }}
/>
</>
) : (
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 04687ca23d..df6539b824 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -18,8 +18,7 @@ describe("Board column context menu", () => {
}
});
- /** Renders the colour picker the menu offers for a column already carrying `color`. */
- async function openPicker(api: BoardApi, color?: string) {
+ function openMenu(api: BoardApi, color?: string, onEditTitle = () => {}) {
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
const event = {
preventDefault: () => {},
@@ -28,9 +27,14 @@ describe("Board column context menu", () => {
pageY: 0
} as ContextMenuEvent;
- openColumnContextMenu(api, event, "To Do", color);
+ openColumnContextMenu(api, event, { value: "To Do", color, onEditTitle });
- const items = show.mock.calls[0][0].items ?? [];
+ return show.mock.calls[0][0].items ?? [];
+ }
+
+ /** Renders the colour picker the menu offers for a column already carrying `color`. */
+ async function openPicker(api: BoardApi, color?: string) {
+ const items = openMenu(api, color);
const custom = items.find(item => item && "kind" in item && item.kind === "custom");
if (!custom || !("componentFn" in custom)) {
throw new Error("expected a colour picker in the menu");
@@ -47,6 +51,19 @@ describe("Board column context menu", () => {
return element;
}
+ it("offers the title editor, which the retired header button used to open", () => {
+ const onEditTitle = vi.fn();
+ const items = openMenu({} as BoardApi, undefined, onEditTitle);
+
+ // Found by its icon: i18next is never initialised under test, so every title is undefined.
+ const entry = items.find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-edit-alt");
+ if (!entry || !("handler" in entry)) throw new Error("expected an edit-title entry");
+
+ entry.handler?.(entry, {} as never);
+ expect(onEditTitle).toHaveBeenCalled();
+ });
+
it("shows the column's own colour as the selected one", async () => {
const api = { setColumnColor: vi.fn() } as unknown as BoardApi;
const picker = await openPicker(api, "#4d99e6");
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index e486f52ed7..db0d5945dd 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -11,9 +11,12 @@ import { t } from "../../../services/i18n";
import ColorPicker from "../../react/ColorPicker";
import Api from "./api";
-export function openColumnContextMenu(
- api: Api, event: ContextMenuEvent, column: string, color?: string
-) {
+export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: {
+ value: string;
+ color?: string;
+ /** Puts the title into its inline editor, the menu being the only way there besides F2. */
+ onEditTitle: () => void;
+}) {
event.preventDefault();
event.stopPropagation();
@@ -21,6 +24,11 @@ export function openColumnContextMenu(
x: event.pageX,
y: event.pageY,
items: [
+ {
+ title: t("board_view.edit-column-title"),
+ uiIcon: "bx bx-edit-alt",
+ handler: column.onEditTitle
+ },
{
title: t("board_view.delete-column"),
uiIcon: "bx bx-trash",
@@ -30,13 +38,13 @@ export function openColumnContextMenu(
return;
}
- await api.removeColumn(column);
+ await api.removeColumn(column.value);
}
},
{ kind: "separator" },
{
kind: "custom",
- componentFn: () => ColumnColorPicker({ api, column, color })
+ componentFn: () => ColumnColorPicker({ api, ...column })
}
],
selectMenuItemHandler() {}
@@ -50,7 +58,7 @@ export function openColumnContextMenu(
* the board redrawing underneath does not reach it. `note-color-picker` is what the menu styles the
* row through, so the class is worn here too.
*/
-function ColumnColorPicker({ api, column, color }: { api: Api, column: string, color?: string }) {
+function ColumnColorPicker({ api, value, color }: { api: Api, value: string, color?: string }) {
const [ currentColor, setCurrentColor ] = useState(color ?? null);
return ColorPicker({
@@ -58,7 +66,7 @@ function ColumnColorPicker({ api, column, color }: { api: Api, column: string, c
currentValue: currentColor,
onChange: (picked) => {
setCurrentColor(picked);
- api.setColumnColor(column, picked);
+ api.setColumnColor(value, picked);
}
});
}
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index 33809836a9..ff66beaf16 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -168,6 +168,12 @@ body.mobile .board-view-container .board-add-column {
cursor: pointer;
}
+.board-view-container .board-column h3 > .column-menu {
+ flex-shrink: 0;
+ margin-inline-start: 0.25em;
+ color: var(--muted-text-color);
+}
+
.board-view-container .board-column > .board-column-content {
flex-grow: 1;
overflow-x: hidden;
@@ -175,7 +181,6 @@ body.mobile .board-view-container .board-add-column {
padding: 0.5em;
}
-.board-view-container .board-column h3:hover .edit-icon,
.board-view-container .board-note:hover .edit-icon {
opacity: 1;
}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 29739fc858..0f6a071c85 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -72,6 +72,12 @@ function Harness({ note, noteIds, initialConfig }: { note: ReturnType<typeof bui
);
}
+/** Opens the title editor the way the keyboard does, the menu entry needing a rendered menu. */
+function startEditingTitle(column: HTMLElement) {
+ column.querySelector("h3")
+ ?.dispatchEvent(new KeyboardEvent("keydown", { key: "F2", bubbles: true }));
+}
+
/** The icon class each column header wears, which is the class its picker button carries. */
function columnIcons(container: HTMLElement) {
return [ ...container.querySelectorAll(".board-column h3 > .column-icon button") ]
@@ -210,7 +216,7 @@ describe("Board column rename", () => {
async function renameSecondColumn(container: HTMLElement, newName: string) {
const column = container.querySelectorAll<HTMLElement>(".board-column")[1];
await act(async () => {
- column.querySelector<HTMLElement>("h3 .edit-icon")?.click();
+ startEditingTitle(column);
await flush();
});
@@ -291,7 +297,7 @@ describe("Board column rename", () => {
// The editor covers the title and its button, so the icon is still the one on the left.
const column = container.querySelectorAll<HTMLElement>(".board-column")[1];
await act(async () => {
- column.querySelector<HTMLElement>("h3 .edit-icon")?.click();
+ startEditingTitle(column);
await flush();
});