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(react/ribbon): display attribute errors
Elian Dorane8ae5486c844
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts b/apps/client/src/widgets/attribute_widgets/attribute_editor.tsindex 0d173cf929..4d0bc64e5b 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts+++ b/apps/client/src/widgets/attribute_widgets/attribute_editor.ts@@ -11,14 +11,11 @@ import linkService from "../../services/link.js";import type AttributeDetailWidget from "./attribute_detail.js";import type { CommandData, EventData, EventListener, FilteredCommandNames } from "../../components/app_context.js";import type { default as FAttribute, AttributeType } from "../../entities/fattribute.js";-import type FNote from "../../entities/fnote.js";import { escapeQuotes } from "../../services/utils.js";const TPL = /*html*/`<div class="bx bx-plus add-new-attribute-button tn-tool-button" title="${escapeQuotes(t("attribute_editor.add_a_new_attribute"))}"></div>-- <div class="attribute-errors" style="display: none;"></div></div>`;@@ -29,11 +26,9 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implemprivate $editor!: JQuery<HTMLElement>;private $addNewAttributeButton!: JQuery<HTMLElement>;private $saveAttributesButton!: JQuery<HTMLElement>;- private $errors!: JQuery<HTMLElement>;private textEditor!: AttributeEditor;private lastUpdatedNoteId!: string | undefined;- private lastSavedContent!: string;constructor(attributeDetailWidget: AttributeDetailWidget) {super();@@ -57,8 +52,6 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implemthis.$addNewAttributeButton.on("click", (e) => this.addNewAttribute(e));this.$saveAttributesButton.on("click", () => this.save());-- this.$errors = this.$widget.find(".attribute-errors");}addNewAttribute(e: JQuery.ClickEvent) {@@ -167,12 +160,6 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implemdataChanged() {this.lastUpdatedNoteId = this.noteId;-- if (this.$errors.is(":visible")) {- // using .hide() instead of .slideUp() since this will also hide the error after confirming- // mention for relation name which suits up. When using.slideUp() error will appear and the slideUp which is weird- this.$errors.hide();- }}async loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string) {diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsxindex c1e59b1140..36c0f6dcfe 100644--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx@@ -165,12 +165,13 @@ export default function AttributeEditor({ note, componentId }: { note: FNote, coonChange={(currentValue) => {currentValueRef.current = currentValue ?? "";setNeedsSaving(lastSavedContent.current !== currentValue);+ setError(undefined);}}onClick={(e, pos) => {if (pos && pos.textNode && pos.textNode.data) {const clickIndex = getClickIndex(pos);- let parsedAttrs;+ let parsedAttrs: Attribute[];try {parsedAttrs = attribute_parser.lexAndParse(getPreprocessedData(currentValueRef.current), true);@@ -215,6 +216,12 @@ export default function AttributeEditor({ note, componentId }: { note: FNote, cotext={escapeQuotes(t("attribute_editor.save_attributes"))}onClick={save}/> }++ { error && (+ <div className="attribute-errors">+ {typeof error === "object" && "message" in error && typeof error.message === "string" && error.message}+ </div>+ )}</div>{attributeDetailWidgetEl}