Skip to content

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

Read a card's UI parameters off the question (#82466)

Romeo Van Snick86a761845ac7
diff --git a/frontend/src/metabase-lib/v1/Question.ts b/frontend/src/metabase-lib/v1/Question.ts
index 646a6fde26e..efdd60a64d4 100644
--- a/frontend/src/metabase-lib/v1/Question.ts
+++ b/frontend/src/metabase-lib/v1/Question.ts
@@ -610,11 +610,7 @@ class Question {
parameters(): ParameterObject[] {
if (this._parameters == null) {
- this._parameters = getCardUiParameters(
- this.card(),
- this.metadata(),
- this._parameterValues,
- );
+ this._parameters = getCardUiParameters(this, this._parameterValues);
}
return this._parameters;
}
diff --git a/frontend/src/metabase-lib/v1/parameters/utils/cards.ts b/frontend/src/metabase-lib/v1/parameters/utils/cards.ts
index c44ee4a33f2..61abdd72708 100644
--- a/frontend/src/metabase-lib/v1/parameters/utils/cards.ts
+++ b/frontend/src/metabase-lib/v1/parameters/utils/cards.ts
@@ -1,7 +1,6 @@
import _ from "underscore";
-import Question from "metabase-lib/v1/Question";
-import type Metadata from "metabase-lib/v1/metadata/Metadata";
+import type Question from "metabase-lib/v1/Question";
import type {
ParameterWithTarget,
UiParameter,
@@ -18,11 +17,11 @@ import type {
import { isDimensionTarget } from "metabase-types/guards";
export function getCardUiParameters(
- card: SeriesCard,
- metadata: Metadata,
+ question: Question,
parameterValues: ParameterValuesMap = {},
- parameters = getParametersFromCard(card, metadata),
+ parameters = getParametersFromCard(question.card(), question.metadata()),
): UiParameter[] {
+ const card = question.card();
if (!card) {
return [];
}
@@ -35,7 +34,7 @@ export function getCardUiParameters(
return hasParamFields(card)
? getSavedCardUiParameters(card, valuePopulatedParameters)
- : getUnsavedCardUiParameters(card, metadata, valuePopulatedParameters);
+ : getUnsavedCardUiParameters(question, valuePopulatedParameters);
}
/**
@@ -82,12 +81,9 @@ function getSavedCardUiParameters(
* against the query.
*/
function getUnsavedCardUiParameters(
- card: SeriesCard,
- metadata: Metadata,
+ question: Question,
parameters: Parameter[] | ParameterWithTarget[],
): UiParameter[] {
- const question = new Question(card, metadata);
-
return parameters.map((parameter) => {
const target = getParameterTarget(parameter);
const field =
diff --git a/frontend/src/metabase-lib/v1/parameters/utils/cards.unit.spec.ts b/frontend/src/metabase-lib/v1/parameters/utils/cards.unit.spec.ts
index fa42dd701ab..3127f790e60 100644
--- a/frontend/src/metabase-lib/v1/parameters/utils/cards.unit.spec.ts
+++ b/frontend/src/metabase-lib/v1/parameters/utils/cards.unit.spec.ts
@@ -52,8 +52,7 @@ describe("parameters/utils/cards", () => {
});
const [dateUiParameter, variableUiParameter] = getCardUiParameters(
- card,
- createMockMetadata({}),
+ new Question(card, createMockMetadata({})),
);
expect(dateUiParameter).toMatchObject({
@@ -79,8 +78,7 @@ describe("parameters/utils/cards", () => {
});
const [dateUiParameter] = getCardUiParameters(
- card,
- createMockMetadata({ fields: [] }),
+ new Question(card, createMockMetadata({ fields: [] })),
);
expect(dateUiParameter).toMatchObject({
@@ -99,8 +97,7 @@ describe("parameters/utils/cards", () => {
});
const [quantityUiParameter] = getCardUiParameters(
- card,
- SAMPLE_METADATA,
+ new Question(card, SAMPLE_METADATA),
);
expect(quantityUiParameter).toMatchObject({
@@ -118,9 +115,10 @@ describe("parameters/utils/cards", () => {
param_fields: {},
});
- const [dateUiParameter] = getCardUiParameters(card, metadata, {
- [dateParameter.id]: "2026-01-01",
- });
+ const [dateUiParameter] = getCardUiParameters(
+ new Question(card, metadata),
+ { [dateParameter.id]: "2026-01-01" },
+ );
expect(dateUiParameter).toMatchObject({
id: dateParameter.id,
@@ -140,8 +138,7 @@ describe("parameters/utils/cards", () => {
});
const [quantityUiParameter] = getCardUiParameters(
- card,
- SAMPLE_METADATA,
+ new Question(card, SAMPLE_METADATA),
);
expect(quantityUiParameter).toMatchObject({
@@ -161,8 +158,7 @@ describe("parameters/utils/cards", () => {
});
const [quantityUiParameter] = getCardUiParameters(
- card,
- SAMPLE_METADATA,
+ new Question(card, SAMPLE_METADATA),
);
expect(quantityUiParameter).toMatchObject({
@@ -184,7 +180,9 @@ describe("parameters/utils/cards", () => {
},
});
- const [dateUiParameter] = getCardUiParameters(card, metadata);
+ const [dateUiParameter] = getCardUiParameters(
+ new Question(card, metadata),
+ );
expect(dateUiParameter).toMatchObject({
id: dateParameter.id,
@@ -198,7 +196,7 @@ describe("parameters/utils/cards", () => {
const metadata = createMockMetadata({});
const card = createMockCard({ parameters: undefined });
- expect(getCardUiParameters(card, metadata)).toEqual([]);
+ expect(getCardUiParameters(new Question(card, metadata))).toEqual([]);
});
// Callers that hold a Question read its `parameters()` rather than calling
@@ -229,12 +227,7 @@ describe("parameters/utils/cards", () => {
// Guards the comparison below: two empty arrays would also match.
expect(viaQuestion).toHaveLength(1);
expect(
- getCardUiParameters(
- card,
- SAMPLE_METADATA,
- values,
- question.parameters(),
- ),
+ getCardUiParameters(question, values, question.parameters()),
).toEqual(viaQuestion);
});
});
diff --git a/frontend/src/metabase/embedding/mcp/McpUiAppRoute.utils.unit.spec.ts b/frontend/src/metabase/embedding/mcp/McpUiAppRoute.utils.unit.spec.ts
index e3f8adfbf52..6e876cef03e 100644
--- a/frontend/src/metabase/embedding/mcp/McpUiAppRoute.utils.unit.spec.ts
+++ b/frontend/src/metabase/embedding/mcp/McpUiAppRoute.utils.unit.spec.ts
@@ -124,7 +124,7 @@ describe("getMcpDeserializedQuery", () => {
const card = deserialized!.card;
const metadata = createMockMetadata({});
- const uiParameters = getCardUiParameters(card, metadata);
+ const uiParameters = getCardUiParameters(new Question(card, metadata));
expect(uiParameters.map((parameter) => parameter.slug)).toEqual(["cat"]);
const parameterValues = getParameterValuesByIdFromQueryParams(