Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Refactor ActionExecuteModal (#65573)

Fraserfafd6bb3d83c
diff --git a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js
index c345a5cb65a..61c0fd22516 100644
--- a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js
+++ b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js
@@ -148,8 +148,7 @@ describe(
assertScoreFormPrefilled(firstScoreRow);
});
});
-
- cy.icon("close").click();
+ cy.button("Close").click();
});
objectDetailModal().icon("close").click();
diff --git a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.tsx b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.tsx
index 53c1368a8da..dc445b108e5 100644
--- a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.tsx
+++ b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.tsx
@@ -3,9 +3,9 @@ import { useCallback } from "react";
import { skipToken, useGetActionQuery } from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import ModalContent from "metabase/common/components/ModalContent";
import { useDispatch } from "metabase/lib/redux";
import { checkNotNull } from "metabase/lib/types";
+import { Modal } from "metabase/ui";
import type {
ParametersForActionExecution,
WritebackActionId,
@@ -16,15 +16,17 @@ import { useActionInitialValues } from "../../hooks/use-action-initial-values";
import ActionParametersInputForm from "../ActionParametersInputForm";
export interface ActionExecuteModalProps {
+ opened: boolean;
actionId: WritebackActionId | undefined;
initialValues?: ParametersForActionExecution;
fetchInitialValues?: () => Promise<ParametersForActionExecution>;
shouldPrefetch?: boolean;
- onClose?: () => void;
+ onClose: () => void;
onSuccess?: () => void;
}
export const ActionExecuteModal = ({
+ opened,
actionId,
initialValues: initialValuesProp,
fetchInitialValues,
@@ -38,7 +40,9 @@ export const ActionExecuteModal = ({
error: errorAction,
isLoading: isLoadingAction,
data: action,
- } = useGetActionQuery(actionId != null ? { id: actionId } : skipToken);
+ } = useGetActionQuery(
+ actionId != null && opened ? { id: actionId } : skipToken,
+ );
const {
error: errorInitialValues,
@@ -82,25 +86,24 @@ export const ActionExecuteModal = ({
const isLoading =
isLoadingAction || (isLoadingInitialValues && !hasPrefetchedValues);
- if (error || isLoading) {
- return <LoadingAndErrorWrapper error={error} loading={isLoading} />;
- }
-
- const loadedAction = checkNotNull(action);
-
return (
- <ModalContent
- data-testid="action-execute-modal"
- title={loadedAction.name}
+ <Modal
+ opened={opened}
onClose={onClose}
+ title={action?.name}
+ data-testid="action-execute-modal"
>
- <ActionParametersInputForm
- action={loadedAction}
- initialValues={initialValues}
- onCancel={onClose}
- onSubmit={handleSubmit}
- onSubmitSuccess={handleSubmitSuccess}
- />
- </ModalContent>
+ {error || isLoading || !action ? (
+ <LoadingAndErrorWrapper error={error} loading={isLoading} />
+ ) : (
+ <ActionParametersInputForm
+ action={action}
+ initialValues={initialValues}
+ onCancel={onClose}
+ onSubmit={handleSubmit}
+ onSubmitSuccess={handleSubmitSuccess}
+ />
+ )}
+ </Modal>
);
};
diff --git a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx
index c8ecc257beb..392fdc7fd35 100644
--- a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx
+++ b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx
@@ -52,7 +52,12 @@ function setup(props?: Partial<ActionExecuteModalProps>) {
setupPrefetch();
renderWithProviders(
- <ActionExecuteModal {...props} actionId={implicitUpdateAction.id} />,
+ <ActionExecuteModal
+ opened
+ onClose={() => {}}
+ {...props}
+ actionId={implicitUpdateAction.id}
+ />,
);
}
diff --git a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
index bda95ba9546..d606f565123 100644
--- a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
+++ b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
@@ -382,19 +382,15 @@ export function DetailViewSidesheet({
</Stack>
</Sidesheet>
- <Modal
- isOpen={isActionExecuteModalOpen}
+ <ActionExecuteModal
+ opened={isActionExecuteModalOpen}
+ actionId={actionId}
+ initialValues={initialValues}
+ fetchInitialValues={fetchInitialValues}
+ shouldPrefetch
onClose={handleExecuteModalClose}
- >
- <ActionExecuteModal
- actionId={actionId}
- initialValues={initialValues}
- fetchInitialValues={fetchInitialValues}
- shouldPrefetch
- onClose={handleExecuteModalClose}
- onSuccess={handleActionSuccess}
- />
- </Modal>
+ onSuccess={handleActionSuccess}
+ />
<Modal isOpen={isDeleteModalOpen} onClose={handleDeleteModalClose}>
<DeleteObjectModal
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
index 8292614b5d7..5dd7f5d329e 100644
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
@@ -1,10 +1,10 @@
+import { useDisclosure } from "@mantine/hooks";
import { useCallback, useMemo } from "react";
import { t } from "ttag";
import { ActionExecuteModal } from "metabase/actions/containers/ActionExecuteModal";
import EntityMenu from "metabase/common/components/EntityMenu";
import Link from "metabase/common/components/Link";
-import ModalWithTrigger from "metabase/common/components/ModalWithTrigger";
import { useConfirmation } from "metabase/common/hooks/use-confirmation";
import { Icon } from "metabase/ui";
import * as Lib from "metabase-lib";
@@ -33,10 +33,6 @@ interface Props {
onArchive: (action: WritebackAction) => void;
}
-interface ModalProps {
- onClose?: () => void;
-}
-
function QueryActionCardContent({ action }: { action: WritebackQueryAction }) {
const question = Question.create({ dataset_query: action.dataset_query });
if (!question.isNative()) {
@@ -71,6 +67,10 @@ function ModelActionListItem({
}: Props) {
const { show: askConfirmation, modalContent: confirmationModal } =
useConfirmation();
+ const [
+ executeModalOpened,
+ { open: openExecuteModal, close: closeExecuteModal },
+ ] = useDisclosure(false);
const handleArchive = useCallback(() => {
askConfirmation({
@@ -124,23 +124,23 @@ function ModelActionListItem({
<ImplicitActionCardContent />
) : null}
{canRun && (
- <ModalWithTrigger
- triggerElement={
- <ActionRunButtonContainer>
- <ActionRunButton
- as={Link}
- icon="play"
- onlyIcon
- tooltip={t`Run`}
- aria-label={t`Run`}
- />
- </ActionRunButtonContainer>
- }
- >
- {({ onClose }: ModalProps) => (
- <ActionExecuteModal actionId={action.id} onClose={onClose} />
- )}
- </ModalWithTrigger>
+ <>
+ <ActionRunButtonContainer>
+ <ActionRunButton
+ as={Link}
+ icon="play"
+ onlyIcon
+ tooltip={t`Run`}
+ aria-label={t`Run`}
+ onClick={openExecuteModal}
+ />
+ </ActionRunButtonContainer>
+ <ActionExecuteModal
+ opened={executeModalOpened}
+ actionId={action.id}
+ onClose={closeExecuteModal}
+ />
+ </>
)}
</ActionCardContainer>
{confirmationModal}
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
index 7dfdfffd74e..06362116081 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.tsx
@@ -7,11 +7,11 @@ import { ActionExecuteModal } from "metabase/actions/containers/ActionExecuteMod
import { skipToken, useListActionsQuery } from "metabase/api";
import { NotFound } from "metabase/common/components/ErrorPages";
import LoadingSpinner from "metabase/common/components/LoadingSpinner";
-import Modal from "metabase/common/components/Modal";
import { useDatabaseListQuery } from "metabase/common/hooks";
import { useDispatch } from "metabase/lib/redux";
import { runQuestionQuery } from "metabase/query_builder/actions";
import { ActionsApi, MetabaseApi } from "metabase/services";
+import { Modal } from "metabase/ui";
import * as Lib from "metabase-lib";
import type ForeignKey from "metabase-lib/v1/metadata/ForeignKey";
import { isVirtualCardId } from "metabase-lib/v1/metadata/utils/saved-questions";
@@ -377,21 +377,17 @@ export function ObjectDetailView({
)}
</ObjectDetailContainer>
- <Modal
- isOpen={isActionExecuteModalOpen}
+ <ActionExecuteModal
+ opened={isActionExecuteModalOpen}
+ actionId={actionId}
+ initialValues={initialValues}
+ fetchInitialValues={fetchInitialValues}
+ shouldPrefetch
onClose={handleExecuteModalClose}
- >
- <ActionExecuteModal
- actionId={actionId}
- initialValues={initialValues}
- fetchInitialValues={fetchInitialValues}
- shouldPrefetch
- onClose={handleExecuteModalClose}
- onSuccess={handleActionSuccess}
- />
- </Modal>
+ onSuccess={handleActionSuccess}
+ />
- <Modal isOpen={isDeleteModalOpen} onClose={handleDeleteModalClose}>
+ <Modal opened={isDeleteModalOpen} onClose={handleDeleteModalClose}>
<DeleteObjectModal
actionId={deleteActionId}
objectId={zoomedRowID}
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
index ed894a9b40d..b8f2d79468d 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailView.unit.spec.tsx
@@ -489,10 +489,9 @@ describe("ObjectDetailView", () => {
const modal = await screen.findByTestId("action-execute-modal");
expect(modal).toBeInTheDocument();
-
- expect(within(modal).getByTestId("modal-header")).toHaveTextContent(
- "Update",
- );
+ expect(
+ within(modal).getByRole("heading", { name: "Update" }),
+ ).toBeInTheDocument();
});
it("should show delete object modal on delete action click", async () => {