Skip to content
Snippets Groups Projects
Unverified Commit 74c3fec5 authored by Noah Moss's avatar Noah Moss Committed by GitHub
Browse files

Fix XLSX column names for remapped cols (#22212)

* fix column name for remapped fields

* unskip repro

* remove csv from cypress repro

* fix cypress test

* also check that :remapped_from is set on col metadata

* revert import syntax
parent c38d7d94
Branches
Tags
No related merge requests found
......@@ -24,7 +24,7 @@ const questionDetails = {
},
};
describe.skip("issue 18573", () => {
describe("issue 18573", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
......@@ -37,15 +37,13 @@ describe.skip("issue 18573", () => {
});
});
["csv", "xlsx"].forEach(fileType => {
it(`for the remapped columns, it should preserve renamed column name in exports for ${fileType} (metabase#18573)`, () => {
visitQuestionAdhoc(questionDetails);
it(`for the remapped columns, it should preserve renamed column name in exports for xlsx (metabase#18573)`, () => {
visitQuestionAdhoc(questionDetails);
cy.findByText("Foo");
cy.findByText("Awesome Concrete Shoes");
cy.findByText("Foo");
cy.findByText("Awesome Concrete Shoes");
downloadAndAssert({ fileType }, assertion);
});
downloadAndAssert({ fileType: "xlsx" }, assertion);
});
});
......
......@@ -412,7 +412,9 @@
"Generates the column titles that should be used in the export, taking into account viz settings."
[ordered-cols col-settings]
(for [col ordered-cols]
(let [id-or-name (or (:id col) (:name col))
(let [id-or-name (or (and (:remapped_from col) (:fk_field_id col))
(:id col)
(:name col))
format-settings (or (get col-settings {::mb.viz/field-id id-or-name})
(get col-settings {::mb.viz/column-name id-or-name}))
is-currency? (or (isa? (:semantic_type col) :type/Currency)
......
......@@ -21,7 +21,7 @@
([format-settings semantic-type]
(let [format-strings (@#'qp.xlsx/format-settings->format-strings format-settings {:semantic_type semantic-type
:effective_type :type/Temporal})]
:effective_type :type/Temporal})]
;; If only one format string is returned (for datetimes) or both format strings
;; are equal, just return a single value to make tests more readable.
(cond
......@@ -380,6 +380,13 @@
{::mb.viz/currency "USD",
::mb.viz/currency-style "code",
::mb.viz/currency-in-header false}}}
[])))))
(testing "If a col is remapped to a foreign key field, the title is taken from the viz settings for its fk_field_id (#18573)"
(is (= ["Correct title"]
(first (xlsx-export [{:id 0, :fk_field_id 1, :remapped_from "FIELD_1"}]
{::mb.viz/column-settings {{::mb.viz/field-id 0} {::mb.viz/column-title "Incorrect title"}
{::mb.viz/field-id 1} {::mb.viz/column-title "Correct title"}}}
[]))))))
(deftest scale-test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment