refactor(client): rename to user attributes

This commit is contained in:
Elian Doran 2025-11-15 09:36:18 +02:00
parent 0bc8584c35
commit 455b190a5b
No known key found for this signature in database
3 changed files with 24 additions and 24 deletions

View File

@ -1,4 +1,4 @@
.promoted-attributes { .user-attributes {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 8px;
@ -6,7 +6,7 @@
margin-top: 8px; margin-top: 8px;
} }
.promoted-attributes .promoted-attribute { .user-attributes .user-attribute {
padding: 2px 10px; padding: 2px 10px;
border-radius: 9999px; border-radius: 9999px;
white-space: nowrap; white-space: nowrap;
@ -17,15 +17,15 @@
line-height: 1.2; line-height: 1.2;
} }
.promoted-attributes .promoted-attribute:hover { .user-attributes .user-attribute:hover {
background-color: var(--chip-bg-hover, rgba(0, 0, 0, 0.12)); background-color: var(--chip-bg-hover, rgba(0, 0, 0, 0.12));
border-color: var(--chip-border-hover, rgba(0, 0, 0, 0.22)); border-color: var(--chip-border-hover, rgba(0, 0, 0, 0.22));
} }
.promoted-attributes .promoted-attribute .name { .user-attributes .user-attribute .name {
font-weight: 600; font-weight: 600;
} }
.promoted-attributes .promoted-attribute .value { .user-attributes .user-attribute .value {
opacity: 0.9; opacity: 0.9;
} }

View File

