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

Show a submit button for an action without parameters (#28453)

parent 5e837207
No related branches found
No related tags found
No related merge requests found
import React, { useCallback, useMemo, useState } from "react";
import { useMount } from "react-use";
import title from "metabase/hoc/Title";
import { PublicApi } from "metabase/services";
......@@ -31,7 +30,6 @@ interface Props {
function PublicAction({ action, publicId, onError }: Props) {
const [isSubmitted, setSubmitted] = useState(false);
const hasParameters = action.parameters.length > 0;
const successMessage = getSuccessMessage(action);
const formSettings = useMemo(() => {
......@@ -58,20 +56,10 @@ function PublicAction({ action, publicId, onError }: Props) {
[publicId, formSettings, onError],
);
useMount(() => {
if (!hasParameters) {
handleSubmit({});
}
});
if (isSubmitted) {
return <FormResultMessage>{successMessage}</FormResultMessage>;
}
if (!hasParameters) {
return null;
}
return (
<FormContainer>
<FormTitle>{action.name}</FormTitle>
......
......@@ -184,17 +184,14 @@ describe("PublicAction", () => {
expect(screen.queryByRole("form")).not.toBeInTheDocument();
});
it("immediately executes an action without parameters", async () => {
it("handles actions without parameters", async () => {
const { executeActionEndpointSpy } = await setup({
action: { ...TEST_ACTION, parameters: [] },
expectedRequestBody: { parameters: {} },
});
expect(
await screen.findByText(`${TEST_ACTION.name} ran successfully`),
).toBeInTheDocument();
expect(screen.queryByText(TEST_ACTION.name)).not.toBeInTheDocument();
expect(screen.queryByRole("form")).not.toBeInTheDocument();
expect(executeActionEndpointSpy.isDone()).toBe(true);
expect(screen.getByText(TEST_ACTION.name)).toBeInTheDocument();
userEvent.click(screen.getByRole("button", { name: "Submit" }));
await waitFor(() => expect(executeActionEndpointSpy.isDone()).toBe(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