chore(react/promoted_attributes): multiplicity

This commit is contained in:
Elian Doran
2025-11-13 08:17:32 +02:00
parent 3d0d1fa36e
commit 54c8322960
2 changed files with 21 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import { Attribute } from "../services/attribute_parser";
import { ComponentChild } from "preact";
import FAttribute from "../entities/fattribute";
import { t } from "../services/i18n";
import ActionButton from "./react/ActionButton";
export default function PromotedAttributes() {
const { note } = useNoteContext();
@@ -94,6 +95,26 @@ function PromotedAttributeCell({ noteId, definitionAttr, valueAttr, valueName }:
placeholder={t("promoted_attributes.unset-field-placeholder")}
/>
</div>
<div />
{definition.multiplicity === "multi" && (
<td className="multiplicity">
<ActionButton
icon="bx bx-plus"
className="pointer tn-tool-button"
text={t("promoted_attributes.add_new_attribute")}
noIconActionClass
/>
<ActionButton
icon="bx bx-trash"
className="pointer tn-tool-button"
text={t("promoted_attributes.remove_this_attribute")}
noIconActionClass
/>
</td>
)}
</div>
)
}

View File

@@ -30,13 +30,8 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
async createPromotedAttributeCell(definitionAttr: FAttribute, valueAttr: Attribute, valueName: string) {
// .on("change", (event) => this.promotedAttributeChanged(event));
const $actionCell = $("<div>");
const $multiplicityCell = $("<td>").addClass("multiplicity").attr("nowrap", "true");
const $wrapper = $('<div class="promoted-attribute-cell">')
.append($actionCell)
.append($multiplicityCell);
if (valueAttr.type === "label") {
$wrapper.addClass(`promoted-attribute-label-${definition.labelType}`);
if (definition.labelType === "text") {
@@ -170,8 +165,6 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
if (definition.multiplicity === "multi") {
const $addButton = $("<span>")
.addClass("bx bx-plus pointer tn-tool-button")
.prop("title", t("promoted_attributes.add_new_attribute"))
.on("click", async () => {
const $new = await this.createPromotedAttributeCell(
definitionAttr,