@ -1,16 +1,16 @@
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import FNote from "../../entities/fnote"; import FNote from "../../entities/fnote";
import "./PromotedAttributesDisplay.css"; import "./UserAttributesList.css";
import { useTriliumEvent } from "../react/hooks"; import { useTriliumEvent } from "../react/hooks";
import attributes from "../../services/attributes"; import attributes from "../../services/attributes";
import { DefinitionObject } from "../../services/promoted_attribute_definition_parser"; import { DefinitionObject } from "../../services/promoted_attribute_definition_parser";
import { formatDateTime } from "../../utils/formatters"; import { formatDateTime } from "../../utils/formatters";
import { ComponentChild, ComponentChildren, CSSProperties } from "preact"; import { ComponentChildren, CSSProperties } from "preact";
import Icon from "../react/Icon"; import Icon from "../react/Icon";
import NoteLink from "../react/NoteLink"; import NoteLink from "../react/NoteLink";
import { getReadableTextColor } from "../../services/css_class_manager"; import { getReadableTextColor } from "../../services/css_class_manager";
interface PromotedAttributesDisplayProps { interface UserAttributesListProps {
note: FNote; note: FNote;
ignoredAttributes?: string[]; ignoredAttributes?: string[];
} }
@ -23,39 +23,39 @@ interface AttributeWithDefinitions {
def: DefinitionObject; def: DefinitionObject;
} }
export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) { export default function UserAttributesDisplay({ note, ignoredAttributes }: UserAttributesListProps) {
const promotedDefinitionAttributes = useNoteAttributesWithDefinitions(note, ignoredAttributes); const userAttributes = useNoteAttributesWithDefinitions(note, ignoredAttributes);
return promotedDefinitionAttributes?.length > 0 && ( return userAttributes?.length > 0 && (
<div className="promoted-attributes"> <div className="user-attributes">
{promotedDefinitionAttributes?.map(attr => buildPromotedAttribute(attr))} {userAttributes?.map(attr => buildUserAttribute(attr))}
</div> </div>
) )
} }
function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] { function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
const [ promotedDefinitionAttributes, setPromotedDefinitionAttributes ] = useState<AttributeWithDefinitions[]>(getAttributesWithDefinitions(note, attributesToIgnore)); const [ userAttributes, setUserAttributes ] = useState<AttributeWithDefinitions[]>(getAttributesWithDefinitions(note, attributesToIgnore));
useTriliumEvent("entitiesReloaded", ({ loadResults }) => { useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) { if (loadResults.getAttributeRows().some(attr => attributes.isAffecting(attr, note))) {
setPromotedDefinitionAttributes(getAttributesWithDefinitions(note, attributesToIgnore)); setUserAttributes(getAttributesWithDefinitions(note, attributesToIgnore));
} }
}); });
return promotedDefinitionAttributes; return userAttributes;
} }
function PromotedAttribute({ attr, children, style }: { attr: AttributeWithDefinitions, children: ComponentChildren, style?: CSSProperties }) { function UserAttribute({ attr, children, style }: { attr: AttributeWithDefinitions, children: ComponentChildren, style?: CSSProperties }) {
const className = `${attr.type === "label" ? "label" + " " + attr.def.labelType : "relation"}`; const className = `${attr.type === "label" ? "label" + " " + attr.def.labelType : "relation"}`;
return ( return (
<span key={attr.friendlyName} className={`promoted-attribute type-${className}`} style={style}> <span key={attr.friendlyName} className={`user-attribute type-${className}`} style={style}>
{children} {children}
</span> </span>
) )
} }
function buildPromotedAttribute(attr: AttributeWithDefinitions): ComponentChildren { function buildUserAttribute(attr: AttributeWithDefinitions): ComponentChildren {
const defaultLabel = <><strong>{attr.friendlyName}:</strong>{" "}</>; const defaultLabel = <><strong>{attr.friendlyName}:</strong>{" "}</>;
let content: ComponentChildren; let content: ComponentChildren;
let style: CSSProperties | undefined; let style: CSSProperties | undefined;
@ -102,13 +102,13 @@ function buildPromotedAttribute(attr: AttributeWithDefinitions): ComponentChildr
content = <>{defaultLabel}<NoteLink notePath={attr.value} showNoteIcon /></>; content = <>{defaultLabel}<NoteLink notePath={attr.value} showNoteIcon /></>;
} }
return <PromotedAttribute attr={attr} style={style}>{content}</PromotedAttribute> return <UserAttribute attr={attr} style={style}>{content}</UserAttribute>
} }
function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] { function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {
const promotedDefinitionAttributes = note.getAttributeDefinitions(); const attributeDefintions = note.getAttributeDefinitions();
const result: AttributeWithDefinitions[] = []; const result: AttributeWithDefinitions[] = [];
for (const attr of promotedDefinitionAttributes) { for (const attr of attributeDefintions) {
const def = attr.getDefinition(); const def = attr.getDefinition();
const [ type, name ] = attr.name.split(":", 2); const [ type, name ] = attr.name.split(":", 2);
const friendlyName = def?.promotedAlias || name; const friendlyName = def?.promotedAlias || name;

View File

@ -6,7 +6,7 @@ import { BoardViewContext, TitleEditor } from ".";
import { ContextMenuEvent } from "../../../menus/context_menu"; import { ContextMenuEvent } from "../../../menus/context_menu";
import { openNoteContextMenu } from "./context_menu"; import { openNoteContextMenu } from "./context_menu";
import { t } from "../../../services/i18n"; import { t } from "../../../services/i18n";
import PromotedAttributesDisplay from "../../attribute_widgets/PromotedAttributesDisplay"; import UserAttributesDisplay from "../../attribute_widgets/UserAttributesList";
export const CARD_CLIPBOARD_TYPE = "trilium/board-card"; export const CARD_CLIPBOARD_TYPE = "trilium/board-card";
@ -109,7 +109,7 @@ export default function Card({
title={t("board_view.edit-note-title")} title={t("board_view.edit-note-title")}
onClick={handleEdit} onClick={handleEdit}
/> />
<PromotedAttributesDisplay note={note} ignoredAttributes={[api.statusAttribute]} /> <UserAttributesDisplay note={note} ignoredAttributes={[api.statusAttribute]} />
</> </>
) : ( ) : (
<TitleEditor <TitleEditor