Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): keep the toolbar on a read-only note, marked with a lock

Elian Doranaaf424085903
diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.css
index 4d3694e05f..c1e298a8c0 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.css
+++ b/apps/client/src/widgets/sidebar/AttributeList.css
@@ -127,6 +127,16 @@
white-space: nowrap;
}
+ .attribute-toolbar-read-only {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding-inline: 4px;
+ color: var(--muted-text-color);
+ font-size: 0.85em;
+ white-space: nowrap;
+ }
+
.attribute-toolbar-actions {
display: flex;
align-items: center;
diff --git a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
index d78f2566e2..770b745c8c 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx
@@ -123,12 +123,13 @@ describe("AttributeList on a phone", () => {
expect(url).toBe("notes/phone-bare/attributes");
expect(saved).toEqual([ { type: "label", name: "author", value: "Elian", isInheritable: false } ]);
- // A note that cannot be edited has nothing to paste or add, so it has no toolbar.
+ // A note that cannot be edited has nothing to paste or add, so the toolbar says it is read-only.
render(null, container);
const locked = buildNote({ id: "phone-locked", title: "Locked" });
locked.isContentWritable = false;
renderPanel(locked);
- expect(toolbar()).toBeNull();
+ expect(iconsIn(toolbar())).toEqual([ "bx bx-lock-alt" ]);
+ expect(toolbar()?.querySelector(".attribute-toolbar-read-only")).not.toBeNull();
});
it("still picks rows out, by the press held down, and says what can be done with them", () => {
diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
index a87c157d67..ec607442c6 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
@@ -1160,10 +1160,16 @@ describe("AttributeList", () => {
writeAttributes(null, [ plain("tag") ]);
renderPanel(note);
+ // With nothing selected, the toolbar says the note is read-only and offers no paste or add.
+ expect(container.querySelector(".attribute-toolbar .attribute-toolbar-read-only")).not.toBeNull();
+ expect(toolbarIcons()).toEqual([]);
+
// The toolbar offers clearing and copying only: no paste, delete or add.
checkbox(0).click();
checkbox(1).click();
expect(toolbarIcons()).toEqual([ "bx bx-x", "bx bx-copy" ]);
+ // The count takes the notice's place while rows are selected.
+ expect(container.querySelector(".attribute-toolbar-read-only")).toBeNull();
// So does the row menu, over rows the note owns.
rightPress(0);
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 045114f620..fdd2dd27aa 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -737,9 +737,10 @@ export default function AttributeList() {
const heldAttributes = getHeldAttributes();
// Above the cards rather than in one, since a selection can span several cards.
- const toolbar = note && (canEdit || isSelecting) && (
+ const toolbar = note && (
<AttributeToolbar
selectionCount={selection.size}
+ readOnly={!canEdit}
held={canEdit ? heldAttributes : []}
canAdd={canEdit}
canDelete={canEdit && selectedAttributes().every((candidate) => owned.current.includes(candidate))}
@@ -1580,15 +1581,18 @@ function getClipboardValue(attribute: Attribute) {
}
/**
- * The panel's toolbar, above the cards. It always holds pasting and adding; while rows are selected, it
- * also holds the selection's count and actions. Its height stays the same either way, so starting or
+ * The panel's toolbar, above the cards. It holds pasting and adding; while rows are selected, it also
+ * holds the selection's count and actions. Its height stays the same either way, so starting or
* ending a selection moves nothing.
*
* Paste and add stay at the trailing end in both states, and the selection's actions go before them.
- * Deleting is offered only when every selected row is the note's own.
+ * Deleting is offered only when every selected row is the note's own. On a note that cannot be edited, a
+ * lock and "Read-only" take the place of the paste and add buttons.
*/
-function AttributeToolbar({ selectionCount, held, canAdd, canDelete, onAdd, onCopy, onPaste, onClearClipboard, onDelete, onClearSelection }: {
+function AttributeToolbar({ selectionCount, readOnly, held, canAdd, canDelete, onAdd, onCopy, onPaste, onClearClipboard, onDelete, onClearSelection }: {
selectionCount: number;
+ /** Shows a read-only notice in place of the add and paste buttons, which a read-only note has none of. */
+ readOnly: boolean;
/** What there is to paste; empty when nothing is held or the note cannot be edited. */
held: Attribute[];
canAdd: boolean;
@@ -1617,6 +1621,13 @@ function AttributeToolbar({ selectionCount, held, canAdd, canDelete, onAdd, onCo
</>
)}
+ {!isSelecting && readOnly && (
+ <span class="attribute-toolbar-read-only" title={t("breadcrumb_badges.read_only_locked_description")}>
+ <Icon icon="bx bx-lock-alt" />
+ {t("breadcrumb_badges.read_only_locked")}
+ </span>
+ )}
+
<div class="attribute-toolbar-actions">
{isSelecting && (
<ActionButton