diff --git a/e2e/test/scenarios/custom-column/cc-typing-suggestion.cy.spec.js b/e2e/test/scenarios/custom-column/cc-typing-suggestion.cy.spec.js index 1bed09bca73775e9d95d4c8a4882f9f2cba37198..9bf8bb73dede96d1c8b94e078d5be858f6abf603 100644 --- a/e2e/test/scenarios/custom-column/cc-typing-suggestion.cy.spec.js +++ b/e2e/test/scenarios/custom-column/cc-typing-suggestion.cy.spec.js @@ -1,7 +1,9 @@ import { enterCustomColumnDetails, openProductsTable, + popover, restore, + summarize, } from "e2e/support/helpers"; describe("scenarios > question > custom column > typing suggestion", () => { @@ -10,16 +12,16 @@ describe("scenarios > question > custom column > typing suggestion", () => { cy.signInAsAdmin(); openProductsTable({ mode: "notebook" }); - // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage - cy.findByText("Custom column").click(); }); it("should not suggest arithmetic operators", () => { + addCustomColumn(); enterCustomColumnDetails({ formula: "[Price] " }); cy.findByTestId("expression-suggestions-list").should("not.exist"); }); it("should correctly accept the chosen field suggestion", () => { + addCustomColumn(); enterCustomColumnDetails({ formula: "[Rating]{leftarrow}{leftarrow}{leftarrow}", }); @@ -34,6 +36,7 @@ describe("scenarios > question > custom column > typing suggestion", () => { }); it("should correctly accept the chosen function suggestion", () => { + addCustomColumn(); enterCustomColumnDetails({ formula: "LTRIM([Title])" }); // Place the cursor between "is" and "empty" @@ -47,6 +50,7 @@ describe("scenarios > question > custom column > typing suggestion", () => { }); it("should correctly insert function suggestion with the opening parenthesis", () => { + addCustomColumn(); enterCustomColumnDetails({ formula: "LOW{enter}" }); // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage @@ -54,6 +58,7 @@ describe("scenarios > question > custom column > typing suggestion", () => { }); it("should show expression function helper if a proper function is typed", () => { + addCustomColumn(); enterCustomColumnDetails({ formula: "lower(" }); // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage @@ -74,4 +79,16 @@ describe("scenarios > question > custom column > typing suggestion", () => { "be.visible", ); }); + + it("should not show suggestions for an unfocused field (metabase#31643)", () => { + summarize({ mode: "notebook" }); + popover().findByText("Custom Expression").click(); + enterCustomColumnDetails({ formula: "Count{enter}" }); + popover().findByLabelText("Name").focus(); + cy.findByTestId("expression-suggestions-list").should("not.exist"); + }); }); + +const addCustomColumn = () => { + cy.findByTestId("action-buttons").findByText("Custom column").click(); +}; diff --git a/frontend/src/metabase/query_builder/components/expressions/ExpressionEditorTextfield/ExpressionEditorTextfield.tsx b/frontend/src/metabase/query_builder/components/expressions/ExpressionEditorTextfield/ExpressionEditorTextfield.tsx index 75e44b5bd21d5784c1f5257e0d0a74989a7eb199..1d44821b34d26ada6e8a85bb388691d04007efe8 100644 --- a/frontend/src/metabase/query_builder/components/expressions/ExpressionEditorTextfield/ExpressionEditorTextfield.tsx +++ b/frontend/src/metabase/query_builder/components/expressions/ExpressionEditorTextfield/ExpressionEditorTextfield.tsx @@ -407,7 +407,9 @@ class ExpressionEditorTextfield extends React.Component< }); this.setState({ helpText: helpText || null }); - this.updateSuggestions(suggestions); + if (this.state.isFocused) { + this.updateSuggestions(suggestions); + } } errorAsMarkers(errorMessage: ErrorWithMessage | null = null): IMarker[] {