mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00
refactor(react/ribbon): imperative api for saving, reloading, updating attributes
This commit is contained in:
parent
a934760960
commit
d53faa8c01
@ -17,8 +17,4 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
|
|||||||
this.handleAddNewAttributeCommand("addNewRelation");
|
this.handleAddNewAttributeCommand("addNewRelation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAttributeList(attributes: FAttribute[]) {
|
|
||||||
await this.renderOwnedAttributes(attributes, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import Component from "../../../components/component";
|
|||||||
import link from "../../../services/link";
|
import link from "../../../services/link";
|
||||||
import froca from "../../../services/froca";
|
import froca from "../../../services/froca";
|
||||||
import contextMenu from "../../../menus/context_menu";
|
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 { AttributeType } from "@triliumnext/commons";
|
||||||
import attributes from "../../../services/attributes";
|
import attributes from "../../../services/attributes";
|
||||||
import note_create from "../../../services/note_create";
|
import note_create from "../../../services/note_create";
|
||||||
@ -245,7 +245,14 @@ export default function AttributeEditor({ note, componentId, notePath }: { note:
|
|||||||
|
|
||||||
return result?.note?.getBestNotePathString();
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user