Skip to content
Snippets Groups Projects
Unverified Commit 7fa377af authored by Dalton's avatar Dalton Committed by GitHub
Browse files

Handle scenario where query props are undefined on a StructuredQuery (#20394)

* Handle scenario where query is undefined

* Add repro
parent ecd65274
No related branches found
No related tags found
No related merge requests found
......@@ -212,7 +212,7 @@ export default class StructuredQuery extends AtomicQuery {
* @returns the table ID, if a table is selected.
*/
sourceTableId(): TableId | null | undefined {
return this.query()["source-table"];
return this.query()?.["source-table"];
}
/**
......@@ -1437,7 +1437,7 @@ export default class StructuredQuery extends AtomicQuery {
*/
@memoize
sourceQuery(): StructuredQuery | null | undefined {
const sourceQuery = this.query()["source-query"];
const sourceQuery = this.query()?.["source-query"];
if (sourceQuery) {
return new NestedStructuredQuery(
......
import { restore, popover } from "__support__/e2e/cypress";
describe("issue 20393", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});
it("should show public dashboards with nested cards mapped to parameters (metabase#20393)", () => {
createDashboardWithNestedCard();
// add a date parameter to the dashboard
cy.icon("pencil").click();
cy.icon("filter").click();
popover()
.contains("Time")
.click();
popover()
.contains("All Options")
.click();
// map the date parameter to the card
cy.get(".DashCard")
.contains("Select")
.click();
popover()
.contains("CREATED_AT")
.click();
// save the dashboard
cy.findByText("Save").click();
// open the sharing modal and enable sharing
cy.icon("share").click();
cy.findByText("Sharing and embedding").click();
cy.findByRole("switch").click();
// navigate to the public dashboard link
cy.findByText("Public link")
.parent()
.within(() => {
cy.get("input").then(input => {
cy.visit(input.val());
});
});
// verify that the card is visible on the page
cy.findByText("Q2");
});
});
function createDashboardWithNestedCard() {
cy.createNativeQuestion({
name: "Q1",
native: { query: 'SELECT * FROM "ORDERS"', "template-tags": {} },
}).then(({ body }) =>
cy
.createQuestion({
name: "Q2",
query: { "source-table": `card__${body.id}` },
})
.then(({ body: { id: cardId } }) =>
cy
.createDashboard("Q2 in a dashboard")
.then(({ body: { id: dashId } }) => {
cy.request("POST", `/api/dashboard/${dashId}/cards`, { cardId });
cy.visit(`/dashboard/${dashId}`);
}),
),
);
}
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