Skip to content

Build your personal knowledge base with Trilium Notes

feat(board): leave renaming, quick edit and new groupings out of a read-only board

Elian Doran59b10669fd34
diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx
index 731dd62125..b6456e32d8 100644
--- a/apps/client/src/widgets/collections/board/card.tsx
+++ b/apps/client/src/widgets/collections/board/card.tsx
@@ -337,7 +337,7 @@ function Card({
</span>
{/* On mobile the rail offers the rename, and a hover-revealed icon has no
hover to be revealed by. */}
- {!isMobile() && <span
+ {!isMobile() && !api.isReadOnly && <span
className="edit-icon icon bx bx-rename"
title={t("board_view.edit-note-title")}
onClick={handleEdit}
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 3d1bbda628..c7e4e2686a 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -561,8 +561,8 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, target: N
// What is done to the card itself, which a selection has none of: the menu it opens leads with
// the columns instead.
const identity: MenuItem<CommandNames>[] = !isSingle ? [] : [
- // Space opens the same popup for the card the cursor stands on.
- { ...link_context_menu.getQuickEditItem(), shortcut: "Space" },
+ // Space opens the same popup for the card the cursor stands on. It edits the card's note.
+ ...(api.isReadOnly ? [] : [ { ...link_context_menu.getQuickEditItem(), shortcut: "Space" } ]),
...(api.isReadOnly ? [] : [ {
title: t("board_view.edit-title"),
uiIcon: "bx bx-rename",
diff --git a/apps/client/src/widgets/collections/board/group_by.spec.tsx b/apps/client/src/widgets/collections/board/group_by.spec.tsx
index fb62252c1d..2872cf3b94 100644
--- a/apps/client/src/widgets/collections/board/group_by.spec.tsx
+++ b/apps/client/src/widgets/collections/board/group_by.spec.tsx
@@ -149,7 +149,7 @@ describe("BoardGroupBy", () => {
});
/** Renders the dropdown with its menu open, which is where its items are drawn. */
- async function setup(current = "status") {
+ async function setup(current = "status", canCreate = true) {
const onSelect = vi.fn();
const mountPoint = document.createElement("div");
container = mountPoint;
@@ -160,6 +160,7 @@ describe("BoardGroupBy", () => {
<ParentComponent.Provider value={new Component()}>
<BoardGroupBy
note={board()}
+ canCreate={canCreate}
options={groupingOptions(board(), undefined, current)}
current={current}
onSelect={onSelect}
@@ -183,6 +184,13 @@ describe("BoardGroupBy", () => {
const items = (mountPoint: HTMLElement) =>
[ ...document.querySelectorAll(".dropdown-menu .dropdown-item") ];
+ it("offers no grouping to make where none can be, only the ones the board has", async () => {
+ const { mountPoint } = await setup("status", false);
+
+ expect(items(mountPoint).map(item => item.textContent?.trim())).toEqual([ "Status", "Priority" ]);
+ expect(document.querySelector(".dropdown-menu .dropdown-divider")).toBeNull();
+ });
+
it("offers making a grouping after the ones the board has, behind a divider", async () => {
const { mountPoint } = await setup();
diff --git a/apps/client/src/widgets/collections/board/group_by.tsx b/apps/client/src/widgets/collections/board/group_by.tsx
index 076a28c7dc..f7efa4e1b1 100644
--- a/apps/client/src/widgets/collections/board/group_by.tsx
+++ b/apps/client/src/widgets/collections/board/group_by.tsx
@@ -1,6 +1,7 @@
import { DEFAULT_BOARD_GROUP_BY, normalizeBoardGroupBy } from "@triliumnext/commons";
import { createPortal } from "preact";
+import { lazy, Suspense } from "preact/compat";
import { useCallback, useRef, useState } from "preact/hooks";
import type FNote from "../../../entities/fnote";
@@ -8,9 +9,7 @@ import type { Attribute } from "../../../services/attribute_parser";
import attributes from "../../../services/attributes";
import { t } from "../../../services/i18n";
import toast from "../../../services/toast";
-import {
- AttributeDetail, type AttributeDetailOpts
-} from "../../attribute_widgets/attribute_detail";
+import type { AttributeDetailOpts } from "../../attribute_widgets/attribute_detail";
import Dropdown from "../../react/Dropdown";
import { FormDropdownDivider, FormListItem } from "../../react/FormList";
import Icon from "../../react/Icon";
@@ -41,9 +40,11 @@ const NEW_GROUPING: Attribute = {
};
/** Switches which attribute the board's columns are made from, and makes new ones. */
-export default function BoardGroupBy({ note, options, current, onSelect }: {
+export default function BoardGroupBy({ note, canCreate = true, options, current, onSelect }: {
/** The board note, which carries the definitions and any made here. */
note: FNote;
+ /** Whether a new grouping can be made, which writes its definition onto the board. */
+ canCreate?: boolean;
options: GroupingOption[];
/** The grouping in force, as {@link groupingOptions} spells its value. */
current: string;
@@ -120,31 +121,39 @@ export default function BoardGroupBy({ note, options, current, onSelect }: {
>{option.title}</FormListItem>
))}
- <FormDropdownDivider />
+ {canCreate && <>
+ <FormDropdownDivider />
- <FormListItem
- className="board-group-by-create"
- icon="bx bx-plus"
- onClick={create}
- >{t("promoted_attributes.create_attribute")}</FormListItem>
+ <FormListItem
+ className="board-group-by-create"
+ icon="bx bx-plus"
+ onClick={create}
+ >{t("promoted_attributes.create_attribute")}</FormListItem>
+ </>}
</Dropdown>
{/* Outside the menu, which takes its items down as it closes: the editor is opened by
one of them and outlives it. */}
- {createPortal(
- <AttributeDetail
- opts={detail}
- currentNoteId={note.noteId}
- onDismiss={() => setDetail(null)}
- onCancel={() => setDetail(null)}
- onAttributesChanged={([ definition ]) => { edited.current = definition; }}
- onSaveAndClose={save}
- />,
+ {canCreate && createPortal(
+ <Suspense fallback={null}>
+ <AttributeDetail
+ opts={detail}
+ currentNoteId={note.noteId}
+ onDismiss={() => setDetail(null)}
+ onCancel={() => setDetail(null)}
+ onAttributesChanged={([ definition ]) => { edited.current = definition; }}
+ onSaveAndClose={save}
+ />
+ </Suspense>,
document.body)}
</>
);
}
+/** The attribute editor, loaded only for a board a grouping can be made on. */
+const AttributeDetail = lazy(() => import("../../attribute_widgets/attribute_detail")
+ .then(({ AttributeDetail: editor }) => ({ default: editor })));
+
/**
* The attributes the board offers to group by: the default grouping, the select fields it defines,
* and the grouping in force whatever defines it.
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index c1666227b7..704f54659f 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -5655,6 +5655,7 @@ describe("BoardView, read-only", () => {
expect(board.querySelector(".board-add-column")).toBeNull();
expect(board.querySelector(".board-column h3 > .column-icon.static")).not.toBeNull();
expect(board.querySelector(".board-column h3 > .column-icon button")).toBeNull();
+ expect(board.querySelector(".board-note .edit-icon")).toBeNull();
await act(async () => {
if (column) startEditingTitle(column);
@@ -5676,6 +5677,7 @@ describe("BoardView, read-only", () => {
const cardMenu = menuTitles(show);
expect(cardMenu).toContain("board_view.copy-reference");
expect(cardMenu).not.toContain("board_view.edit-title");
+ expect(cardMenu).not.toContain("link_context_menu.open_note_in_popup");
expect(cardMenu).not.toContain("board_view.delete-note");
board.querySelector(".board-column h3")?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 5a4edef605..b5b7d91fa1 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -364,8 +364,7 @@ export default function BoardView({
}: ViewModeProps<BoardViewData>) {
const { noteContext } = useNoteContext();
const isReadOnly = useEffectiveReadOnly(parentNote, noteContext);
- const [ requestedGroupBy, setRequestedGroupBy ] =
- useNoteLabelWithDefault(parentNote, "board:groupBy", DEFAULT_GROUP_BY);
+ const [ requestedGroupBy, setRequestedGroupBy ] = useGroupBy(parentNote, isReadOnly);
/**
* The grouping the board draws and writes for.
*
@@ -1429,6 +1428,7 @@ export default function BoardView({
>
<BoardGroupBy
note={parentNote}
+ canCreate={!isReadOnly}
options={groupingChoices}
current={currentGrouping}
onSelect={setRequestedGroupBy}
@@ -1714,6 +1714,19 @@ export function findRefreshReason(loadResults: LoadResults, statusAttribute: str
return null;
}
+/**
+ * The attribute the board groups its cards by, `#board:groupBy`. A read-only board keeps the label,
+ * so the reader's choice holds only while the board is shown.
+ */
+function useGroupBy(note: FNote, isReadOnly: boolean): [ string, (groupBy: string) => void ] {
+ const [ label, setLabel ] = useNoteLabelWithDefault(note, "board:groupBy", DEFAULT_GROUP_BY);
+ const [ viewed, setViewed ] = useState<string>();
+
+ useEffect(() => setViewed(undefined), [ note ]);
+
+ return isReadOnly ? [ viewed ?? label, setViewed ] : [ label, setLabel ];
+}
+
function AddNewColumn({
api, isInRelationMode, columnCount, onCreated, isCreating, setIsCreating
}: {
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
index 9e99d5fcd9..7a94ad1806 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
@@ -322,7 +322,7 @@
or colors, deleting them, or archiving them.</p>
<p>You can select multiple cards in the following ways:</p>
<ul>
- <li class="ck-list-marker-bold"><strong>Using a mouse and keyboard:</strong>
+ <li><strong>Using a mouse and keyboard:</strong>
<ul>
<li>To add a card to the selection, hold <kbd>Ctrl</kbd> and click the card.
Repeat this for other cards until all the desired cards are selected. Clicking
@@ -333,7 +333,7 @@
<li>Press <kbd>Esc</kbd> to clear the selection.</li>
</ul>
</li>
- <li class="ck-list-marker-bold"><strong>On mobile:</strong>
+ <li><strong>On mobile:</strong>
<ol>
<li>To enter selection mode, tap the&nbsp;<span class="tn-icon bx bx-select-multiple"></span> button
at the top of the screen. A selection toolbar will appear in the header,
@@ -345,7 +345,7 @@
<li>Use the side toolbar to apply actions to the selected cards.</li>
</ol>
</li>
- <li class="ck-list-marker-bold"><strong>Using only the keyboard:</strong>
+ <li><strong>Using only the keyboard:</strong>
<ul>
<li>To add the currently focused card to the selection, press <kbd>Ctrl</kbd> + <kbd>Space</kbd>.
Repeat this for the other cards you want to select. Pressing <kbd>Ctrl</kbd> + <kbd>Space</kbd> again
@@ -658,11 +658,17 @@ class="admonition warning">
</ul>
<p>To use relations for grouping:</p>
<ol>
- <li>Create a Kanban board from scratch rather than from a template.</li>
- <li>Assign <code>#viewType=board #hidePromotedAttributes</code> to emulate the
- default template.</li>
- <li>Set <code>#board:groupBy</code> to the name of a relation, <strong>including the</strong> <code>~</code> <strong>prefix</strong> (for
- example, <code>~status</code>).</li>
+ <li>
+ <p>Create a Kanban board from scratch rather than from a template.</p>
+ </li>
+ <li>
+ <p>Assign <code>#viewType=board #hidePromotedAttributes</code> to emulate the
+ default template.</p>
+ </li>
+ <li>
+ <p>Set <code>#board:groupBy</code> to the name of a relation, <strong>including the</strong> <code>~</code> <strong>prefix</strong> (for
+ example, <code>~status</code>).</p>
+ </li>
<li>
<p>Optionally, use&nbsp;<a class="reference-link" href="#root/_help_OFXdgB2nNk1F">Promoted Attributes</a>&nbsp;to
make changing the status within the note easier:</p><pre><code class="language-text-x-trilium-auto">#relation:status(inheritable)="promoted,alias=Status,single"</code></pre>
@@ -697,4 +703,13 @@ class="admonition warning">
the column or card it points to. In a Markdown or code note, the plain
link address is pasted instead. Opening the link scrolls the board to the
column or card and focuses it. If the column belongs to a different grouping
- attribute, the board switches to that attribute first.</p>
\ No newline at end of file
+ attribute, the board switches to that attribute first.</p>
+<h2>Read-only boards</h2>
+<p>A board marked as <a href="#root/_help_CoFPLs3dRlXc">read-only</a> only
+ shows its cards. It has no buttons to add a card or a column, column and
+ card titles can't be renamed, and column icons can't be changed. The context
+ menus of a card or a column keep only the entries that change nothing,
+ such as opening the note or <span class="tn-icon bx bx-copy"></span> <em>Copy reference</em>,
+ and the board's own menu doesn't open. The cards can still be grouped by
+ another attribute, but the choice isn't saved, and no new grouping attribute
+ can be created.</p>
\ No newline at end of file
diff --git a/docs/User Guide/User Guide/Collections/Kanban Board.md b/docs/User Guide/User Guide/Collections/Kanban Board.md
index bdaed5d3ab..e95dfe32fb 100644
--- a/docs/User Guide/User Guide/Collections/Kanban Board.md
+++ b/docs/User Guide/User Guide/Collections/Kanban Board.md
@@ -448,4 +448,8 @@ The filter persists even after you close the tab. When you reopen the collection
You can create a link that opens the board and points out a specific column or card. Open the **column menu** or the card’s context menu, select <span class="tn-icon bx bx-copy"></span> **Copy reference**, and then paste the link where you need it.
-In a text note, the pasted link displays the title, icon, and color of the column or card it points to. In a Markdown or code note, the plain link address is pasted instead. Opening the link scrolls the board to the column or card and focuses it. If the column belongs to a different grouping attribute, the board switches to that attribute first.
\ No newline at end of file
+In a text note, the pasted link displays the title, icon, and color of the column or card it points to. In a Markdown or code note, the plain link address is pasted instead. Opening the link scrolls the board to the column or card and focuses it. If the column belongs to a different grouping attribute, the board switches to that attribute first.
+
+## Read-only boards
+
+A board marked as [read-only](../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md) only shows its cards. It has no buttons to add a card or a column, column and card titles can't be renamed, and column icons can't be changed. The context menus of a card or a column keep only the entries that change nothing, such as opening the note or <span class="tn-icon bx bx-copy"></span> _Copy reference_, and the board's own menu doesn't open. The cards can still be grouped by another attribute, but the choice isn't saved, and no new grouping attribute can be created.
\ No newline at end of file