Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(promoted attributes): bind the suggestion list only where there is something to suggest
Elian Doran2b949a9aba4c
diff --git a/apps/client/src/widgets/PromotedAttributes.spec.tsx b/apps/client/src/widgets/PromotedAttributes.spec.tsxindex 36fcc4ec89..7241a83f0b 100644--- a/apps/client/src/widgets/PromotedAttributes.spec.tsx+++ b/apps/client/src/widgets/PromotedAttributes.spec.tsx@@ -72,7 +72,8 @@ import PromotedAttributes, { buildPromotedCells, PromotedAttributesContent, useP// A text field offers the values other notes hold under its name through the Algolia plugin, which// is not loaded here; a stub that chains like jQuery does keeps the field's setup on its feet.type PluggedIn = { autocomplete(...args: unknown[]): PluggedIn };-($.fn as unknown as PluggedIn).autocomplete = function (this: PluggedIn) { return this; };+const autocompleteMock = vi.fn(function (this: PluggedIn) { return this; });+($.fn as unknown as PluggedIn).autocomplete = autocompleteMock;// The fields reach the server through these three; every suite stands them down, and the ones// asserting on what was written reach for these same handles.@@ -577,6 +578,20 @@ describe("PromotedAttributesContent rendering", () => {await renderCells(note, [ buildCell(note, { definition: { labelType: "number" }, uniqueId: "num" }) ]);expect(serverGetMock).not.toHaveBeenCalled();});++ it("binds the suggestion list only where there is something to suggest", async () => {+ serverGetMock.mockResolvedValueOnce([ "one", "two" ]);+ await renderCells(note, [ buildCell(note, { name: "tags", definition: { labelType: "text" } }) ]);+ expect(autocompleteMock).toHaveBeenCalled();++ autocompleteMock.mockClear();+ await renderCells(note, [ buildCell(note, { name: "flag", definition: { labelType: "boolean" }, uniqueId: "flag" }) ]);+ expect(autocompleteMock).not.toHaveBeenCalled();++ // A text field whose name nothing else holds a value under is bound no more than a flag is.+ await renderCells(note, [ buildCell(note, { name: "fresh", definition: { labelType: "text" }, uniqueId: "fresh" }) ]);+ expect(autocompleteMock).not.toHaveBeenCalled();+ });});describe("usePromotedAttributeData", () => {diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsxindex 6ea05c3ef3..b547281de9 100644--- a/apps/client/src/widgets/PromotedAttributes.tsx+++ b/apps/client/src/widgets/PromotedAttributes.tsx@@ -396,7 +396,7 @@ function useTextLabelAutocomplete(inputId: string, valueAttr: Attribute, definit// Initialize autocomplete.useEffect(() => {- if (attributeValues?.length === 0) return;+ if (!attributeValues?.length) return;const el = document.getElementById(inputId) as HTMLInputElement | null;if (!el) return;