Skip to content

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

UXW-2228 Properly mention available subscription & alert channels for non-admins (#66273)

Gabriel Moreno89443cda941a
diff --git a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js b/e2e/test/scenarios/sharing/alert/alert.cy.spec.js
index 1e6db16e022..21d00c4aeca 100644
--- a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js
+++ b/e2e/test/scenarios/sharing/alert/alert.cy.spec.js
@@ -21,10 +21,10 @@ describe("scenarios > alert", () => {
H.modal().within(() => {
cy.findByText(
- "To get notified when something happens, or to send this chart on a schedule, first set up SMTP, Slack, or a webhook.",
+ "To get notified when something happens, or to send this chart on a schedule, first set up email, Slack, or a webhook.",
);
- cy.findByText("Set up SMTP")
+ cy.findByText("Set up email")
.should("be.visible")
.closest("a")
.should("have.attr", "href", "/admin/settings/email");
@@ -49,10 +49,10 @@ describe("scenarios > alert", () => {
H.modal().within(() => {
cy.findByText(
- "To get notified when something happens, or to send this chart on a schedule, ask your Admin to set up SMTP or Slack.",
+ "To get notified when something happens, or to send this chart on a schedule, ask your admin to set up email, Slack, or a webhook.",
);
- cy.findByText("Set up SMTP").should("not.exist");
+ cy.findByText("Set up email").should("not.exist");
cy.findByText("Set up Slack").should("not.exist");
cy.findByText("Add a webhook").should("not.exist");
});
diff --git a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js b/e2e/test/scenarios/sharing/subscriptions.cy.spec.js
index 58046f9435a..31095f37326 100644
--- a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js
+++ b/e2e/test/scenarios/sharing/subscriptions.cy.spec.js
@@ -516,13 +516,11 @@ describe("scenarios > dashboard > subscriptions", () => {
.should("not.be.disabled");
});
- it("should disable subscriptions for non-admin users", () => {
+ it("should allow non-admin users to create subscriptions", () => {
cy.signInAsNormalUser();
H.visitDashboard(ORDERS_DASHBOARD_ID);
H.openSharingMenu();
- H.sharingMenu()
- .findByText("Can't send subscriptions")
- .should("be.visible");
+ H.sharingMenu().findByText("Subscriptions").should("be.visible");
});
});
diff --git a/frontend/src/metabase/common/hooks/use-notification-channels/use-notification-channels.ts b/frontend/src/metabase/common/hooks/use-notification-channels/use-notification-channels.ts
index ed9b61329e8..4f300adc237 100644
--- a/frontend/src/metabase/common/hooks/use-notification-channels/use-notification-channels.ts
+++ b/frontend/src/metabase/common/hooks/use-notification-channels/use-notification-channels.ts
@@ -13,3 +13,9 @@ export const useHasEmailSetup = (): boolean => {
return !!channelInfo?.channels?.email?.configured;
};
+
+export const useHasSlackSetup = (): boolean => {
+ const { data: channelInfo } = useGetChannelInfoQuery();
+
+ return !!channelInfo?.channels?.slack?.configured;
+};
diff --git a/frontend/src/metabase/embedding/components/SharingMenu/test/DashboardSharingMenu.unit.spec.tsx b/frontend/src/metabase/embedding/components/SharingMenu/test/DashboardSharingMenu.unit.spec.tsx
index 300d3bb530a..98394f7d790 100644
--- a/frontend/src/metabase/embedding/components/SharingMenu/test/DashboardSharingMenu.unit.spec.tsx
+++ b/frontend/src/metabase/embedding/components/SharingMenu/test/DashboardSharingMenu.unit.spec.tsx
@@ -76,7 +76,7 @@ describe("DashboardSharingMenu", () => {
});
describe("non-admins", () => {
- it("should show 'subscriptions' option when email is set up", async () => {
+ it("should show 'subscriptions' option when email is set up, but slack is not setup", async () => {
setupDashboardSharingMenu({
isAdmin: false,
isEmailSetup: true,
@@ -86,7 +86,7 @@ describe("DashboardSharingMenu", () => {
expect(screen.getByText("Subscriptions")).toBeInTheDocument();
});
- it("should show disabled 'subscriptions' option when email is not set up", async () => {
+ it("should show 'subscriptions' option when email is not set up, but slack is setup", async () => {
setupDashboardSharingMenu({
isAdmin: false,
isEmailSetup: false,
@@ -94,7 +94,7 @@ describe("DashboardSharingMenu", () => {
});
await openMenu();
expect(
- await screen.findByText("Can't send subscriptions"),
+ await screen.findByText("Subscriptions", { exact: true }),
).toBeInTheDocument();
});
diff --git a/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.tsx b/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.tsx
index 175faba967e..d3358d130cf 100644
--- a/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.tsx
+++ b/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.tsx
@@ -1,6 +1,6 @@
import { t } from "ttag";
-import { useHasEmailSetup } from "metabase/common/hooks";
+import { useHasEmailSetup, useHasSlackSetup } from "metabase/common/hooks";
import { useSelector } from "metabase/lib/redux";
import {
canManageSubscriptions as canManageSubscriptionsSelector,
@@ -18,6 +18,7 @@ export function DashboardSubscriptionMenuItem({
}) {
const isAdmin = useSelector(getUserIsAdmin);
const hasEmailSetup = useHasEmailSetup();
+ const hasSlackSetup = useHasSlackSetup();
const canManageSubscriptions = useSelector(canManageSubscriptionsSelector);
@@ -26,11 +27,13 @@ export function DashboardSubscriptionMenuItem({
(dashCard) => !["text", "heading"].includes(dashCard.card.display),
);
+ const hasAnySubscriptionChannel = hasEmailSetup || hasSlackSetup;
+
if (!canManageSubscriptions || !hasDataCards) {
return null;
}
- if (!isAdmin && !hasEmailSetup) {
+ if (!isAdmin && !hasAnySubscriptionChannel) {
return (
<Menu.Item
data-testid="dashboard-subscription-menu-item"
@@ -38,7 +41,10 @@ export function DashboardSubscriptionMenuItem({
disabled
>
<Text size="md" c="inherit">{t`Can't send subscriptions`}</Text>
- <Text size="sm" c="inherit">{t`Ask your admin to set up email`}</Text>
+ <Text
+ size="sm"
+ c="inherit"
+ >{t`Ask your admin to set up email or Slack`}</Text>
</Menu.Item>
);
}
diff --git a/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.unit.spec.tsx b/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.unit.spec.tsx
new file mode 100644
index 00000000000..28b408a6cce
--- /dev/null
+++ b/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.unit.spec.tsx
@@ -0,0 +1,113 @@
+import { setupNotificationChannelsEndpoints } from "__support__/server-mocks/pulse";
+import { renderWithProviders, screen } from "__support__/ui";
+import { Menu } from "metabase/ui";
+import type { ChannelApiResponse } from "metabase-types/api";
+import {
+ createMockCard,
+ createMockDashboard,
+ createMockDashboardCard,
+ createMockUser,
+} from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
+
+import { DashboardSubscriptionMenuItem } from "./DashboardSubscriptionMenuItem";
+
+const mockOnClick = jest.fn();
+
+const createDashboardWithDataCards = () => {
+ return createMockDashboard({
+ dashcards: [
+ createMockDashboardCard({
+ card: createMockCard({ display: "table" }),
+ }),
+ ],
+ });
+};
+
+const setup = ({
+ isSuperuser = false,
+ hasEmailSetup = false,
+ hasSlackSetup = false,
+ dashboard: mockDashboard = createDashboardWithDataCards(),
+}: {
+ isSuperuser?: boolean;
+ hasEmailSetup?: boolean;
+ hasSlackSetup?: boolean;
+ dashboard?: ReturnType<typeof createMockDashboard>;
+} = {}) => {
+ const currentUser = createMockUser({
+ is_superuser: isSuperuser,
+ });
+ const storeInitialState = createMockState({
+ currentUser,
+ });
+
+ setupNotificationChannelsEndpoints({
+ email: { configured: hasEmailSetup },
+ slack: { configured: hasSlackSetup },
+ } as ChannelApiResponse["channels"]);
+
+ renderWithProviders(
+ <Menu opened>
+ <Menu.Dropdown>
+ <DashboardSubscriptionMenuItem
+ onClick={mockOnClick}
+ dashboard={mockDashboard}
+ />
+ </Menu.Dropdown>
+ </Menu>,
+ { storeInitialState },
+ );
+};
+
+describe("DashboardSubscriptionMenuItem", () => {
+ it("should show 'Subscriptions' menu item when can manage subscriptions and has no email or slack setup", async () => {
+ setup({
+ isSuperuser: true,
+ hasEmailSetup: false,
+ hasSlackSetup: false,
+ });
+
+ expect(
+ screen.getByTestId("dashboard-subscription-menu-item"),
+ ).toBeInTheDocument();
+ expect(await screen.findByText("Subscriptions")).toBeInTheDocument();
+ });
+
+ describe("when user can't manage subscriptions and dashboard has data cards", () => {
+ it.each([
+ { hasEmailSetup: true, hasSlackSetup: false },
+ { hasEmailSetup: false, hasSlackSetup: true },
+ { hasEmailSetup: true, hasSlackSetup: true },
+ ])(
+ "should show 'Subscriptions' menu item when email is $hasEmailSetup and slack is $hasSlackSetup",
+ async ({ hasEmailSetup, hasSlackSetup }) => {
+ setup({
+ isSuperuser: false,
+ hasEmailSetup,
+ hasSlackSetup,
+ });
+
+ expect(
+ screen.getByTestId("dashboard-subscription-menu-item"),
+ ).toBeInTheDocument();
+ expect(await screen.findByText("Subscriptions")).toBeInTheDocument();
+ },
+ );
+
+ it('should show "Can\'t send subscriptions" menu item when email and slack are not set up', async () => {
+ setup({
+ isSuperuser: false,
+ hasEmailSetup: false,
+ hasSlackSetup: false,
+ });
+
+ expect(
+ screen.getByTestId("dashboard-subscription-menu-item"),
+ ).toBeInTheDocument();
+ expect(
+ await screen.findByText("Can't send subscriptions"),
+ ).toBeInTheDocument();
+ });
+ });
+});
diff --git a/frontend/src/metabase/notifications/modals/ChannelSetupModal.tsx b/frontend/src/metabase/notifications/modals/ChannelSetupModal.tsx
index 3d72d9f9377..d838c220b86 100644
--- a/frontend/src/metabase/notifications/modals/ChannelSetupModal.tsx
+++ b/frontend/src/metabase/notifications/modals/ChannelSetupModal.tsx
@@ -11,7 +11,7 @@ const CHANNELS_CONFIG: {
}[] = [
{
get title() {
- return t`Set up SMTP`;
+ return t`Set up email`;
},
icon: "mail",
link: "/admin/settings/email",
@@ -51,8 +51,8 @@ export const ChannelSetupModal = ({
<Stack gap="0.5rem">
<Text mb="1rem">
{userCanAccessSettings
- ? t`To get notified when something happens, or to send this chart on a schedule, first set up SMTP, Slack, or a webhook.`
- : t`To get notified when something happens, or to send this chart on a schedule, ask your Admin to set up SMTP or Slack.`}
+ ? t`To get notified when something happens, or to send this chart on a schedule, first set up email, Slack, or a webhook.`
+ : t`To get notified when something happens, or to send this chart on a schedule, ask your admin to set up email, Slack, or a webhook.`}
</Text>
{userCanAccessSettings &&