refactor(react/ribbon): imperative api for saving, reloading, updating attributes

This commit is contained in:
Elian Doran 2025-08-23 20:49:54 +03:00
parent a934760960
commit d53faa8c01
No known key found for this signature in database
3 changed files with 9 additions and 46 deletions

View File

@ -17,8 +17,4 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.handleAddNewAttributeCommand("addNewRelation");
}
}
async updateAttributeList(attributes: FAttribute[]) {
await this.renderOwnedAttributes(attributes, false);
}
}

View File

@ -17,7 +17,7 @@ import Component from "../../../components/component";
import link from "../../../services/link";
import froca from "../../../services/froca";
import contextMenu from "../../../menus/context_menu";
import type { CommandData, FilteredCommandNames } from "../../../components/app_context";
import type { CommandData, CommandListenerData, FilteredCommandNames } from "../../../components/app_context";
import { AttributeType } from "@triliumnext/commons";
import attributes from "../../../services/attributes";
import note_create from "../../../services/note_create";
@ -245,7 +245,14 @@ export default function AttributeEditor({ note, componentId, notePath }: { note:
return result?.note?.getBestNotePathString();
}
}), [ notePath ]))
}), [ notePath ]));
// Interaction with the attribute editor.
useLegacyImperativeHandlers(useMemo(() => ({
saveAttributesCommand: save,
reloadAttributesCommand: refresh,
updateAttributeListCommand: ({ attributes }: CommandListenerData<"updateAttributeList">) => renderOwnedAttributes(attributes as FAttribute[], false)
}), []));
return (
<>

View File

@ -1,40 +0,0 @@
import { t } from "../../services/i18n.js";
import NoteContextAwareWidget from "../note_context_aware_widget.js";
import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";
import AttributeEditorWidget from "../attribute_widgets/attribute_editor.js";
import type { CommandListenerData } from "../../components/app_context.js";
import type FAttribute from "../../entities/fattribute.js";
export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
private attributeDetailWidget: AttributeDetailWidget;
private attributeEditorWidget: AttributeEditorWidget;
private $title!: JQuery<HTMLElement>;
constructor() {
super();
this.attributeDetailWidget = new AttributeDetailWidget().contentSized().setParent(this);
this.attributeEditorWidget = new AttributeEditorWidget(this.attributeDetailWidget).contentSized().setParent(this);
this.child(this.attributeEditorWidget, this.attributeDetailWidget);
}
async saveAttributesCommand() {
await this.attributeEditorWidget.save();
}
async reloadAttributesCommand() {
await this.attributeEditorWidget.refresh();
}
async updateAttributeListCommand({ attributes }: CommandListenerData<"updateAttributeList">) {
// TODO: See why we need FAttribute[] and Attribute[]
await this.attributeEditorWidget.updateAttributeList(attributes as FAttribute[]);
}
focus() {
this.attributeEditorWidget.focus();
}
}