Skip to content
Snippets Groups Projects
Unverified Commit 7bbe5365 authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Keep Pivoted Option works in Subscriptions (#49559) (#49803)


* Keep Pivoted Option works in Subscriptions

Fixes: #49525

Even though the user could toggle 'Keep data pivoted` in the Sharing Sidebar UI, the setting was not being propagated
to the backend, so attachments would not be pivoted.

* add a cypress test

* add viz settings to get the pivot working

* fix for linter

* remove eslint ignore

---------

Co-authored-by: default avataradam-james <21064735+adam-james-v@users.noreply.github.com>
Co-authored-by: default avatarAleksandr Lesnenko <alxnddr@gmail.com>
parent 6249b99a
No related branches found
No related tags found
No related merge requests found
import { SAMPLE_DB_ID, USERS } from "e2e/support/cypress_data";
import { SAMPLE_DB_ID, USERS, WEBMAIL_CONFIG } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
ADMIN_USER_ID,
......@@ -50,6 +50,7 @@ const {
REVIEWS_ID,
PEOPLE,
} = SAMPLE_DATABASE;
const { WEB_PORT } = WEBMAIL_CONFIG;
describe("issue 18009", { tags: "@external" }, () => {
beforeEach(() => {
......@@ -1002,3 +1003,84 @@ describe("issue 16108", () => {
tooltip().findByText("Sharing");
});
});
describe("issue 49525", { tags: "@external" }, () => {
const {
admin: { first_name, last_name },
} = USERS;
const q1Details = {
name: "Pivot Table",
query: {
"source-table": PRODUCTS_ID,
aggregation: [["count"]],
breakout: [
["datetime-field", ["field-id", PRODUCTS.CREATED_AT], "year"],
["field-id", PRODUCTS.CATEGORY],
],
},
display: "pivot",
visualization_settings: {
"pivot_table.column_split": {
rows: ["CREATED_AT"],
columns: ["CATEGORY"],
values: ["COUNT"],
},
},
};
beforeEach(() => {
restore();
cy.signInAsAdmin();
setupSMTP();
createQuestionAndDashboard({
questionDetails: q1Details,
}).then(({ body: { dashboard_id } }) => {
visitDashboard(dashboard_id);
});
});
it("Subscriptions with 'Keep data pivoted' checked should work (metabase#49525)", () => {
// Send a test email subscription
openSharingMenu("Subscriptions");
sidebar().within(() => {
cy.findByText("Email it").click();
cy.findByPlaceholderText("Enter user names or email addresses").click();
});
popover().findByText(`${first_name} ${last_name}`).click();
sidebar().within(() => {
// Click this just to close the popover that is blocking the "Send email now" button
cy.findByText("To:").click();
cy.findByLabelText("Attach results").click();
cy.findByText("Keep data pivoted").click();
cy.findByText("Questions to attach").click();
});
sendEmailAndAssert(email => {
// Get the CSV attachment data
const csvAttachment = email.attachments.find(
attachment => attachment.contentType === "text/csv",
);
expect(csvAttachment).to.exist;
// get the csv attachment file's contents
cy.request({
method: "GET",
url: `http://localhost:${WEB_PORT}/email/${email.id}/attachment/${csvAttachment.fileName}`,
encoding: "utf8",
}).then(response => {
const csvContent = response.body;
const rows = csvContent.split("\n");
const headers = rows[0];
expect(headers).to.equal(
"Created At,Doohickey,Gadget,Gizmo,Widget,Row totals\r",
);
});
});
});
});
......@@ -79,6 +79,7 @@ const cardsToPulseCards = (cards, pulseCards) => {
return {
...card,
format_rows: pulseCard.format_rows,
pivot_results: pulseCard.pivot_results,
include_csv: pulseCard.include_csv,
include_xls: pulseCard.include_xls,
};
......
......@@ -186,6 +186,7 @@
[:include_csv ms/BooleanValue]
[:include_xls ms/BooleanValue]
[:format_rows {:optional true} [:maybe ms/BooleanValue]]
[:pivot_results {:optional true} [:maybe ms/BooleanValue]]
[:dashboard_card_id {:optional true} [:maybe ms/PositiveInt]]]
(deferred-tru "value must be a map with the keys `{0}`, `{1}`, and `{2}`." "include_csv" "include_xls" "dashboard_card_id")))
......
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