From 49189bc63ecc4d2aac87edcb61562c9b4f71d150 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 23 Nov 2025 11:38:53 +0200 Subject: [PATCH] chore(react/promoted_attributes): map promoted attribute types --- apps/client/src/widgets/PromotedAttributes.tsx | 16 ++++++++++++++-- apps/client/src/widgets/promoted_attributes.ts | 14 -------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx index bcf6d5bdc..bfed6f6a2 100644 --- a/apps/client/src/widgets/PromotedAttributes.tsx +++ b/apps/client/src/widgets/PromotedAttributes.tsx @@ -5,9 +5,10 @@ import { Attribute } from "../services/attribute_parser"; import FAttribute from "../entities/fattribute"; import clsx from "clsx"; import { t } from "../services/i18n"; -import { DefinitionObject } from "../services/promoted_attribute_definition_parser"; +import { DefinitionObject, LabelType } from "../services/promoted_attribute_definition_parser"; import server from "../services/server"; import FNote from "../entities/fnote"; +import { HTMLInputTypeAttribute } from "preact"; interface Cell { definitionAttr: FAttribute; @@ -116,6 +117,17 @@ function PromotedAttributeCell(props: CellProps) { ) } +const LABEL_MAPPINGS: Record = { + text: "text", + number: "number", + boolean: "checkbox", + date: "date", + datetime: "datetime-local", + time: "time", + color: "hidden", // handled separately. + url: "url" +}; + function LabelInput({ inputId, ...props }: CellProps & { inputId: string }) { const { valueAttr, definition, definitionAttr } = props.cell; @@ -136,6 +148,7 @@ function LabelInput({ inputId, ...props }: CellProps & { inputId: string }) { className="form-control promoted-attribute-input" tabIndex={200 + definitionAttr.position} id={inputId} + type={LABEL_MAPPINGS[definition.labelType ?? "text"]} value={valueAttr.value} placeholder={t("promoted_attributes.unset-field-placeholder")} data-attribute-id={valueAttr.attributeId} @@ -207,7 +220,6 @@ function MultiplicityCell({ cell, cells, setCells, setCellToFocus, note, compone } }) } - console.log("Delete at ", index, isLastOneOfType); setCells(cells.toSpliced(index, 1, ...newOnesToInsert)); }} /> diff --git a/apps/client/src/widgets/promoted_attributes.ts b/apps/client/src/widgets/promoted_attributes.ts index 1e0c5037e..4f9d9bcc5 100644 --- a/apps/client/src/widgets/promoted_attributes.ts +++ b/apps/client/src/widgets/promoted_attributes.ts @@ -28,16 +28,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { if (valueAttr.type === "label") { $wrapper.addClass(`promoted-attribute-label-${definition.labelType}`); if (definition.labelType === "text") { - $input.prop("type", "text"); - - // autocomplete for label values is just nice to have, mobile can keep labels editable without autocomplete - if (utils.isDesktop()) { - - }); - } } else if (definition.labelType === "number") { - $input.prop("type", "number"); - let step = 1; for (let i = 0; i < (definition.numberPrecision || 0) && i < 10; i++) { @@ -47,8 +38,6 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { $input.prop("step", step); $input.css("text-align", "right").css("width", "120"); } else if (definition.labelType === "boolean") { - $input.prop("type", "checkbox"); - $input.wrap($(``)); $wrapper.find(".input-group").removeClass("input-group"); @@ -56,11 +45,8 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { $input.prop("checked", "checked"); } } else if (definition.labelType === "date") { - $input.prop("type", "date"); } else if (definition.labelType === "datetime") { - $input.prop("type", "datetime-local"); } else if (definition.labelType === "time") { - $input.prop("type", "time"); } else if (definition.labelType === "url") { $input.prop("placeholder", t("promoted_attributes.url_placeholder"));