Skip to content

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

Center buttons vertically in CreateOrEditQuestionAlertModal footer (#72366)

Nick Fitzpatrick2b5b417b1ff2
diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
index d23f4fb8eb4..30301f70fc7 100644
--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useState } from "react";
+import { P, match } from "ts-pattern";
import { t } from "ttag";
import { isEqual } from "underscore";
@@ -9,7 +10,6 @@ import {
useSendUnsavedNotificationMutation,
useUpdateNotificationMutation,
} from "metabase/api";
-import { ActionButton } from "metabase/common/components/ActionButton";
import CS from "metabase/css/core/index.css";
import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import { getDefaultQuestionAlertRequest } from "metabase/notifications/utils";
@@ -163,8 +163,10 @@ export const CreateOrEditQuestionAlertModal = ({
useGetChannelInfoQuery();
const { data: hookChannels } = useListChannelsQuery();
- const [createNotification] = useCreateNotificationMutation();
- const [updateNotification] = useUpdateNotificationMutation();
+ const [createNotification, { isLoading: isCreating, error: errorCreating }] =
+ useCreateNotificationMutation();
+ const [updateNotification, { isLoading: isUpdating, error: errorUpdating }] =
+ useUpdateNotificationMutation();
const [sendUnsavedNotification, { isLoading }] =
useSendUnsavedNotificationMutation();
@@ -233,8 +235,7 @@ export const CreateOrEditQuestionAlertModal = ({
}),
);
- // need to throw to show error in ActionButton
- throw result.error;
+ return;
}
dispatch(
@@ -304,6 +305,16 @@ export const CreateOrEditQuestionAlertModal = ({
const isValid = alertIsValid(notification, channelSpec);
const hasChanges = !isEqual(editingNotification, notification);
+ const hasError = errorCreating || errorUpdating;
+
+ const submitButtonLabel = match({
+ hasError,
+ isEditMode,
+ hasChanges,
+ })
+ .with({ hasError: P.nonNullable }, () => t`Save failed`)
+ .with({ isEditMode: true, hasChanges: true }, () => t`Save changes`)
+ .otherwise(() => t`Done`);
return (
<Modal
@@ -317,6 +328,7 @@ export const CreateOrEditQuestionAlertModal = ({
body: {
paddingLeft: 0,
paddingRight: 0,
+ paddingBottom: "1.5rem",
},
}}
>
@@ -416,6 +428,7 @@ export const CreateOrEditQuestionAlertModal = ({
</Stack>
<Flex
justify="space-between"
+ align="center"
px="2.5rem"
pt="lg"
className={CS.borderTop}
@@ -428,16 +441,18 @@ export const CreateOrEditQuestionAlertModal = ({
>
{isLoading ? t`Sending…` : t`Send now`}
</Button>
- <div>
- <Button onClick={onClose} className={CS.mr2}>{t`Cancel`}</Button>
- <ActionButton
- primary
- disabled={!isValid}
- actionFn={onCreateOrEditAlert}
+ <Flex align="center" gap="sm">
+ <Button onClick={onClose}>{t`Cancel`}</Button>
+ <Button
+ variant="filled"
+ bg={hasError ? "error" : "brand"}
+ disabled={!isValid || isCreating || isUpdating}
+ loading={isCreating || isUpdating}
+ onClick={onCreateOrEditAlert}
>
- {isEditMode && hasChanges ? t`Save changes` : t`Done`}
- </ActionButton>
- </div>
+ {submitButtonLabel}
+ </Button>
+ </Flex>
</Flex>
</Modal>
);
diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx
index 5e085e1e8d8..751dbbcc5ad 100644
--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx
+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx
@@ -334,6 +334,58 @@ describe("CreateOrEditQuestionAlertModalWithQuestion", () => {
expect(onAlertCreatedMock).toHaveBeenCalledTimes(1);
});
+ it("should update submit button label through Done → Save changes → Save failed", async () => {
+ const notificationId = 42;
+ fetchMock.putOnce(`path:/api/notification/${notificationId}`, {
+ status: 500,
+ body: { message: "Internal server error" },
+ });
+
+ const mockNotification = createMockNotification({
+ id: notificationId,
+ subscriptions: [
+ createMockNotificationCronSubscription({
+ cron_schedule: "0 0 14 ? * 2 *",
+ }),
+ ],
+ payload: {
+ card_id: 1,
+ send_once: false,
+ send_condition: "has_result",
+ },
+ });
+
+ setup({
+ isAdmin: true,
+ isEmailSetup: true,
+ editingNotification: mockNotification,
+ });
+
+ await screen.findByText("Edit alert");
+
+ // No changes yet — button should say "Done"
+ expect(screen.getByRole("button", { name: /done/i })).toBeInTheDocument();
+
+ // Make a change — button should say "Save changes"
+ const weekdaySelector = screen.getByTestId("select-weekday");
+ await userEvent.click(weekdaySelector);
+ const tuesdayOption = screen.getByRole("option", { name: /Tuesday/i });
+ await userEvent.click(tuesdayOption);
+
+ expect(
+ screen.getByRole("button", { name: /save changes/i }),
+ ).toBeInTheDocument();
+
+ // Submit with a failing API — button should say "Save failed"
+ await userEvent.click(
+ screen.getByRole("button", { name: /save changes/i }),
+ );
+
+ expect(
+ await screen.findByRole("button", { name: /save failed/i }),
+ ).toBeInTheDocument();
+ });
+
it("should update an existing notification when in edit mode", async () => {
const notificationId = 42;
// Setup fetchMock for API call