Skip to content
Snippets Groups Projects
Unverified Commit 28b1789c authored by Kamil Mielnik's avatar Kamil Mielnik Committed by GitHub
Browse files

Fix missing confirmation when running an action without parameters in dashboards (#31058)

* Add a test case for #28981

* Always open ActionParametersInputModal when clicking an action
- update unit tests to reflect this behavior
parent a1405914
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,13 @@ import React from "react";
import fetchMock from "fetch-mock";
import userEvent from "@testing-library/user-event";
import { renderWithProviders, screen, getIcon, waitFor } from "__support__/ui";
import {
getIcon,
renderWithProviders,
screen,
waitFor,
within,
} from "__support__/ui";
import {
setupDatabasesEndpoints,
setupUnauthorizedDatabasesEndpoints,
......@@ -176,7 +182,7 @@ describe("Actions > ActionViz > Action", () => {
expect(screen.getByRole("button")).toHaveTextContent("Please Click Me");
});
it("clicking an action button should open a modal action form", async () => {
it("clicking an action button with parameters should open a modal action form", async () => {
await setup();
userEvent.click(screen.getByRole("button"));
......@@ -185,6 +191,22 @@ describe("Actions > ActionViz > Action", () => {
expect(screen.getByLabelText("Parameter 1")).toBeInTheDocument();
});
it("clicking an action button without parameters should open a confirmation modal", async () => {
await setup({
dashcard: createMockActionDashboardCard({
action: createMockQueryAction({
database_id: DATABASE.id,
}),
parameter_mappings: [],
}),
});
userEvent.click(screen.getByRole("button"));
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(screen.getByTestId("action-form")).toBeInTheDocument();
expect(screen.queryByLabelText(/^Parameter/)).not.toBeInTheDocument();
});
it("the modal should have the action name as a title", async () => {
await setup();
......@@ -242,6 +264,13 @@ describe("Actions > ActionViz > Action", () => {
});
userEvent.click(screen.getByRole("button", { name: "Click me" }));
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(screen.getByTestId("action-form")).toBeInTheDocument();
userEvent.click(
within(screen.getByRole("dialog")).getByRole("button", {
name: action.name,
}),
);
await waitFor(async () => {
const call = fetchMock.lastCall(ACTION_EXEC_MOCK_PATH);
......
import React, { useState } from "react";
import useActionForm from "metabase/actions/hooks/use-action-form";
import { getFormTitle } from "metabase/actions/utils";
import type {
......@@ -50,21 +49,13 @@ function ActionVizForm({
}: ActionFormProps) {
const [showModal, setShowModal] = useState(false);
const title = getFormTitle(action);
const { getCleanValues } = useActionForm({
action,
initialValues: dashcardParamValues,
});
// only show confirmation if there are no missing parameters
const showConfirmMessage =
shouldShowConfirmation(action) && !missingParameters.length;
shouldShowConfirmation(action) && missingParameters.length === 0;
const onClick = () => {
if (missingParameters.length > 0 || showConfirmMessage) {
setShowModal(true);
} else {
onSubmit(getCleanValues());
}
setShowModal(true);
};
const onModalSubmit = async (params: ParametersForActionExecution) => {
......
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