Skip to content

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

UXW-2179 Replace 'Add to dashboard' modal with a toast (#65400)

Denis Berezind3f45bcced2f
diff --git a/e2e/support/helpers/e2e-misc-helpers.js b/e2e/support/helpers/e2e-misc-helpers.js
index 1afa25e0ba7..ff0499b4738 100644
--- a/e2e/support/helpers/e2e-misc-helpers.js
+++ b/e2e/support/helpers/e2e-misc-helpers.js
@@ -1,5 +1,5 @@
import { pickEntity } from "./e2e-collection-helpers";
-import { modal } from "./e2e-ui-elements-helpers";
+import { modal, undoToast } from "./e2e-ui-elements-helpers";
// Find a text field by label text, type it in, then blur the field.
// Commonly used in our Admin section as we auto-save settings.
@@ -336,15 +336,17 @@ export function saveQuestion(
const wasSavedToCollection = !body.dashboard_id;
if (wasSavedToCollection) {
- cy.get("#QuestionSavedModal").within(() => {
- cy.findByText(/add this to a dashboard/i).should("be.visible");
-
- if (addToDashboard) {
- cy.button("Yes please!").click();
- } else {
- cy.button("Not now").click();
- }
- });
+ checkSavedToCollectionQuestionToast(addToDashboard);
+ }
+ });
+}
+
+export function checkSavedToCollectionQuestionToast(addToDashboard) {
+ undoToast().within(() => {
+ cy.findByText(/Saved/i).should("be.visible");
+
+ if (addToDashboard) {
+ cy.button(/Add this to a dashboard/i).click();
}
});
}
diff --git a/e2e/test/scenarios/admin/performance/helpers/e2e-performance-helpers.ts b/e2e/test/scenarios/admin/performance/helpers/e2e-performance-helpers.ts
index 2f5ea8eb956..658d83db7e0 100644
--- a/e2e/test/scenarios/admin/performance/helpers/e2e-performance-helpers.ts
+++ b/e2e/test/scenarios/admin/performance/helpers/e2e-performance-helpers.ts
@@ -85,7 +85,7 @@ export const saveQuestion = ({ withName }: { withName: string }) => {
cy.findByTestId("qb-header").button(/^Save/).click();
cy.findByLabelText("Name").type(withName);
modal().button("Save").click();
- cy.findByText("Not now").click();
+
cy.wait("@saveQuestion");
};
diff --git a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
index 3363ed48611..5f995a3c460 100644
--- a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
+++ b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
@@ -88,8 +88,6 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
expect(response.statusCode).to.eq(200);
});
- cy.button("Not now").click();
-
cy.log("saving copied question");
getItemId(ANALYTICS_COLLECTION_NAME, PEOPLE_MODEL_NAME).then((id) => {
diff --git a/e2e/test/scenarios/dashboard/dashboard.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard.cy.spec.js
index bf2344f09c4..4ddcff87565 100644
--- a/e2e/test/scenarios/dashboard/dashboard.cy.spec.js
+++ b/e2e/test/scenarios/dashboard/dashboard.cy.spec.js
@@ -200,10 +200,8 @@ describe("scenarios > dashboard", () => {
cy.wait("@saveQuestion");
cy.log("Add this new question to a dashboard created on the fly");
- H.modal().within(() => {
- cy.findByText("Saved! Add this to a dashboard?");
- cy.button("Yes please!").click();
- });
+
+ H.checkSavedToCollectionQuestionToast(true);
H.entityPickerModal()
.findByRole("tab", { name: /Dashboards/ })
diff --git a/e2e/test/scenarios/joins/joins-reproductions.cy.spec.js b/e2e/test/scenarios/joins/joins-reproductions.cy.spec.js
index 0f9367247ec..01e93f5d434 100644
--- a/e2e/test/scenarios/joins/joins-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/joins/joins-reproductions.cy.spec.js
@@ -813,8 +813,6 @@ describe("issue 23293", () => {
cy.findByTestId("save-question-modal").button("Save").click();
cy.wait("@saveQuestion").then(({ response }) => {
- cy.button("Not now").click();
-
const id = response.body.id;
const questionDetails = {
query: {
diff --git a/e2e/test/scenarios/models/helpers/e2e-models-helpers.js b/e2e/test/scenarios/models/helpers/e2e-models-helpers.js
index b2f5beaf7ad..ddb4effc64a 100644
--- a/e2e/test/scenarios/models/helpers/e2e-models-helpers.js
+++ b/e2e/test/scenarios/models/helpers/e2e-models-helpers.js
@@ -39,8 +39,6 @@ export function saveQuestionBasedOnModel({ modelId, name }) {
}
cy.findByText("Save").click();
});
-
- modal().findByText("Not now").click();
}
export function selectDimensionOptionFromSidebar(name) {
diff --git a/e2e/test/scenarios/models/reproductions.cy.spec.ts b/e2e/test/scenarios/models/reproductions.cy.spec.ts
index 7c68788adfa..139503e3154 100644
--- a/e2e/test/scenarios/models/reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/models/reproductions.cy.spec.ts
@@ -522,7 +522,6 @@ describe("issue 40635", () => {
cy.button("Save").click();
H.modal().button("Save").click();
- H.modal().findByText("Not now").click();
assertSettingsSidebar();
assertVisualizationColumns();
diff --git a/e2e/test/scenarios/native/native.cy.spec.js b/e2e/test/scenarios/native/native.cy.spec.js
index d932d1fd175..10fe08d9350 100644
--- a/e2e/test/scenarios/native/native.cy.spec.js
+++ b/e2e/test/scenarios/native/native.cy.spec.js
@@ -140,9 +140,6 @@ describe("scenarios > question > native", () => {
expect(parameter.default).to.equal("Gizmo");
});
});
-
- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Not now").click();
});
it("should recognize template tags and save them as parameters", () => {
@@ -169,8 +166,6 @@ describe("scenarios > question > native", () => {
cy.wrap(xhr.response.body.id).as("questionId");
});
});
- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Not now").click();
// Now load the question again and parameters[] should still be there
cy.get("@questionId").then((questionId) => {
diff --git a/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
index 2733f9c7ba3..f134a6bfe9b 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
+++ b/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
@@ -669,10 +669,6 @@ describe("issue 17910", () => {
});
cy.wait("@card");
- cy.get("#QuestionSavedModal").within(() => {
- cy.findByText("Not now").click();
- });
-
H.questionInfoButton().click();
H.sidesheet().within(() => {
diff --git a/e2e/test/scenarios/question/native-query-drill.cy.spec.ts b/e2e/test/scenarios/question/native-query-drill.cy.spec.ts
index 0d29b42e808..d947b58a8c3 100644
--- a/e2e/test/scenarios/question/native-query-drill.cy.spec.ts
+++ b/e2e/test/scenarios/question/native-query-drill.cy.spec.ts
@@ -104,7 +104,6 @@ describe("scenarios > question > native query drill", () => {
cy.button("Save").click();
cy.wait("@saveCard");
});
- H.modal().findByText("Not now").click();
H.tableInteractive().findByText("October 7, 2023, 1:34 AM").click();
H.popover().within(() => {
diff --git a/e2e/test/scenarios/question/new.cy.spec.js b/e2e/test/scenarios/question/new.cy.spec.js
index e1d1a239e97..0ccdb1a7e86 100644
--- a/e2e/test/scenarios/question/new.cy.spec.js
+++ b/e2e/test/scenarios/question/new.cy.spec.js
@@ -531,10 +531,7 @@ describe("scenarios > question > new", () => {
cy.findByTestId("save-question-modal").should("not.exist");
- H.modal().within(() => {
- cy.findByText(/add this to a dashboard/i);
- cy.button("Yes please!").click();
- });
+ H.checkSavedToCollectionQuestionToast(true);
H.entityPickerModal().within(() => {
cy.findByText("Add this question to a dashboard").should("be.visible");
@@ -565,7 +562,7 @@ describe("scenarios > question > new", () => {
cy.findByTestId("save-question-modal").button("Save").click();
cy.wait("@createQuestion");
- cy.get("#QuestionSavedModal").findByText("Yes please!").click();
+ H.checkSavedToCollectionQuestionToast(true);
H.entityPickerModal().within(() => {
cy.findByText("Add this question to a dashboard").should("be.visible");
@@ -604,9 +601,7 @@ describe("scenarios > question > new", () => {
cy.wait("@createQuestion");
});
- cy.get("#QuestionSavedModal").within(() => {
- cy.findByText("Yes please!").click();
- });
+ H.checkSavedToCollectionQuestionToast(true);
});
it("when selecting a collection", () => {
diff --git a/e2e/test/scenarios/question/saved.cy.spec.js b/e2e/test/scenarios/question/saved.cy.spec.js
index ab302edbead..28395477956 100644
--- a/e2e/test/scenarios/question/saved.cy.spec.js
+++ b/e2e/test/scenarios/question/saved.cy.spec.js
@@ -71,8 +71,6 @@ describe("scenarios > question > saved", () => {
cy.wait("@cardCreate");
});
- cy.button("Not now").click();
-
cy.findByTestId("qb-header-left-side").within(() => {
cy.findByDisplayValue("Orders - Duplicate");
});
@@ -147,8 +145,6 @@ describe("scenarios > question > saved", () => {
cy.wait("@cardCreate");
});
- cy.button("Not now").click();
-
cy.findByTestId("qb-header-left-side").within(() => {
cy.findByDisplayValue("Orders - Duplicate");
});
diff --git a/e2e/test/scenarios/question/settings.cy.spec.js b/e2e/test/scenarios/question/settings.cy.spec.js
index 6a79c8ce35f..86b50647e44 100644
--- a/e2e/test/scenarios/question/settings.cy.spec.js
+++ b/e2e/test/scenarios/question/settings.cy.spec.js
@@ -548,7 +548,8 @@ describe("scenarios > question > settings", () => {
H.pickEntity({ tab: "Browse", path: ["Our analytics"], select: false });
H.entityPickerModal().findByText("Select this collection").click();
cy.findByTestId("save-question-modal").findByText("Save").click();
- H.modal().findByText("Yes please!").click();
+ H.checkSavedToCollectionQuestionToast(true);
+
H.entityPickerModal().within(() => {
cy.findByText("Orders in a dashboard").click();
cy.findByText("Cancel").click();
diff --git a/e2e/test/scenarios/visualizations-charts/sankey.cy.spec.js b/e2e/test/scenarios/visualizations-charts/sankey.cy.spec.js
index 22fa0f06f9f..1a27dbd4fe8 100644
--- a/e2e/test/scenarios/visualizations-charts/sankey.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-charts/sankey.cy.spec.js
@@ -135,7 +135,8 @@ describe("scenarios > visualizations > sankey", () => {
"My Sankey chart",
);
cy.findByTestId("save-question-modal").findByText("Save").click();
- H.modal().findByText("Saved! Add this to a dashboard?");
+
+ H.checkSavedToCollectionQuestionToast();
});
[false, true].forEach((devMode) => {
diff --git a/frontend/src/metabase/common/components/QuestionSavedModal/QuestionSavedModal.tsx b/frontend/src/metabase/common/components/QuestionSavedModal/QuestionSavedModal.tsx
deleted file mode 100644
index efb69d78622..00000000000
--- a/frontend/src/metabase/common/components/QuestionSavedModal/QuestionSavedModal.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import cx from "classnames";
-import { t } from "ttag";
-
-import ModalContent from "metabase/common/components/ModalContent";
-import ButtonsS from "metabase/css/components/buttons.module.css";
-import CS from "metabase/css/core/index.css";
-
-interface QuestionSavedModalProps {
- onClose: () => void;
- addToDashboard: () => void;
-}
-const QuestionSavedModal = ({
- addToDashboard,
- onClose,
-}: QuestionSavedModalProps) => {
- return (
- <ModalContent
- id="QuestionSavedModal"
- title={t`Saved! Add this to a dashboard?`}
- onClose={onClose}
- >
- <div>
- <button
- className={cx(ButtonsS.Button, ButtonsS.ButtonPrimary)}
- onClick={addToDashboard}
- >{t`Yes please!`}</button>
- <button
- className={cx(ButtonsS.Button, CS.ml3)}
- onClick={onClose}
- >{t`Not now`}</button>
- </div>
- </ModalContent>
- );
-};
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default QuestionSavedModal;
diff --git a/frontend/src/metabase/common/components/QuestionSavedModal/index.ts b/frontend/src/metabase/common/components/QuestionSavedModal/index.ts
deleted file mode 100644
index 1bb3379b603..00000000000
--- a/frontend/src/metabase/common/components/QuestionSavedModal/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./QuestionSavedModal";
diff --git a/frontend/src/metabase/common/hooks/use-toast/use-toast.ts b/frontend/src/metabase/common/hooks/use-toast/use-toast.ts
index 1d9b26a8d6e..e03c717cf1f 100644
--- a/frontend/src/metabase/common/hooks/use-toast/use-toast.ts
+++ b/frontend/src/metabase/common/hooks/use-toast/use-toast.ts
@@ -4,7 +4,7 @@ import { useDispatch } from "metabase/lib/redux";
import { addUndo, dismissUndo } from "metabase/redux/undo";
import type { Undo } from "metabase-types/store/undo";
-type ToastArgs = Omit<Undo, "id" | "timeoutId">;
+export type ToastArgs = Omit<Undo, "id" | "timeoutId">;
// A handy convenience hook for adding toast/undo notifications
export const useToast = () => {
diff --git a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
index 4f13b64c401..c21dd0b3200 100644
--- a/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
+++ b/frontend/src/metabase/query_builder/components/QueryModals/QueryModals.tsx
@@ -1,12 +1,13 @@
import { useCallback } from "react";
import { push } from "react-router-redux";
+import { t } from "ttag";
import _ from "underscore";
import { getDashboard } from "metabase/api";
import { useGetDefaultCollectionId } from "metabase/collections/hooks";
import Modal from "metabase/common/components/Modal";
-import QuestionSavedModal from "metabase/common/components/QuestionSavedModal";
import { SaveQuestionModal } from "metabase/common/components/SaveQuestionModal";
+import { type ToastArgs, useToast } from "metabase/common/hooks";
import EntityCopyModal from "metabase/entities/containers/EntityCopyModal";
import { useDispatch, useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
@@ -22,6 +23,7 @@ import ArchiveQuestionModal from "metabase/questions/containers/ArchiveQuestionM
import EditEventModal from "metabase/timelines/questions/containers/EditEventModal";
import MoveEventModal from "metabase/timelines/questions/containers/MoveEventModal";
import NewEventModal from "metabase/timelines/questions/containers/NewEventModal";
+import { Text } from "metabase/ui";
import type Question from "metabase-lib/v1/Question";
import type { Card, DashboardTabId } from "metabase-types/api";
import type { QueryBuilderMode } from "metabase-types/store";
@@ -65,6 +67,7 @@ export function QueryModals({
onChangeLocation,
}: QueryModalsProps) {
const dispatch = useDispatch();
+ const [sendToast] = useToast();
const initialCollectionId = useGetDefaultCollectionId();
const underlyingQuestion = useSelector(getQuestionWithoutComposing);
@@ -131,17 +134,21 @@ export function QueryModals({
options?.dashboardTabId,
);
} else {
- onOpenModal(MODAL_TYPES.SAVED);
+ onCloseModal();
+ setQueryBuilderMode("view");
+
+ sendToast(getAddToDashboardToastProps(onOpenModal));
}
return newQuestion;
},
[
- onCloseModal,
onCreate,
- onOpenModal,
+ onCloseModal,
setQueryBuilderMode,
navigateToDashboardQuestionDashboard,
+ sendToast,
+ onOpenModal,
],
);
@@ -164,14 +171,18 @@ export function QueryModals({
onCloseModal();
setQueryBuilderMode("view");
} else {
- onOpenModal(MODAL_TYPES.SAVED);
+ onCloseModal();
+ setQueryBuilderMode("view");
+
+ sendToast(getAddToDashboardToastProps(onOpenModal));
}
},
[
- onOpenModal,
navigateToDashboardQuestionDashboard,
- setQueryBuilderMode,
onCloseModal,
+ setQueryBuilderMode,
+ sendToast,
+ onOpenModal,
],
);
@@ -188,37 +199,6 @@ export function QueryModals({
opened={true}
/>
);
- case MODAL_TYPES.SAVED:
- return (
- <Modal small onClose={onCloseModal}>
- <QuestionSavedModal
- onClose={onCloseModal}
- addToDashboard={() => {
- onOpenModal(MODAL_TYPES.ADD_TO_DASHBOARD);
- }}
- />
- </Modal>
- );
- case MODAL_TYPES.ADD_TO_DASHBOARD_SAVE:
- return (
- <SaveQuestionModal
- question={question}
- originalQuestion={originalQuestion}
- initialCollectionId={initialCollectionId}
- onSave={async (question) => {
- await onSave(question);
- onOpenModal(MODAL_TYPES.ADD_TO_DASHBOARD);
- }}
- onCreate={async (question, options) => {
- const newQuestion = await onCreate(question, options);
- onOpenModal(MODAL_TYPES.ADD_TO_DASHBOARD);
- return newQuestion;
- }}
- onClose={onCloseModal}
- opened={true}
- multiStep
- />
- );
case MODAL_TYPES.ADD_TO_DASHBOARD:
return (
<AddToDashSelectDashModal
@@ -331,3 +311,13 @@ export function QueryModals({
);
}
}
+
+function getAddToDashboardToastProps(
+ onOpenModal: (modalType: QueryModalType) => void,
+): ToastArgs {
+ return {
+ message: () => <Text c="inherit" fw="bold" mr="2.5rem">{t`Saved`}</Text>,
+ actionLabel: t`Add this to a dashboard`,
+ action: () => onOpenModal(MODAL_TYPES.ADD_TO_DASHBOARD),
+ };
+}
diff --git a/frontend/src/metabase/query_builder/constants.ts b/frontend/src/metabase/query_builder/constants.ts
index 5b258796c15..605ef4924dd 100644
--- a/frontend/src/metabase/query_builder/constants.ts
+++ b/frontend/src/metabase/query_builder/constants.ts
@@ -4,8 +4,6 @@ export const MODAL_TYPES = {
MOVE: "move",
CLONE: "clone",
ARCHIVE: "archive",
- SAVED: "saved",
- ADD_TO_DASHBOARD_SAVE: "add-to-dashboard-save",
CREATE_ALERT: "create-alert",
SAVE_QUESTION_BEFORE_EMBED: "save-question-before-embed",
TURN_INTO_DATASET: "turn-into-dataset",