Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): badge and unlock the views that honour #readOnly

Elian Doran2057f9e0bfbd
diff --git a/apps/client/src/components/note_context.spec.ts b/apps/client/src/components/note_context.spec.ts
index 1facdb4ee6..f762b21ac2 100644
--- a/apps/client/src/components/note_context.spec.ts
+++ b/apps/client/src/components/note_context.spec.ts
@@ -32,16 +32,28 @@ describe("NoteContext read-only capability", () => {
});
it("reports a collection read-only only where its view honours the label", async () => {
- // The geo map is the one view that reads #readOnly, so it is the one that can report it:
- // a table wearing the same label is still editable, and saying otherwise would put a
+ // A list or a grid wearing #readOnly is still editable, so reporting it would put a
// read-only badge over a collection that can be changed.
- for (const [ viewType, expected ] of [ [ "geoMap", true ], [ "table", false ] ] as const) {
+ const viewTypes = [
+ [ "board", true ], [ "calendar", true ], [ "dashboard", true ], [ "geoMap", true ],
+ [ "presentation", true ], [ "table", true ], [ "list", false ], [ "grid", false ]
+ ] as const;
+ for (const [ viewType, expected ] of viewTypes) {
const note = buildNote({
"title": viewType, "type": "book", "#viewType": viewType, "#readOnly": ""
});
noteContext.noteId = note.noteId;
- expect(await noteContext.isReadOnly()).toBe(expected);
+ expect(await noteContext.isReadOnly(), viewType).toBe(expected);
+ }
+ });
+
+ it("reports the note maps and render notes read-only under the label", async () => {
+ for (const type of [ "noteMap", "relationMap", "render" ] as const) {
+ const note = buildNote({ "title": type, "type": type, "#readOnly": "" });
+ noteContext.noteId = note.noteId;
+
+ expect(await noteContext.isReadOnly(), type).toBe(true);
}
});
diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.ts
index a5a5449793..e9859d45ac 100644
--- a/apps/client/src/components/note_context.ts
+++ b/apps/client/src/components/note_context.ts
@@ -38,17 +38,25 @@ const READ_ONLY_CAPABLE_TYPES: string[] = [
"mermaid",
"canvas",
"mindMap",
- "spreadsheet"
+ "spreadsheet",
+ "noteMap",
+ "relationMap",
+ "render"
];
/**
* Collection view types that honour `#readOnly`, making a `book` note read-only capable.
*
* Listed by view type rather than by note type because the other views ignore the label: reporting
- * a table or a board as read-only would put a badge over a collection that can still be edited.
+ * a list or a grid as read-only would put a badge over a collection that can still be edited.
*/
const READ_ONLY_CAPABLE_VIEW_TYPES: string[] = [
- "geoMap"
+ "board",
+ "calendar",
+ "dashboard",
+ "geoMap",
+ "presentation",
+ "table"
];
export interface NoteContextDataMap {
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
index d32b7c7448..1e6e573a20 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
@@ -16,7 +16,7 @@ import { pasteNotes } from "../../../services/note_paste";
import type { ShortcutHintDefinition } from "../../../services/shortcut_hints";
import toast from "../../../services/toast";
import { isMobile } from "../../../services/utils";
-import { useContextualShortcutHints, useEditorSpacedUpdate, useNoteLabelBoolean, useTriliumEvent } from "../../react/hooks";
+import { useContextualShortcutHints, useEditorSpacedUpdate, useEffectiveReadOnly, useTriliumEvent } from "../../react/hooks";
import { useZoomPanPinch, useZoomPanWheel } from "../../react/zoom_pan";
import { useZoomPanKeyboard, ZOOM_PAN_HINTS } from "../../react/zoom_pan_keyboard";
import ShortcutHintButton from "../../shortcut_hints/shortcut_hint_button";
@@ -39,8 +39,7 @@ interface RelationMapProps extends TypeWidgetProps {
export default function RelationMap({ note, noteContext, ntxId, onOpenNote }: RelationMapProps) {
const [ data, setData ] = useState<MapData>();
- // The same read-only the note's own bar of actions read while the + stood there.
- const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
+ const isReadOnly = useEffectiveReadOnly(note, noteContext);
const wrapperRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const mapApiRef = useRef<RelationMapApi>(null);