Skip to content

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

"Send now" in the question alert modal is never disabled (#80439)

Egor Grushina28a9af7351b
diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
index 1a530cb32e9..6991f3a251d 100644
--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.tsx
@@ -19,6 +19,7 @@ import {
} from "metabase/current-user";
import { isEmbeddingSdk } from "metabase/embedding-sdk/config";
import {
+ alertHasValidTarget,
alertIsValid,
getAlertTriggerOptions,
getDefaultQuestionAlertRequest,
@@ -294,6 +295,7 @@ export const CreateOrEditQuestionAlertModal = ({
}
const isValid = alertIsValid(notification, channelSpec);
+ const hasValidTarget = alertHasValidTarget(notification, channelSpec);
const hasChanges = !isEqual(editingNotification, notification);
const hasError = errorCreating || errorUpdating;
@@ -441,6 +443,7 @@ export const CreateOrEditQuestionAlertModal = ({
<Button
variant="outline"
color="core-brand"
+ disabled={!hasValidTarget}
loading={isLoading}
onClick={onSendNow}
>
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 84b601f9fb2..89ad8cf89ba 100644
--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx
+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/CreateOrEditQuestionAlertModal.unit.spec.tsx
@@ -167,6 +167,18 @@ describe("CreateOrEditQuestionAlertModal", () => {
expect(screen.getByRole("button", { name: /send now/i })).toBeEnabled();
});
+ it("should disable 'Send now' when there is nowhere to send the alert to", async () => {
+ setup({
+ isAdmin: true,
+ isEmailSetup: false,
+ isSlackSetup: true,
+ });
+
+ expect(await screen.findByTestId("alert-create")).toBeInTheDocument();
+
+ expect(screen.getByRole("button", { name: /send now/i })).toBeDisabled();
+ });
+
it("should show the editing alert data when in edit mode", async () => {
// Create a custom notification with weekly schedule on Monday at 2pm
const mockNotification = createMockNotification({
diff --git a/frontend/src/metabase/notifications/utils.ts b/frontend/src/metabase/notifications/utils.ts
index 1fd596133e3..3ecb17853d8 100644
--- a/frontend/src/metabase/notifications/utils.ts
+++ b/frontend/src/metabase/notifications/utils.ts
@@ -254,15 +254,14 @@ const notificationHandlerTypeToChannelMap: Record<
["channel/http"]: "http",
};
-export function alertIsValid(
+export const alertHasValidTarget = (
notification: CreateAlertNotificationRequest | UpdateAlertNotificationRequest,
channelSpec: ChannelApiResponse | undefined,
-) {
+) => {
const handlers = notification.handlers;
- return (
+ return Boolean(
channelSpec?.channels &&
- notification.subscriptions.length > 0 &&
handlers.length > 0 &&
handlers.every((handlers) => channelIsValid(handlers)) &&
handlers.every((c) => {
@@ -270,7 +269,17 @@ export function alertIsValid(
notificationHandlerTypeToChannelMap[c.channel_type];
return channelSpec?.channels[handlerChannelType]?.configured;
- })
+ }),
+ );
+};
+
+export function alertIsValid(
+ notification: CreateAlertNotificationRequest | UpdateAlertNotificationRequest,
+ channelSpec: ChannelApiResponse | undefined,
+) {
+ return (
+ notification.subscriptions.length > 0 &&
+ alertHasValidTarget(notification, channelSpec)
);
}