Skip to content

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

Drop the question the click-behavior source filters never read (#82149)

Romeo Van Snicke584e95d48e5
diff --git a/frontend/src/metabase/dashboard/components/ClickMappings/ClickMappings.tsx b/frontend/src/metabase/dashboard/components/ClickMappings/ClickMappings.tsx
index 2789d595979..dcbf013cc58 100644
--- a/frontend/src/metabase/dashboard/components/ClickMappings/ClickMappings.tsx
+++ b/frontend/src/metabase/dashboard/components/ClickMappings/ClickMappings.tsx
@@ -25,7 +25,6 @@ export function ClickMappings(props: ClickMappingsOwnProps) {
const {
setTargets,
unsetTargets,
- question,
sourceOptions: baseSourceOptions,
} = useClickMappingsData(props);
const userAttributes = useUserAttributes();
@@ -55,25 +54,21 @@ export function ClickMappings(props: ClickMappingsOwnProps) {
const targetSourceOptions: SourceOptionsByType = {};
const columnOptions = sourceOptions.column
- .filter((column) => target.sourceFilters.column(column, question))
+ .filter((column) => target.sourceFilters.column(column))
.map(getSourceOption.column);
if (columnOptions.length > 0) {
targetSourceOptions.column = columnOptions;
}
const parameterOptions = sourceOptions.parameter
- .filter((parameter) =>
- target.sourceFilters.parameter(parameter, question),
- )
+ .filter((parameter) => target.sourceFilters.parameter(parameter))
.map(getSourceOption.parameter);
if (parameterOptions.length > 0) {
targetSourceOptions.parameter = parameterOptions;
}
const userAttributeOptions = sourceOptions.userAttribute
- .filter((name) =>
- target.sourceFilters.userAttribute(name, question),
- )
+ .filter((name) => target.sourceFilters.userAttribute(name))
.map(getSourceOption.userAttribute);
if (userAttributeOptions.length > 0) {
targetSourceOptions.userAttribute = userAttributeOptions;
@@ -88,7 +83,7 @@ export function ClickMappings(props: ClickMappingsOwnProps) {
({ sourceOptions }: { sourceOptions: SourceOptionsByType }) =>
Object.keys(sourceOptions).length > 0,
),
- [question, sourceOptions, unsetTargets],
+ [sourceOptions, unsetTargets],
);
if (unsetTargetsWithSourceOptions.length === 0 && setTargets.length === 0) {
diff --git a/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts b/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts
index 9b3c0e53b4c..bf9a1d34c40 100644
--- a/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts
+++ b/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts
@@ -6,7 +6,6 @@ import {
getTargetsForDashboard,
getTargetsForQuestion,
} from "metabase/dashboard/utils/click-behavior";
-import { getMetadata } from "metabase/metadata-store";
import { loadMetadataForCard } from "metabase/questions/actions";
import { useDispatch, useSelector } from "metabase/redux";
import { isQuestionDashCard } from "metabase/utils/dashboard";
@@ -24,7 +23,6 @@ type ClickMappingsData = {
column: DatasetColumn[];
parameter: Parameter[];
};
- question: Question;
};
export function useClickMappingsData(
@@ -33,14 +31,11 @@ export function useClickMappingsData(
const { object, isDashboard, dashcard, clickBehavior } = props;
const parameters = useSelector(getParameters);
- const metadata = useSelector(getMetadata);
const dashcardData = useSelector((state) =>
getDashcardData(state, dashcard.id),
);
return useMemo(() => {
- const question = new Question(dashcard.card, metadata);
-
let filteredParameters = parameters;
if (props.excludeParametersSources) {
@@ -84,13 +79,12 @@ export function useClickMappingsData(
parameter: filteredParameters,
};
- return { setTargets, unsetTargets, sourceOptions, question };
+ return { setTargets, unsetTargets, sourceOptions };
}, [
clickBehavior,
dashcard,
dashcardData,
isDashboard,
- metadata,
object,
parameters,
props.excludeParametersSources,
diff --git a/frontend/src/metabase/dashboard/components/ClickMappings/types.ts b/frontend/src/metabase/dashboard/components/ClickMappings/types.ts
index d3b6e96a171..28ced2c5b53 100644
--- a/frontend/src/metabase/dashboard/components/ClickMappings/types.ts
+++ b/frontend/src/metabase/dashboard/components/ClickMappings/types.ts
@@ -1,22 +1,13 @@
+import type { Target } from "metabase/dashboard/utils/click-behavior";
import type Question from "metabase-lib/v1/Question";
import type {
ClickBehavior,
ClickBehaviorTarget,
Dashboard,
DashboardCard,
- DatasetColumn,
- Parameter,
} from "metabase-types/api";
-export type TargetItem = {
- id: string;
- name: string | null | undefined;
- target: ClickBehaviorTarget;
- sourceFilters: {
- column: (source: DatasetColumn, question: Question) => boolean;
- parameter: (source: Parameter, question: Question) => boolean;
- userAttribute: (source: string, question: Question) => boolean;
- };
+export type TargetItem = Target & {
type?: ClickBehaviorTarget["type"];
};
diff --git a/frontend/src/metabase/dashboard/utils/click-behavior.ts b/frontend/src/metabase/dashboard/utils/click-behavior.ts
index 9a170c29f90..1da653a7574 100644
--- a/frontend/src/metabase/dashboard/utils/click-behavior.ts
+++ b/frontend/src/metabase/dashboard/utils/click-behavior.ts
@@ -35,15 +35,15 @@ import type {
} from "metabase-types/api";
import { clickBehaviorIsValid } from "metabase-types/guards";
-interface Target {
+export interface Target {
id: Parameter["id"];
name: Parameter["name"] | null | undefined;
target: ClickBehaviorTarget;
sourceFilters: SourceFilters;
}
-interface SourceFilters {
- column: (column: DatasetColumn, question: Question) => boolean;
+export interface SourceFilters {
+ column: (column: DatasetColumn) => boolean;
parameter: (parameter: Parameter) => boolean;
userAttribute: (userAttribute: string) => boolean;
}
diff --git a/frontend/src/metabase/dashboard/utils/click-behavior.unit.spec.ts b/frontend/src/metabase/dashboard/utils/click-behavior.unit.spec.ts
index 32280b81c1e..d9962e32f6d 100644
--- a/frontend/src/metabase/dashboard/utils/click-behavior.unit.spec.ts
+++ b/frontend/src/metabase/dashboard/utils/click-behavior.unit.spec.ts
@@ -310,7 +310,6 @@ describe("metabase/dashboard/utils/click-behavior", () => {
],
] as [string, Record<string, unknown>][]) {
it(`should filter sources for a ${targetParameterType} parameter target`, () => {
- const question = new Question(createMockCard(), metadata);
const parameter = createMockParameter({
id: "foo123",
name: "My Param",
@@ -323,9 +322,7 @@ describe("metabase/dashboard/utils/click-behavior", () => {
);
const filteredSources = {
- column: sources.column.filter((column) =>
- sourceFilters.column(column, question),
- ),
+ column: sources.column.filter(sourceFilters.column),
parameter: sources.parameter.filter(sourceFilters.parameter),
userAttribute: sources.userAttribute.filter(
sourceFilters.userAttribute,
@@ -401,9 +398,7 @@ describe("metabase/dashboard/utils/click-behavior", () => {
const [{ sourceFilters }] = getTargetsForQuestion(question);
const filteredSources = {
- column: sources.column.filter((column) =>
- sourceFilters.column(column, question),
- ),
+ column: sources.column.filter(sourceFilters.column),
parameter: sources.parameter.filter(sourceFilters.parameter),
userAttribute: sources.userAttribute.filter(
sourceFilters.userAttribute,
@@ -492,9 +487,7 @@ describe("metabase/dashboard/utils/click-behavior", () => {
const [{ sourceFilters }] = getTargetsForQuestion(question);
const filteredSources = {
- column: sources.column.filter((column) =>
- sourceFilters.column(column, question),
- ),
+ column: sources.column.filter(sourceFilters.column),
parameter: sources.parameter.filter(sourceFilters.parameter),
userAttribute: sources.userAttribute.filter(
sourceFilters.userAttribute,