mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 18:08:56 +01:00
refactor(board): use hook for obtaining the list of attributes
This commit is contained in:
parent
e006afc5a2
commit
b11b3ff67f
@ -6,22 +6,23 @@ interface PromotedAttributesDisplayProps {
|
|||||||
ignoredAttributes?: string[];
|
ignoredAttributes?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) {
|
interface AttributeWithDefinitions {
|
||||||
const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes();
|
name: string;
|
||||||
|
type: string;
|
||||||
|
friendlyName: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
return promotedDefinitionAttributes.length > 0 && (
|
export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) {
|
||||||
|
const promotedDefinitionAttributes = useNoteAttributesWithDefinitions(note);
|
||||||
|
return promotedDefinitionAttributes?.length > 0 && (
|
||||||
<div className="promoted-attributes">
|
<div className="promoted-attributes">
|
||||||
{promotedDefinitionAttributes.map((attr) => {
|
{promotedDefinitionAttributes?.map((attr) => {
|
||||||
const def = attr.getDefinition();
|
if (ignoredAttributes && ignoredAttributes.includes(attr.name)) return null;
|
||||||
const [ type, name ] = attr.name.split(":", 2);
|
|
||||||
const value = note.getLabelValue(name);
|
|
||||||
const friendlyName = def?.promotedAlias ?? name;
|
|
||||||
if (!value) return null;
|
|
||||||
if (ignoredAttributes && ignoredAttributes.includes(name)) return null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span key={attr.name} className="promoted-attribute">
|
<span key={attr.friendlyName} className="promoted-attribute">
|
||||||
<strong>{friendlyName}:</strong> {value}
|
<strong>{attr.friendlyName}:</strong> {attr.value}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -30,3 +31,19 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P
|
|||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useNoteAttributesWithDefinitions(note: FNote) {
|
||||||
|
const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes();
|
||||||
|
const result: AttributeWithDefinitions[] = [];
|
||||||
|
|
||||||
|
for (const attr of promotedDefinitionAttributes) {
|
||||||
|
const def = attr.getDefinition();
|
||||||
|
const [ type, name ] = attr.name.split(":", 2);
|
||||||
|
const value = note.getLabelValue(name);
|
||||||
|
const friendlyName = def?.promotedAlias ?? name;
|
||||||
|
if (!value) continue;
|
||||||
|
|
||||||
|
result.push({ name, type, friendlyName, value });
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user