diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx index 1086c350e..bcf6d5bdc 100644 --- a/apps/client/src/widgets/PromotedAttributes.tsx +++ b/apps/client/src/widgets/PromotedAttributes.tsx @@ -93,7 +93,7 @@ export default function PromotedAttributes() { } function PromotedAttributeCell(props: CellProps) { - const { valueName, valueAttr, definition, definitionAttr } = props.cell; + const { valueName, valueAttr, definition } = props.cell; const inputId = useUniqueName(`value-${valueAttr.name}`); useEffect(() => { @@ -108,16 +108,7 @@ function PromotedAttributeCell(props: CellProps) {
- +
@@ -125,6 +116,39 @@ function PromotedAttributeCell(props: CellProps) { ) } +function LabelInput({ inputId, ...props }: CellProps & { inputId: string }) { + const { valueAttr, definition, definitionAttr } = props.cell; + + useEffect(() => { + if (definition.labelType === "text") { + const el = document.getElementById(inputId); + if (el) { + setupTextLabelAutocomplete(el as HTMLInputElement, valueAttr, () => { + // TODO: Implement me. + console.log("Got change"); + }); + } + } + }, []); + + return ( + + ) +} + +function RelationInput() { + +} + function ActionCell() { return (
@@ -205,3 +229,40 @@ function PromotedActionButton({ icon, title, onClick }: { /> ) } + +function setupTextLabelAutocomplete(el: HTMLInputElement, valueAttr: Attribute, onChangeListener: () => void) { + // no need to await for this, can be done asynchronously + const $input = $(el); + server.get(`attribute-values/${encodeURIComponent(valueAttr.name)}`).then((_attributeValues) => { + if (_attributeValues.length === 0) { + return; + } + + const attributeValues = _attributeValues.map((attribute) => ({ value: attribute })); + + $input.autocomplete( + { + appendTo: document.querySelector("body"), + hint: false, + autoselect: false, + openOnFocus: true, + minLength: 0, + tabAutocomplete: false + }, + [ + { + displayKey: "value", + source: function (term, cb) { + term = term.toLowerCase(); + + const filtered = attributeValues.filter((attr) => attr.value.toLowerCase().includes(term)); + + cb(filtered); + } + } + ] + ); + + $input.on("autocomplete:selected", onChangeListener); + }); +} diff --git a/apps/client/src/widgets/promoted_attributes.ts b/apps/client/src/widgets/promoted_attributes.ts index 3625cf4e0..1e0c5037e 100644 --- a/apps/client/src/widgets/promoted_attributes.ts +++ b/apps/client/src/widgets/promoted_attributes.ts @@ -32,38 +32,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget { // autocomplete for label values is just nice to have, mobile can keep labels editable without autocomplete if (utils.isDesktop()) { - // no need to await for this, can be done asynchronously - server.get(`attribute-values/${encodeURIComponent(valueAttr.name)}`).then((_attributeValues) => { - if (_attributeValues.length === 0) { - return; - } - const attributeValues = _attributeValues.map((attribute) => ({ value: attribute })); - - $input.autocomplete( - { - appendTo: document.querySelector("body"), - hint: false, - autoselect: false, - openOnFocus: true, - minLength: 0, - tabAutocomplete: false - }, - [ - { - displayKey: "value", - source: function (term, cb) { - term = term.toLowerCase(); - - const filtered = attributeValues.filter((attr) => attr.value.toLowerCase().includes(term)); - - cb(filtered); - } - } - ] - ); - - $input.on("autocomplete:selected", (e) => this.promotedAttributeChanged(e)); }); } } else if (definition.labelType === "number") {