Skip to content

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

Reset parameter values if all parameters are equal to new values, not per parameter (#62757)

Alexander Polyankin15e73ac7cf0d
diff --git a/e2e/test/scenarios/dashboard-cards/click-behavior-reproductions.cy.spec.ts b/e2e/test/scenarios/dashboard-cards/click-behavior-reproductions.cy.spec.ts
new file mode 100644
index 00000000000..f9e3d00d26a
--- /dev/null
+++ b/e2e/test/scenarios/dashboard-cards/click-behavior-reproductions.cy.spec.ts
@@ -0,0 +1,135 @@
+const { H } = cy;
+
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
+import type { StructuredQuestionDetails } from "e2e/support/helpers";
+
+const { PRODUCTS_ID, PRODUCTS } = SAMPLE_DATABASE;
+
+describe("issue 59049", () => {
+ const questionDetails: StructuredQuestionDetails = {
+ query: {
+ "source-table": PRODUCTS_ID,
+ },
+ };
+
+ const categoryParameter = {
+ id: "1b9cd9f1",
+ name: "Category",
+ slug: "category",
+ type: "string/=",
+ sectionId: "string",
+ };
+
+ const vendorParameter = {
+ id: "1b9cd9f2",
+ name: "Vendor",
+ slug: "vendor",
+ type: "string/=",
+ sectionId: "string",
+ };
+
+ const dashboardDetails = {
+ parameters: [categoryParameter, vendorParameter],
+ };
+
+ function createDashboard() {
+ H.createQuestionAndDashboard({
+ questionDetails,
+ dashboardDetails,
+ }).then(({ body: card, questionId }) => {
+ H.addOrUpdateDashboardCard({
+ dashboard_id: card.dashboard_id,
+ card_id: questionId,
+ card: {
+ id: card.id,
+ parameter_mappings: [
+ {
+ card_id: questionId,
+ parameter_id: categoryParameter.id,
+ target: [
+ "dimension",
+ ["field", PRODUCTS.CATEGORY, null],
+ { "stage-number": 0 },
+ ],
+ },
+ {
+ card_id: questionId,
+ parameter_id: vendorParameter.id,
+ target: [
+ "dimension",
+ ["field", PRODUCTS.VENDOR, null],
+ { "stage-number": 0 },
+ ],
+ },
+ ],
+ visualization_settings: {
+ column_settings: {
+ '["name","CATEGORY"]': {
+ click_behavior: {
+ parameterMapping: {
+ [categoryParameter.id]: {
+ id: categoryParameter.id,
+ source: {
+ type: "column",
+ id: "CATEGORY",
+ name: "Category",
+ },
+ target: {
+ type: "parameter",
+ id: categoryParameter.id,
+ },
+ },
+ [vendorParameter.id]: {
+ id: vendorParameter.id,
+ source: {
+ type: "column",
+ id: "VENDOR",
+ name: "Vendor",
+ },
+ target: {
+ type: "parameter",
+ id: vendorParameter.id,
+ },
+ },
+ },
+ type: "crossfilter",
+ },
+ },
+ },
+ },
+ },
+ });
+ cy.wrap(card.dashboard_id).as("dashboardId");
+ });
+ }
+
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsNormalUser();
+ });
+
+ it("should not reset parameter values in click behaviors when they are partially equal to the new values (metabase#59049)", () => {
+ createDashboard();
+ H.visitDashboard("@dashboardId");
+
+ cy.log(
+ "when not all old parameter values are equal to new values, do not reset",
+ );
+ H.filterWidget().first().click();
+ H.popover().within(() => {
+ cy.findByText("Gadget").click();
+ cy.button("Add filter").click();
+ });
+ H.assertTableRowsCount(53);
+ H.getDashboardCard().findAllByText("Gadget").first().click();
+ H.filterWidget().eq(0).should("contain", "Gadget");
+ H.filterWidget().eq(1).should("contain", "Price, Schultz and Daniel");
+ H.assertTableRowsCount(1);
+
+ cy.log("when all old parameter values are equal to new values, reset");
+ H.getDashboardCard().findAllByText("Gadget").first().click();
+ H.filterWidget().eq(0).should("not.contain", "Gadget");
+ H.filterWidget().eq(1).should("not.contain", "Price, Schultz and Daniel");
+ H.assertTableRowsCount(200);
+ });
+});
diff --git a/frontend/src/metabase/dashboard/actions/parameters.tsx b/frontend/src/metabase/dashboard/actions/parameters.tsx
index d27a13ca00b..21abc475435 100644
--- a/frontend/src/metabase/dashboard/actions/parameters.tsx
+++ b/frontend/src/metabase/dashboard/actions/parameters.tsx
@@ -955,13 +955,11 @@ export const setOrUnsetParameterValues =
(parameterIdValuePairs: any[][]) =>
(dispatch: Dispatch, getState: GetState) => {
const parameterValues = getParameterValues(getState());
+ const areAllSet = parameterIdValuePairs.every(([id, value]) =>
+ _.isEqual(value, parameterValues[id]),
+ );
parameterIdValuePairs
- .map(([id, value]) =>
- setParameterValue(
- id,
- _.isEqual(value, parameterValues[id]) ? null : value,
- ),
- )
+ .map(([id, value]) => setParameterValue(id, areAllSet ? null : value))
.forEach(dispatch);
};