Skip to content

Build your personal knowledge base with Trilium Notes

refactor(attributes): port the inverse relation field to Preact

Elian Doran88d7e6182b2e
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index bc1b969265..9e6e7ca7b6 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -465,6 +465,23 @@ function AttributeForm({ opts, attrType, currentNoteId, onAttributesChanged, onS
</tr>
)}
+ {attrType === "relation-definition" && (
+ <tr class="attr-row-inverse-relation">
+ <th title={t("attribute_detail.inverse_relation_title")}>{t("attribute_detail.inverse_relation")}</th>
+ <td>
+ <FormTextBox
+ className="attr-input-inverse-relation"
+ currentValue={definition.inverseRelation ?? ""}
+ disabled={!isOwned}
+ onChange={(inverseRelation) => commitDefinition({
+ // A relation name, so the same characters are dropped as in the name field
+ inverseRelation: utils.filterAttributeName(inverseRelation)
+ })}
+ />
+ </td>
+ </tr>
+ )}
+
<tr title={t("attribute_detail.inheritable_title")}>
<th></th>
<td>
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail_old.ts b/apps/client/src/widgets/attribute_widgets/attribute_detail_old.ts
index 84128d16c5..0134e4879a 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail_old.ts
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail_old.ts
@@ -1,7 +1,6 @@
import type { Attribute } from "../../services/attribute_parser.js";
import { t } from "../../services/i18n.js";
import linkService from "../../services/link.js";
-import promotedAttributeDefinitionParser from "../../services/promoted_attribute_definition_parser.js";
import { openInAppHelpFromUrl } from "../../services/utils.js";
import NoteContextAwareWidget from "../note_context_aware_widget.js";
import { ATTR_HELP } from "./attr_help.js";
@@ -13,26 +12,14 @@ const TPL = /*html*/`
<table class="attr-edit-table">
<tr class="attr-help"></tr>
- <tr class="attr-row-inverse-relation">
- <th title="${t("attribute_detail.inverse_relation_title")}">${t("attribute_detail.inverse_relation")}</th>
- <td>
- <div class="input-group">
- <input type="text" class="attr-input-inverse-relation form-control" />
- </div>
- </td>
- </tr>
</table>
</div>`;
export default class AttributeDetailWidget extends NoteContextAwareWidget {
private $inputName!: JQuery<HTMLElement>;
- private $inputInverseRelation!: JQuery<HTMLElement>;
- private $rowInverseRelation!: JQuery<HTMLElement>;
private $attrIsOwnedBy!: JQuery<HTMLElement>;
private $attrHelp!: JQuery<HTMLElement>;
- private attribute!: Attribute;
- private allAttributes?: Attribute[];
private attrType!: ReturnType<AttributeDetailWidget["getAttrType"]>;
doRender() {
@@ -40,15 +27,6 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
this.$inputName = this.$widget.find(".attr-input-name");
- this.$rowInverseRelation = this.$widget.find(".attr-row-inverse-relation");
- this.$inputInverseRelation = this.$widget.find(".attr-input-inverse-relation");
- this.$inputInverseRelation.on("input", (ev) => {
- if (!(ev.originalEvent as KeyboardEvent)?.isComposing) {
- // https://github.com/zadam/trilium/pull/3812
- this.userEditedAttribute();
- }
- });
-
this.$attrIsOwnedBy = this.$widget.find(".attr-is-owned-by");
this.$attrHelp = this.$widget.find(".attr-help");
@@ -57,11 +35,6 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
async showAttributeDetail({ allAttributes, attribute, isOwned, x, y, focus, hideMultiplicity }: AttributeDetailOpts) {
this.attrType = this.getAttrType(attribute);
- const definition = this.attrType?.endsWith("-definition") ? promotedAttributeDefinitionParser.parse(attribute.value || "") : {};
-
- this.allAttributes = allAttributes;
- this.attribute = attribute;
-
if (isOwned) {
this.$attrIsOwnedBy.hide();
} else if (attribute.noteId) {
@@ -73,20 +46,11 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
.append(await linkService.createLink(attribute.noteId));
}
- const disabledFn = () => (!isOwned ? "true" : undefined);
-
- this.$rowInverseRelation.toggle(this.attrType === "relation-definition");
- this.$inputInverseRelation.val(definition.inverseRelation || "").attr("disabled", disabledFn);
-
this.updateHelp();
this.toggleInt(true);
}
- userEditedAttribute() {
- this.updateHelp();
- }
-
updateHelp() {
const attrName = String(this.$inputName.val());