Skip to content

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

Update "Customize Homepage" modal UI (#62280)

Anton Kulykb8b61d06478c
diff --git a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
index 646b86f5fd0..3380aa76d56 100644
--- a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
@@ -315,7 +315,7 @@ describe("scenarios > home > custom homepage", () => {
cy.findByTestId("custom-homepage-dashboard-setting").should(
"contain",
- "Select a dashboard",
+ "Pick a dashboard",
);
cy.findByTestId("custom-homepage-dashboard-setting")
@@ -370,8 +370,8 @@ describe("scenarios > home > custom homepage", () => {
cy.get("main").findByText("Customize").click();
H.modal().within(() => {
- cy.findByRole("button", { name: "Save" }).should("be.disabled");
- cy.findByText(/Select a dashboard/i).click();
+ cy.findByRole("button", { name: "Done" }).should("be.disabled");
+ cy.findByText("Pick a dashboard").click();
});
H.entityPickerModal().within(() => {
@@ -390,7 +390,7 @@ describe("scenarios > home > custom homepage", () => {
cy.findByText("Orders in a dashboard").click();
});
- H.modal().findByRole("button", { name: "Save" }).click();
+ H.modal().findByRole("button", { name: "Done" }).click();
cy.location("pathname").should(
"equal",
`/dashboard/${ORDERS_DASHBOARD_ID}`,
@@ -603,12 +603,10 @@ H.describeWithSnowplow("scenarios > setup", () => {
it("should send snowplow events through homepage", () => {
cy.visit("/");
cy.get("main").findByText("Customize").click();
- H.modal()
- .findByText(/Select a dashboard/i)
- .click();
+ H.modal().findByText("Pick a dashboard").click();
H.entityPickerModal().findByText("Orders in a dashboard").click();
- H.modal().findByText("Save").click();
+ H.modal().findByText("Done").click();
H.expectUnstructuredSnowplowEvent({
event: "homepage_dashboard_enabled",
source: "homepage",
diff --git a/frontend/src/metabase/admin/settings/components/widgets/CustomHomepageDashboardSetting.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/widgets/CustomHomepageDashboardSetting.unit.spec.tsx
index 3df05c2b27b..4299fcb0d55 100644
--- a/frontend/src/metabase/admin/settings/components/widgets/CustomHomepageDashboardSetting.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/widgets/CustomHomepageDashboardSetting.unit.spec.tsx
@@ -93,7 +93,7 @@ describe("CustomHomepageDashboardSetting", () => {
).toBeInTheDocument();
expect(screen.getByRole("switch")).toBeInTheDocument();
expect(screen.getByRole("switch")).not.toBeChecked();
- expect(screen.queryByText(/select a dashboard/i)).not.toBeInTheDocument();
+ expect(screen.queryByText("Pick a dashboard")).not.toBeInTheDocument();
});
it("should render dashboard picker if toggle is on", async () => {
@@ -101,7 +101,7 @@ describe("CustomHomepageDashboardSetting", () => {
await waitFor(() => {
expect(screen.getByRole("switch")).toBeChecked();
});
- expect(screen.getByText(/select a dashboard/i)).toBeInTheDocument();
+ expect(screen.getByText("Pick a dashboard")).toBeInTheDocument();
});
it("should update the toggle value", async () => {
@@ -123,7 +123,7 @@ describe("CustomHomepageDashboardSetting", () => {
it("should update the dashboard value", async () => {
setup({ "custom-homepage": true });
- const dashboardSelector = await screen.findByText(/select a dashboard/i);
+ const dashboardSelector = await screen.findByText("Pick a dashboard");
await userEvent.click(dashboardSelector);
await screen.findByText("Choose a dashboard"); // modal opens
@@ -157,12 +157,12 @@ describe("CustomHomepageDashboardSetting", () => {
await userEvent.click(toggle);
expect(await screen.findByRole("switch")).not.toBeChecked();
expect(screen.queryByText(/my dashboard/i)).not.toBeInTheDocument();
- expect(screen.queryByText(/select a dashboard/i)).not.toBeInTheDocument();
+ expect(screen.queryByText("Pick a dashboard")).not.toBeInTheDocument();
});
it("should refresh current user after updating settings", async () => {
setup({ "custom-homepage": true });
- const dashboardSelector = await screen.findByText(/select a dashboard/i);
+ const dashboardSelector = await screen.findByText("Pick a dashboard");
await userEvent.click(dashboardSelector);
await userEvent.click(await screen.findByText("My dashboard"));
diff --git a/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.styled.tsx b/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.styled.tsx
index e76de3b6eb1..aaa8da3e6d0 100644
--- a/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.styled.tsx
+++ b/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.styled.tsx
@@ -4,5 +4,5 @@ import styled from "@emotion/styled";
import SelectButton from "metabase/common/components/SelectButton/SelectButton";
export const DashboardPickerButton = styled(SelectButton)`
- min-width: 400px;
+ font-weight: 400;
`;
diff --git a/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.tsx b/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.tsx
index 7020877c153..34bdeb9af73 100644
--- a/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.tsx
+++ b/frontend/src/metabase/common/components/DashboardSelector/DashboardSelector.tsx
@@ -15,11 +15,13 @@ import { DashboardPickerButton } from "./DashboardSelector.styled";
interface DashboardSelectorProps {
onChange: (value?: DashboardId) => void;
value?: DashboardId;
+ fullWidth?: boolean;
}
export const DashboardSelector = ({
onChange,
value,
+ fullWidth = true,
}: DashboardSelectorProps) => {
const [isOpen, setIsOpen] = useState(false);
const {
@@ -56,8 +58,11 @@ export const DashboardSelector = ({
``;
return (
<Flex>
- <DashboardPickerButton onClick={() => setIsOpen(true)}>
- {dashboard?.name || t`Select a dashboard`}
+ <DashboardPickerButton
+ fullWidth={fullWidth}
+ onClick={() => setIsOpen(true)}
+ >
+ {dashboard?.name || t`Pick a dashboard`}
</DashboardPickerButton>
{isOpen && (
<DashboardPickerModal
diff --git a/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.tsx b/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.tsx
index e39d0f237b8..775080fd092 100644
--- a/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.tsx
+++ b/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.tsx
@@ -1,17 +1,15 @@
import { useCallback, useState } from "react";
-import { t } from "ttag";
+import { jt, t } from "ttag";
import { trackCustomHomepageDashboardEnabled } from "metabase/admin/settings/analytics";
import { updateSettings } from "metabase/admin/settings/settings";
-import Button from "metabase/common/components/Button/Button";
import { DashboardSelector } from "metabase/common/components/DashboardSelector/DashboardSelector";
-import Modal from "metabase/common/components/Modal";
-import ModalContent from "metabase/common/components/ModalContent";
-import { useDispatch, useSelector } from "metabase/lib/redux";
+import Link from "metabase/common/components/Link";
+import CS from "metabase/css/core/index.css";
+import { useDispatch } from "metabase/lib/redux";
import { addUndo, dismissUndo } from "metabase/redux/undo";
import { refreshCurrentUser } from "metabase/redux/user";
-import { getApplicationName } from "metabase/selectors/whitelabel";
-import { Box, Text } from "metabase/ui";
+import { Box, Button, Flex, Modal, Text } from "metabase/ui";
import type { DashboardId } from "metabase-types/api";
const CUSTOM_HOMEPAGE_SETTING_KEY = "custom-homepage";
@@ -49,7 +47,6 @@ export const CustomHomePageModal = ({
c="text-white"
fw={700}
>{t`This dashboard has been set as your homepage.`}</Text>
- <br />
<Text
span
c="text-white"
@@ -84,30 +81,35 @@ export const CustomHomePageModal = ({
onClose();
}, [onClose, setDashboardId]);
- const applicationName = useSelector(getApplicationName);
-
return (
- <Modal isOpen={isOpen} onClose={onClose}>
- <ModalContent
- title={t`Customize Homepage`}
- onClose={handleClose}
- footer={[
- <Button onClick={handleClose} key="custom-homepage-modal-cancel">
- {t`Cancel`}
- </Button>,
- <Button
- primary
- onClick={handleSave}
- key="custom-homepage-modal-save"
- disabled={!dashboardId}
- >
- {t`Save`}
- </Button>,
- ]}
- >
- <p>{t`Pick a dashboard to serve as the homepage. If people lack permissions to view the selected dashboard, ${applicationName} will redirect them to the default homepage. You can update or reset the homepage at any time in Admin Settings > Settings > General.`}</p>
- <DashboardSelector value={dashboardId} onChange={handleChange} />
- </ModalContent>
+ <Modal
+ title={t`Pick a dashboard to appear on the homepage`}
+ opened={isOpen}
+ onClose={handleClose}
+ size="544px"
+ >
+ <Box mt="sm">
+ <Text>
+ {t`If anyone lacks permission to see the dashboard you pick, they'll be redirected to the default homepage.`}
+ </Text>
+ <Text mt="sm">{jt`You can always change the homepage in ${(<Link key="link" className={CS.link} to="/admin/settings/general" style={{ textDecoration: "underline" }}>{t`admin settings`}</Link>)} under General.`}</Text>
+ <Box mt="lg">
+ <DashboardSelector
+ value={dashboardId}
+ fullWidth={false}
+ onChange={handleChange}
+ />
+ </Box>
+ </Box>
+
+ <Flex mt="lg" justify="flex-end" gap="0.5rem">
+ <Button variant="subtle" onClick={handleClose}>
+ {t`Cancel`}
+ </Button>
+ <Button variant="filled" disabled={!dashboardId} onClick={handleSave}>
+ {t`Done`}
+ </Button>
+ </Flex>
</Modal>
);
};
diff --git a/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.unit.spec.tsx b/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.unit.spec.tsx
index 446e3b44369..6d9375561a9 100644
--- a/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.unit.spec.tsx
+++ b/frontend/src/metabase/home/components/CustomHomePageModal/CustomHomePageModal.unit.spec.tsx
@@ -13,6 +13,6 @@ const setup = ({ ...props } = {}) => {
describe("custom hompage modal", () => {
it("should only enable the save button if a dashboard has been selected", () => {
setup();
- expect(screen.getByRole("button", { name: /save/i })).toBeDisabled();
+ expect(screen.getByRole("button", { name: "Done" })).toBeDisabled();
});
});