Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/promoted_attributes): map promoted attribute types

Elian Doran49189bc63ecc
diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx
index bcf6d5bdca..bfed6f6a29 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<LabelType, HTMLInputTypeAttribute> = {
+ 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 1e0c5037e9..4f9d9bcc51 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($(`<label class="tn-checkbox"></label>`));
$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"));