Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): mark a system attribute in the detail popup

Elian Doran7ecc4910b4b3
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 7604e7d97c..1bdb116f52 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -681,7 +681,8 @@
"type_relation_definition": "Relation definition"
},
"attribute_names": {
- "system": "System"
+ "system": "System",
+ "system_description": "Trilium attaches a meaning to this name: its value can change how the note behaves, rather than only describing it."
},
"abstract_bulk_action": {
"remove_this_search_action": "Remove this search action"
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
index 820e9b37ed..4b08313fba 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css
@@ -13,6 +13,16 @@
contain: none;
}
+/*
+ * The same mark the name completion puts against a system name, and so the same colour: quiet, because
+ * it tells the reader whose name this is rather than asking anything of them. Without a `--color` the
+ * outline variant has neither border nor text colour to draw, and reads as a bare word.
+ */
+.attr-detail-system-badge {
+ --color: var(--muted-text-color);
+ flex-shrink: 0;
+}
+
/* The help sits beside the name rather than under it: only a handful of names have any, and the ones
that do run to several lines, which would push the rest of the form out of reach. */
.attr-name-field {
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts
index b58267b8e0..48f093fedc 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.spec.ts
@@ -166,6 +166,22 @@ describe("attribute detail popup naming", () => {
expect(lookupAttributeHelp("label", "somethingInvented")).toBeUndefined();
expect(lookupAttributeHelp(undefined, "customRequestHandler")).toBeUndefined();
});
+
+ it("marks the names Trilium reads for itself, a definition named after one excepted", async () => {
+ const { isSystemAttribute } = await import("./attribute_detail");
+
+ expect(isSystemAttribute("label", "archived")).toBe(true);
+ expect(isSystemAttribute("relation", "template")).toBe(true);
+ // Most system attributes have no help entry, which is what the mark is for.
+ expect(isSystemAttribute("label", "dateNote")).toBe(true);
+ expect(isSystemAttribute("label", "somethingInvented")).toBe(false);
+
+ // A definition sets up a field named after a system attribute without being one, and the popup
+ // edits it under the bare name -- so the name alone would wrongly say yes.
+ expect(isSystemAttribute("label-definition", "archived")).toBe(false);
+ expect(isSystemAttribute("relation-definition", "template")).toBe(false);
+ expect(isSystemAttribute(undefined, "archived")).toBe(false);
+ });
});
const NO_OFFSET = { top: 0, left: 0 };
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index ac8363a02d..1c7212a2cb 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -372,6 +372,7 @@ function AttributeForm({ opts, attrType: initialAttrType, currentNoteId, onCance
// characters being composed: https://github.com/zadam/trilium/pull/3812
const isComposing = useRef(false);
const nameHelp = lookupAttributeHelp(attrType, name);
+ const isSystem = isSystemAttribute(attrType, name);
useEffect(() => {
if (focus === "name") {
@@ -435,6 +436,20 @@ function AttributeForm({ opts, attrType: initialAttrType, currentNoteId, onCance
<div class="attr-detail-header">
<h5 class="attr-detail-title">{attrType ? ATTR_TITLES[attrType] : ""}</h5>
+ {/* Beside the related-notes badge rather than by the name field, for the same reason: a
+ mark that comes and going as the name is typed would resize the popup under the
+ pointer. The help button by the field explains what a name does; this says the name
+ is Trilium's at all, which most system attributes have no explanation to say for
+ them. */}
+ {isSystem && (
+ <Badge
+ outline
+ className="attr-detail-system-badge"
+ text={t("attribute_names.system")}
+ tooltip={t("attribute_names.system_description")}
+ />
+ )}
+
{/* Sits in the header, and not in a section of its own, so that the popup keeps the size it
was positioned at: the lookup behind it is asynchronous and re-runs as the attribute is
edited, and a block coming and going below the form would resize the popup under the
@@ -684,6 +699,17 @@ function AttributeNameSuggestion({ type, name }: { type: "label" | "relation"; n
);
}
+/**
+ * Whether the attribute being edited is one Trilium reads for itself, and so is marked as such.
+ *
+ * A definition is excluded on purpose: `label:archived` sets up a field named after a system attribute
+ * without being one, and the popup edits it under the stripped name — so the name alone would answer
+ * yes where {@link isBuiltinAttribute}, which sees the whole name, answers no.
+ */
+export function isSystemAttribute(attrType: AttrType, name: string) {
+ return (attrType === "label" || attrType === "relation") && isBuiltinAttribute(attrType, name);
+}
+
/** Normalised so that the shorthand entries, which are the description alone, read like the rest. */
export function lookupAttributeHelp(attrType: AttrType, name: string): AttrHelpEntry | undefined {
const entry = attrType ? ATTR_HELP[attrType]?.[name] : undefined;