The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
DSN-79 In questions and metrics, Alerts shouldn't be within Sharing menu (#64510)
Kamil Mielnik6ab4cca8f250
diff --git a/e2e/test/scenarios/permissions/application-permissions.cy.spec.js b/e2e/test/scenarios/permissions/application-permissions.cy.spec.jsindex be65d21ab61..4b828374738 100644--- a/e2e/test/scenarios/permissions/application-permissions.cy.spec.js+++ b/e2e/test/scenarios/permissions/application-permissions.cy.spec.js@@ -88,7 +88,8 @@ describe("scenarios > admin > permissions > application", () => {cy.log("Create a question alert");H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu(/alert/i);+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().findByText("New alert").should("be.visible");});});diff --git a/e2e/test/scenarios/question/saved.cy.spec.js b/e2e/test/scenarios/question/saved.cy.spec.jsindex 9e786f71355..ab302edbead 100644--- a/e2e/test/scenarios/question/saved.cy.spec.js+++ b/e2e/test/scenarios/question/saved.cy.spec.js@@ -645,7 +645,7 @@ describe(it("should allow you to enable a webhook alert", () => {H.visitQuestion(ORDERS_COUNT_QUESTION_ID);- cy.findByTestId("sharing-menu-button").click();+ cy.findByLabelText("Move, trash, and more…").click();H.popover().findByText("Create an alert").click();H.modal().findByText("New alert").should("be.visible");@@ -655,7 +655,8 @@ describe(});H.modal().button("Done").click();- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().findByText(/Created by you/).should("be.exist")@@ -668,7 +669,7 @@ describe(it("should allow you to test a webhook", { tags: "@skip" }, () => {cy.intercept("POST", "/api/pulse/test").as("testAlert");H.visitQuestion(ORDERS_COUNT_QUESTION_ID);- cy.findByTestId("sharing-menu-button").click();+ cy.findByLabelText("Move, trash, and more…").click();H.popover().findByText("Create an alert").click();H.modal().within(() => {diff --git a/e2e/test/scenarios/sharing/alert/alert-permissions.cy.spec.js b/e2e/test/scenarios/sharing/alert/alert-permissions.cy.spec.jsindex b42ab6c5941..c15a126978c 100644--- a/e2e/test/scenarios/sharing/alert/alert-permissions.cy.spec.js+++ b/e2e/test/scenarios/sharing/alert/alert-permissions.cy.spec.js@@ -49,7 +49,8 @@ describe("scenarios > alert > alert permissions", { tags: "@external" }, () => {// Change alertH.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().findByText(/Created by you/)@@ -71,15 +72,16 @@ describe("scenarios > alert > alert permissions", { tags: "@external" }, () => {it("should not let you see other people's alerts", () => {H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu();+ cy.findByLabelText("Move, trash, and more…").click();- H.sharingMenu().findByText("Edit alerts").should("not.exist");- H.sharingMenu().findByText("Create an alert").should("be.visible");+ H.popover().findByText("Edit alerts").should("not.exist");+ H.popover().findByText("Create an alert").should("be.visible");});it("should let you see other alerts where you are a recipient", () => {H.visitQuestion(ORDERS_COUNT_QUESTION_ID);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().within(() => {cy.findByText(`Created by ${H.getFullName(admin)}`, {@@ -91,14 +93,17 @@ describe("scenarios > alert > alert permissions", { tags: "@external" }, () => {it("should let you see your own alerts", () => {H.visitQuestion(ORDERS_BY_YEAR_QUESTION_ID);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().findByText(/Created by you/);});it("should let you unsubscribe from others' alerts", () => {H.visitQuestion(ORDERS_COUNT_QUESTION_ID);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();+H.modal().within(() => {cy.findByText(`Created by ${H.getFullName(admin)}`, {exact: false,@@ -118,7 +123,9 @@ describe("scenarios > alert > alert permissions", { tags: "@external" }, () => {cy.intercept("PUT", "/api/notification/*").as("updatedAlert");H.visitQuestion(ORDERS_BY_YEAR_QUESTION_ID);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();+H.modal().findByText(/Created by you/).click();@@ -144,7 +151,8 @@ describe("scenarios > alert > alert permissions", { tags: "@external" }, () => {});function createBasicAlert({ includeNormal } = {}) {- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();if (includeNormal) {cy.findByText("Email")diff --git a/e2e/test/scenarios/sharing/alert/alert-types.cy.spec.js b/e2e/test/scenarios/sharing/alert/alert-types.cy.spec.jsindex 9199fba8d36..85a34ba834a 100644--- a/e2e/test/scenarios/sharing/alert/alert-types.cy.spec.js+++ b/e2e/test/scenarios/sharing/alert/alert-types.cy.spec.js@@ -55,7 +55,8 @@ describe("scenarios > alert > types", { tags: "@external" }, () => {it(`should be supported for ${questionType}`, () => {H.visitQuestion(questionId);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();cy.wait("@channel");H.modal().within(() => {@@ -90,7 +91,8 @@ describe("scenarios > alert > types", { tags: "@external" }, () => {H.visitQuestion(timeSeriesQuestionId);cy.findByTestId("chart-container").should("contain", "Goal");- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();cy.wait("@channel");H.modal().findByTestId("alert-goal-select").should("be.enabled").click();@@ -117,7 +119,8 @@ describe("scenarios > alert > types", { tags: "@external" }, () => {it("should not be possible to create goal based alert for a multi-series question", () => {H.createQuestion(multiSeriesQuestionWithGoal, { visitQuestion: true });- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();cy.wait("@channel");H.modal().within(() => {diff --git a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js b/e2e/test/scenarios/sharing/alert/alert.cy.spec.jsindex a830cfbe84f..1e6db16e022 100644--- a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js+++ b/e2e/test/scenarios/sharing/alert/alert.cy.spec.js@@ -15,7 +15,9 @@ describe("scenarios > alert", () => {describe("with nothing set", () => {it("should prompt you to add email/slack credentials", () => {H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Create an alert");++ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().within(() => {cy.findByText(@@ -41,7 +43,9 @@ describe("scenarios > alert", () => {cy.signInAsNormalUser();H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Create an alert");++ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().within(() => {cy.findByText(@@ -70,7 +74,9 @@ describe("scenarios > alert", () => {it("should be able to create and delete alerts with webhooks enabled", () => {H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Create an alert");++ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.addNotificationHandlerChannel("Bar Hook");@@ -78,7 +84,8 @@ describe("scenarios > alert", () => {H.notificationList().findByText("Your alert is all set up.");- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().within(() => {cy.findByText("Edit alerts").should("be.visible");@@ -129,10 +136,12 @@ describe("scenarios > alert", () => {{ visitQuestion: true },);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, duplicate, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().button("Done").click();- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, duplicate, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().within(() => {cy.findByText("Edit alerts").should("be.visible");cy.findByText(/Created by you/).should("be.visible");@@ -171,7 +180,8 @@ describe("scenarios > alert", () => {it("should validate approved email domains for a question alert", () => {H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().within(() => {cy.findByText("New alert").should("be.visible");@@ -204,7 +214,8 @@ describe("scenarios > alert", () => {cy.signInAsNormalUser();H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().within(() => {cy.findByText("New alert").should("be.visible");diff --git a/e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js b/e2e/test/scenarios/sharing/alert/email-alert.cy.spec.jsindex cb64a73ac12..0fdbcf80bed 100644--- a/e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js+++ b/e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js@@ -81,7 +81,8 @@ describe("scenarios > alert > email_alert", { tags: "@external" }, () => {cy.log("ensure that when the alert is deleted, the delete modal is correct metabase#48402",);- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().within(() => {cy.findByText("Edit alerts").should("be.visible");cy.findByText(/Created by you/).realHover();@@ -120,7 +121,8 @@ describe("scenarios > alert > email_alert", { tags: "@external" }, () => {.findByText("Your alert is all set up.").should("be.visible");- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, duplicate, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().within(() => {cy.findByText("Edit alerts").should("be.visible");@@ -181,7 +183,8 @@ describe("scenarios > alert > email_alert", { tags: "@external" }, () => {function openAlertForQuestion(id) {H.visitQuestion(id);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();}function saveAlert() {@@ -193,7 +196,8 @@ function saveAlert() {});cy.wait("@saveCard");- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, duplicate, and more…").click();+ H.popover().findByText("Create an alert").click();H.modal().button("Done").click();}@@ -206,7 +210,8 @@ function sendTestAlertForQuestion(name) {{ visitQuestion: true },);- H.openSharingMenu("Create an alert");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Create an alert").click();H.sendAlertAndVisitIt();cy.findAllByRole("link").filter(`:contains(${name})`).should("be.visible");}diff --git a/e2e/test/scenarios/sharing/sharing-reproductions.cy.spec.js b/e2e/test/scenarios/sharing/sharing-reproductions.cy.spec.jsindex f300bf1144d..0f53a8d662c 100644--- a/e2e/test/scenarios/sharing/sharing-reproductions.cy.spec.js+++ b/e2e/test/scenarios/sharing/sharing-reproductions.cy.spec.js@@ -929,7 +929,8 @@ describe("issue 17547", () => {});it("editing an alert should not delete it (metabase#17547)", () => {- H.openSharingMenu("Edit alerts");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit alerts").click();H.modal().findByText("Check daily at 9:00 AM").should("be.visible").click();H.modal().within(() => {diff --git a/frontend/src/metabase/embedding/components/SharingMenu/QuestionSharingMenu.tsx b/frontend/src/metabase/embedding/components/SharingMenu/QuestionSharingMenu.tsxindex 344c5a09c3c..13f68e14f64 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/QuestionSharingMenu.tsx+++ b/frontend/src/metabase/embedding/components/SharingMenu/QuestionSharingMenu.tsx@@ -4,14 +4,13 @@ import { t } from "ttag";import { isInstanceAnalyticsCollection } from "metabase/collections/utils";import { useSetting } from "metabase/common/hooks";import { useDispatch, useSelector } from "metabase/lib/redux";-import { QuestionAlertsMenuItem } from "metabase/notifications/NotificationsActionsMenu/QuestionAlertsMenuItem";import { setUIControls } from "metabase/query_builder/actions";import { MODAL_TYPES } from "metabase/query_builder/constants";import {canManageSubscriptions as canManageSubscriptionsSelector,getUserIsAdmin,} from "metabase/selectors/user";-import { Flex, Menu } from "metabase/ui";+import { Flex } from "metabase/ui";import type Question from "metabase-lib/v1/Question";import { EmbedMenuItem } from "./MenuItems/EmbedMenuItem";@@ -85,12 +84,6 @@ export function QuestionSharingMenu({ question }: { question: Question }) {return (<Flex><SharingMenu>- <QuestionAlertsMenuItem- question={question}- onClick={() => setModalType("question-alert")}- />-- <Menu.Divider /><PublicLinkMenuItemhasPublicLink={hasPublicLink}onClick={() => setModalType("question-public-link")}diff --git a/frontend/src/metabase/embedding/components/SharingMenu/SharingModals.tsx b/frontend/src/metabase/embedding/components/SharingMenu/SharingModals.tsxindex fe334843341..6e78f262d15 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/SharingModals.tsx+++ b/frontend/src/metabase/embedding/components/SharingMenu/SharingModals.tsx@@ -1,7 +1,6 @@import { type Ref, forwardRef } from "react";import { DashboardSharingEmbeddingModal } from "metabase/dashboard/containers/DashboardSharingEmbeddingModal";-import { QuestionAlertListModal } from "metabase/notifications/modals";import { QuestionEmbedWidget } from "metabase/query_builder/components/QuestionEmbedWidget";import { Box } from "metabase/ui";import type Question from "metabase-lib/v1/Question";@@ -53,10 +52,6 @@ export const SharingModals = ({question,dashboard,}: SharingModalProps) => {- if (modalType === "question-alert") {- return <QuestionAlertListModal question={question} onClose={onClose} />;- }-if (modalType === "question-public-link") {return (<QuestionPublicLinkPopoverdiff --git a/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.enterprise.unit.spec.tsx b/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.enterprise.unit.spec.tsxindex ada2e621ec2..b92c4d3032e 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.enterprise.unit.spec.tsx+++ b/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.enterprise.unit.spec.tsx@@ -3,31 +3,11 @@ import userEvent from "@testing-library/user-event";import { screen } from "__support__/ui";import { createMockCollection } from "metabase-types/api/mocks";-import { openMenu, setupQuestionSharingMenu } from "./setup";+import { setupQuestionSharingMenu } from "./setup";describe("QuestionSharingMenu > Enterprise", () => {describe("non-admins", () => {- it('Should show the "Create an alert" menu item to non-admins if the user has subscriptions/alerts permissions', async () => {- setupQuestionSharingMenu({- canManageSubscriptions: true,- isEmailSetup: true,- isEnterprise: true,- });- await openMenu();- expect(screen.getByText("Create an alert")).toBeInTheDocument();- });-describe("alerts permission disabled", () => {- it('Should not show the "Create an alert" menu item to non-admins if the user lacks subscriptions/alerts permissions', async () => {- setupQuestionSharingMenu({- canManageSubscriptions: false,- isEmailSetup: true,- isEnterprise: true,- });- await openMenu();- expect(screen.queryByText("Create an alert")).not.toBeInTheDocument();- });-it('should show a "Public link" button item if public sharing is enabled and the user lacks alerts permissions', async () => {setupQuestionSharingMenu({canManageSubscriptions: false,diff --git a/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.unit.spec.tsx b/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.unit.spec.tsxindex a8be8ca5d22..6ee359e5c5f 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.unit.spec.tsx+++ b/frontend/src/metabase/embedding/components/SharingMenu/test/QuestionSharingMenu.unit.spec.tsx@@ -1,7 +1,6 @@import userEvent from "@testing-library/user-event";import { screen } from "__support__/ui";-import { createMockNotification } from "metabase-types/api/mocks";import { openMenu, setupQuestionSharingMenu } from "./setup";@@ -44,79 +43,6 @@ describe("QuestionSharingMenu", () => {);});- describe("notifications", () => {- describe("admins", () => {- it("should show the 'Create an alert' menu item if no alerts exist", async () => {- setupQuestionSharingMenu({- isAdmin: true,- isEmailSetup: true,- alerts: [],- });- await openMenu();- expect(screen.getByText("Create an alert")).toBeInTheDocument();- });-- it("should show the 'Edit alerts' menu item if alerts exist", async () => {- setupQuestionSharingMenu({- isAdmin: true,- isEmailSetup: true,- alerts: [createMockNotification()],- });- await openMenu();- expect(await screen.findByText("Edit alerts")).toBeInTheDocument();- });-- it("clicking to edit alerts should open the alert popover", async () => {- setupQuestionSharingMenu({- isAdmin: true,- isEmailSetup: true,- alerts: [createMockNotification()],- });- await openMenu();- await userEvent.click(screen.getByText("Edit alerts"));- expect(- await screen.findByTestId("alert-list-modal"),- ).toBeInTheDocument();- });- });-- describe("non-admins", () => {- // NOTE: canManageSubscriptions doesn't do anything here as it is always "true" for non-EE- it("should show the 'Create an alert' menu item if no alerts exist", async () => {- setupQuestionSharingMenu({- isAdmin: false,- isEmailSetup: true,- alerts: [],- });- await openMenu();- expect(screen.getByText("Create an alert")).toBeInTheDocument();- });-- it("should show the 'Edit alerts' menu item if alerts exist", async () => {- setupQuestionSharingMenu({- isAdmin: false,- isEmailSetup: true,- alerts: [createMockNotification()],- });- await openMenu();- expect(screen.getByText("Edit alerts")).toBeInTheDocument();- });-- it("clicking to edit alerts should open the alert popover", async () => {- setupQuestionSharingMenu({- isAdmin: false,- isEmailSetup: true,- alerts: [createMockNotification()],- });- await openMenu();- await userEvent.click(screen.getByText("Edit alerts"));- expect(- await screen.findByTestId("alert-list-modal"),- ).toBeInTheDocument();- });- });- });-describe("public links", () => {describe("admins", () => {it('should show a "Create Public link" menu item if public sharing is enabled', async () => {diff --git a/frontend/src/metabase/embedding/components/SharingMenu/test/setup.tsx b/frontend/src/metabase/embedding/components/SharingMenu/test/setup.tsxindex e8c76d55c98..39985787400 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/test/setup.tsx+++ b/frontend/src/metabase/embedding/components/SharingMenu/test/setup.tsx@@ -1,4 +1,5 @@/* eslint-disable i18next/no-literal-string */+import userEvent from "@testing-library/user-event";import { setupEnterprisePlugins } from "__support__/enterprise";diff --git a/frontend/src/metabase/embedding/components/SharingMenu/types.ts b/frontend/src/metabase/embedding/components/SharingMenu/types.tsindex 857fff95740..674cefdac4a 100644--- a/frontend/src/metabase/embedding/components/SharingMenu/types.ts+++ b/frontend/src/metabase/embedding/components/SharingMenu/types.ts@@ -5,8 +5,7 @@ export type PublicLinkModalType =export type QuestionSharingModalType =| "question-public-link"- | "question-embed"- | "question-alert";+ | "question-embed";export type DashboardSharingModalType =| "dashboard-public-link"diff --git a/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx b/frontend/src/metabase/home/components/Onboarding/Onboarding.tsxindex 2c5f3543563..0b4696f8fc3 100644--- a/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx+++ b/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx@@ -593,8 +593,8 @@ export const Onboarding = () => {<Text>{jt`Go to a question and click on the ${(<Icon- key="sharing-icon"- name="share"+ key="more-icon"+ name="ellipsis"className={S.inlineIcon}/>)} icon on the top bar, then ${(diff --git a/frontend/src/metabase/notifications/NotificationsActionsMenu/CommonNotificationsMenuItem.tsx b/frontend/src/metabase/notifications/NotificationsActionsMenu/CommonNotificationsMenuItem.tsxindex 9c5e42c7981..5867eff6dd3 100644--- a/frontend/src/metabase/notifications/NotificationsActionsMenu/CommonNotificationsMenuItem.tsx+++ b/frontend/src/metabase/notifications/NotificationsActionsMenu/CommonNotificationsMenuItem.tsx@@ -1,6 +1,6 @@import type { MouseEventHandler } from "react";-import { Center, Icon, type IconName, Menu } from "metabase/ui";+import { Icon, type IconName, Menu } from "metabase/ui";type CommonNotificationsMenuItemProps = {iconName: IconName;@@ -18,11 +18,7 @@ export const CommonNotificationsMenuItem = ({return (<Menu.Itemdata-testid="question-alert-menu-item"- leftSection={- <Center mr="xs">- <Icon name={iconName} />- </Center>- }+ leftSection={<Icon name={iconName} />}disabled={disabled}onClick={onClick}>diff --git a/frontend/src/metabase/notifications/NotificationsActionsMenu/index.ts b/frontend/src/metabase/notifications/NotificationsActionsMenu/index.tsindex cdc0e256cab..9b35580e03c 100644--- a/frontend/src/metabase/notifications/NotificationsActionsMenu/index.ts+++ b/frontend/src/metabase/notifications/NotificationsActionsMenu/index.ts@@ -1,2 +1 @@export * from "./DashboardSubscriptionMenuItem";-export * from "./QuestionAlertsMenuItem";diff --git a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsxindex 6123a8f8bc4..4f13b64c401 100644--- a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx+++ b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx@@ -10,7 +10,7 @@ import { SaveQuestionModal } from "metabase/common/components/SaveQuestionModal"import EntityCopyModal from "metabase/entities/containers/EntityCopyModal";import { useDispatch, useSelector } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";-import { CreateOrEditQuestionAlertModal } from "metabase/notifications/modals";+import { QuestionAlertListModal } from "metabase/notifications/modals";import { ImpossibleToCreateModelModal } from "metabase/query_builder/components/ImpossibleToCreateModelModal";import { NewDatasetModal } from "metabase/query_builder/components/NewDatasetModal";import { QuestionEmbedWidget } from "metabase/query_builder/components/QuestionEmbedWidget";@@ -229,10 +229,7 @@ export function QueryModals({);case MODAL_TYPES.CREATE_ALERT:return (- <CreateOrEditQuestionAlertModal- onAlertCreated={onCloseModal}- onClose={onCloseModal}- />+ <QuestionAlertListModal question={question} onClose={onCloseModal} />);case MODAL_TYPES.SAVE_QUESTION_BEFORE_EMBED:return (diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.unit.spec.tsxindex 35f3a991ed8..77a4a08bd4f 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.unit.spec.tsx@@ -1,5 +1,6 @@import userEvent from "@testing-library/user-event";+import { setupListNotificationEndpoints } from "__support__/server-mocks/notification";import { setupGetUserKeyValueEndpoint } from "__support__/server-mocks/user-key-value";import { createMockEntitiesState } from "__support__/store";import {@@ -69,6 +70,8 @@ function setup({value: hasAcknowledgedModelModal,});+ setupListNotificationEndpoints({ card_id: card.id }, []);+const state = createMockState({entities: createMockEntitiesState({databases: hasDataPermissions ? [createSampleDatabase()] : [],diff --git a/frontend/src/metabase/notifications/NotificationsActionsMenu/QuestionAlertsMenuItem.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionAlertsMenuItem.tsxsimilarity index 86%rename from frontend/src/metabase/notifications/NotificationsActionsMenu/QuestionAlertsMenuItem.tsxrename to frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionAlertsMenuItem.tsxindex 35a156b4cca..01388d702c5 100644--- a/frontend/src/metabase/notifications/NotificationsActionsMenu/QuestionAlertsMenuItem.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionAlertsMenuItem.tsx@@ -11,10 +11,10 @@ export function QuestionAlertsMenuItem({question: Question;onClick: () => void;}) {- const { data: questionNotifications, isLoading } = useListNotificationsQuery({- card_id: question.id() ?? skipToken,- include_inactive: false,- });+ const id = question.id();+ const { data: questionNotifications, isLoading } = useListNotificationsQuery(+ id == null ? skipToken : { card_id: id, include_inactive: false },+ );return (<CommonNotificationsMenuItemdiff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionMoreActionsMenu.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionMoreActionsMenu.tsxindex 446d7feddd4..ec89e68dd2a 100644--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionMoreActionsMenu.tsx+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/QuestionMoreActionsMenu.tsx@@ -2,6 +2,7 @@ import { Fragment, type JSX, useState } from "react";import { c, t } from "ttag";import _ from "underscore";+import { isInstanceAnalyticsCollection } from "metabase/collections/utils";import { ToolbarButton } from "metabase/common/components/ToolbarButton";import { useUserAcknowledgement } from "metabase/common/hooks/use-user-acknowledgement";import { useDispatch, useSelector } from "metabase/lib/redux";@@ -21,6 +22,10 @@ import {type QueryModalType,} from "metabase/query_builder/constants";import { getQuestionWithoutComposing } from "metabase/query_builder/selectors";+import {+ canManageSubscriptions as canManageSubscriptionsSelector,+ getUserIsAdmin,+} from "metabase/selectors/user";import { Icon, Menu } from "metabase/ui";import * as Lib from "metabase-lib";import type Question from "metabase-lib/v1/Question";@@ -28,6 +33,7 @@ import { checkCanBeModel } from "metabase-lib/v1/metadata/utils/models";import type { DatasetEditorTab, QueryBuilderMode } from "metabase-types/store";import QuestionActionsS from "./QuestionActions.module.css";+import { QuestionAlertsMenuItem } from "./QuestionAlertsMenuItem";const ADD_TO_DASH_TESTID = "add-to-dashboard-button";const MOVE_TESTID = "move-button";@@ -56,6 +62,8 @@ export const QuestionMoreActionsMenu = ({const underlyingQuestion = useSelector(getQuestionWithoutComposing);const dispatch = useDispatch();+ const isAdmin = useSelector(getUserIsAdmin);+ const canManageSubscriptions = useSelector(canManageSubscriptionsSelector);const isQuestion = question.type() === "question";const isModel = question.type() === "model";@@ -66,6 +74,9 @@ export const QuestionMoreActionsMenu = ({const isStandaloneQuestion =isQuestion && !_.isNumber(question.dashboardId());+ const collection = question.collection();+ const isAnalytics = collection && isInstanceAnalyticsCollection(collection);+const hasCollectionPermissions = question.canWrite();const enableSettingsSidebar = shouldShowQuestionSettingsSidebar(question);@@ -117,6 +128,13 @@ export const QuestionMoreActionsMenu = ({{t`Add to dashboard`}</Menu.Item>),+ (isAdmin || canManageSubscriptions) && !isModel && !isAnalytics && (+ <QuestionAlertsMenuItem+ key="alerts"+ question={question}+ onClick={() => onOpenModal(MODAL_TYPES.CREATE_ALERT)}+ />+ ),...PLUGIN_MODERATION.useQuestionMenuItems(question, reload),hasCollectionPermissions && isModelOrMetric && hasDataPermissions && (<Menu.Item@@ -172,17 +190,18 @@ export const QuestionMoreActionsMenu = ({{t`Edit settings`}</Menu.Item>),+ (hasCollectionPermissions || hasDataPermissions) && (+ <Menu.Divider key="divider" />+ ),hasCollectionPermissions && (- <Fragment key="move">- <Menu.Divider />- <Menu.Item- leftSection={<Icon name="move" />}- data-testid={MOVE_TESTID}- onClick={() => onOpenModal(MODAL_TYPES.MOVE)}- >- {c("A verb, not a noun").t`Move`}- </Menu.Item>- </Fragment>+ <Menu.Item+ key="move"+ leftSection={<Icon name="move" />}+ data-testid={MOVE_TESTID}+ onClick={() => onOpenModal(MODAL_TYPES.MOVE)}+ >+ {c("A verb, not a noun").t`Move`}+ </Menu.Item>),hasDataPermissions && (<Menu.Itemdiff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.enterprise.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.enterprise.unit.spec.tsxnew file mode 100644index 00000000000..6465826247a--- /dev/null+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.enterprise.unit.spec.tsx@@ -0,0 +1,31 @@+import { screen } from "__support__/ui";++import { openMenu, setup } from "./setup";++describe("QuestionMoreActionsMenu > Enterprise", () => {+ describe("non-admins", () => {+ it('Should show the "Create an alert" menu item to non-admins if the user has subscriptions/alerts permissions', async () => {+ setup({+ canManageSubscriptions: true,+ isAdmin: false,+ isEmailSetup: true,+ isEnterprise: true,+ });+ await openMenu();+ expect(screen.getByText("Create an alert")).toBeInTheDocument();+ });++ describe("alerts permission disabled", () => {+ it('Should not show the "Create an alert" menu item to non-admins if the user lacks subscriptions/alerts permissions', async () => {+ setup({+ canManageSubscriptions: false,+ isAdmin: false,+ isEmailSetup: true,+ isEnterprise: true,+ });+ await openMenu();+ expect(screen.queryByText("Create an alert")).not.toBeInTheDocument();+ });+ });+ });+});diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.unit.spec.tsxnew file mode 100644index 00000000000..f4aff5555b8--- /dev/null+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/QuestionMoreActionsMenu.unit.spec.tsx@@ -0,0 +1,87 @@+import userEvent from "@testing-library/user-event";++import { screen } from "__support__/ui";+import { createMockNotification } from "metabase-types/api/mocks";++import { openMenu, setup } from "./setup";++describe("QuestionMoreActionsMenu >", () => {+ describe("admins", () => {+ it("should show the 'Create an alert' menu item if no alerts exist", async () => {+ setup({+ alerts: [],+ canManageSubscriptions: false,+ isAdmin: true,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ expect(screen.getByText("Create an alert")).toBeInTheDocument();+ });++ it("should show the 'Edit alerts' menu item if alerts exist", async () => {+ setup({+ alerts: [createMockNotification()],+ canManageSubscriptions: false,+ isAdmin: true,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ expect(await screen.findByText("Edit alerts")).toBeInTheDocument();+ });++ it("clicking to edit alerts should open the alert popover", async () => {+ setup({+ alerts: [createMockNotification()],+ canManageSubscriptions: false,+ isAdmin: true,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ await userEvent.click(screen.getByText("Edit alerts"));+ expect(await screen.findByTestId("alert-list-modal")).toBeInTheDocument();+ });+ });++ describe("non-admins", () => {+ // NOTE: canManageSubscriptions doesn't do anything here as it is always "true" for non-EE+ it("should show the 'Create an alert' menu item if no alerts exist", async () => {+ setup({+ alerts: [],+ canManageSubscriptions: false,+ isAdmin: false,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ expect(screen.getByText("Create an alert")).toBeInTheDocument();+ });++ it("should show the 'Edit alerts' menu item if alerts exist", async () => {+ setup({+ alerts: [createMockNotification()],+ canManageSubscriptions: false,+ isAdmin: false,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ expect(screen.getByText("Edit alerts")).toBeInTheDocument();+ });++ it("clicking to edit alerts should open the alert popover", async () => {+ setup({+ alerts: [createMockNotification()],+ canManageSubscriptions: false,+ isAdmin: false,+ isEmailSetup: true,+ isEnterprise: false,+ });+ await openMenu();+ await userEvent.click(screen.getByText("Edit alerts"));+ expect(await screen.findByTestId("alert-list-modal")).toBeInTheDocument();+ });+ });+});diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/setup.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/setup.tsxnew file mode 100644index 00000000000..70d61d9975d--- /dev/null+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionMoreActionsMenu/tests/setup.tsx@@ -0,0 +1,115 @@+import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";+import { useState } from "react";++import { setupEnterprisePlugins } from "__support__/enterprise";+import { setupGetUserKeyValueEndpoint } from "__support__/server-mocks";+import { setupWebhookChannelsEndpoint } from "__support__/server-mocks/channel";+import { setupListNotificationEndpoints } from "__support__/server-mocks/notification";+import { mockSettings } from "__support__/settings";+import { renderWithProviders, screen } from "__support__/ui";+import { QuestionAlertListModal } from "metabase/notifications/modals";+import Question from "metabase-lib/v1/Question";+import type { Card, Notification, User } from "metabase-types/api";+import {+ createMockCard,+ createMockSettings,+ createMockTokenFeatures,+ createMockUser,+} from "metabase-types/api/mocks";+import { createMockState } from "metabase-types/store/mocks";++import { QuestionMoreActionsMenu } from "../QuestionMoreActionsMenu";++type SetupOpts = {+ alerts?: Notification[];+ canManageSubscriptions: boolean;+ isAdmin: boolean;+ isEmailSetup: boolean;+ isEnterprise: boolean;+};++export function setup({+ alerts = [],+ canManageSubscriptions = false,+ isAdmin = false,+ isEmailSetup = false,+ isEnterprise = false,+}: SetupOpts) {+ const card = createMockCard();++ const tokenFeatures = createMockTokenFeatures({+ advanced_permissions: isEnterprise,+ dashboard_subscription_filters: isEnterprise,+ audit_app: isEnterprise,+ });++ const settingValues = createMockSettings({+ "token-features": tokenFeatures,+ "email-configured?": isEmailSetup,+ });++ const user = createMockUser({ is_superuser: isAdmin });++ const state = createMockState({+ settings: mockSettings(settingValues),+ currentUser: {+ ...user,+ permissions: {+ can_access_subscription: canManageSubscriptions,+ },+ qb: {+ card,+ },+ } as User,+ });++ fetchMock.get("path:/api/user/recipients", { data: [] });+ setupWebhookChannelsEndpoint();+ setupListNotificationEndpoints({ card_id: card.id }, alerts);+ setupGetUserKeyValueEndpoint({+ namespace: "user_acknowledgement",+ key: "turn_into_model_modal",+ value: false,+ });++ if (isEnterprise) {+ setupEnterprisePlugins();+ }++ renderWithProviders(<TestComponent card={card} />, {+ storeInitialState: state,+ });+}++interface Props {+ card: Card;+}++const TestComponent = ({ card }: Props) => {+ const question = new Question(card);+ const [isModalOpen, setIsModalOpen] = useState(false);++ return (+ <>+ <QuestionMoreActionsMenu+ question={question}+ onOpenModal={() => setIsModalOpen(true)}+ onSetQueryBuilderMode={jest.fn()}+ />++ {isModalOpen && (+ <QuestionAlertListModal+ question={question}+ onClose={() => setIsModalOpen(false)}+ />+ )}+ </>+ );+};++export function openMenu() {+ return userEvent.click(+ screen.getByRole("button", { name: /Move, trash, and more/ }),+ );+}