From 99c03061388722d7a75c8ecc3756784c6d4a3578 Mon Sep 17 00:00:00 2001 From: "Mahatthana (Kelvin) Nomsawadi" <me@bboykelvin.dev> Date: Wed, 22 Feb 2023 14:36:49 +0000 Subject: [PATCH] Fix Missing type property on a card breaks the frontend on the Notebook view (#28458) * Fix missing type property on a card breaks frontend UI * Add E2E test --- frontend/src/metabase-lib/Dimension.ts | 5 +- ...1-missing-custom-field-metadata.cy.spec.js | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 frontend/test/metabase/scenarios/question/reproductions/28221-missing-custom-field-metadata.cy.spec.js diff --git a/frontend/src/metabase-lib/Dimension.ts b/frontend/src/metabase-lib/Dimension.ts index d49fda38657..2b554ef6b93 100644 --- a/frontend/src/metabase-lib/Dimension.ts +++ b/frontend/src/metabase-lib/Dimension.ts @@ -1247,8 +1247,9 @@ export class ExpressionDimension extends Dimension { return dimension?.field(); }; - type = infer(expr, mbql => field(mbql)?.base_type); - semantic_type = infer(expr, mbql => field(mbql)?.semantic_type); + type = infer(expr, mbql => field(mbql)?.base_type) ?? type; + semantic_type = + infer(expr, mbql => field(mbql)?.semantic_type) ?? semantic_type; } else { type = infer(this._expressionName); } diff --git a/frontend/test/metabase/scenarios/question/reproductions/28221-missing-custom-field-metadata.cy.spec.js b/frontend/test/metabase/scenarios/question/reproductions/28221-missing-custom-field-metadata.cy.spec.js new file mode 100644 index 00000000000..ac6d7d94af3 --- /dev/null +++ b/frontend/test/metabase/scenarios/question/reproductions/28221-missing-custom-field-metadata.cy.spec.js @@ -0,0 +1,48 @@ +import { restore } from "__support__/e2e/helpers"; + +import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; + +const { PRODUCTS_ID, PRODUCTS, ORDERS_ID, ORDERS } = SAMPLE_DATABASE; + +describe("issue 28221", () => { + beforeEach(() => { + restore(); + cy.signInAsAdmin(); + }); + + it("should be able to select see notebook view even if a question custom field metadata is missing#27462", () => { + const questionName = "Reproduce 28221"; + const customFieldName = "Non-existing field"; + const questionDetails = { + name: questionName, + query: { + "source-table": ORDERS_ID, + joins: [ + { + fields: "all", + "source-table": PRODUCTS_ID, + condition: [ + "=", + ["field", ORDERS.PRODUCT_ID, null], + ["field", PRODUCTS.ID, { "join-alias": "Products" }], + ], + alias: "Products", + }, + ], + expressions: { + [customFieldName]: ["field", 9999, null], + }, + }, + }; + + cy.createQuestion(questionDetails).then(({ body }) => { + const questionId = body.id; + + cy.visit(`/question/${questionId}/notebook`); + }); + + cy.findByDisplayValue(questionName).should("be.visible"); + + cy.findByText(customFieldName).should("be.visible"); + }); +}); -- GitLab