Skip to content

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

Migrate notifications components from Emotion to Mantine + CSS modules (#73068)

Andrei Chernykh3888390bb9bc
diff --git a/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.styled.tsx b/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.styled.tsx
deleted file mode 100644
index 76814935202..00000000000
--- a/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.styled.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const ModalMessage = styled.div`
- &:not(:last-child) {
- margin-bottom: 1rem;
- }
-`;
diff --git a/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.tsx b/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.tsx
index f53ff0d4621..eed135711ba 100644
--- a/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.tsx
+++ b/frontend/src/metabase/account/notifications/components/ArchiveModal/ArchiveModal.tsx
@@ -5,14 +5,13 @@ import { Button } from "metabase/common/components/Button";
import { ModalContent } from "metabase/common/components/ModalContent";
import { FormMessage } from "metabase/forms";
import { formatChannelRecipients } from "metabase/pulse";
+import { Box, Stack } from "metabase/ui";
import { formatDateTimeWithUnit } from "metabase/utils/formatting";
import Settings from "metabase/utils/settings";
import type { Alert, DashboardSubscription, User } from "metabase-types/api";
import type { NotificationType } from "../../types";
-import { ModalMessage } from "./ArchiveModal.styled";
-
type ArchiveModalProps = {
item: Alert | DashboardSubscription;
type: NotificationType;
@@ -58,16 +57,18 @@ function ArchiveNotificationModal({
]}
onClose={onClose}
>
- {isCreator(item, user) && hasUnsubscribed && (
- <ModalMessage data-server-date>
- {getCreatorMessage(type, user)}
- {t`As the creator you can also choose to delete this if it's no longer relevant to others as well.`}
- </ModalMessage>
- )}
- <ModalMessage>
- {getDateMessage(item, type)}
- {getRecipientsMessage(item)}
- </ModalMessage>
+ <Stack gap="md">
+ {isCreator(item, user) && hasUnsubscribed && (
+ <Box data-server-date>
+ {getCreatorMessage(type, user)}
+ {t`As the creator you can also choose to delete this if it's no longer relevant to others as well.`}
+ </Box>
+ )}
+ <Box>
+ {getDateMessage(item, type)}
+ {getRecipientsMessage(item)}
+ </Box>
+ </Stack>
</ModalContent>
);
}
diff --git a/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.styled.tsx b/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.styled.tsx
deleted file mode 100644
index 76814935202..00000000000
--- a/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.styled.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const ModalMessage = styled.div`
- &:not(:last-child) {
- margin-bottom: 1rem;
- }
-`;
diff --git a/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.tsx b/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.tsx
index 2b3c6266a1b..496df49b05c 100644
--- a/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.tsx
+++ b/frontend/src/metabase/account/notifications/components/HelpModal/HelpModal.tsx
@@ -5,10 +5,9 @@ import { ExternalLink } from "metabase/common/components/ExternalLink";
import { ModalContent } from "metabase/common/components/ModalContent";
import { useSelector } from "metabase/redux";
import { getApplicationName } from "metabase/selectors/whitelabel";
+import { Box, Stack } from "metabase/ui";
import Settings from "metabase/utils/settings";
-import { ModalMessage } from "./HelpModal.styled";
-
type HelpModalProps = {
onClose: (confirmed: boolean) => void;
};
@@ -29,13 +28,15 @@ function HelpModal({ onClose }: HelpModalProps): JSX.Element {
}
onClose={handleClose}
>
- <ModalMessage>
- {t`It's possible you may also receive emails from ${applicationName} if you're a member of an email distribution list, like "[email protected]" and that list is used as the recipient for an alert or dashboard subscription instead of your individual email.`}
- </ModalMessage>
- <ModalMessage>
- <AdminMessage email={email} applicationName={applicationName} />
- {t`Hopefully they'll be able to help you out!`}
- </ModalMessage>
+ <Stack gap="md">
+ <Box>
+ {t`It's possible you may also receive emails from ${applicationName} if you're a member of an email distribution list, like "[email protected]" and that list is used as the recipient for an alert or dashboard subscription instead of your individual email.`}
+ </Box>
+ <Box>
+ <AdminMessage email={email} applicationName={applicationName} />
+ {t`Hopefully they'll be able to help you out!`}
+ </Box>
+ </Stack>
</ModalContent>
);
}
diff --git a/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.module.css b/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.module.css
new file mode 100644
index 00000000000..7edc35ef793
--- /dev/null
+++ b/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.module.css
@@ -0,0 +1,23 @@
+.root {
+ border: 1px solid var(--mb-color-border);
+ border-radius: var(--mantine-radius-sm);
+
+ &:not(:last-child) {
+ margin-bottom: 1.25rem;
+ }
+}
+
+.message {
+ &:not(:last-child)::after {
+ content: " · ";
+ white-space: pre;
+ }
+}
+
+.icon {
+ cursor: pointer;
+
+ &:hover {
+ color: var(--mb-color-text-secondary);
+ }
+}
diff --git a/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.styled.tsx b/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.styled.tsx
deleted file mode 100644
index 2d7a4dc1d7c..00000000000
--- a/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.styled.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Icon } from "metabase/ui";
-
-export const NotificationCardRoot = styled.div`
- display: flex;
- align-items: center;
- padding: 1rem 1.5rem;
- border: 1px solid var(--mb-color-border);
- border-radius: 6px;
- background-color: var(--mb-color-background-primary);
-
- &:not(:last-child) {
- margin-bottom: 1.25rem;
- }
-`;
-
-export const NotificationContent = styled.div`
- flex: 1 1 auto;
-`;
-
-export const NotificationDescription = styled.div`
- display: flex;
- flex-wrap: wrap;
- margin-top: 0.25rem;
-`;
-
-export const NotificationMessage = styled.span`
- color: var(--mb-color-text-secondary);
- font-size: 0.75rem;
- line-height: 0.875rem;
-
- &:not(:last-child)::after {
- content: " · ";
- white-space: pre;
- }
-`;
-
-export const NotificationIcon = styled(Icon)`
- color: var(--mb-color-text-tertiary);
- cursor: pointer;
- width: 1rem;
- height: 1rem;
-
- &:hover {
- color: var(--mb-color-text-secondary);
- }
-`;
diff --git a/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.tsx b/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.tsx
index 86f4cc19b17..a43394c9fc9 100644
--- a/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.tsx
+++ b/frontend/src/metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.tsx
@@ -7,16 +7,11 @@ import type { DashboardSubscriptionListItem } from "metabase/account/notificatio
import { Link } from "metabase/common/components/Link";
import { formatTitle } from "metabase/notifications/utils";
import { canArchiveLegacyAlert, formatChannel } from "metabase/pulse";
+import { Box, Flex, Icon, Text } from "metabase/ui";
import * as Urls from "metabase/utils/urls";
import type { Channel, User } from "metabase-types/api";
-import {
- NotificationCardRoot,
- NotificationContent,
- NotificationDescription,
- NotificationIcon,
- NotificationMessage,
-} from "./DashboardNotificationCard.styled";
+import S from "./DashboardNotificationCard.module.css";
type Props = {
listItem: DashboardSubscriptionListItem;
@@ -49,8 +44,14 @@ export const DashboardNotificationCard = ({
}, [listItem, onArchive]);
return (
- <NotificationCardRoot>
- <NotificationContent>
+ <Flex
+ className={S.root}
+ align="center"
+ px="lg"
+ py="md"
+ bg="background-primary"
+ >
+ <Box flex="1 1 auto">
{dashboardEntityLink ? (
<Link variant="brandBold" to={dashboardEntityLink}>
{formatTitle(listItem)}
@@ -58,33 +59,53 @@ export const DashboardNotificationCard = ({
) : (
formatTitle(listItem)
)}
- <NotificationDescription>
+ <Flex wrap="wrap" mt="xs">
{item.channels.map((channel, index) => (
- <NotificationMessage key={index}>
+ <Text
+ key={index}
+ component="span"
+ className={S.message}
+ c="text-secondary"
+ fz="sm"
+ lh="0.875rem"
+ >
{getChannelMessage(channel)}
- </NotificationMessage>
+ </Text>
))}
- <NotificationMessage data-server-date>
+ <Text
+ component="span"
+ className={S.message}
+ c="text-secondary"
+ fz="sm"
+ lh="0.875rem"
+ data-server-date
+ >
{formatCreatorMessage(item, user.id)}
- </NotificationMessage>
- </NotificationDescription>
- </NotificationContent>
+ </Text>
+ </Flex>
+ </Box>
{isEditable && !hasArchive && (
- <NotificationIcon
+ <Icon
+ className={S.icon}
name="close"
+ size={16}
+ c="text-tertiary"
tooltip={t`Unsubscribe`}
onClick={onUnsubscribeClick}
/>
)}
{isEditable && hasArchive && (
- <NotificationIcon
+ <Icon
+ className={S.icon}
name="close"
+ size={16}
+ c="text-tertiary"
tooltip={t`Delete`}
onClick={onArchiveClick}
/>
)}
- </NotificationCardRoot>
+ </Flex>
);
};
diff --git a/frontend/src/metabase/account/notifications/components/NotificationCard/NotificationCard.tsx b/frontend/src/metabase/account/notifications/components/NotificationCard/NotificationCard.tsx
index a6bca2cb662..5e645a34c5b 100644
--- a/frontend/src/metabase/account/notifications/components/NotificationCard/NotificationCard.tsx
+++ b/frontend/src/metabase/account/notifications/components/NotificationCard/NotificationCard.tsx
@@ -1,13 +1,6 @@
import { type JSX, useCallback } from "react";
import { t } from "ttag";
-import {
- NotificationCardRoot,
- NotificationContent,
- NotificationDescription,
- NotificationIcon,
- NotificationMessage,
-} from "metabase/account/notifications/components/NotificationCard/DashboardNotificationCard.styled";
import { formatCreatorMessage } from "metabase/account/notifications/components/NotificationCard/utils";
import type { QuestionNotificationListItem } from "metabase/account/notifications/types";
import { Link } from "metabase/common/components/Link/Link";
@@ -17,10 +10,12 @@ import {
formatTitle,
getNotificationEnabledChannelsMap,
} from "metabase/notifications/utils";
-import { Group, Icon } from "metabase/ui";
+import { Box, Flex, Group, Icon, Text } from "metabase/ui";
import * as Urls from "metabase/utils/urls";
import type { User } from "metabase-types/api";
+import S from "./DashboardNotificationCard.module.css";
+
type NotificationCardProps = {
listItem: QuestionNotificationListItem;
user: User;
@@ -57,13 +52,26 @@ export const NotificationCard = ({
}, [listItem, onArchive]);
return (
- <NotificationCardRoot data-testid="notification-alert-item">
- <NotificationContent>
+ <Flex
+ className={S.root}
+ data-testid="notification-alert-item"
+ align="center"
+ px="lg"
+ py="md"
+ bg="background-primary"
+ >
+ <Box flex="1 1 auto">
<Link variant="brandBold" to={entityLink}>
{formatTitle(listItem)}
</Link>
- <NotificationDescription>
- <NotificationMessage>
+ <Flex wrap="wrap" mt="xs">
+ <Text
+ component="span"
+ className={S.message}
+ c="text-secondary"
+ fz="sm"
+ lh="0.875rem"
+ >
<Group gap="0.75rem" align="center" c="text-secondary">
{enabledChannelsMap["channel/email"] && <Icon name="mail" />}
{enabledChannelsMap["channel/slack"] && (
@@ -80,24 +88,30 @@ export const NotificationCard = ({
{<span>{formatCreatorMessage(item, user.id)}</span>}
</Group>
</Group>
- </NotificationMessage>
- </NotificationDescription>
- </NotificationContent>
+ </Text>
+ </Flex>
+ </Box>
{isEditable && !hasArchive && (
- <NotificationIcon
+ <Icon
+ className={S.icon}
name="close"
+ size={16}
+ c="text-tertiary"
tooltip={t`Unsubscribe`}
onClick={onUnsubscribeClick}
/>
)}
{isEditable && hasArchive && (
- <NotificationIcon
+ <Icon
+ className={S.icon}
name="close"
+ size={16}
+ c="text-tertiary"
tooltip={t`Delete`}
onClick={onArchiveClick}
/>
)}
- </NotificationCardRoot>
+ </Flex>
);
};
diff --git a/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.styled.tsx b/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.styled.tsx
deleted file mode 100644
index a26edfc2df8..00000000000
--- a/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.styled.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Label } from "metabase/common/components/type/Label";
-import { Icon } from "metabase/ui";
-
-export const NotificationHeader = styled.div`
- display: flex;
- align-items: center;
- margin-bottom: 1.5rem;
-`;
-
-export const NotificationLabel = styled(Label)`
- flex: 1 1 auto;
- margin: 0;
-`;
-
-export const NotificationSection = styled.div`
- display: flex;
- flex-direction: column;
- align-items: center;
-`;
-
-export const NotificationIcon = styled(Icon)`
- color: var(--mb-color-background-tertiary-inverse);
- width: 3.25rem;
- height: 3.25rem;
- margin-top: 4.875rem;
- margin-bottom: 1.75rem;
-`;
-
-export const NotificationMessage = styled.div`
- max-width: 24rem;
- text-align: center;
-`;
diff --git a/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.tsx b/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.tsx
index 1c29eac3535..287e5924436 100644
--- a/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.tsx
+++ b/frontend/src/metabase/account/notifications/components/NotificationList/NotificationList.tsx
@@ -4,7 +4,7 @@ import { t } from "ttag";
import type { NotificationListItem } from "metabase/account/notifications/types";
import CS from "metabase/css/core/index.css";
-import { UnstyledButton } from "metabase/ui";
+import { Box, Flex, Icon, Text, UnstyledButton } from "metabase/ui";
import type { User } from "metabase-types/api";
import {
@@ -12,14 +12,6 @@ import {
NotificationCard,
} from "../NotificationCard";
-import {
- NotificationHeader,
- NotificationIcon,
- NotificationLabel,
- NotificationMessage,
- NotificationSection,
-} from "./NotificationList.styled";
-
type NotificationListProps = {
listItems: NotificationListItem[];
user: User;
@@ -45,8 +37,10 @@ export const NotificationList = ({
return (
<div data-testid="notifications-list">
- <NotificationHeader>
- <NotificationLabel>{t`You receive or created these`}</NotificationLabel>
+ <Flex align="center" mb="lg">
+ <Text c="text-primary" fz="md" fw={700} flex="1 1 auto" m={0}>
+ {t`You receive or created these`}
+ </Text>
<UnstyledButton
fz="sm"
fw="bold"
@@ -55,7 +49,7 @@ export const NotificationList = ({
>
{t`Not seeing one here?`}
</UnstyledButton>
- </NotificationHeader>
+ </Flex>
{listItems.map((listItem) =>
listItem.type === "pulse" ? (
<DashboardNotificationCard
@@ -84,14 +78,18 @@ export const NotificationList = ({
const NotificationEmptyState = ({ children }: { children?: ReactNode }) => {
return (
- <>
- <NotificationSection>
- <NotificationIcon name="bell" />
- <NotificationMessage>
- {t`If you subscribe or are added to dashboard subscriptions or alerts you’ll be able to manage those here.`}
- </NotificationMessage>
- {children}
- </NotificationSection>
- </>
+ <Flex direction="column" align="center">
+ <Icon
+ name="bell"
+ size="3.25rem"
+ c="background-tertiary-inverse"
+ mt="4.875rem"
+ mb="1.75rem"
+ />
+ <Box maw="24rem" ta="center">
+ {t`If you subscribe or are added to dashboard subscriptions or alerts you’ll be able to manage those here.`}
+ </Box>
+ {children}
+ </Flex>
);
};