Skip to content

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

Migrate the public action page off Emotion, drop LegaleseStep (#83488)

Andrei Chernykhf349f44d32fd
diff --git a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.styled.tsx b/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.styled.tsx
deleted file mode 100644
index a2d38dc94bc..00000000000
--- a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.styled.tsx
+++ /dev/null
@@ -1,13 +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";
-
-import { Stack } from "metabase/ui";
-
-export const LegaleseStepDetailsContainer = styled(Stack)`
- ${({ theme }) => css`
- border: 1px solid ${theme.colors["border-neutral"][0]};
- border-radius: ${theme.radius.sm};
- `}
-`;
diff --git a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.tsx b/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.tsx
deleted file mode 100644
index 3f12aae8c07..00000000000
--- a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-import { jt, t } from "ttag";
-
-import { ExternalLink } from "metabase/common/components/ExternalLink";
-import { LegaleseStepDetailsContainer } from "metabase/public/components/widgets/LegaleseStep/LegaleseStep.styled";
-import { useUpdateSettingMutation } from "metabase/settings";
-import { Button, Center, Stack, Text, Title } from "metabase/ui";
-
-export const LegaleseStep = ({
- goToNextStep,
-}: {
- goToNextStep: () => void;
-}) => {
- const [updateSetting] = useUpdateSettingMutation();
-
- const onAcceptTerms = () => {
- updateSetting({
- key: "show-static-embed-terms",
- value: false,
- });
- goToNextStep();
- };
-
- return (
- <Center bg="background_page-primary" px="18rem" pt="6.25rem" pb="11.75rem">
- <Stack align="center" gap="3rem">
- <Title order={3} fz="1.25rem">{t`First, some legalese`}</Title>
-
- <LegaleseStepDetailsContainer p="xl" w="40rem">
- <Text fw={700}>
- {jt`By clicking "Agree and continue" you're agreeing to ${(
- <ExternalLink
- key="embed-license-link"
- href="https://metabase.com/license/embedding"
- target="_blank"
- >
- {t`our embedding license.`}
- </ExternalLink>
- )}`}
- </Text>
- <Text>
- {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- This only shows for admins */}
- {t`When you embed charts or dashboards from Metabase in your own application that application isn't subject to the Affero General Public License that covers the rest of Metabase, provided you keep the Metabase logo and the "Powered by Metabase" visible on those embeds.`}
- </Text>
- <Text>
- {t`You should, however, read the license text linked above as that is the actual license that you will be agreeing to by enabling this feature.`}
- </Text>
- </LegaleseStepDetailsContainer>
-
- <Button
- variant="filled"
- onClick={onAcceptTerms}
- data-testid="accept-legalese-terms-button"
- >{t`Agree and continue`}</Button>
- </Stack>
- </Center>
- );
-};
diff --git a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.unit.spec.tsx b/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.unit.spec.tsx
deleted file mode 100644
index cb67334c4de..00000000000
--- a/frontend/src/metabase/public/components/widgets/LegaleseStep/LegaleseStep.unit.spec.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import userEvent from "@testing-library/user-event";
-import fetchMock from "fetch-mock";
-
-import {
- setupPropertiesEndpoints,
- setupSettingsEndpoints,
-} from "__support__/server-mocks";
-import { renderWithProviders, screen } from "__support__/ui";
-import {
- createMockSettingDefinition,
- createMockSettings,
-} from "metabase-types/api/mocks";
-
-import { LegaleseStep } from "./LegaleseStep";
-
-const setup = () => {
- const goToNextStep = jest.fn();
-
- setupSettingsEndpoints([
- createMockSettingDefinition({
- key: "show-static-embed-terms",
- value: true,
- }),
- ]);
-
- setupPropertiesEndpoints(createMockSettings());
-
- renderWithProviders(<LegaleseStep goToNextStep={goToNextStep} />);
-
- return { goToNextStep };
-};
-
-describe("LegaleseStep", () => {
- it("should render", () => {
- setup();
-
- expect(screen.getByText("First, some legalese")).toBeInTheDocument();
- expect(
- screen.getByText('By clicking "Agree and continue" you\'re agreeing to'),
- ).toBeInTheDocument();
- expect(
- screen.getByText(
- `When you embed charts or dashboards from Metabase in your own application that application isn't subject to the Affero General Public License that covers the rest of Metabase, provided you keep the Metabase logo and the "Powered by Metabase" visible on those embeds.`,
- ),
- ).toBeInTheDocument();
- expect(
- screen.getByText(
- "You should, however, read the license text linked above as that is the actual license that you will be agreeing to by enabling this feature.",
- ),
- ).toBeInTheDocument();
- expect(screen.getByText("Agree and continue")).toBeInTheDocument();
- });
-
- it("calls goToNextStep and updates setting on clicking 'Agree and continue'", async () => {
- fetchMock.put("path:/api/setting/show-static-embed-terms", 204);
-
- const { goToNextStep } = setup();
- await userEvent.click(screen.getByText("Agree and continue"));
-
- const settingPutCalls = fetchMock.callHistory.calls(
- "path:/api/setting/show-static-embed-terms",
- );
-
- expect(settingPutCalls.length).toBe(1);
- expect(await settingPutCalls[0]?.request?.json()).toEqual({
- value: false,
- });
- expect(goToNextStep).toHaveBeenCalled();
- });
-});
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx b/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx
deleted file mode 100644
index d75b2eb97cf..00000000000
--- a/frontend/src/metabase/public/containers/PublicAction/PublicAction.styled.tsx
+++ /dev/null
@@ -1,48 +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";
-
-import { LoadingAndErrorWrapper as BaseLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { breakpointMaxSmall } from "metabase/styled-components/theme";
-
-export const LoadingAndErrorWrapper = styled(BaseLoadingAndErrorWrapper)`
- display: flex;
- flex: 1 0 auto;
-`;
-
-export const ContentContainer = styled.div`
- display: flex;
- flex: 1 0 auto;
- align-items: center;
- justify-content: center;
- padding: 1.5rem;
-`;
-
-export const FormContainer = styled.div`
- display: flex;
- flex-direction: column;
- width: 430px;
-
- ${breakpointMaxSmall} {
- width: 100%;
- padding: 0 0.5rem;
- }
-`;
-
-const titleStyle = css`
- font-weight: 700;
- font-size: 1.125rem;
- line-height: 1.375rem;
- color: var(--mb-color-text-primary);
-`;
-
-export const FormTitle = styled.h1`
- ${titleStyle}
- margin-bottom: 21px;
-`;
-
-export const FormResultMessage = styled.h1`
- ${titleStyle}
- text-align: center;
-`;
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx b/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
index 629a1a8127a..8c77a0ab43c 100644
--- a/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
+++ b/frontend/src/metabase/public/containers/PublicAction/PublicAction.tsx
@@ -7,17 +7,12 @@ import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";
import { usePageTitle } from "metabase/hooks/use-page-title";
import { useDispatch } from "metabase/redux";
import type { AppErrorDescriptor } from "metabase/redux/store";
+import { Stack, Title } from "metabase/ui";
import type {
ParametersForActionExecution,
WritebackAction,
} from "metabase-types/api";
-import {
- FormContainer,
- FormResultMessage,
- FormTitle,
-} from "./PublicAction.styled";
-
interface Props {
action: WritebackAction;
publicId: string;
@@ -49,18 +44,28 @@ function PublicAction({ action, publicId, onError }: Props) {
);
if (isSubmitted) {
- return <FormResultMessage>{successMessage}</FormResultMessage>;
+ return (
+ <Title order={1} size="h4" c="text-primary" ta="center">
+ {successMessage}
+ </Title>
+ );
}
return (
- <FormContainer>
- <FormTitle>{action.name}</FormTitle>
+ <Stack
+ gap={0}
+ w={{ base: "100%", sm: "26.875rem" }}
+ px={{ base: "sm", sm: 0 }}
+ >
+ <Title order={1} size="h4" c="text-primary" mb="xl">
+ {action.name}
+ </Title>
<ActionForm
action={action}
submitButtonFullWidth
onSubmit={handleSubmit}
/>
- </FormContainer>
+ </Stack>
);
}
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.module.css b/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.module.css
new file mode 100644
index 00000000000..c444031bbfe
--- /dev/null
+++ b/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.module.css
@@ -0,0 +1,4 @@
+.loadingWrapper {
+ display: flex;
+ flex: 1 0 auto;
+}
diff --git a/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.tsx b/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.tsx
index 13f5a3c5c09..65a4b09d018 100644
--- a/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.tsx
+++ b/frontend/src/metabase/public/containers/PublicAction/PublicActionLoader.tsx
@@ -3,16 +3,15 @@ import { useAsyncFn, useMount } from "react-use";
import { publicApi } from "metabase/api";
import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { SyncedEmbedFrame } from "metabase/public/components/EmbedFrame";
import { connect, useDispatch } from "metabase/redux";
import { setErrorPage } from "metabase/redux/app";
import { useParams } from "metabase/router";
+import { Flex } from "metabase/ui";
import PublicAction from "./PublicAction";
-import {
- ContentContainer,
- LoadingAndErrorWrapper,
-} from "./PublicAction.styled";
+import S from "./PublicActionLoader.module.css";
interface DispatchProps {
setErrorPage: (error: any) => void;
@@ -52,15 +51,15 @@ function PublicActionLoader({ setErrorPage }: Props) {
return null;
}
return (
- <ContentContainer>
+ <Flex flex="1 0 auto" align="center" justify="center" p="xl">
<PublicAction action={action} publicId={uuid} onError={setErrorPage} />
- </ContentContainer>
+ </Flex>
);
}, [action, uuid, setErrorPage]);
return (
<SyncedEmbedFrame footerVariant="large">
- <LoadingAndErrorWrapper loading={!action}>
+ <LoadingAndErrorWrapper className={S.loadingWrapper} loading={!action}>
{renderContent}
</LoadingAndErrorWrapper>
</SyncedEmbedFrame>