Skip to content

Build your personal knowledge base with Trilium Notes

feat(status_bar): display system links in dev mode

Elian Doran79d639108b75
diff --git a/apps/client/src/widgets/layout/StatusBar.css b/apps/client/src/widgets/layout/StatusBar.css
index c8d01c83be..f0a10ab8b8 100644
--- a/apps/client/src/widgets/layout/StatusBar.css
+++ b/apps/client/src/widgets/layout/StatusBar.css
@@ -87,7 +87,8 @@
font-weight: 600;
}
- .inherited-attributes-widget {
+ .inherited-attributes-widget,
+ .auto-link-attributes-widget {
display: inline;
> div {
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 077c59ef4f..50657867cd 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -26,6 +26,7 @@ import LinkButton from "../react/LinkButton";
import { ParentComponent } from "../react/react_utils";
import { ContentLanguagesModal, NoteTypeCodeNoteList, NoteTypeOptionsModal, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/components/AttributeEditor";
+import AutoLinkAttributesTab from "../ribbon/AutoLinkAttributesTab";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
@@ -401,6 +402,11 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShown
<span class="attributes-panel-label">{t("inherited_attribute_list.title")}</span>
<InheritedAttributesTab {...context} emptyListString="inherited_attribute_list.none" />
+ {glob.isDev && <div>
+ <span class="attributes-panel-label">{t("auto_link_attribute_list.title")}</span>
+ <AutoLinkAttributesTab {...context} />
+ </div>}
+
<AttributeEditor
{...context}
api={api}
diff --git a/apps/client/src/widgets/ribbon/AutoLinkAttributesTab.tsx b/apps/client/src/widgets/ribbon/AutoLinkAttributesTab.tsx
new file mode 100644
index 0000000000..132a55a8a3
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/AutoLinkAttributesTab.tsx
@@ -0,0 +1,65 @@
+import { useEffect, useState } from "preact/hooks";
+
+import FAttribute from "../../entities/fattribute";
+import attributes from "../../services/attributes";
+import froca from "../../services/froca";
+import { useTriliumEvent } from "../react/hooks";
+import { joinElements } from "../react/react_utils";
+import { TabContext } from "./ribbon-interface";
+
+type AutoLinkAttributesTabArgs = Pick<TabContext, "note" | "componentId">;
+
+export default function AutoLinkAttributesTab({ note, componentId }: AutoLinkAttributesTabArgs) {
+ const [autoLinkAttributes, setAutoLinkAttributes] = useState<FAttribute[]>();
+
+ function refresh() {
+ if (!note) return;
+ const attrs = note.getAttributes().filter((attr) => attr.isAutoLink && attr.noteId === note.noteId);
+ setAutoLinkAttributes(attrs);
+ }
+
+ useEffect(refresh, [note]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ if (loadResults.getAttributeRows(componentId).find((attr) => attributes.isAffecting(attr, note))) {
+ refresh();
+ }
+ });
+
+ if (!autoLinkAttributes?.length) {
+ return null;
+ }
+
+ return (
+ <div className="auto-link-attributes-widget">
+ <div className="auto-link-attributes-container selectable-text">
+ {joinElements(autoLinkAttributes.map((attribute) => (
+ <AutoLinkAttribute key={attribute.attributeId} attribute={attribute} />
+ )), " ")}
+ </div>
+ </div>
+ );
+}
+
+function AutoLinkAttribute({ attribute }: { attribute: FAttribute }) {
+ const [html, setHtml] = useState<string>("");
+
+ useEffect(() => {
+ renderAutoLink(attribute).then(setHtml);
+ }, [attribute]);
+
+ return <span dangerouslySetInnerHTML={{ __html: html }} />;
+}
+
+async function renderAutoLink(attribute: FAttribute) {
+ const note = await froca.getNote(attribute.value);
+ if (!note) return "";
+
+ const link = `<a href="#root/${attribute.value}" class="reference-link">${escapeHtml(note.title)}</a>`;
+ return `~${escapeHtml(attribute.name)}=${link}`;
+}
+
+function escapeHtml(text: string) {
+ const el = document.createElement("span");
+ el.textContent = text;
+ return el.innerHTML;
+}