Skip to content
Snippets Groups Projects
Unverified Commit 220156d4 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Fix creating new questions from the dashboard empty state (#31893)

parent 23ebbbf0
No related branches found
No related tags found
No related merge requests found
import {
restore,
popover,
modal,
queryBuilderHeader,
getDashboardCard,
} from "e2e/support/helpers";
describe("issue 31848", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
cy.intercept("POST", "/api/card").as("createQuestion");
});
it("should allow creating questions from an empty dashboard (metabase#31848)", () => {
const dashboardName = "New dashboard";
const questionName = "New question";
cy.visit("/");
cy.findByTestId("app-bar").findByText("New").click();
popover().findByText("Dashboard").click();
modal().within(() => {
cy.findByLabelText("Name").type(dashboardName);
cy.button("Create").click();
});
cy.findByTestId("dashboard-empty-state")
.findByText("ask a new one")
.click();
popover().within(() => {
cy.findByText("Sample Database").click();
cy.findByText("Orders").click();
});
queryBuilderHeader().findByText("Save").click();
modal().within(() => {
cy.findByLabelText("Name").clear().type(questionName);
cy.button("Save").click();
});
cy.wait("@createQuestion");
modal().within(() => {
cy.button("Yes please!").click();
cy.findByText(dashboardName).click();
});
cy.findByTestId("edit-bar")
.findByText("You're editing this dashboard.")
.should("be.visible");
getDashboardCard().findByText(questionName).should("be.visible");
});
});
......@@ -364,6 +364,7 @@ class Dashboard extends Component {
<TabEmptyState isNightMode={shouldRenderAsNightMode} />
) : (
<DashboardEmptyState
dashboard={dashboard}
isNightMode={shouldRenderAsNightMode}
addQuestion={this.onAddQuestion}
closeNavbar={this.props.closeNavbar}
......
import { t } from "ttag";
import * as Urls from "metabase/lib/urls";
import Link from "metabase/core/components/Link";
import Button from "metabase/core/components/Button";
import EmptyState from "metabase/components/EmptyState";
import { Dashboard } from "metabase-types/api";
import { Container } from "./DashboardEmptyState.styled";
function QuestionIllustration() {
......@@ -11,18 +12,20 @@ function QuestionIllustration() {
}
interface DashboardEmptyStateProps {
dashboard: Dashboard;
isNightMode: boolean;
addQuestion: () => void;
closeNavbar: () => void;
}
export function DashboardEmptyState({
dashboard,
isNightMode,
addQuestion,
closeNavbar,
}: DashboardEmptyStateProps) {
return (
<Container isNightMode={isNightMode}>
<Container isNightMode={isNightMode} data-testid="dashboard-empty-state">
<EmptyState
illustrationElement={<QuestionIllustration />}
title={t`This dashboard is looking empty.`}
......@@ -34,7 +37,11 @@ export function DashboardEmptyState({
{t`, or `}
<Link
variant="brandBold"
to="/question/new"
to={Urls.newQuestion({
mode: "notebook",
creationType: "custom_question",
collectionId: dashboard.collection_id ?? undefined,
})}
className="text-bold text-brand"
onClick={closeNavbar}
>
......
import { render, screen } from "@testing-library/react";
import { createMockDashboard } from "metabase-types/api/mocks";
import { DashboardEmptyState, TabEmptyState } from "./DashboardEmptyState";
describe("DashboardEmptyState", () => {
it("renders", () => {
render(
<DashboardEmptyState
dashboard={createMockDashboard()}
isNightMode={false}
addQuestion={jest.fn()}
closeNavbar={jest.fn()}
......
......@@ -14,7 +14,7 @@ export default function QuestionDataSelector({
selectedDatabaseId={query.databaseId()}
selectedTableId={query.tableId()}
setSourceTableFn={tableId =>
updateQuestion(query.setTableId(tableId), {
updateQuestion(query.setTableId(tableId).question(), {
run: true,
})
}
......
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