Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): show shared dashboards with the app's dashboard, read-only

Elian Doran8e9e53256cdc
diff --git a/apps/client/src/widgets/collections/dashboard/context_menu.ts b/apps/client/src/widgets/collections/dashboard/context_menu.ts
index e019c651d6..0f03262166 100644
--- a/apps/client/src/widgets/collections/dashboard/context_menu.ts
+++ b/apps/client/src/widgets/collections/dashboard/context_menu.ts
@@ -4,21 +4,23 @@ import link_context_menu from "../../../menus/link_context_menu";
import branches from "../../../services/branches";
import { t } from "../../../services/i18n";
-export default function openWidgetContextMenu(notePath: string, branchId: string, e: ContextMenuEvent, { onRefresh }: {
+export default function openWidgetContextMenu(notePath: string, branchId: string, e: ContextMenuEvent, { isReadOnly, onRefresh }: {
+ /** Whether the dashboard is read-only, which leaves out removing the widget. */
+ isReadOnly: boolean;
/** When provided (i.e. the widget is a render note or web view), adds a "Refresh" item that re-renders it. */
onRefresh?: () => void;
}) {
- const items: MenuItem<CommandNames>[] = [
- ...link_context_menu.getItems(e),
- { kind: "separator" }
- ];
+ const items: MenuItem<CommandNames>[] = [ ...link_context_menu.getItems(e) ];
if (onRefresh) {
- items.push({ title: t("dashboard_view.refresh-widget"), uiIcon: "bx bx-refresh", handler: () => onRefresh() });
items.push({ kind: "separator" });
+ items.push({ title: t("dashboard_view.refresh-widget"), uiIcon: "bx bx-refresh", handler: () => onRefresh() });
}
- items.push({ title: t("dashboard_view.remove-widget"), uiIcon: "bx bx-trash", handler: () => branches.deleteNotes([ branchId ], false, false) });
+ if (!isReadOnly) {
+ items.push({ kind: "separator" });
+ items.push({ title: t("dashboard_view.remove-widget"), uiIcon: "bx bx-trash", handler: () => branches.deleteNotes([ branchId ], false, false) });
+ }
contextMenu.show({
x: e.pageX,
diff --git a/apps/client/src/widgets/collections/dashboard/index.tsx b/apps/client/src/widgets/collections/dashboard/index.tsx
index d1d22c2374..1166ece597 100644
--- a/apps/client/src/widgets/collections/dashboard/index.tsx
+++ b/apps/client/src/widgets/collections/dashboard/index.tsx
@@ -13,7 +13,7 @@ import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
import CollectionProperties from "../../note_bars/CollectionProperties";
import ActionButton from "../../react/ActionButton";
-import { useCollectionTreeDrag, useElementSize, useNoteLabelBoolean, useSpacedUpdate } from "../../react/hooks";
+import { useCollectionTreeDrag, useEffectiveReadOnly, useElementSize, useNoteContext, useNoteLabelBoolean, useSpacedUpdate } from "../../react/hooks";
import Icon from "../../react/Icon";
import NoteLink from "../../react/NoteLink";
import { ViewModeProps } from "../interface";
@@ -33,6 +33,8 @@ const SINGLE_COLUMN_BREAKPOINT = 768;
export default function DashboardView({ note, noteIds, viewConfig, saveConfig, highlightedTokens, showTextRepresentation }: ViewModeProps<DashboardViewConfig>) {
const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");
+ const { noteContext } = useNoteContext();
+ const isReadOnly = useEffectiveReadOnly(note, noteContext);
const containerRef = useRef<HTMLDivElement>(null);
// The grid only spans its content height, so drops land on the taller scroll container instead.
const scrollContainerRef = useRef<HTMLDivElement>(null);
@@ -40,8 +42,8 @@ export default function DashboardView({ note, noteIds, viewConfig, saveConfig, h
const notes = useDashboardNotes(noteIds);
const isCollapsed = useIsCollapsed(containerRef);
- const dropPositionsRef = useNoteTreeDropToDashboard(note, includeArchived, scrollContainerRef, containerRef, gridRef);
- useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, gridRef, dropPositionsRef, isCollapsed });
+ const dropPositionsRef = useNoteTreeDropToDashboard(note, includeArchived, isReadOnly, scrollContainerRef, containerRef, gridRef);
+ useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, gridRef, dropPositionsRef, isStatic: isCollapsed || isReadOnly });
return (
<div className="dashboard-view">
@@ -55,6 +57,7 @@ export default function DashboardView({ note, noteIds, viewConfig, saveConfig, h
parentNote={note}
highlightedTokens={highlightedTokens}
includeArchived={includeArchived}
+ isReadOnly={isReadOnly}
showTextRepresentation={showTextRepresentation}
/>
))}
@@ -179,7 +182,7 @@ function useDashboardLayoutPersistence({ note, viewConfig, saveConfig, gridRef,
/** Owns the gridstack instance and keeps it reconciled with the Preact-rendered widgets: Preact owns
* the element lifecycle (keyed by noteId), gridstack owns the geometry. Saving and restoring the
* geometry is delegated to {@link useDashboardLayoutPersistence}. */
-function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, gridRef, dropPositionsRef, isCollapsed }: {
+function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, gridRef, dropPositionsRef, isStatic }: {
note: FNote;
notes: FNote[];
viewConfig: DashboardViewConfig | undefined;
@@ -187,7 +190,8 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
containerRef: RefObject<HTMLDivElement | null>;
gridRef: RefObject<GridStack | null>;
dropPositionsRef: RefObject<WidgetLayouts>;
- isCollapsed: boolean;
+ /** Whether the widgets can be neither dragged nor resized: on a single column or a read-only dashboard. */
+ isStatic: boolean;
}) {
const { persistLayout, savedWidgetsRef } = useDashboardLayoutPersistence({ note, viewConfig, saveConfig, gridRef, containerRef });
@@ -201,6 +205,7 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
cellHeight: CELL_HEIGHT,
margin: GRID_MARGIN,
mode: "float",
+ staticGrid: isStatic,
handle: ".dashboard-widget-header",
columnOpts: {
// Collapse to a vertical stack when the dashboard itself gets narrow,
@@ -222,8 +227,8 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
}, [ note ]);
useEffect(() => {
- gridRef.current?.setStatic(isCollapsed);
- }, [ isCollapsed ]);
+ gridRef.current?.setStatic(isStatic);
+ }, [ isStatic ]);
// Reconcile the rendered children with the gridstack engine.
useLayoutEffect(() => {
@@ -274,11 +279,11 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
* the dashboard and the first one is positioned under the cursor. Returns a ref holding the drop
* positions of the freshly cloned notes, which the reconcile effect consumes (once) when it
* promotes them to grid widgets — kept out of savedWidgetsRef so persistLayout still saves them. */
-function useNoteTreeDropToDashboard(note: FNote, includeArchived: boolean, dropAreaRef: RefObject<HTMLDivElement | null>, gridContainerRef: RefObject<HTMLDivElement | null>, gridRef: RefObject<GridStack | null>) {
+function useNoteTreeDropToDashboard(note: FNote, includeArchived: boolean, isReadOnly: boolean, dropAreaRef: RefObject<HTMLDivElement | null>, gridContainerRef: RefObject<HTMLDivElement | null>, gridRef: RefObject<GridStack | null>) {
const dropPositionsRef = useRef<WidgetLayouts>({});
useCollectionTreeDrag(dropAreaRef, {
- dragEnabled: true,
+ dragEnabled: !isReadOnly,
includeArchived,
async callback(treeData, e) {
const grid = gridRef.current;
@@ -316,10 +321,11 @@ interface DashboardWidgetProps {
parentNote: FNote;
highlightedTokens: (string | HighlightedTokenInfo)[] | null | undefined;
includeArchived: boolean;
+ isReadOnly: boolean;
showTextRepresentation?: boolean;
}
-function DashboardWidget({ note, parentNote, highlightedTokens, includeArchived, showTextRepresentation }: DashboardWidgetProps) {
+function DashboardWidget({ note, parentNote, highlightedTokens, includeArchived, isReadOnly, showTextRepresentation }: DashboardWidgetProps) {
const notePath = getNotePath(parentNote, note);
// Bumping the key remounts NoteContent, which re-runs the render — meaningful for render notes
// (re-runs the script) and web views (reloads the embedded page).
@@ -348,6 +354,7 @@ function DashboardWidget({ note, parentNote, highlightedTokens, includeArchived,
const branchId = note.parentToBranch[parentNote.noteId];
if (!branchId) return;
openWidgetContextMenu(notePath, branchId, e, {
+ isReadOnly,
onRefresh: canRefresh ? () => setRefreshKey((key) => key + 1) : undefined
});
}} />
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
index 3e737407b2..0ee7350707 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing.html
@@ -129,8 +129,9 @@ class="image">
</td>
<td>
<ul>
- <li>The other view types (such as the calendar, the table or the board) are
- not supported, and the child notes are shown as cards instead.</li>
+ <li>The calendar, table, board, geo map and dashboard view types are shown
+ as in the app, but read-only. The presentation view type is not supported,
+ and its child notes are shown as cards instead.</li>
</ul>
</td>
</tr>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Dashboard.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Dashboard.html
index da3aa57e79..2b36b88dd2 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Dashboard.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Dashboard.html
@@ -56,4 +56,9 @@
<li>From the&nbsp;<a class="reference-link" href="#root/_help_oPVyFC7WL2Lp">Note Tree</a>,
drag an existing note onto the dashboard and it will be placed there. This
will <a href="#root/_help_IakOLONlIfGI">clone</a> the note into the collection.</li>
-</ul>
\ No newline at end of file
+</ul>
+<h2>Read-only dashboards</h2>
+<p>On a <a href="#root/_help_CoFPLs3dRlXc">read-only</a> dashboard, the widgets
+ can't be moved or resized, notes dragged from the <a class="reference-link"
+ href="#root/_help_oPVyFC7WL2Lp">Note Tree</a> aren't added, and the menu
+ of a widget no longer offers to remove it.</p>
\ No newline at end of file
diff --git a/docs/User Guide/User Guide/Advanced Usage/Sharing.md b/docs/User Guide/User Guide/Advanced Usage/Sharing.md
index ef8f0ad381..c4488b82fd 100644
--- a/docs/User Guide/User Guide/Advanced Usage/Sharing.md
+++ b/docs/User Guide/User Guide/Advanced Usage/Sharing.md
@@ -65,7 +65,7 @@ Trilium allows you to share selected notes as **publicly accessible** read-only
<tr>
<th><a class="reference-link" href="../Collections.md">Collections</a></th>
<td><ul><li>The child notes are shown as cards, or as a list when the view type of the collection is <em>List</em>. Each shows its icon and the start of its text (or its <code>#shareDescription</code>), or, for a child note without text, links to its own first child notes.</li></ul></td>
- <td><ul><li>The other view types (such as the calendar, the table or the board) are not supported, and the child notes are shown as cards instead.</li></ul></td>
+ <td><ul><li>The calendar, table, board, geo map and dashboard view types are shown as in the app, but read-only. The presentation view type is not supported, and its child notes are shown as cards instead.</li></ul></td>
</tr>
<tr>
<th><a class="reference-link" href="../Note%20Types/Mermaid%20Diagrams.md">Mermaid Diagrams</a></th>
diff --git a/docs/User Guide/User Guide/Collections/Dashboard.md b/docs/User Guide/User Guide/Collections/Dashboard.md
index e1a61fed2a..b101ad7b9c 100644
--- a/docs/User Guide/User Guide/Collections/Dashboard.md
+++ b/docs/User Guide/User Guide/Collections/Dashboard.md
@@ -31,4 +31,8 @@ The dashboard uses the same rendering mechanism as the <a class="reference-link
There are two ways to add widgets to a dashboard:
* Create a child note of any type, the dashboard will automatically pick it up and add it onto the grid.
-* From the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tree.md">Note Tree</a>, drag an existing note onto the dashboard and it will be placed there. This will [clone](../Basic%20Concepts%20and%20Features/Notes/Cloning%20Notes.md) the note into the collection.
\ No newline at end of file
+* From the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tree.md">Note Tree</a>, drag an existing note onto the dashboard and it will be placed there. This will [clone](../Basic%20Concepts%20and%20Features/Notes/Cloning%20Notes.md) the note into the collection.
+
+## Read-only dashboards
+
+On a [read-only](../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md) dashboard, the widgets can't be moved or resized, notes dragged from the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20Tree.md">Note Tree</a> aren't added, and the menu of a widget no longer offers to remove it.
\ No newline at end of file
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index 7816cfb1c6..debd653ecf 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -964,7 +964,7 @@ function hostInAppView(result: Result, note: SNote, container: string) {
}
/** The view types of the collections the share theme shows with the app's own view. */
-const HOSTED_VIEW_TYPES = new Set([ "board", "calendar", "geoMap", "table" ]);
+const HOSTED_VIEW_TYPES = new Set([ "board", "calendar", "dashboard", "geoMap", "table" ]);
/**
* The options the app's views read to draw a note as the app does, which a shared page receives. Only