Skip to content

Build your personal knowledge base with Trilium Notes

fix(board): offer no delete for the cards picked out of a read-only board

Elian Doranced8b9768dbb
diff --git a/apps/client/src/widgets/collections/board/card_toolbar.tsx b/apps/client/src/widgets/collections/board/card_toolbar.tsx
index a0e4336b3f..04da34794d 100644
--- a/apps/client/src/widgets/collections/board/card_toolbar.tsx
+++ b/apps/client/src/widgets/collections/board/card_toolbar.tsx
@@ -104,7 +104,8 @@ interface SelectionToolbarProps {
isLeaving: boolean;
/** How many cards are picked out. With none, there is nothing to press. */
count: number;
- onDelete: () => void;
+ /** Deletes the cards picked out, which a read-only board does not offer. */
+ onDelete?: () => void;
/** Opens the context menu for the selection, at the button. */
onMore: (event: MouseEvent) => void;
}
@@ -118,13 +119,13 @@ export function SelectionToolbar({
}: SelectionToolbarProps) {
return (
<Rail host={host} isLeaving={isLeaving}>
- <OverlayControlButton
+ {onDelete && <OverlayControlButton
title={t("board_view.delete-note")}
icon="bx-trash"
className="board-remove-button"
disabled={count === 0}
onClick={onDelete}
- />
+ />}
<OverlayControlButton
title={t("board_view.more-actions")}
icon="bx-dots-vertical-rounded"
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index f07e858705..c03e4ce01a 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -5237,7 +5237,7 @@ describe("Selection mode on mobile", () => {
});
/** A collection note, so the header the mode is switched on from is drawn. */
- async function setup() {
+ async function setup(labels: Record<string, string> = {}) {
disposeShownModals();
const note = buildNote({
@@ -5245,6 +5245,7 @@ describe("Selection mode on mobile", () => {
type: "book",
"#collection": "",
"#viewType": "board",
+ ...labels,
children: [
{ id: "pick1", title: "First", "#status": "To Do" },
{ id: "pick2", title: "Second", "#status": "To Do" },
@@ -5323,6 +5324,16 @@ describe("Selection mode on mobile", () => {
expect(board()?.classList.contains("selecting")).toBe(false);
});
+ it("offers no way to delete what is picked out of a read-only board", async () => {
+ await setup({ "#readOnly": "" });
+ await startSelecting();
+ await tap("pick1");
+
+ expect(selected()).toEqual([ "pick1" ]);
+ expect(railButton("bx-dots-vertical-rounded")).toBeTruthy();
+ expect(container.querySelector(".board-card-toolbar button.bx-trash")).toBeNull();
+ });
+
it("is left out off mobile", async () => {
layout.onMobile = false;
await setup();
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 838fa03132..21146e55b5 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -1604,7 +1604,7 @@ function Board({
host={containerRef.current}
isLeaving={!isSelecting}
count={selectionCount}
- onDelete={() => branches.deleteNotes(
+ onDelete={isReadOnly ? undefined : () => branches.deleteNotes(
api.getCards(selection.keys).map((card) => card.branch.branchId),
false, false)}
onMore={(e) => {