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
chore(client/ts): port inherited_attribute_list
Elian Doranc27d5afdf257
diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.ts b/src/public/app/widgets/attribute_widgets/attribute_detail.tsindex 866cff8050..2a3f3e2b46 100644--- a/src/public/app/widgets/attribute_widgets/attribute_detail.ts+++ b/src/public/app/widgets/attribute_widgets/attribute_detail.ts@@ -288,7 +288,7 @@ const ATTR_HELP: Record<string, Record<string, string>> = {};interface AttributeDetailOpts {- allAttributes: Attribute[];+ allAttributes?: Attribute[];attribute: Attribute;isOwned: boolean;x: number;@@ -338,7 +338,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {private relatedNotesSpacedUpdate!: SpacedUpdate;private attribute!: Attribute;- private allAttributes!: Attribute[];+ private allAttributes?: Attribute[];private attrType!: ReturnType<AttributeDetailWidget["getAttrType"]>;async refresh() {@@ -434,7 +434,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {this.attribute.value = pathChunks[pathChunks.length - 1]; // noteId- this.triggerCommand("updateAttributeList", { attributes: this.allAttributes });+ this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] });this.updateRelatedNotes();});@@ -454,7 +454,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {this.$deleteButton = this.$widget.find(".attr-delete-button");this.$deleteButton.on("click", async () => {await this.triggerCommand("updateAttributeList", {- attributes: this.allAttributes.filter((attr) => attr !== this.attribute)+ attributes: (this.allAttributes || []).filter((attr) => attr !== this.attribute)});await this.triggerCommand("saveAttributes");@@ -714,7 +714,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {this.attribute.value = String(this.$inputValue.val());}- this.triggerCommand("updateAttributeList", { attributes: this.allAttributes });+ this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] });}buildDefinitionValue() {diff --git a/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.js b/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.tssimilarity index 88%rename from src/public/app/widgets/ribbon_widgets/inherited_attribute_list.jsrename to src/public/app/widgets/ribbon_widgets/inherited_attribute_list.tsindex 6e6f435edf..667f12753b 100644--- a/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.js+++ b/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.ts@@ -3,6 +3,8 @@ import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";import attributeRenderer from "../../services/attribute_renderer.js";import attributeService from "../../services/attributes.js";import { t } from "../../services/i18n.js";+import type FNote from "../../entities/fnote.js";+import type { EventData } from "../../components/app_context.js";const TPL = `<div class="inherited-attributes-widget">@@ -10,7 +12,7 @@ const TPL = `.inherited-attributes-widget {position: relative;}-+.inherited-attributes-container {color: var(--muted-text-color);max-height: 200px;@@ -23,6 +25,11 @@ const TPL = `</div>`;export default class InheritedAttributesWidget extends NoteContextAwareWidget {++ private attributeDetailWidget: AttributeDetailWidget;++ private $container!: JQuery<HTMLElement>;+get name() {return "inheritedAttributes";}@@ -34,7 +41,6 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {constructor() {super();- /** @type {AttributeDetailWidget} */this.attributeDetailWidget = new AttributeDetailWidget().contentSized().setParent(this);this.child(this.attributeDetailWidget);@@ -42,7 +48,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {getTitle() {return {- show: !this.note.isLaunchBarConfig(),+ show: !this.note?.isLaunchBarConfig(),title: t("inherited_attribute_list.title"),icon: "bx bx-list-plus"};@@ -56,7 +62,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {this.$widget.append(this.attributeDetailWidget.render());}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {this.$container.empty();const inheritedAttributes = this.getInheritedAttributes(note);@@ -90,7 +96,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {}}- getInheritedAttributes(note) {+ getInheritedAttributes(note: FNote) {const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId);attrs.sort((a, b) => {@@ -105,7 +111,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {return attrs;}- entitiesReloadedEvent({ loadResults }) {+ entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) {this.refresh();}