Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

feat(sdk-bundle): Add SqlParametersList component for InteractiveQuestion and StaticQuestion (#64187)

Timofey Kachalov4d0d576c13f4
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.tsx
index 9f7fd213927..9119c338b5e 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
@@ -3,6 +3,7 @@ import { useState } from "react";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
+ type NativeQuestionDetails,
createNativeQuestion,
tableInteractiveBody,
} from "e2e/support/helpers";
@@ -15,122 +16,281 @@ import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embeddin
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 { createMockParameter } from "metabase-types/api/mocks";
const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
+const setup = ({ question }: { question: NativeQuestionDetails }) => {
+ signInAsAdminAndEnableEmbeddingSdk();
+
+ createNativeQuestion(question, { wrapId: true });
+
+ cy.signOut();
+ mockAuthProviderAndJwtSignIn();
+};
+
+const ensureParameterColumnValue = ({
+ columnName,
+ columnValue,
+}: {
+ columnName: string;
+ columnValue: string;
+}) => {
+ tableInteractiveBody().within(() => {
+ cy.get(`[data-column-id="${columnName}"]`).each((cell) => {
+ cy.wrap(cell).should("have.text", columnValue);
+ });
+ });
+};
+
describe("scenarios > embedding-sdk > interactive-question > native", () => {
- beforeEach(() => {
- signInAsAdminAndEnableEmbeddingSdk();
-
- createNativeQuestion(
- {
- native: {
- query: "SELECT * FROM orders WHERE {{ID}}",
- "template-tags": {
- ID: {
- id: "6b8b10ef-0104-1047-1e1b-2492d5954322",
- name: "ID",
- "display-name": "ID",
- type: "dimension",
- dimension: ["field", ORDERS.ID, null],
- "widget-type": "category",
- default: null,
+ describe("common", () => {
+ beforeEach(() => {
+ setup({
+ question: {
+ native: {
+ query: "SELECT * FROM orders WHERE {{ID}}",
+ "template-tags": {
+ ID: {
+ id: "6b8b10ef-0104-1047-1e1b-2492d5954322",
+ name: "ID",
+ "display-name": "ID",
+ type: "dimension",
+ dimension: ["field", ORDERS.ID, null],
+ "widget-type": "category",
+ default: null,
+ },
},
},
},
- },
- { wrapId: true },
- );
-
- cy.signOut();
- mockAuthProviderAndJwtSignIn();
- });
+ });
+ });
- it("supports passing sql parameters to native questions", () => {
- mountInteractiveQuestion({ initialSqlParameters: { ID: ORDERS_ID } });
+ it("supports passing sql parameters to native questions", () => {
+ mountInteractiveQuestion({ initialSqlParameters: { ID: ORDERS_ID } });
- cy.wait("@cardQuery").then(({ response }) => {
- const { body } = response ?? {};
+ cy.wait("@cardQuery").then(({ response }) => {
+ const { body } = response ?? {};
- const rows = tableInteractiveBody().findAllByRole("row");
+ const rows = tableInteractiveBody().findAllByRole("row");
- // There should be one row in the table
- rows.should("have.length", 1);
+ // There should be one row in the table
+ rows.should("have.length", 1);
- const idColumnIndex = body.data.cols.findIndex(
- (column: DatasetColumn) => column.name === "ID",
- );
+ const idColumnIndex = body.data.cols.findIndex(
+ (column: DatasetColumn) => column.name === "ID",
+ );
- // The first row should have the same ID column value as the initial SQL parameters
- // eslint-disable-next-line no-unsafe-element-filtering
- rows
- .findAllByTestId("cell-data")
- .eq(idColumnIndex)
- .should("have.text", String(ORDERS_ID));
+ // The first row should have the same ID column value as the initial SQL parameters
+ // eslint-disable-next-line no-unsafe-element-filtering
+ rows
+ .findAllByTestId("cell-data")
+ .eq(idColumnIndex)
+ .should("have.text", String(ORDERS_ID));
+ });
});
- });
- it("should not crash when switching from new question to native question (metabase#60160)", () => {
- const TestComponent = ({
- nativeQuestionId,
- }: {
- nativeQuestionId: string | number;
- }) => {
- const [questionId, setQuestionId] = useState<string | number>("new");
+ it("should not crash when switching from new question to native question (metabase#60160)", () => {
+ const TestComponent = ({
+ nativeQuestionId,
+ }: {
+ nativeQuestionId: string | number;
+ }) => {
+ const [questionId, setQuestionId] = useState<string | number>("new");
- return (
- <Box>
- <InteractiveQuestion questionId={questionId} />
+ return (
+ <Box>
+ <InteractiveQuestion questionId={questionId} />
- <Button onClick={() => setQuestionId(nativeQuestionId)}>
- use native question
- </Button>
- </Box>
- );
- };
+ <Button onClick={() => setQuestionId(nativeQuestionId)}>
+ use native question
+ </Button>
+ </Box>
+ );
+ };
- cy.get<string>("@questionId").then((nativeQuestionId) => {
- mountSdkContent(<TestComponent nativeQuestionId={nativeQuestionId} />);
+ cy.get<string>("@questionId").then((nativeQuestionId) => {
+ mountSdkContent(<TestComponent nativeQuestionId={nativeQuestionId} />);
- getSdkRoot().within(() => {
- cy.findByText("Pick your starting data").should("be.visible");
+ getSdkRoot().within(() => {
+ cy.findByText("Pick your starting data").should("be.visible");
+ });
+
+ cy.findByText("use native question").click();
+
+ cy.log("should show native question table data");
+ getSdkRoot().within(() => {
+ cy.findByText("Pick your starting data").should("not.exist");
+ cy.findByText("test question").should("be.visible");
+ cy.findByText("110.93").should("be.visible");
+ });
+
+ cy.log("should not crash due to preview-query error");
+ cy.on("uncaught:exception", (error) => {
+ expect(
+ error.message.includes(
+ "preview-query cannot be called on native queries",
+ ),
+ ).to.be.false;
+ });
});
+ });
- cy.findByText("use native question").click();
+ it("should not show filter/summarize/breakout buttons for native questions", () => {
+ mountInteractiveQuestion({});
- cy.log("should show native question table data");
getSdkRoot().within(() => {
- cy.findByText("Pick your starting data").should("not.exist");
+ cy.log("should show native question data");
cy.findByText("test question").should("be.visible");
- cy.findByText("110.93").should("be.visible");
- });
- cy.log("should not crash due to preview-query error");
- cy.on("uncaught:exception", (error) => {
- expect(
- error.message.includes(
- "preview-query cannot be called on native queries",
- ),
- ).to.be.false;
+ cy.log("should not show Filter button");
+ cy.findByText("Filter").should("not.exist");
+
+ cy.log("should not show Summarize button");
+ cy.findByText("Summarize").should("not.exist");
+
+ cy.log("should not show Group button");
+ cy.findByText("Group").should("not.exist");
});
});
});
- it("should not show filter/summarize/breakout buttons for native questions", () => {
- mountInteractiveQuestion({});
+ describe("editable parameters for a native question", () => {
+ beforeEach(() => {
+ setup({
+ question: {
+ native: {
+ query:
+ "SELECT * FROM people WHERE state = {{State}} [[ and city = {{City}} ]] [[ and source = {{Source}} ]]",
+ "template-tags": {
+ State: {
+ type: "text",
+ name: "State",
+ id: "1",
+ "display-name": "State",
+ },
+ City: {
+ type: "text",
+ name: "City",
+ id: "2",
+ "display-name": "City",
+ },
+ Source: {
+ type: "text",
+ name: "Source",
+ id: "3",
+ "display-name": "Source",
+ },
+ },
+ },
+ parameters: [
+ createMockParameter({
+ id: "1",
+ slug: "State",
+ }),
+ createMockParameter({
+ id: "2",
+ slug: "City",
+ }),
+ createMockParameter({
+ id: "3",
+ slug: "Source",
+ }),
+ ],
+ },
+ });
+ });
+
+ it("does not show editable sql parameters controls for the default view", () => {
+ mountInteractiveQuestion({
+ initialSqlParameters: { State: "NY" },
+ hiddenParameters: ["Source"],
+ });
+
+ cy.wait("@cardQuery");
+
+ cy.findByTestId("parameter-widget").should("not.exist");
+ cy.findByPlaceholderText("State").should("not.exist");
+ cy.findByPlaceholderText("City").should("not.exist");
+ cy.findByPlaceholderText("Source").should("not.exist");
+ });
+
+ describe("when `SqlParametersList` component is defined in a custom question layout", () => {
+ it("allows to edit sql parameters", () => {
+ mountInteractiveQuestion({
+ hiddenParameters: ["Source"],
+ children: (
+ <>
+ <InteractiveQuestion.Title />
+ <InteractiveQuestion.SqlParametersList />
+ <InteractiveQuestion.QuestionVisualization />
+ </>
+ ),
+ });
+
+ cy.wait("@cardQuery");
- getSdkRoot().within(() => {
- cy.log("should show native question data");
- cy.findByText("test question").should("be.visible");
+ cy.findByPlaceholderText("State").should("exist");
+ cy.findByPlaceholderText("City").should("exist");
+ cy.findByPlaceholderText("Source").should("not.exist");
- cy.log("should not show Filter button");
- cy.findByText("Filter").should("not.exist");
+ getSdkRoot().within(() => {
+ cy.findByPlaceholderText("State").clear().type("NY{enter}");
+ });
- cy.log("should not show Summarize button");
- cy.findByText("Summarize").should("not.exist");
+ ensureParameterColumnValue({
+ columnName: "STATE",
+ columnValue: "NY",
+ });
- cy.log("should not show Group button");
- cy.findByText("Group").should("not.exist");
+ getSdkRoot().within(() => {
+ cy.findByPlaceholderText("State").clear().type("AR{enter}");
+ });
+
+ ensureParameterColumnValue({
+ columnName: "STATE",
+ columnValue: "AR",
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByPlaceholderText("City").type("El Paso{enter}");
+ });
+
+ ensureParameterColumnValue({
+ columnName: "CITY",
+ columnValue: "El Paso",
+ });
+ });
+
+ it("initializes sql parameters controls with initial values and keeps an initial value when changing other parameters", () => {
+ mountInteractiveQuestion({
+ initialSqlParameters: { State: "AR" },
+ hiddenParameters: ["Source"],
+ children: (
+ <>
+ <InteractiveQuestion.Title />
+ <InteractiveQuestion.SqlParametersList />
+ <InteractiveQuestion.QuestionVisualization />
+ </>
+ ),
+ });
+
+ cy.wait("@cardQuery");
+
+ ensureParameterColumnValue({
+ columnName: "STATE",
+ columnValue: "AR",
+ });
+
+ getSdkRoot().within(() => {
+ cy.findByPlaceholderText("City").type("El Paso{enter}");
+ });
+
+ ensureParameterColumnValue({
+ columnName: "CITY",
+ columnValue: "El Paso",
+ });
+ });
});
});
});
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.module.css b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.module.css
new file mode 100644
index 00000000000..8d9abc589db
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.module.css
@@ -0,0 +1,4 @@
+.SqlParametersList {
+ /* Reset ResponsiveList margins */
+ margin: 0;
+}
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.tsx
new file mode 100644
index 00000000000..488bb09874d
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/SqlParametersList.tsx
@@ -0,0 +1,77 @@
+import { useMemo } from "react";
+
+import { useSdkQuestionContext } from "embedding-sdk-bundle/components/private/SdkQuestion/context";
+import { ResponsiveParametersList } from "metabase/query_builder/components/ResponsiveParametersList";
+import * as Lib from "metabase-lib";
+import type { ParameterId } from "metabase-types/api";
+
+import SqlParametersListS from "./SqlParametersList.module.css";
+
+/**
+ * Parameters list for SQL questions
+ *
+ * @function
+ * @category InteractiveQuestion
+ */
+export const SqlParametersList = () => {
+ const {
+ question,
+ originalQuestion,
+ parameterValues,
+ updateParameterValues,
+ hiddenParameters,
+ } = useSdkQuestionContext();
+
+ const isNativeQuestion = useMemo(() => {
+ if (!question) {
+ return false;
+ }
+
+ const { isNative } = Lib.queryDisplayInfo(question.query());
+
+ return isNative;
+ }, [question]);
+
+ const parameters = useMemo(() => {
+ if (!question || !originalQuestion) {
+ return [];
+ }
+
+ const originalParameters = originalQuestion.card().parameters ?? [];
+
+ return question
+ .parameters()
+ .filter(
+ ({ id, slug }) =>
+ originalParameters.find(
+ (originalParameter) => originalParameter.id === id,
+ ) && !hiddenParameters?.includes(slug),
+ );
+ }, [question, originalQuestion, hiddenParameters]);
+
+ if (!question || !isNativeQuestion) {
+ return null;
+ }
+
+ const setParameterValue = (parameterId: ParameterId, value: string) => {
+ const nextParameterValues = {
+ ...parameterValues,
+ [parameterId]: value,
+ };
+
+ updateParameterValues(nextParameterValues);
+ };
+
+ return (
+ <ResponsiveParametersList
+ className={SqlParametersListS.SqlParametersList}
+ cardId={question.id()}
+ dashboardId={question.dashboardId() ?? undefined}
+ parameters={parameters}
+ setParameterValue={setParameterValue}
+ enableParameterRequiredBehavior
+ commitImmediately={false}
+ isSortable={false}
+ />
+ );
+};
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/index.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/index.ts
new file mode 100644
index 00000000000..9a6a9a80519
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/SqlParametersList/index.ts
@@ -0,0 +1 @@
+export * from "./SqlParametersList";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
index aa542483bdd..7b7796a5a5c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
@@ -14,3 +14,4 @@ export * from "./Title";
export * from "./Visualization";
export * from "./VisualizationButton";
export * from "./QuestionSettings";
+export * from "./SqlParametersList";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
index c017b6d661c..7f8b02761ab 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
@@ -45,6 +45,7 @@ export const SdkQuestionProvider = ({
entityTypes,
targetCollection,
initialSqlParameters,
+ hiddenParameters,
withDownloads,
targetDashboardId,
backToDashboard,
@@ -94,6 +95,7 @@ export const SdkQuestionProvider = ({
const {
question,
originalQuestion,
+ parameterValues,
queryResults,
@@ -104,6 +106,7 @@ export const SdkQuestionProvider = ({
replaceQuestion,
loadAndQueryQuestion,
updateQuestion,
+ updateParameterValues,
navigateToNewCard,
} = useLoadQuestion({
questionId,
@@ -144,6 +147,7 @@ export const SdkQuestionProvider = ({
queryQuestion,
replaceQuestion,
updateQuestion,
+ updateParameterValues,
navigateToNewCard:
userNavigateToNewCard !== undefined
? userNavigateToNewCard
@@ -151,6 +155,7 @@ export const SdkQuestionProvider = ({
plugins,
question,
originalQuestion,
+ parameterValues,
queryResults,
mode,
onSave: handleSave,
@@ -160,6 +165,7 @@ export const SdkQuestionProvider = ({
withDownloads,
onRun,
backToDashboard,
+ hiddenParameters,
onVisualizationChange,
};
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/types.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/types.ts
index 37148c27357..a6827169530 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/types.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/types.ts
@@ -34,6 +34,11 @@ type SdkQuestionConfig = {
**/
initialSqlParameters?: SqlParameterValues;
+ /**
+ * A list of parameters to hide.
+ **/
+ hiddenParameters?: string[];
+
/**
* Enables the ability to download results in the interactive question.
*/
@@ -128,6 +133,7 @@ export type SdkQuestionContextType = Omit<
| "targetCollection"
| "withDownloads"
| "backToDashboard"
+ | "hiddenParameters"
| "onVisualizationChange"
> & {
plugins: SdkQuestionConfig["componentPlugins"] | null;
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts
index c85324b39ca..8cf1f807622 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts
@@ -17,6 +17,7 @@ const propsSchema: Yup.SchemaOf<InteractiveQuestionProps> = Yup.object({
entityTypes: Yup.mixed().optional(),
height: Yup.mixed().optional(),
initialSqlParameters: Yup.mixed().optional(),
+ hiddenParameters: Yup.mixed().optional(),
isSaveEnabled: Yup.mixed().optional(),
onBeforeSave: Yup.mixed().optional(),
onNavigateBack: Yup.mixed().optional(),
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
index 7c5a3cc86f0..c90f84dd7dc 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx
@@ -16,6 +16,7 @@ import {
QuestionVisualization,
SaveButton,
SdkSaveQuestionForm,
+ SqlParametersList,
Summarize,
SummarizeDropdown,
Title,
@@ -67,6 +68,7 @@ export type InteractiveQuestionComponents = {
BreakoutDropdown: typeof BreakoutDropdown;
DownloadWidget: typeof DownloadWidget;
DownloadWidgetDropdown: typeof DownloadWidgetDropdown;
+ SqlParametersList: typeof SqlParametersList;
};
export const _InteractiveQuestion = (props: InteractiveQuestionProps) => (
@@ -97,6 +99,7 @@ const subComponents: InteractiveQuestionComponents = {
DownloadWidget: DownloadWidget,
DownloadWidgetDropdown: DownloadWidgetDropdown,
VisualizationButton: VisualizationButton,
+ SqlParametersList: SqlParametersList,
};
export const InteractiveQuestion = Object.assign(
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.stories.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.stories.tsx
index 15576b8fe7f..e5a0c99ab46 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.stories.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.stories.tsx
@@ -1,4 +1,5 @@
import type { StoryFn } from "@storybook/react";
+import { HttpResponse, http } from "msw";
import type { ComponentProps } from "react";
import { CommonSdkStoryWrapper } from "embedding-sdk-bundle/test/CommonSdkStoryWrapper";
@@ -6,9 +7,18 @@ import {
questionIdArgType,
questionIds,
} from "embedding-sdk-bundle/test/storybook-id-args";
+import { InteractiveQuestion } from "embedding-sdk-package";
import { Box } from "metabase/ui";
+import {
+ createMockNativeCard,
+ createMockNativeDatasetQuery,
+ createMockNativeQuery,
+ createMockParameter,
+} from "metabase-types/api/mocks";
+import { SAMPLE_DB_ID } from "metabase-types/api/mocks/presets";
import { SdkQuestion } from "./SdkQuestion";
+import { nativeQuestionWithParametersData } from "./data/data";
const QUESTION_ID = (window as any).QUESTION_ID || questionIds.numberId;
@@ -84,6 +94,88 @@ export const Default = {
},
};
+export const WithEditableSqlParametersCustomLayout = {
+ render(args: SdkQuestionComponentProps) {
+ return (
+ <Box bg="var(--mb-color-background)" mih="100vh">
+ <SdkQuestion {...args}>
+ <InteractiveQuestion.Title />
+ <InteractiveQuestion.SqlParametersList />
+ <InteractiveQuestion.QuestionVisualization />
+ </SdkQuestion>
+ </Box>
+ );
+ },
+
+ args: {
+ questionId: QUESTION_ID,
+ initialSqlParameters: {
+ State: "AR",
+ },
+ hiddenParameters: ["Source"],
+ },
+
+ parameters: {
+ msw: {
+ handlers: [
+ http.get(`*/api/card/${QUESTION_ID}`, () =>
+ HttpResponse.json(
+ createMockNativeCard({
+ name: "Test Question",
+ display: "table",
+ id: QUESTION_ID,
+ dataset_query: createMockNativeDatasetQuery({
+ native: createMockNativeQuery({
+ query:
+ "SELECT * FROM people WHERE state = {{State}} [[ and city = {{City}} ]] [[ and source = {{Source}} ]]",
+ "template-tags": {
+ State: {
+ type: "text",
+ name: "State",
+ id: "1",
+ "display-name": "State",
+ },
+ City: {
+ type: "text",
+ name: "City",
+ id: "2",
+ "display-name": "City",
+ },
+ Source: {
+ type: "text",
+ name: "Source",
+ id: "3",
+ "display-name": "Source",
+ },
+ },
+ }),
+ database: SAMPLE_DB_ID,
+ }),
+ parameters: [
+ createMockParameter({
+ id: "1",
+ slug: "State",
+ }),
+ createMockParameter({
+ id: "2",
+ slug: "City",
+ }),
+ createMockParameter({
+ id: "3",
+ slug: "Source",
+ }),
+ ],
+ }),
+ ),
+ ),
+ http.post(`*/api/card/${QUESTION_ID}/query`, () =>
+ HttpResponse.json(nativeQuestionWithParametersData),
+ ),
+ ],
+ },
+ },
+};
+
export const EditorOnly = {
render(args: SdkQuestionComponentProps) {
return (
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.tsx
index 104db415ed7..17b7a7bc571 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.tsx
@@ -19,6 +19,7 @@ import {
QuestionVisualization,
SaveButton,
SdkSaveQuestionForm,
+ SqlParametersList,
Summarize,
SummarizeDropdown,
Title,
@@ -110,6 +111,7 @@ export type SdkQuestionComponents = {
BreakoutDropdown: typeof BreakoutDropdown;
DownloadWidget: typeof DownloadWidget;
DownloadWidgetDropdown: typeof DownloadWidgetDropdown;
+ SqlParametersList: typeof SqlParametersList;
};
export const _SdkQuestion = ({
@@ -126,6 +128,7 @@ export const _SdkQuestion = ({
entityTypes,
targetCollection,
initialSqlParameters,
+ hiddenParameters,
withDownloads = false,
targetDashboardId,
backToDashboard,
@@ -154,6 +157,7 @@ export const _SdkQuestion = ({
entityTypes={entityTypes}
targetCollection={targetCollection}
initialSqlParameters={initialSqlParameters}
+ hiddenParameters={hiddenParameters}
withDownloads={withDownloads}
targetDashboardId={targetDashboardId}
backToDashboard={backToDashboard}
@@ -199,6 +203,7 @@ const subComponents: SdkQuestionComponents = {
DownloadWidget: DownloadWidget,
DownloadWidgetDropdown: DownloadWidgetDropdown,
VisualizationButton: VisualizationButton,
+ SqlParametersList: SqlParametersList,
};
export const SdkQuestion = Object.assign(
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/data/data.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/data/data.ts
new file mode 100644
index 00000000000..56d3ec8aed2
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/data/data.ts
@@ -0,0 +1,772 @@
+export const nativeQuestionWithParametersData = {
+ data: {
+ rows: [
+ [
+ 15,
+ "258 Opal Road",
+ "2734ae7a-aa25-4907-9d2e-a6992750db60",
+ "Bertrand Romaguera",
+ "El Paso",
+ -92.0101859,
+ "AR",
+ "Twitter",
+ "2000-02-14T00:00:00Z",
+ "72045",
+ 35.1080351,
+ "2024-12-20T17:50:32.296Z",
+ ],
+ [
+ 25,
+ "1201-2099 Plumberosa Drive",
+ "51421352-6fdf-456e-93c9-41875c275480",
+ "Araceli Stiedemann",
+ "Fayetteville",
+ -94.20265719999999,
+ "AR",
+ "Twitter",
+ "1979-02-05T00:00:00Z",
+ "72701",
+ 36.0479853,
+ "2022-08-16T02:51:36.698Z",
+ ],
+ ],
+ results_timezone: "UTC",
+ download_perms: "full",
+ results_metadata: {
+ columns: [
+ {
+ database_type: "BIGINT",
+ semantic_type: "type/PK",
+ "lib/deduplicated-name": "ID",
+ "lib/original-name": "ID",
+ name: "ID",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ID",
+ {
+ "base-type": "type/BigInteger",
+ },
+ ],
+ effective_type: "type/BigInteger",
+ display_name: "ID",
+ fingerprint: null,
+ base_type: "type/BigInteger",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: null,
+ "lib/deduplicated-name": "ADDRESS",
+ "lib/original-name": "ADDRESS",
+ name: "ADDRESS",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ADDRESS",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "ADDRESS",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 19.163265306122447,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: null,
+ "lib/deduplicated-name": "EMAIL",
+ "lib/original-name": "EMAIL",
+ name: "EMAIL",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "EMAIL",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "EMAIL",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 1,
+ "percent-state": 0,
+ "average-length": 24.26530612244898,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: null,
+ "lib/deduplicated-name": "PASSWORD",
+ "lib/original-name": "PASSWORD",
+ name: "PASSWORD",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "PASSWORD",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "PASSWORD",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 36,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: "type/Name",
+ "lib/deduplicated-name": "NAME",
+ "lib/original-name": "NAME",
+ name: "NAME",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "NAME",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "NAME",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 13.816326530612244,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: "type/City",
+ "lib/deduplicated-name": "CITY",
+ "lib/original-name": "CITY",
+ name: "CITY",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "CITY",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "CITY",
+ fingerprint: {
+ global: {
+ "distinct-count": 44,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 8.551020408163266,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DOUBLE PRECISION",
+ semantic_type: "type/Longitude",
+ "lib/deduplicated-name": "LONGITUDE",
+ "lib/original-name": "LONGITUDE",
+ name: "LONGITUDE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "LONGITUDE",
+ {
+ "base-type": "type/Float",
+ },
+ ],
+ effective_type: "type/Float",
+ display_name: "LONGITUDE",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Number": {
+ min: -94.5138154,
+ q1: -93.53949217499999,
+ q3: -91.599448025,
+ max: -90.246799,
+ sd: 1.1850640123925205,
+ avg: -92.42678023265306,
+ },
+ },
+ },
+ base_type: "type/Float",
+ },
+ {
+ database_type: "CHARACTER",
+ semantic_type: null,
+ "lib/deduplicated-name": "STATE",
+ "lib/original-name": "STATE",
+ name: "STATE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "STATE",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "STATE",
+ fingerprint: {
+ global: {
+ "distinct-count": 1,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 1,
+ "average-length": 2,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ semantic_type: "type/Source",
+ "lib/deduplicated-name": "SOURCE",
+ "lib/original-name": "SOURCE",
+ name: "SOURCE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "SOURCE",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "SOURCE",
+ fingerprint: {
+ global: {
+ "distinct-count": 5,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 7.26530612244898,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DATE",
+ semantic_type: null,
+ "lib/deduplicated-name": "BIRTH_DATE",
+ "lib/original-name": "BIRTH_DATE",
+ name: "BIRTH_DATE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "BIRTH_DATE",
+ {
+ "base-type": "type/Date",
+ },
+ ],
+ effective_type: "type/Date",
+ display_name: "BIRTH_DATE",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/DateTime": {
+ earliest: "1960-01-13",
+ latest: "2000-02-14",
+ },
+ },
+ },
+ base_type: "type/Date",
+ },
+ {
+ database_type: "CHARACTER",
+ semantic_type: null,
+ "lib/deduplicated-name": "ZIP",
+ "lib/original-name": "ZIP",
+ name: "ZIP",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ZIP",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "ZIP",
+ fingerprint: {
+ global: {
+ "distinct-count": 44,
+ "nil%": 0,
+ },
+ type: {
+ "type/Text": {
+ "percent-json": 0,
+ "percent-url": 0,
+ "percent-email": 0,
+ "percent-state": 0,
+ "average-length": 5,
+ },
+ },
+ },
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DOUBLE PRECISION",
+ semantic_type: "type/Latitude",
+ "lib/deduplicated-name": "LATITUDE",
+ "lib/original-name": "LATITUDE",
+ name: "LATITUDE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "LATITUDE",
+ {
+ "base-type": "type/Float",
+ },
+ ],
+ effective_type: "type/Float",
+ display_name: "LATITUDE",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/Number": {
+ min: 33.1818402,
+ q1: 33.96992525,
+ q3: 35.808187849999996,
+ max: 36.4587022,
+ sd: 1.0305278500002746,
+ avg: 34.88922432653061,
+ },
+ },
+ },
+ base_type: "type/Float",
+ },
+ {
+ database_type: "TIMESTAMP",
+ semantic_type: "type/CreationTimestamp",
+ "lib/deduplicated-name": "CREATED_AT",
+ "lib/original-name": "CREATED_AT",
+ name: "CREATED_AT",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "CREATED_AT",
+ {
+ "base-type": "type/DateTime",
+ },
+ ],
+ effective_type: "type/DateTime",
+ display_name: "CREATED_AT",
+ fingerprint: {
+ global: {
+ "distinct-count": 49,
+ "nil%": 0,
+ },
+ type: {
+ "type/DateTime": {
+ earliest: "2022-05-19T05:23:03.686Z",
+ latest: "2025-03-01T08:21:10.872Z",
+ },
+ },
+ },
+ base_type: "type/DateTime",
+ },
+ ],
+ },
+ "format-rows?": true,
+ "pivot-export-options": {
+ "show-row-totals": true,
+ "show-column-totals": true,
+ },
+ cols: [
+ {
+ database_type: "BIGINT",
+ "lib/deduplicated-name": "ID",
+ "lib/original-name": "ID",
+ name: "ID",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ID",
+ {
+ "base-type": "type/BigInteger",
+ },
+ ],
+ effective_type: "type/BigInteger",
+ display_name: "ID",
+ base_type: "type/BigInteger",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "ADDRESS",
+ "lib/original-name": "ADDRESS",
+ name: "ADDRESS",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ADDRESS",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "ADDRESS",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "EMAIL",
+ "lib/original-name": "EMAIL",
+ name: "EMAIL",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "EMAIL",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "EMAIL",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "PASSWORD",
+ "lib/original-name": "PASSWORD",
+ name: "PASSWORD",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "PASSWORD",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "PASSWORD",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "NAME",
+ "lib/original-name": "NAME",
+ name: "NAME",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "NAME",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "NAME",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "CITY",
+ "lib/original-name": "CITY",
+ name: "CITY",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "CITY",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "CITY",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DOUBLE PRECISION",
+ "lib/deduplicated-name": "LONGITUDE",
+ "lib/original-name": "LONGITUDE",
+ name: "LONGITUDE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "LONGITUDE",
+ {
+ "base-type": "type/Float",
+ },
+ ],
+ effective_type: "type/Float",
+ display_name: "LONGITUDE",
+ base_type: "type/Float",
+ },
+ {
+ database_type: "CHARACTER",
+ "lib/deduplicated-name": "STATE",
+ "lib/original-name": "STATE",
+ name: "STATE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "STATE",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "STATE",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "CHARACTER VARYING",
+ "lib/deduplicated-name": "SOURCE",
+ "lib/original-name": "SOURCE",
+ name: "SOURCE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "SOURCE",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "SOURCE",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DATE",
+ "lib/deduplicated-name": "BIRTH_DATE",
+ "lib/original-name": "BIRTH_DATE",
+ name: "BIRTH_DATE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "BIRTH_DATE",
+ {
+ "base-type": "type/Date",
+ },
+ ],
+ effective_type: "type/Date",
+ display_name: "BIRTH_DATE",
+ base_type: "type/Date",
+ },
+ {
+ database_type: "CHARACTER",
+ "lib/deduplicated-name": "ZIP",
+ "lib/original-name": "ZIP",
+ name: "ZIP",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "ZIP",
+ {
+ "base-type": "type/Text",
+ },
+ ],
+ effective_type: "type/Text",
+ display_name: "ZIP",
+ base_type: "type/Text",
+ },
+ {
+ database_type: "DOUBLE PRECISION",
+ "lib/deduplicated-name": "LATITUDE",
+ "lib/original-name": "LATITUDE",
+ name: "LATITUDE",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "LATITUDE",
+ {
+ "base-type": "type/Float",
+ },
+ ],
+ effective_type: "type/Float",
+ display_name: "LATITUDE",
+ base_type: "type/Float",
+ },
+ {
+ database_type: "TIMESTAMP",
+ "lib/deduplicated-name": "CREATED_AT",
+ "lib/original-name": "CREATED_AT",
+ name: "CREATED_AT",
+ "lib/source": "source/native",
+ source: "native",
+ field_ref: [
+ "field",
+ "CREATED_AT",
+ {
+ "base-type": "type/DateTime",
+ },
+ ],
+ effective_type: "type/DateTime",
+ display_name: "CREATED_AT",
+ base_type: "type/DateTime",
+ },
+ ],
+ native_form: {
+ "lib/type": "mbql.stage/native",
+ params: ["AR"],
+ query: "SELECT\n *\nFROM\n people\nWHERE\n state = ?",
+ },
+ is_sandboxed: false,
+ insights: null,
+ },
+ cached: null,
+ database_id: 1,
+ started_at: "2025-09-29T05:53:34.028607Z",
+ json_query: {
+ constraints: {
+ "max-results": 10000,
+ "max-results-bare-rows": 2000,
+ },
+ type: "native",
+ middleware: {
+ "js-int-to-string?": true,
+ "ignore-cached-results?": false,
+ "process-viz-settings?": false,
+ "userland-query?": true,
+ },
+ "cache-strategy": null,
+ native: {
+ "template-tags": {
+ State: {
+ type: "text",
+ name: "State",
+ id: "92792d2c-9c80-4174-ae55-a2f521e4d080",
+ "display-name": "State",
+ },
+ city: {
+ type: "text",
+ name: "city",
+ id: "370cc09b-d3f7-47e4-b062-391fb6f3b0f2",
+ "display-name": "City",
+ },
+ },
+ query:
+ "SELECT\n *\nFROM\n people\nWHERE\n state = {{State}} [[ and city = {{city}} ]]",
+ },
+ "viz-settings": {
+ "table.pivot_column": "COUNT(*)",
+ },
+ database: 1,
+ parameters: [
+ {
+ id: "92792d2c-9c80-4174-ae55-a2f521e4d080",
+ type: "string/=",
+ target: ["variable", ["template-tag", "State"]],
+ value: ["AR"],
+ },
+ {
+ id: "370cc09b-d3f7-47e4-b062-391fb6f3b0f2",
+ type: "string/=",
+ target: ["variable", ["template-tag", "city"]],
+ value: null,
+ },
+ ],
+ },
+ average_execution_time: null,
+ status: "completed",
+ context: "question",
+ row_count: 49,
+ running_time: 36,
+};
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts
index 2dcc0bfd346..5e650297e1c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts
@@ -9,6 +9,7 @@ const propsSchema: Yup.SchemaOf<StaticQuestionProps> = Yup.object({
className: Yup.mixed().optional(),
height: Yup.mixed().optional(),
initialSqlParameters: Yup.mixed().optional(),
+ hiddenParameters: Yup.mixed().optional(),
questionId: Yup.mixed().required(),
style: Yup.mixed().optional(),
title: Yup.mixed().optional(),
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx
index c3de9dad4be..2f149839bb8 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx
@@ -14,6 +14,7 @@ import {
QuestionSettings,
QuestionSettingsDropdown,
QuestionVisualization,
+ SqlParametersList,
Summarize,
SummarizeDropdown,
Title,
@@ -46,6 +47,7 @@ export type StaticQuestionProps = PropsWithChildren<
| "className"
| "style"
| "initialSqlParameters"
+ | "hiddenParameters"
| "withDownloads"
| "title"
>
@@ -70,6 +72,7 @@ export type StaticQuestionComponents = {
BreakoutDropdown: typeof BreakoutDropdown;
DownloadWidget: typeof DownloadWidget;
DownloadWidgetDropdown: typeof DownloadWidgetDropdown;
+ SqlParametersList: typeof SqlParametersList;
};
const _StaticQuestion = ({
@@ -80,6 +83,7 @@ const _StaticQuestion = ({
className,
style,
initialSqlParameters,
+ hiddenParameters,
withDownloads,
title = false, // Hidden by default for backwards-compatibility.
children,
@@ -104,6 +108,7 @@ const _StaticQuestion = ({
getClickActionMode={getClickActionMode}
navigateToNewCard={null}
initialSqlParameters={initialSqlParameters}
+ hiddenParameters={hiddenParameters}
withDownloads={withDownloads}
>
{children ?? (
@@ -152,6 +157,7 @@ const subComponents: StaticQuestionComponents = {
BreakoutDropdown: BreakoutDropdown,
DownloadWidget: DownloadWidget,
DownloadWidgetDropdown: DownloadWidgetDropdown,
+ SqlParametersList: SqlParametersList,
};
export const StaticQuestion = Object.assign(_StaticQuestion, subComponents, {
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-load-question.ts b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-load-question.ts
index 8d77379faad..e9053c85e06 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-load-question.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-load-question.ts
@@ -16,6 +16,7 @@ import type {
} from "embedding-sdk-bundle/types/question";
import { type Deferred, defer } from "metabase/lib/promise";
import type Question from "metabase-lib/v1/Question";
+import type { ParameterValuesMap } from "metabase-types/api";
import { isObject } from "metabase-types/guards";
type LoadQuestionResult = Promise<
@@ -25,6 +26,7 @@ type LoadQuestionResult = Promise<
export interface LoadQuestionHookResult {
question?: Question;
originalQuestion?: Question;
+ parameterValues?: ParameterValuesMap;
queryResults?: any[];
@@ -39,6 +41,7 @@ export interface LoadQuestionHookResult {
question: Question,
options?: { run?: boolean },
): Promise<void>;
+ updateParameterValues(parameterValues: ParameterValuesMap): Promise<void>;
/**
* Replaces both the question and originalQuestion object directly.
@@ -64,7 +67,8 @@ export function useLoadQuestion({
// Keep track of the latest question and query results.
// They can be updated from the below actions.
const [questionState, mergeQuestionState] = useReducer(questionReducer, {});
- const { question, originalQuestion, queryResults } = questionState;
+ const { question, originalQuestion, queryResults, parameterValues } =
+ questionState;
const deferredRef = useRef<Deferred>();
@@ -126,6 +130,7 @@ export function useLoadQuestion({
question: undefined,
originalQuestion: undefined,
queryResults: undefined,
+ parameterValues: undefined,
});
setIsQuestionLoading(false);
@@ -169,16 +174,47 @@ export function useLoadQuestion({
nextQuestion,
previousQuestion: question,
originalQuestion,
+ nextParameterValues: parameterValues ?? {},
cancelDeferred: deferred(),
optimisticUpdateQuestion: (question) =>
mergeQuestionState({ question }),
shouldRunQueryOnQuestionChange: run,
+ shouldStartAdHocQuestion: true,
}),
);
mergeQuestionState(state);
},
- [dispatch, question, originalQuestion],
+ [dispatch, question, originalQuestion, parameterValues],
+ );
+
+ const [updateParameterValuesState, updateParameterValues] = useAsyncFn(
+ async (nextParameterValues: ParameterValuesMap) => {
+ if (!question) {
+ return;
+ }
+
+ mergeQuestionState({
+ parameterValues: nextParameterValues,
+ });
+
+ const state = await dispatch(
+ updateQuestionSdk({
+ nextQuestion: question,
+ previousQuestion: question,
+ originalQuestion,
+ nextParameterValues,
+ cancelDeferred: deferred(),
+ optimisticUpdateQuestion: (question) =>
+ mergeQuestionState({ question }),
+ shouldRunQueryOnQuestionChange: true,
+ shouldStartAdHocQuestion: false,
+ }),
+ );
+
+ mergeQuestionState(state);
+ },
+ [dispatch, question, originalQuestion, parameterValues],
);
const [navigateToNewCardState, navigateToNewCard] = useAsyncFn(
@@ -205,6 +241,7 @@ export function useLoadQuestion({
const isQueryRunning =
runQuestionState.loading ||
updateQuestionState.loading ||
+ updateParameterValuesState.loading ||
navigateToNewCardState.loading;
const replaceQuestion = (question: Question) =>
@@ -213,6 +250,7 @@ export function useLoadQuestion({
return {
question,
originalQuestion,
+ parameterValues,
queryResults,
@@ -223,6 +261,7 @@ export function useLoadQuestion({
replaceQuestion,
loadAndQueryQuestion,
updateQuestion,
+ updateParameterValues,
navigateToNewCard,
};
}
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts
index f6c58be60bb..5da41793c6c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/load-question.ts
@@ -1,6 +1,9 @@
import _ from "underscore";
-import type { LoadSdkQuestionParams } from "embedding-sdk-bundle/types/question";
+import type {
+ LoadSdkQuestionParams,
+ SdkQuestionState,
+} from "embedding-sdk-bundle/types/question";
import { resolveCards } from "metabase/query_builder/actions";
import { getParameterValuesForQuestion } from "metabase/query_builder/actions/core/parameterUtils";
import { loadMetadataForCard } from "metabase/questions/actions";
@@ -19,7 +22,10 @@ export const loadQuestionSdk =
async (
dispatch: Dispatch,
getState: GetState,
- ): Promise<{ question: Question; originalQuestion?: Question }> => {
+ ): Promise<
+ Required<Pick<SdkQuestionState, "question">> &
+ Pick<SdkQuestionState, "originalQuestion" | "parameterValues">
+ > => {
const questionId = initQuestionId === "new" ? undefined : initQuestionId;
const { card, originalCard } = await resolveCards({
@@ -57,5 +63,5 @@ export const loadQuestionSdk =
question = question.setParameterValues(parameterValues);
}
- return { question, originalQuestion };
+ return { question, originalQuestion, parameterValues };
};
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/update-question.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/update-question.ts
index 5357e803337..0781a99e8bc 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/update-question.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/sdk-question/update-question.ts
@@ -9,6 +9,7 @@ import { loadMetadataForCard } from "metabase/questions/actions";
import { getMetadata } from "metabase/selectors/metadata";
import * as Lib from "metabase-lib";
import Question from "metabase-lib/v1/Question";
+import type { ParameterValuesMap } from "metabase-types/api";
import type { Dispatch, GetState } from "metabase-types/store";
import { runQuestionQuerySdk } from "./run-question-query";
@@ -17,7 +18,20 @@ interface UpdateQuestionParams {
previousQuestion: Question;
nextQuestion: Question;
originalQuestion?: Question;
- shouldStartAdHocQuestion?: boolean;
+ nextParameterValues: ParameterValuesMap;
+
+ /**
+ * When the question change is due to a drill thru action, it must be set to `true`
+ * It includes everything that calls the `dataset` endpoint that accepts the `query` in payload:
+ * - drills when clicking in a visualization
+ * - filters
+ * - breakouts
+ *
+ * For cases when the update change must call the `query` endpoint, it must be set to `false`:
+ * - sql parameters change
+ **/
+ shouldStartAdHocQuestion: boolean;
+
queryResults?: any[];
cancelDeferred?: Deferred;
@@ -35,7 +49,8 @@ export const updateQuestionSdk =
previousQuestion,
nextQuestion,
originalQuestion,
- shouldStartAdHocQuestion = true,
+ nextParameterValues,
+ shouldStartAdHocQuestion,
cancelDeferred,
queryResults,
optimisticUpdateQuestion: onQuestionChange,
@@ -96,7 +111,11 @@ export const updateQuestionSdk =
}
const metadata = getMetadata(getState());
- nextQuestion = new Question(nextQuestion.card(), metadata);
+ nextQuestion = new Question(
+ nextQuestion.card(),
+ metadata,
+ nextParameterValues,
+ );
// In most cases, we only update the question when the query change.
// We don't usually run the query right away unless specified.
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/question.ts b/enterprise/frontend/src/embedding-sdk-bundle/types/question.ts
index dde913d741d..e2bbc68c6e9 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/types/question.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/types/question.ts
@@ -4,7 +4,7 @@ import type { Deferred } from "metabase/lib/promise";
import type { QueryParams } from "metabase/query_builder/actions";
import type { ObjectId } from "metabase/visualizations/components/ObjectDetail/types";
import type InternalQuestion from "metabase-lib/v1/Question";
-import type { Card } from "metabase-types/api";
+import type { Card, ParameterValuesMap } from "metabase-types/api";
import type { SdkDashboardId } from "./dashboard";
import type { SdkEntityId } from "./entity-id";
@@ -17,6 +17,7 @@ export interface SdkQuestionState {
question?: InternalQuestion;
originalQuestion?: InternalQuestion;
queryResults?: any[];
+ parameterValues?: ParameterValuesMap;
}
export type LoadSdkQuestionParams = {
diff --git a/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx b/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
index 39c49f0dbb1..7c53029a63b 100644
--- a/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-package/components/public/InteractiveQuestion/InteractiveQuestion.tsx
@@ -117,6 +117,11 @@ const subComponents: InteractiveQuestionComponents = {
getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.InteractiveQuestion
?.VisualizationButton,
),
+ SqlParametersList: createComponent(
+ () =>
+ getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.InteractiveQuestion
+ ?.SqlParametersList,
+ ),
};
/**
diff --git a/enterprise/frontend/src/embedding-sdk-package/components/public/StaticQuestion/StaticQuestion.tsx b/enterprise/frontend/src/embedding-sdk-package/components/public/StaticQuestion/StaticQuestion.tsx
index fc0a9d575c8..34e5f19cb38 100644
--- a/enterprise/frontend/src/embedding-sdk-package/components/public/StaticQuestion/StaticQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-package/components/public/StaticQuestion/StaticQuestion.tsx
@@ -73,6 +73,11 @@ const subComponents: StaticQuestionComponents = {
getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.StaticQuestion
?.DownloadWidgetDropdown,
),
+ SqlParametersList: createComponent(
+ () =>
+ getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.StaticQuestion
+ ?.SqlParametersList,
+ ),
};
/**
diff --git a/frontend/src/metabase/parameters/components/ParameterWidget/ParameterWidget.tsx b/frontend/src/metabase/parameters/components/ParameterWidget/ParameterWidget.tsx
index 6d70d260b19..0e75171a504 100644
--- a/frontend/src/metabase/parameters/components/ParameterWidget/ParameterWidget.tsx
+++ b/frontend/src/metabase/parameters/components/ParameterWidget/ParameterWidget.tsx
@@ -79,7 +79,8 @@ export const ParameterWidget = ({
const [isFocused, setIsFocused] = useState(false);
const isEditingParameter = editingParameter?.id === parameter.id;
const wasEditingParameter = usePrevious(isEditingParameter);
- const fieldHasValueOrFocus = parameter.value != null || isFocused;
+ const isEmptyValue = parameter.value == null || parameter.value === "";
+ const fieldHasValueOrFocus = !isEmptyValue || isFocused;
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
diff --git a/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.tsx b/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.tsx
index 8747db6883a..e27585f281d 100644
--- a/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.tsx
+++ b/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.tsx
@@ -91,10 +91,7 @@ export class TextWidget extends Component<TextWidgetProps, State> {
return;
}
const target = e.target as HTMLInputElement;
- if (e.key === "Escape") {
- target.blur();
- } else if (e.key === "Enter") {
- setValue(this.state.value ?? null);
+ if (e.key === "Enter") {
target.blur();
}
}}
diff --git a/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.unit.spec.tsx b/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.unit.spec.tsx
index 21acde78ddc..2583ebcb04d 100644
--- a/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.unit.spec.tsx
+++ b/frontend/src/metabase/parameters/components/widgets/TextWidget/TextWidget.unit.spec.tsx
@@ -5,10 +5,25 @@ import { fireEvent, render, screen } from "__support__/ui";
import { TextWidget } from "./TextWidget";
-const TextInputWithStateWrapper = ({ value }: { value?: number | string }) => {
+const TextInputWithStateWrapper = ({
+ value,
+ onChange,
+ focusChanged,
+}: {
+ value?: number | string;
+ onChange?: (value: string | number | null) => void;
+ focusChanged?: (focused: boolean) => void;
+}) => {
const [val, setVal] = useState<number | string | null>(value ?? "");
return (
- <TextWidget value={val ?? ""} setValue={setVal} focusChanged={jest.fn()} />
+ <TextWidget
+ value={val ?? ""}
+ setValue={(value) => {
+ setVal(value);
+ onChange?.(value);
+ }}
+ focusChanged={focusChanged ?? jest.fn()}
+ />
);
};
@@ -64,4 +79,35 @@ describe("TextWidget", () => {
await userEvent.type(textbox, "0{enter}");
expect(textbox).toHaveValue("0");
});
+
+ it("should not call setValue twice when pressing enter", async () => {
+ const onChangeSpy = jest.fn();
+
+ render(<TextInputWithStateWrapper onChange={onChangeSpy} />);
+
+ const textbox = screen.getByRole("textbox");
+
+ await userEvent.type(textbox, "0{enter}");
+
+ expect(onChangeSpy).toHaveBeenCalledTimes(1);
+ });
+
+ it("should not call handlers when pressing `esc`", async () => {
+ const onChangeSpy = jest.fn();
+ const focusChangedSpy = jest.fn();
+
+ render(
+ <TextInputWithStateWrapper
+ onChange={onChangeSpy}
+ focusChanged={focusChangedSpy}
+ />,
+ );
+
+ const textbox = screen.getByRole("textbox");
+
+ await userEvent.type(textbox, "Foo{esc}");
+
+ expect(onChangeSpy).toHaveBeenCalledTimes(0);
+ expect(focusChangedSpy).not.toHaveBeenCalledWith(false);
+ });
});
diff --git a/frontend/src/metabase/public/lib/types.ts b/frontend/src/metabase/public/lib/types.ts
index 6c94725f48e..be371336302 100644
--- a/frontend/src/metabase/public/lib/types.ts
+++ b/frontend/src/metabase/public/lib/types.ts
@@ -33,7 +33,10 @@ export type EmbeddingParameterVisibility = "disabled" | "enabled" | "locked";
export type EmbeddingParameters = Record<string, EmbeddingParameterVisibility>;
-export type EmbeddingParametersValues = Record<string, string>;
+export type EmbeddingParametersValues = Record<
+ string,
+ number | string | string[] | null | undefined
+>;
/**
* This is a type for all the display options in static embedding sharing modal's Look and Feel tab.
diff --git a/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx b/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx
index 2e5f19867df..362d23cb9b2 100644
--- a/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx
+++ b/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx
@@ -11,21 +11,27 @@ import ResponsiveParametersListS from "./ResponsiveParametersList.module.css";
import { SyncedParametersList } from "./SyncedParametersList";
interface ResponsiveParametersListProps {
+ className?: string;
cardId?: CardId;
dashboardId?: DashboardId;
parameters: Parameter[];
setParameterValue: (parameterId: string, value: string) => void;
- setParameterIndex: (parameterId: string, parameterIndex: number) => void;
+ setParameterIndex?: (parameterId: string, parameterIndex: number) => void;
enableParameterRequiredBehavior: boolean;
+ commitImmediately?: boolean;
+ isSortable?: boolean;
}
export const ResponsiveParametersList = ({
+ className,
cardId,
dashboardId,
parameters,
setParameterValue,
setParameterIndex,
enableParameterRequiredBehavior,
+ commitImmediately = true,
+ isSortable,
}: ResponsiveParametersListProps) => {
const [mobileShowParameterList, setShowMobileParameterList] = useState(false);
const isSmallScreen = useIsSmallScreen();
@@ -79,7 +85,10 @@ export const ResponsiveParametersList = ({
</Flex>
)}
<SyncedParametersList
- className={ResponsiveParametersListS.StyledParametersList}
+ className={cx(
+ ResponsiveParametersListS.StyledParametersList,
+ className,
+ )}
cardId={cardId}
dashboardId={dashboardId}
parameters={parameters}
@@ -87,7 +96,8 @@ export const ResponsiveParametersList = ({
setParameterIndex={setParameterIndex}
enableParameterRequiredBehavior={enableParameterRequiredBehavior}
isEditing
- commitImmediately
+ isSortable={isSortable}
+ commitImmediately={commitImmediately}
/>
</Box>
</Box>
diff --git a/frontend/src/metabase/query_builder/components/SyncedParametersList.tsx b/frontend/src/metabase/query_builder/components/SyncedParametersList.tsx
index 5c1d6095dd9..8f890e63b52 100644
--- a/frontend/src/metabase/query_builder/components/SyncedParametersList.tsx
+++ b/frontend/src/metabase/query_builder/components/SyncedParametersList.tsx
@@ -22,6 +22,7 @@ export const SyncedParametersList = ({
isFullscreen,
isNightMode,
isEditing,
+ isSortable,
commitImmediately,
setParameterValue,
@@ -49,6 +50,7 @@ export const SyncedParametersList = ({
editingParameter={editingParameter}
isFullscreen={isFullscreen}
isNightMode={isNightMode}
+ isSortable={isSortable}
hideParameters={hideParameters}
isEditing={isEditing}
commitImmediately={commitImmediately}