Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(attributes): show a definition by the icon of the field it sets up
Elian Doran7fe9f254d987
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 72a78d28f9..f0e5eb9815 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -661,8 +661,10 @@ export const LABEL_TYPES = [* What a definition can set its field up to hold, the note it can point at instead included. The last* of them is set apart: the others only decide which field the value is typed into, while this one* decides what the attribute is, renaming it and leaving whatever was filled in under the old name.+ *+ * Exported so that hosts listing definitions can show them by the same icon the popup edits them with.*/-const DEFINITION_TYPES: { value: string; title: string; icon: string; startsGroup?: boolean }[] = [+export const DEFINITION_TYPES: { value: string; title: string; icon: string; startsGroup?: boolean }[] = [...LABEL_TYPES,{value: RELATION_DEFINITION_TYPE,diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex 4190b40d5d..df1e5a083f 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -39,12 +39,12 @@}/*- * Both markers are the icon of what the attribute is with a second glyph on its corner, so a definition- * of a label still reads as a label and `cssClass` still reads as the label it is — rather than either- * becoming a kind of its own with an icon to learn.+ * A cog on the corner of the icon for the names Trilium reads for itself: settings of the note rather+ * than a word for it. A second glyph rather than an icon of its own, so `cssClass` still reads as the+ * label it is.*/-.attribute-list-panel .attribute-kind.marker-definition::after,.attribute-list-panel .attribute-kind.marker-system::after {+ content: "\ea6e"; /* lookup code for "cog" in boxicons.css */position: absolute;inset-inline-end: -3px;bottom: -2px;@@ -58,16 +58,6 @@0 0 2px var(--card-background-color, var(--main-background-color));}-/* A definition flags the attribute it names rather than being one. */-.attribute-list-panel .attribute-kind.marker-definition::after {- content: "\eade"; /* lookup code for "flag" in boxicons.css */-}--/* A cog for the names Trilium reads for itself: settings of the note rather than a word for it. */-.attribute-list-panel .attribute-kind.marker-system::after {- content: "\ea6e"; /* lookup code for "cog" in boxicons.css */-}-/* What separates the note's own vocabulary from the names Trilium reads for itself. Quiet: the sort iswhat carries the split, the rule only marks where it falls. */.attribute-list-panel .attribute-rows-divider {diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex 2daa8ef01e..791ba8751c 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -13,7 +13,7 @@ import attributes, { isBuiltinAttribute } from "../../services/attributes";import dialog from "../../services/dialog";import { t } from "../../services/i18n";import server from "../../services/server";-import { AttributeDetail, AttributeDetailOpts, AttrType, getAttrType, LABEL_TYPES } from "../attribute_widgets/attribute_detail";+import { AttributeDetail, AttributeDetailOpts, AttrType, DEFINITION_TYPES, getAttrType, LABEL_TYPES, RELATION_DEFINITION_TYPE } from "../attribute_widgets/attribute_detail";import ActionButton from "../react/ActionButton";import HelpButton from "../react/HelpButton";import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";@@ -311,16 +311,13 @@ function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDeleteonOpen(rowRef.current, e);}}>- {/* The kind is the icon: a definition carries the icon of what it defines, flagged as a- definition, so `label:foo` reads as a label rather than as a label named "label:foo".- A system attribute carries a cog on the same corner — the two never coincide, a- definition being named by whoever writes it. Its own tooltip names it, the marker being- the only thing that says so. */}+ {/* The kind is the icon, and a system attribute carries a cog on its corner: its own tooltip+ names it, the marker being the only thing that says so. */}<span- class={clsx("attribute-kind", isDefinition(attrType) ? "marker-definition" : isSystem && "marker-system")}+ class={clsx("attribute-kind", isSystem && "marker-system")}title={isSystem ? t("attribute_names.system") : undefined}>- <Icon icon={attrType === "relation" || attrType === "relation-definition" ? "bx bx-transfer" : "bx bx-hash"} />+ <Icon icon={getKindIcon(attribute, attrType)} /></span><span class="attribute-name">{getDisplayName(attribute, attrType)}</span>@@ -354,6 +351,31 @@ function AttributeRow({ attribute, active, isSystem, showOwner, onOpen, onDelete);}+/**+ * What the attribute is, as an icon. A definition takes the icon of the field it sets up, the same one+ * the popup offers that field under — it needs no marker of its own, being only ever listed in a card+ * of definitions. Everything else is the icon of a label or of a relation.+ */+function getKindIcon(attribute: Attribute, attrType: AttributeKind) {+ if (isDefinition(attrType)) {+ // A definition written by hand can name a field the popup knows nothing of, leaving the icon of+ // the label it defines to stand for it.+ return getDefinitionType(attribute, attrType)?.icon ?? "bx bx-hash";+ }++ return attrType === "relation" ? "bx bx-transfer" : "bx bx-hash";+}++/** The entry of the popup's definition-type list that the definition is currently set to. */+function getDefinitionType(attribute: Attribute, attrType: AttributeKind) {+ // A relation definition is named after what it points at rather than after a field it fills in.+ const value = attrType === "relation-definition"+ ? RELATION_DEFINITION_TYPE+ : promotedAttributeDefinitionParser.parse(attribute.value ?? "").labelType ?? "text";++ return DEFINITION_TYPES.find((definitionType) => definitionType.value === value);+}+/** A preview of what the attribute holds — the row stands for the attribute, the popup shows it in full. */function AttributeValue({ attribute, attrType }: { attribute: Attribute; attrType: AttributeKind }) {if (attrType === "relation") {