From 6ce6e76dfe1367f72f3e77ae513ff3cf5111bc71 Mon Sep 17 00:00:00 2001 From: Alexander Polyankin <alexander.polyankin@metabase.com> Date: Tue, 2 Aug 2022 16:25:15 +0300 Subject: [PATCH] Fix column duplication when adding a new breakout (#24503) --- frontend/src/metabase-lib/lib/Question.ts | 15 ++++++++------- .../binning/binning-reproductions.cy.spec.js | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/src/metabase-lib/lib/Question.ts b/frontend/src/metabase-lib/lib/Question.ts index 19390191428..ade301dc79b 100644 --- a/frontend/src/metabase-lib/lib/Question.ts +++ b/frontend/src/metabase-lib/lib/Question.ts @@ -660,8 +660,9 @@ class QuestionInner { query.columnNames(), ); + const graphMetrics = this.setting("graph.metrics"); if ( - this.setting("graph.metrics") && + graphMetrics && addedColumnNames.length > 0 && removedColumnNames.length === 0 ) { @@ -672,22 +673,22 @@ class QuestionInner { if (addedMetricColumnNames.length > 0) { return this.updateSettings({ - "graph.metrics": [ - ...this.setting("graph.metrics"), - ...addedMetricColumnNames, - ], + "graph.metrics": [...graphMetrics, ...addedMetricColumnNames], }); } } + const tableColumns = this.setting("table.columns"); if ( - this.setting("table.columns") && + tableColumns && addedColumnNames.length > 0 && removedColumnNames.length === 0 ) { return this.updateSettings({ "table.columns": [ - ...this.setting("table.columns"), + ...tableColumns.filter( + column => !addedColumnNames.includes(column.name), + ), ...addedColumnNames.map(name => { const dimension = query.columnDimensionWithName(name); return { diff --git a/frontend/test/metabase/scenarios/binning/binning-reproductions.cy.spec.js b/frontend/test/metabase/scenarios/binning/binning-reproductions.cy.spec.js index 952447b75d5..6fb237d5276 100644 --- a/frontend/test/metabase/scenarios/binning/binning-reproductions.cy.spec.js +++ b/frontend/test/metabase/scenarios/binning/binning-reproductions.cy.spec.js @@ -188,7 +188,7 @@ describe("binning related reproductions", () => { cy.findByText("Hour of Day"); }); - it.skip("shouldn't duplicate the breakout field (metabase#22382)", () => { + it("shouldn't duplicate the breakout field (metabase#22382)", () => { const questionDetails = { name: "22382", query: { @@ -206,7 +206,7 @@ describe("binning related reproductions", () => { cy.findByTestId("sidebar-left").within(() => { cy.findByTextEnsureVisible("Table options"); - cy.findByText("Count").siblings(".Icon-close").click(); + cy.findByText("Created At").siblings(".Icon-close").click(); cy.button("Done").click(); }); -- GitLab