Skip to content

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

Migrate error components from Emotion to Mantine and CSS modules (#74986)

Andrei Chernykh4c2b33b3dc7a
diff --git a/frontend/src/metabase/common/components/ErrorDetails/ErrorBox.tsx b/frontend/src/metabase/common/components/ErrorDetails/ErrorBox.tsx
index d88b78affbc..87ba94faf7e 100644
--- a/frontend/src/metabase/common/components/ErrorDetails/ErrorBox.tsx
+++ b/frontend/src/metabase/common/components/ErrorDetails/ErrorBox.tsx
@@ -1,13 +1,22 @@
-import { MonospaceErrorDisplay } from "./ErrorDetails.styled";
+import { Box } from "metabase/ui";
+
+import S from "./ErrorDetails.module.css";
import type { ErrorDetails } from "./types";
export const ErrorBox = ({ children }: { children: ErrorDetails }) => (
- <MonospaceErrorDisplay>
+ <Box
+ className={S.monospace}
+ p="md"
+ mt="sm"
+ fw="bold"
+ bg="background-secondary"
+ mah="16rem"
+ >
{/* ensure we don't try to render anything except a string */}
{typeof children === "string"
? children
: typeof children.message === "string"
? children.message
: String(children)}
- </MonospaceErrorDisplay>
+ </Box>
);
diff --git a/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.module.css b/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.module.css
new file mode 100644
index 00000000000..beb8fa9a557
--- /dev/null
+++ b/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.module.css
@@ -0,0 +1,7 @@
+.monospace {
+ font-family: monospace;
+ white-space: pre-wrap;
+ border: 1px solid var(--mb-color-border);
+ border-radius: var(--mantine-radius-md);
+ overflow-y: auto;
+}
diff --git a/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.styled.tsx b/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.styled.tsx
deleted file mode 100644
index 457f7e71d54..00000000000
--- a/frontend/src/metabase/common/components/ErrorDetails/ErrorDetails.styled.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const MonospaceErrorDisplay = styled.div`
- font-family: monospace;
- white-space: pre-wrap;
- padding: 1rem;
- margin-top: 0.5rem;
- font-weight: bold;
- border-radius: 0.5rem;
- background-color: var(--mb-color-background-secondary);
- border: 1px solid var(--mb-color-border);
- max-height: 16rem;
- overflow-y: auto;
-`;
diff --git a/frontend/src/metabase/common/components/ErrorPages/ErrorPages.module.css b/frontend/src/metabase/common/components/ErrorPages/ErrorPages.module.css
new file mode 100644
index 00000000000..28daf7ab29d
--- /dev/null
+++ b/frontend/src/metabase/common/components/ErrorPages/ErrorPages.module.css
@@ -0,0 +1,8 @@
+.root {
+ border-radius: var(--mantine-radius-md);
+ overflow: hidden;
+}
+
+.bordered {
+ border: 1px solid var(--mb-color-border);
+}
diff --git a/frontend/src/metabase/common/components/ErrorPages/ErrorPages.styled.tsx b/frontend/src/metabase/common/components/ErrorPages/ErrorPages.styled.tsx
deleted file mode 100644
index b8595e3fdab..00000000000
--- a/frontend/src/metabase/common/components/ErrorPages/ErrorPages.styled.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const ErrorPageRoot = styled.div<{ bordered?: boolean }>`
- display: flex;
- width: 100%;
- height: 100%;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- ${({ bordered }) =>
- bordered &&
- css`
- border: 1px solid var(--mb-color-border);
- `}
- border-radius: 0.5rem;
- overflow: hidden;
-`;
diff --git a/frontend/src/metabase/common/components/ErrorPages/ErrorPages.tsx b/frontend/src/metabase/common/components/ErrorPages/ErrorPages.tsx
index 10be864c779..b42118aee38 100644
--- a/frontend/src/metabase/common/components/ErrorPages/ErrorPages.tsx
+++ b/frontend/src/metabase/common/components/ErrorPages/ErrorPages.tsx
@@ -10,13 +10,13 @@ import { useToggle } from "metabase/common/hooks/use-toggle";
import CS from "metabase/css/core/index.css";
import QueryBuilderS from "metabase/css/query_builder.module.css";
import { getIsEmbeddingIframe } from "metabase/selectors/embed";
-import { Button, Icon, Tooltip } from "metabase/ui";
+import { Button, Flex, Icon, Tooltip } from "metabase/ui";
import {
ErrorDiagnosticModalTrigger,
ErrorExplanationModal,
} from "./ErrorDiagnosticModal";
-import { ErrorPageRoot } from "./ErrorPages.styled";
+import S from "./ErrorPages.module.css";
interface GenericErrorProps {
title?: string;
@@ -33,7 +33,15 @@ export const GenericError = forwardRef<HTMLDivElement, GenericErrorProps>(
ref,
) {
return (
- <ErrorPageRoot ref={ref}>
+ <Flex
+ ref={ref}
+ className={S.root}
+ direction="column"
+ w="100%"
+ h="100%"
+ justify="center"
+ align="center"
+ >
<EmptyState
title={title}
message={message}
@@ -48,7 +56,7 @@ export const GenericError = forwardRef<HTMLDivElement, GenericErrorProps>(
/>
<ErrorDetails className={CS.pt2} details={details} centered />
<ErrorDiagnosticModalTrigger />
- </ErrorPageRoot>
+ </Flex>
);
},
);
@@ -60,22 +68,37 @@ export const NotFound = ({
title?: string;
message?: string;
}) => (
- <ErrorPageRoot aria-label="error page">
+ <Flex
+ aria-label="error page"
+ className={S.root}
+ direction="column"
+ w="100%"
+ h="100%"
+ justify="center"
+ align="center"
+ >
<EmptyState
illustrationElement={<img src={NoResults} />}
title={title}
message={message}
/>
- </ErrorPageRoot>
+ </Flex>
);
export const Unauthorized = () => (
- <ErrorPageRoot>
+ <Flex
+ className={S.root}
+ direction="column"
+ w="100%"
+ h="100%"
+ justify="center"
+ align="center"
+ >
<EmptyState
title={t`Sorry, you don’t have permission to see that.`}
illustrationElement={<Icon name="key" size={100} />}
/>
- </ErrorPageRoot>
+ </Flex>
);
export const Archived = ({
@@ -85,13 +108,20 @@ export const Archived = ({
entityName: string;
linkTo: string;
}) => (
- <ErrorPageRoot>
+ <Flex
+ className={S.root}
+ direction="column"
+ w="100%"
+ h="100%"
+ justify="center"
+ align="center"
+ >
<EmptyState
title={t`This ${entityName} has been archived`}
illustrationElement={<Icon name="view_archive" size={100} />}
link={linkTo}
/>
- </ErrorPageRoot>
+ </Flex>
);
export const SmallGenericError = forwardRef<
@@ -114,7 +144,16 @@ export const SmallGenericError = forwardRef<
: message + t` Click for more information`;
return (
- <ErrorPageRoot bordered={bordered} {...props} ref={ref}>
+ <Flex
+ ref={ref}
+ className={cx(S.root, { [S.bordered]: bordered })}
+ direction="column"
+ w="100%"
+ h="100%"
+ justify="center"
+ align="center"
+ {...props}
+ >
<Tooltip label={tooltipMessage}>
{isEmbeddingIframe ? (
<Icon name="warning" size={32} c="text-tertiary" />
@@ -128,6 +167,6 @@ export const SmallGenericError = forwardRef<
)}
</Tooltip>
<ErrorExplanationModal isModalOpen={isModalOpen} onClose={closeModal} />
- </ErrorPageRoot>
+ </Flex>
);
});