The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Allow passing arrays of string as sqlInitialParameters in InteractiveQuestion (#67282)
Sébastienad5cc2877dae
diff --git a/e2e/support/helpers/e2e-ui-elements-helpers.js b/e2e/support/helpers/e2e-ui-elements-helpers.jsindex 5bd0ec37084..7deb3375d15 100644--- a/e2e/support/helpers/e2e-ui-elements-helpers.js+++ b/e2e/support/helpers/e2e-ui-elements-helpers.js@@ -662,6 +662,20 @@ export function leaveConfirmationModal() {return cy.findByTestId("leave-confirmation");}+export function getUniqueTableColumnValues(columnName) {+ const values = [];++ tableInteractiveBody().within(() => {+ cy.get(`[data-column-id="${columnName}"]`)+ .each(($item) => values.push($item.text()))+ .then(() => {+ cy.wrap(Array.from(new Set(values))).as("items");+ });+ });++ return cy.get("@items");+}+export function ensureParameterColumnValue({ columnName, columnValue }) {tableInteractiveBody().within(() => {cy.get(`[data-column-id="${columnName}"]`).each((cell) => {diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsxindex a3280dfa13a..06951027b57 100644--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx@@ -15,11 +15,11 @@ import {import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";import { Box, Button } from "metabase/ui";-import type { DatasetColumn } from "metabase-types/api";+import type { DatasetColumn, TemplateTags } from "metabase-types/api";import { createMockParameter } from "metabase-types/api/mocks";const { H } = cy;-const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;+const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATABASE;const setup = ({ question }: { question: NativeQuestionDetails }) => {signInAsAdminAndEnableEmbeddingSdk();@@ -280,4 +280,65 @@ describe("scenarios > embedding-sdk > interactive-question > native", () => {});});});++ describe("editable parameters for a native question with multi-select parameter", () => {+ const PARAMETERS = [+ createMockParameter({+ id: "category",+ name: "Category",+ slug: "category",+ type: "number/=",+ target: ["dimension", ["template-tag", "category"]],+ isMultiSelect: true,+ }),+ ];+ const TEMPLATE_TAGS: TemplateTags = {+ category: {+ id: "category",+ name: "category",+ "display-name": "Category",+ type: "dimension",+ "widget-type": "number/=",+ dimension: ["field", PRODUCTS.CATEGORY, null],+ },+ };++ beforeEach(() => {+ setup({+ question: {+ name: "Products native question",+ native: {+ query: "SELECT * FROM PRODUCTS WHERE {{category}}",+ "template-tags": TEMPLATE_TAGS,+ },+ parameters: PARAMETERS,+ },+ });+ });++ it("allows to pass in initial values for multi-select sql parameter (metabase#64673)", () => {+ mountInteractiveQuestion({+ initialSqlParameters: { category: ["Gizmo", "Widget"] },+ children: (+ <>+ <InteractiveQuestion.Title />+ <InteractiveQuestion.SqlParametersList />+ <InteractiveQuestion.QuestionVisualization />+ </>+ ),+ });++ cy.wait("@cardQuery");++ H.getUniqueTableColumnValues("CATEGORY").should("deep.equal", [+ "Gizmo",+ "Widget",+ ]);++ cy.findByLabelText("Category").should(+ "have.text",+ "Category:\u00a02 selections", // \u00a0 is a non-breaking space, aka + );+ });+ });});diff --git a/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts b/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.tsindex 5bb830cb399..0601898b35f 100644--- a/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts+++ b/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts@@ -1,5 +1,3 @@-import _ from "underscore";-import { getIsGuestEmbed } from "embedding-sdk-bundle/store/selectors";import type {SdkDispatch,@@ -76,14 +74,10 @@ export const loadQuestionSdk =question = question.applyTemplateTagParameters();}- const queryParams = initialSqlParameters- ? _.mapObject(initialSqlParameters, String)- : {};-const parameterValues = getParameterValuesForQuestion({card,metadata,- queryParams,+ queryParams: initialSqlParameters,});if (parameterValues) {