Skip to content
Snippets Groups Projects
Unverified Commit e0ac6bc8 authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Fix Zoom drill doesn't work with joined fields (#31117)

This is because `source-field` was missing from a field dimension.
parent b64cd267
No related merge requests found
......@@ -28,3 +28,4 @@ export * from "./e2e-permissions-helpers";
export * from "./e2e-visual-tests-helpers";
export * from "./e2e-users-helpers";
export * from "./e2e-viz-settings-helpers";
export * from "./e2e-models-metadata-helpers";
......@@ -3,50 +3,49 @@ import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATABASE;
const questionDetails = {
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
[
"field",
PRODUCTS.CREATED_AT,
{ "source-field": ORDERS.PRODUCT_ID, "temporal-unit": "month" },
],
],
},
display: "line",
};
describe.skip("issue 27380", () => {
describe("issue 27380", () => {
beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");
restore();
cy.signInAsAdmin();
});
it("should not drop fields from joined table on dashboard 'zoom-in' (metabase#27380)", () => {
const questionDetails = {
query: {
"source-table": ORDERS_ID,
aggregation: [["count"]],
breakout: [
[
"field",
PRODUCTS.CREATED_AT,
{ "source-field": ORDERS.PRODUCT_ID, "temporal-unit": "month" },
],
],
},
display: "line",
};
cy.createQuestionAndDashboard({ questionDetails }).then(
({ body: { dashboard_id } }) => {
visitDashboard(dashboard_id);
},
);
});
it("should not drop fields from joined table on dashboard 'zoom-in' (metabase#27380)", () => {
// Doesn't really matter which 'circle" we click on the graph
cy.get("circle").last().realClick();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Zoom in").click();
cy.findByText("See this month by week").click();
cy.wait("@dataset");
// Graph should still exist
// Let's check only the y-axis label
cy.get("y-axis-label").invoke("text").should("eq", "Count");
cy.get(".y-axis-label").invoke("text").should("eq", "Count");
cy.icon("notebook").click();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Pick a column to group by").should("not.exist");
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText(/Products? → Created At: Month/);
cy.findByText("Product → Created At: Week");
});
});
......@@ -3,10 +3,10 @@ import {
openQuestionActions,
popover,
sidebar,
openColumnOptions,
} from "e2e/support/helpers";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { openColumnOptions } from "./helpers/e2e-models-metadata-helpers";
const { PRODUCTS_ID, PEOPLE_ID } = SAMPLE_DATABASE;
......
......@@ -7,16 +7,14 @@ import {
openQuestionActions,
questionInfoButton,
addOrUpdateDashboardCard,
} from "e2e/support/helpers";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { startQuestionFromModel } from "./helpers/e2e-models-helpers";
import {
openColumnOptions,
renameColumn,
setColumnType,
mapColumnTo,
setModelMetadata,
} from "./helpers/e2e-models-metadata-helpers";
} from "e2e/support/helpers";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { startQuestionFromModel } from "./helpers/e2e-models-helpers";
const { PEOPLE, PRODUCTS, PRODUCTS_ID, REVIEWS } = SAMPLE_DATABASE;
......
......@@ -4,9 +4,9 @@ import {
popover,
restore,
visitDashboard,
setModelMetadata,
} from "e2e/support/helpers";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { setModelMetadata } from "../helpers/e2e-models-metadata-helpers";
const { PRODUCTS } = SAMPLE_DATABASE;
......
......@@ -8,7 +8,10 @@ import {
} from "metabase-lib/types/utils/isa";
import { TYPE } from "metabase-lib/types/constants";
import { isExpressionField } from "metabase-lib/queries/utils/field-ref";
import {
isExpressionField,
isSameField,
} from "metabase-lib/queries/utils/field-ref";
import { FieldDimension } from "metabase-lib/Dimension";
// Drill-down progressions are defined as a series of steps, where each step has one or more dimension <-> breakout
// transforms.
......@@ -451,7 +454,13 @@ function columnToFieldDimension(column, metadata) {
return;
}
const dimension = new FieldDimension(column.id, null, metadata);
let dimension = new FieldDimension(column.id, null, metadata);
// When aggregating fields from foreign keys, `dimension`'s options could be
// missing `source-field`, so if `dimension` still is the same field as `column.field_ref`,
// try parsing the `ref_field` directly as it might contain missing options.
if (isSameField(column.field_ref, dimension.mbql())) {
dimension = FieldDimension.parseMBQL(column.field_ref, metadata);
}
if (column.unit) {
return dimension.withTemporalUnit(column.unit);
......
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