Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix click behavior not working for pivot table header cells and tables pivoted (pivoted column cells) #39569

161 changes: 161 additions & 0 deletions e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
createMockActionParameter,
createMockDashboardCard,
} from "metabase-types/api/mocks";
const { PRODUCTS, SAMPLE_DB_ID } = SAMPLE_DATABASE;

const COUNT_COLUMN_ID = "count";
const COUNT_COLUMN_NAME = "Count";
Expand Down Expand Up @@ -1857,6 +1858,166 @@ describe("scenarios > dashboard > dashboard cards > click behavior", () => {
});
});
});

it("should allow click behavior on left/top header rows on a pivot table (metabase#25203)", () => {
const QUESTION_NAME = "Cypress Pivot Table";
const DASHBOARD_NAME = "Pivot Table Dashboard";
const testQuery = {
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
[
"field",
PEOPLE.SOURCE,
{ "base-type": "type/Text", "source-field": ORDERS.USER_ID },
],
[
"field",
PRODUCTS.CATEGORY,
{ "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },
],
],
},
database: SAMPLE_DB_ID,
};

cy.createQuestionAndDashboard({
questionDetails: {
name: QUESTION_NAME,
query: testQuery.query,
display: "pivot",
},
dashboardDetails: {
name: DASHBOARD_NAME,
},
cardDetails: {
size_x: 16,
size_y: 8,
},
}).then(({ body: { dashboard_id } }) => {
cy.wrap(dashboard_id).as("targetDashboardId");
visitDashboard(dashboard_id);
});

editDashboard();

getDashboardCard().realHover().icon("click").click();
addUrlDestination();

modal().within(() => {
const urlInput = cy.findAllByRole("textbox").eq(0);

cy.get("@targetDashboardId").then(targetDashboardId => {
urlInput.type(
`http://localhost:4000/dashboard/${targetDashboardId}?source={{source}}&category={{category}}&count={{count}}`,
{
parseSpecialCharSequences: false,
},
);
});
cy.button("Done").click();
});

cy.get("aside").button("Done").click();

saveDashboard();

// test top header row
getDashboardCard().findByText("Doohickey").click();
cy.get("@targetDashboardId").then(targetDashboardId => {
cy.location().should(({ pathname, search }) => {
expect(pathname).to.equal(`/dashboard/${targetDashboardId}`);
expect(search).to.equal("?category=Doohickey&count=&source=");
});
});

// test left header row
getDashboardCard().findByText("Affiliate").click();
cy.get("@targetDashboardId").then(targetDashboardId => {
cy.location().should(({ pathname, search }) => {
expect(pathname).to.equal(`/dashboard/${targetDashboardId}`);
expect(search).to.equal("?category=&count=&source=Affiliate");
});
});
});

it("should allow click through on the pivot column of a regular table that has been pivoted (metabase#25203)", () => {
const QUESTION_NAME = "Cypress Table Pivoted";
const DASHBOARD_NAME = "Table Pivoted Dashboard";
const testQuery = {
type: "query",
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
[
"field",
PEOPLE.SOURCE,
{ "base-type": "type/Text", "source-field": ORDERS.USER_ID },
],
[
"field",
PRODUCTS.CATEGORY,
{ "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },
],
],
},
database: SAMPLE_DB_ID,
};

cy.createQuestionAndDashboard({
questionDetails: {
name: QUESTION_NAME,
query: testQuery.query,
display: "table",
},
dashboardDetails: {
name: DASHBOARD_NAME,
},
cardDetails: {
size_x: 16,
size_y: 8,
},
}).then(({ body: { dashboard_id } }) => {
cy.wrap(dashboard_id).as("targetDashboardId");
visitDashboard(dashboard_id);
});

editDashboard();

getDashboardCard().realHover().icon("click").click();
cy.get("aside").findByText("User → Source").click();
addUrlDestination();

modal().within(() => {
const urlInput = cy.findAllByRole("textbox").eq(0);

cy.get("@targetDashboardId").then(targetDashboardId => {
urlInput.type(
`http://localhost:4000/dashboard/${targetDashboardId}?source={{source}}`,
{
parseSpecialCharSequences: false,
},
);
});
cy.button("Done").click();
});

cy.get("aside").button("Done").click();

saveDashboard();

// test pivoted column
getDashboardCard().findByText("Organic").click();
cy.get("@targetDashboardId").then(targetDashboardId => {
cy.location().should(({ pathname, search }) => {
expect(pathname).to.equal(`/dashboard/${targetDashboardId}`);
expect(search).to.equal("?source=Organic");
});
});
});
});

/**
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/metabase/lib/data_grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function formatValuesInTree(
value: formatter(value),
rawValue: value,
children: formatValuesInTree(children, formatters, columns),
clicked: { value, column },
clicked: { value, column, data: [{ value, col: column }] },
}));
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/metabase/visualizations/lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export function getTableCellClickedObject(
if (isPivoted) {
// if it's a pivot table, the first column is
if (columnIndex === 0) {
return row._dimension;
const { value, column: col } = row._dimension;
return { value, column: col, settings, data: [{ value, col }] };
} else {
return {
value,
Expand Down