Skip to content
Snippets Groups Projects
Unverified Commit 859f8a2c authored by Dalton's avatar Dalton Committed by GitHub
Browse files

fix issue with missing parameter options in cloned, targeted dashboard (#22289)

* fix issue with missing parameter options in cloned, targeted dashboard

* Fix unit tests
parent 096d0e4b
No related branches found
No related tags found
No related merge requests found
......@@ -33,11 +33,13 @@ import { getParameters } from "metabase/dashboard/selectors";
)
.filter(mapping => getIn(mapping, ["source", "type"]) === "parameter")
.map(mapping => mapping.source.id);
parameters = parameters.filter(p => parametersUsedAsSources.includes(p.id));
parameters = parameters.filter(p => {
return parametersUsedAsSources.includes(p.id);
});
}
const [setTargets, unsetTargets] = _.partition(
getTargetsWithSourceFilters({ isDash, object, metadata }),
getTargetsWithSourceFilters({ isDash, dashcard, object, metadata }),
({ id }) =>
getIn(clickBehavior, ["parameterMapping", id, "source"]) != null,
);
......
......@@ -72,9 +72,14 @@ function notRelativeDateOrRange({ type }) {
return type !== "date/range" && type !== "date/relative";
}
export function getTargetsWithSourceFilters({ isDash, object, metadata }) {
export function getTargetsWithSourceFilters({
isDash,
dashcard,
object,
metadata,
}) {
return isDash
? getTargetsForDashboard(object)
? getTargetsForDashboard(object, dashcard)
: getTargetsForQuestion(object, metadata);
}
......@@ -128,7 +133,7 @@ function getTargetsForQuestion(question, metadata) {
});
}
function getTargetsForDashboard(dashboard) {
function getTargetsForDashboard(dashboard, dashcard) {
return dashboard.parameters.map(parameter => {
const { type, id, name } = parameter;
const filter = baseTypeFilterForParameterType(type);
......@@ -138,9 +143,14 @@ function getTargetsForDashboard(dashboard) {
target: { type: "parameter", id },
sourceFilters: {
column: c => notRelativeDateOrRange(parameter) && filter(c.base_type),
parameter: sourceParam =>
parameter.type === sourceParam.type &&
parameter.id !== sourceParam.id,
parameter: sourceParam => {
// parameter IDs are generated client-side, so they might not be unique
// if dashboard is a clone, it will have identical parameter IDs to the original
const isSameParameter =
dashboard.id === dashcard.dashboard_id &&
parameter.id === sourceParam.id;
return parameter.type === sourceParam.type && !isSameParameter;
},
userAttribute: () => !parameter.type.startsWith("date"),
},
};
......
......@@ -66,6 +66,9 @@ describe("metabase/lib/click-behavior", () => {
const [{ id, name, target }] = getTargetsWithSourceFilters({
isDash: true,
object: { parameters: [parameter] },
dashcard: {
dashboard_id: 111,
},
});
expect(id).toEqual("foo123");
expect(name).toEqual("My Param");
......@@ -219,6 +222,9 @@ describe("metabase/lib/click-behavior", () => {
const [{ sourceFilters }] = getTargetsWithSourceFilters({
isDash: true,
object: { parameters: [parameter] },
dashcard: {
dashboard_id: 111,
},
});
const filteredSources = _.mapObject(sources, (sources, sourceType) =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment