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
client/content manager: use badges
Adorian Doran8bfe26368536
diff --git a/apps/client/src/services/content_manager.spec.ts b/apps/client/src/services/content_manager.spec.tsindex 36aef479d5..5094f7d6e4 100644--- a/apps/client/src/services/content_manager.spec.ts+++ b/apps/client/src/services/content_manager.spec.ts@@ -246,8 +246,9 @@ describe("resolveProperties", () => {const script = buildNote({ title: "S", "#run": "daily", "#runOnInstance": "main" });expect(resolveProperties(script, categoryById("backendScripts"))).toEqual([- { titleKey: "content_manager.property_trigger", values: [ { titleKey: "content_manager.trigger_daily" } ] },- { titleKey: "content_manager.property_instance", values: [ { text: "main" } ] }+ // The trigger is one of a fixed set, so it is badged; the instance name is free-form.+ { titleKey: "content_manager.property_trigger", badge: true, values: [ { titleKey: "content_manager.trigger_daily" } ] },+ { titleKey: "content_manager.property_instance", badge: undefined, values: [ { text: "main" } ] }]);// The bare `workspaceTemplate` condition is a presence test, so an unrestricted template@@ -256,7 +257,7 @@ describe("resolveProperties", () => {const plain = buildNote({ title: "P", "#template": "" });expect(resolveProperties(workspace, categoryById("templates"))).toEqual([- { titleKey: "content_manager.property_scope", values: [ { titleKey: "content_manager.scope_workspace" } ] }+ { titleKey: "content_manager.property_scope", badge: true, values: [ { titleKey: "content_manager.scope_workspace" } ] }]);expect(resolveProperties(plain, categoryById("templates"))).toEqual([]);});@@ -270,6 +271,7 @@ describe("resolveProperties", () => {expect(resolveProperties(note, categoryById("eventHandlers"))).toEqual([ {titleKey: "content_manager.property_event",+ badge: true,values: [{ titleKey: "content_manager.event_note_creation" },{ titleKey: "content_manager.event_branch_deletion" }@@ -296,8 +298,9 @@ describe("resolveProperties", () => {const note = buildNote({ title: "API", "#customRequestHandler": "api/my-handler/([a-z]+)" });expect(resolveProperties(note, categoryById("endpoints"))).toEqual([- { titleKey: "content_manager.property_kind", values: [ { titleKey: "content_manager.endpoint_request_handler" } ] },- { titleKey: "content_manager.property_path", values: [ { text: "api/my-handler/([a-z]+)" } ] }+ { titleKey: "content_manager.property_kind", badge: true, values: [ { titleKey: "content_manager.endpoint_request_handler" } ] },+ // A path pattern is free-form, so it stays plain text rather than becoming a badge.+ { titleKey: "content_manager.property_path", badge: undefined, values: [ { text: "api/my-handler/([a-z]+)" } ] }]);});diff --git a/apps/client/src/services/content_manager.ts b/apps/client/src/services/content_manager.tsindex d810db83e4..94652c14da 100644--- a/apps/client/src/services/content_manager.ts+++ b/apps/client/src/services/content_manager.ts@@ -36,6 +36,12 @@ export interface ContentProperty {/** Translation key for the property name. */titleKey: string;values: ContentPropertyValue[];+ /**+ * Renders each value as a badge, with the property name as its tooltip. Suits a small fixed set+ * of values a row can be scanned for; free-form values (a path, an icon prefix) read better as+ * plain text, where the property name gives them meaning.+ */+ badge?: boolean;}export interface ContentCategory {@@ -80,6 +86,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [filter: "#template OR #disabled:template",properties: [ {titleKey: "content_manager.property_scope",+ badge: true,// A bare condition tests only that the label is present.values: [ { titleKey: "content_manager.scope_workspace", condition: { label: "workspaceTemplate" } } ]} ]@@ -104,6 +111,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [filter: "#appTheme OR #disabled:appTheme",properties: [ {titleKey: "content_manager.property_base_theme",+ badge: true,values: [ { valueOfLabel: "appThemeBase" } ]} ]},@@ -119,6 +127,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [+ " OR #disabled:shareRaw OR ~disabled:shareJs OR ~disabled:shareHtml OR ~disabled:shareTemplate",properties: [ {titleKey: "content_manager.property_kind",+ badge: true,values: [{ titleKey: "content_manager.share_raw", condition: { label: "shareRaw" } },{ titleKey: "content_manager.share_js", condition: { relation: "shareJs" } },@@ -134,6 +143,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [+ " OR #disabled:run = frontendStartup OR #disabled:run = mobileStartup",properties: [ {titleKey: "content_manager.property_trigger",+ badge: true,values: [{ titleKey: "content_manager.trigger_frontend_startup", condition: { label: "run", is: "frontendStartup" } },{ titleKey: "content_manager.trigger_mobile_startup", condition: { label: "run", is: "mobileStartup" } }@@ -166,6 +176,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [filter: EVENT_HANDLERS.flatMap(({ relation }) => [ `~${relation}`, `~disabled:${relation}` ]).join(" OR "),properties: [ {titleKey: "content_manager.property_event",+ badge: true,values: EVENT_HANDLERS.map(({ relation, titleKey }) => ({ titleKey, condition: { relation } }))} ]},@@ -177,6 +188,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [properties: [{titleKey: "content_manager.property_kind",+ badge: true,values: [{ titleKey: "content_manager.endpoint_request_handler", condition: { label: "customRequestHandler" } },{ titleKey: "content_manager.endpoint_resource_provider", condition: { label: "customResourceProvider" } }@@ -200,6 +212,7 @@ export const CONTENT_CATEGORIES: ContentCategory[] = [properties: [{titleKey: "content_manager.property_trigger",+ badge: true,values: [{ titleKey: "content_manager.trigger_backend_startup", condition: { label: "run", is: "backendStartup" } },{ titleKey: "content_manager.trigger_hourly", condition: { label: "run", is: "hourly" } },@@ -280,6 +293,7 @@ export interface ResolvedPropertyValue {export interface ResolvedProperty {titleKey: string;values: ResolvedPropertyValue[];+ badge?: boolean;}/**@@ -310,7 +324,7 @@ export function resolveProperties(note: FNote, category: ContentCategory): Resol}if (values.length) {- resolved.push({ titleKey: property.titleKey, values });+ resolved.push({ titleKey: property.titleKey, values, badge: property.badge });}}diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.css b/apps/client/src/widgets/type_widgets/options/content_manager.cssindex d87b535b14..9f77f28938 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager.css+++ b/apps/client/src/widgets/type_widgets/options/content_manager.css@@ -21,14 +21,26 @@white-space: nowrap;}+/* Values sit on the item's own line, so a row stays one line tall. */.content-manager-properties {- font-size: .75em;- opacity: .75;+ display: flex;+ flex-wrap: wrap;+ justify-content: flex-end;+ align-items: center;+ gap: 0.35em;}-/* Separate consecutive properties: "Trigger: hourly; Mode: authentic". */-.content-manager-property:not(:last-child)::after {- content: "; ";+/* `Badge` paints its background from `--color`. The selector repeats `.ext-badge` so the text colour+ outranks the component's own `color: white`, which is unreadable on this light fill. */+.ext-badge.content-manager-badge {+ --color: var(--more-accented-background-color);+ color: var(--main-text-color);+}++/* Free-form values (a path, an icon prefix) stay plain text, where the name gives them meaning. */+.content-manager-property {+ font-size: .75em;+ opacity: .75;}.content-manager-loading {diff --git a/apps/client/src/widgets/type_widgets/options/content_manager.tsx b/apps/client/src/widgets/type_widgets/options/content_manager.tsxindex d7f3687a74..198053c8e7 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager.tsx@@ -22,6 +22,7 @@ import debounce from "../../../services/debounce";import { t } from "../../../services/i18n";import { ListView, type ListViewOptions } from "../../collections/legacy/ListOrGridView";import ActionButton from "../../react/ActionButton";+import { Badge } from "../../react/Badge";import Button, { ButtonGroup } from "../../react/Button";import FormTextBox from "../../react/FormTextBox";import FormToggle from "../../react/FormToggle";@@ -87,7 +88,12 @@ function ContentItemMenu({ note }: { note: FNote }) {type ContentItemCommand = "openNoteInNewTab" | "deleteNote";-/** Renders a note's extra detail, e.g. `Trigger: backend startup, hourly; Mode: authentic`. */+/**+ * A note's extra detail as badges — `Hourly`, `main` — one per value.+ *+ * The value is shown rather than the property name so a row stays scannable at a glance; the name+ * ("Trigger", "Instance") is the badge's tooltip, since it is only needed once to learn the pattern.+ */function ContentProperties({ note, category }: { note: FNote, category: ContentCategory }) {const properties = resolveProperties(note, category);@@ -95,13 +101,22 @@ function ContentProperties({ note, category }: { note: FNote, category: ContentCreturn (<span className="content-manager-properties">- {properties.map(({ titleKey, values }) => (- <span key={titleKey} className="content-manager-property">- <strong>{t(titleKey)}:</strong>- {" "}- {values.map((value) => value.titleKey ? t(value.titleKey) : value.text).join(", ")}- </span>- ))}+ {properties.flatMap(({ titleKey, values, badge }) => badge+ ? values.map((value, index) => (+ <Badge+ key={`${titleKey}-${index}`}+ className="content-manager-badge"+ text={value.titleKey ? t(value.titleKey) : value.text}+ tooltip={t(titleKey)}+ />+ ))+ : (+ <span key={titleKey} className="content-manager-property">+ <strong>{t(titleKey)}:</strong>+ {" "}+ {values.map((value) => value.titleKey ? t(value.titleKey) : value.text).join(", ")}+ </span>+ ))}</span>);}