Skip to content

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

Remove unused EmbeddingSetup components and hooks (#63841)

Phoomparin Mano38260ca6084e
diff --git a/frontend/src/metabase-types/analytics/event.ts b/frontend/src/metabase-types/analytics/event.ts
index 905124b678d..8031bb9aca3 100644
--- a/frontend/src/metabase-types/analytics/event.ts
+++ b/frontend/src/metabase-types/analytics/event.ts
@@ -168,29 +168,6 @@ export type VisualizerModalEvent = ValidateEvent<
}
>;
-export type EmbeddingSetupStepKey =
- | "welcome"
- | "user-creation"
- | "data-connection"
- | "table-selection"
- | "processing"
- | "add-to-your-app"
- | "done";
-export type EmbeddingSetupStepSeenEvent = ValidateEvent<{
- event: "embedding_setup_step_seen";
- event_detail: EmbeddingSetupStepKey;
-}>;
-
-export type EmbeddingSetupClickEvent = ValidateEvent<{
- event: "embedding_setup_click";
- event_detail:
- | "setup-up-manually"
- | "add-data-later-or-skip"
- | "snippet-copied"
- | "ill-do-this-later";
- triggered_from: EmbeddingSetupStepKey;
-}>;
-
export type EventsClickedEvent = ValidateEvent<{
event: "events_clicked";
triggered_from: "chart" | "collection";
@@ -504,8 +481,6 @@ export type SimpleEvent =
| NewButtonItemClickedEvent
| VisualizeAnotherWayClickedEvent
| VisualizerModalEvent
- | EmbeddingSetupStepSeenEvent
- | EmbeddingSetupClickEvent
| EventsClickedEvent
| AddDataModalOpenedEvent
| AddDataModalTabEvent
diff --git a/frontend/src/metabase/App.tsx b/frontend/src/metabase/App.tsx
index 4b518f265c0..07401e4781e 100644
--- a/frontend/src/metabase/App.tsx
+++ b/frontend/src/metabase/App.tsx
@@ -25,7 +25,6 @@ import {
getErrorPage,
getIsAdminApp,
getIsAppBarVisible,
- getIsEmbeddingSetup,
getIsNavBarEnabled,
} from "metabase/selectors/app";
import StatusListing from "metabase/status/components/StatusListing";
@@ -56,7 +55,6 @@ const getErrorComponent = ({ status, data, context }: AppErrorDescriptor) => {
interface AppStateProps {
errorPage: AppErrorDescriptor | null;
isAdminApp: boolean;
- isEmbeddingSetup: boolean;
bannerMessageDescriptor?: string;
isAppBarVisible: boolean;
isNavBarEnabled: boolean;
@@ -79,7 +77,6 @@ const mapStateToProps = (
): AppStateProps => ({
errorPage: getErrorPage(state),
isAdminApp: getIsAdminApp(state, props),
- isEmbeddingSetup: getIsEmbeddingSetup(state, props),
isAppBarVisible: getIsAppBarVisible(state, props),
isNavBarEnabled: getIsNavBarEnabled(state, props),
});
@@ -91,7 +88,6 @@ const mapDispatchToProps: AppDispatchProps = {
function App({
errorPage,
isAdminApp,
- isEmbeddingSetup,
isAppBarVisible,
isNavBarEnabled,
children,
@@ -104,16 +100,13 @@ function App({
initializeIframeResizer();
}, []);
- const isAppBannerVisible = !isEmbeddingSetup;
- const isStatusListingVisible = !isEmbeddingSetup;
-
return (
<ErrorBoundary onError={onError}>
<ScrollToTop>
<KBarProvider>
<KeyboardTriggeredErrorModal />
<AppContainer className={CS.spread}>
- {isAppBannerVisible && <AppBanner />}
+ <AppBanner />
{isAppBarVisible && <AppBar />}
<AppContentContainer isAdminApp={isAdminApp}>
{isNavBarEnabled && <Navbar />}
@@ -125,7 +118,7 @@ function App({
</ContentViewportContext.Provider>
</AppContent>
<UndoListing />
- {isStatusListingVisible && <StatusListing />}
+ <StatusListing />
<NewModals />
<PLUGIN_METABOT.Metabot hide={isAdminApp} />
</AppContentContainer>
diff --git a/frontend/src/metabase/selectors/app.ts b/frontend/src/metabase/selectors/app.ts
index 78ec8a85dd5..37bcf3f00a4 100644
--- a/frontend/src/metabase/selectors/app.ts
+++ b/frontend/src/metabase/selectors/app.ts
@@ -62,10 +62,6 @@ export const getIsAdminApp = createSelector([getRouterPath], (path) => {
return path.startsWith("/admin/");
});
-export const getIsEmbeddingSetup = createSelector([getRouterPath], (path) => {
- return path.startsWith("/setup/embedding");
-});
-
export const getIsCollectionPathVisible = createSelector(
[
getQuestion,
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetup.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetup.tsx
deleted file mode 100644
index 9f705116170..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetup.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import { t } from "ttag";
-
-import { Box, Flex } from "metabase/ui";
-
-import {
- EmbeddingSetupProvider,
- useEmbeddingSetup,
-} from "./EmbeddingSetupContext";
-import { EmbeddingSetupSidebar } from "./EmbeddingSetupSidebar";
-
-const EmbeddingSetupInner = () => {
- const {
- stepKey,
- goToStep,
- stepIndex,
- totalSteps,
- goToNextStep,
- StepComponent,
- } = useEmbeddingSetup();
-
- return (
- <Flex
- justify="center"
- style={{
- minHeight: "100vh",
- alignItems: "start",
- width: "100%",
- }}
- >
- <Flex h="100vh" style={{ position: "sticky", top: 0 }}>
- <EmbeddingSetupSidebar />
- </Flex>
- <Box
- component="section"
- aria-label={t`Embedding setup current step`}
- p="xl"
- flex={1}
- maw="53rem"
- >
- <Box
- p="xl"
- flex={1}
- bg="bg-white"
- bd="1px solid var(--mb-color-border)"
- w="100%"
- style={{ borderRadius: "0.5rem" }}
- >
- <StepComponent
- nextStep={goToNextStep}
- goToStep={goToStep}
- stepKey={stepKey}
- stepIndex={stepIndex}
- totalSteps={totalSteps}
- />
- </Box>
- </Box>
- </Flex>
- );
-};
-
-export const EmbeddingSetup = () => (
- <EmbeddingSetupProvider>
- <EmbeddingSetupInner />
- </EmbeddingSetupProvider>
-);
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupContext.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupContext.tsx
deleted file mode 100644
index 6d45753ba5a..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupContext.tsx
+++ /dev/null
@@ -1,148 +0,0 @@
-import {
- createContext,
- useCallback,
- useContext,
- useEffect,
- useState,
-} from "react";
-
-import { trackSimpleEvent } from "metabase/lib/analytics";
-import { useSelector } from "metabase/lib/redux";
-import { getLocale } from "metabase/setup/selectors";
-import type { EmbeddingSetupClickEvent } from "metabase-types/analytics";
-import type { Dashboard, DatabaseData, Table } from "metabase-types/api";
-
-import { DataConnectionStep } from "./steps/DataConnectionStep";
-import { DoneStep } from "./steps/DoneStep";
-import { FinalStep } from "./steps/FinalStep";
-import { ProcessingStep } from "./steps/ProcessingStep";
-import { TableSelectionStep } from "./steps/TableSelectionStep";
-import { UserCreationStep } from "./steps/UserCreationStep";
-import { WelcomeStep } from "./steps/WelcomeStep";
-import type {
- EmbeddingSetupStepKey,
- StepDefinition,
-} from "./steps/embeddingSetupSteps";
-import { STEPS, getStepIndexByKey } from "./steps/embeddingSetupSteps";
-
-export const STEP_COMPONENTS = [
- WelcomeStep,
- UserCreationStep,
- DataConnectionStep,
- TableSelectionStep,
- ProcessingStep,
- FinalStep,
- DoneStep,
-] as const;
-
-type EmbeddingSetupContextType = {
- database: DatabaseData | null;
- setDatabase: (database: DatabaseData | null) => void;
- processingStatus: string;
- setProcessingStatus: (status: string) => void;
- error: string;
- setError: (error: string) => void;
- selectedTables: Table[];
- setSelectedTables: (tables: Table[]) => void;
- createdDashboard2: Dashboard[];
- setCreatedDashboard: (dashboards: Dashboard[]) => void;
- stepKey: EmbeddingSetupStepKey;
- goToStep: (key: EmbeddingSetupStepKey) => void;
- steps: StepDefinition[];
- stepIndex: number;
- totalSteps: number;
- goToNextStep: () => void;
- StepComponent: (typeof STEP_COMPONENTS)[number];
- trackEmbeddingSetupClick: (
- eventDetail: EmbeddingSetupClickEvent["event_detail"],
- ) => void;
-};
-
-const EmbeddingSetupContext = createContext<EmbeddingSetupContextType | null>(
- null,
-);
-
-export const useEmbeddingSetup = () => {
- // This forces the components where it's used to re-render, making `t` use the new locale
- // This is needed because we allow changing the locale from the sidebar, without this trick
- // the components on the page wouldn't re-render with the new locale
- useSelector(getLocale);
-
- const context = useContext(EmbeddingSetupContext);
-
- if (!context) {
- throw new Error(
- "useEmbeddingSetup must be used within EmbeddingSetupProvider",
- );
- }
- return context;
-};
-
-export const EmbeddingSetupProvider = ({
- children,
-}: {
- children: React.ReactNode;
-}) => {
- const [database, setDatabase] = useState<DatabaseData | null>(null);
- const [processingStatus, setProcessingStatus] = useState("");
- const [error, setError] = useState("");
- const [selectedTables, setSelectedTables] = useState<Table[]>([]);
- const [createdDashboard2, setCreatedDashboard] = useState<Dashboard[]>([]);
- const [stepKey, goToStep] = useState<EmbeddingSetupStepKey>(STEPS[0].key);
-
- const stepIndex = getStepIndexByKey(stepKey);
- const totalSteps = STEP_COMPONENTS.length;
- const StepComponent = STEP_COMPONENTS[stepIndex];
-
- const goToNextStep = useCallback(() => {
- const nextKey = STEPS[stepIndex + 1]?.key;
- if (nextKey) {
- goToStep(nextKey);
- }
- }, [stepIndex, goToStep]);
-
- useEffect(() => {
- trackSimpleEvent({
- event: "embedding_setup_step_seen",
- event_detail: stepKey,
- });
- }, [stepKey]);
-
- const trackEmbeddingSetupClick = useCallback(
- (eventDetail: EmbeddingSetupClickEvent["event_detail"]) => {
- trackSimpleEvent({
- event: "embedding_setup_click",
- event_detail: eventDetail,
- triggered_from: stepKey,
- });
- },
- [stepKey],
- );
-
- return (
- <EmbeddingSetupContext.Provider
- value={{
- database,
- setDatabase,
- processingStatus,
- setProcessingStatus,
- error,
- setError,
- selectedTables,
- setSelectedTables,
- createdDashboard2,
- setCreatedDashboard,
- stepKey,
- goToStep,
- steps: STEPS,
- stepIndex,
- totalSteps,
- goToNextStep,
- StepComponent,
- trackEmbeddingSetupClick,
- }}
- >
- {children}
- </EmbeddingSetupContext.Provider>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupSidebar.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupSidebar.tsx
deleted file mode 100644
index 3007eb7627c..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/EmbeddingSetupSidebar.tsx
+++ /dev/null
@@ -1,187 +0,0 @@
-import { match } from "ts-pattern";
-import { t } from "ttag";
-
-import LogoIcon from "metabase/common/components/LogoIcon";
-import { useUniqueId } from "metabase/common/hooks/use-unique-id";
-import { Box, Center, Flex, Icon, type IconName, Text } from "metabase/ui";
-
-import { LanguageSelector } from "../LanguageSelector";
-
-import { useEmbeddingSetup } from "./EmbeddingSetupContext";
-import type { StepDefinition } from "./steps/embeddingSetupSteps";
-
-const ICON_SIZE = 30;
-const STEP_GAP = 22;
-
-export const EmbeddingSetupSidebar = () => {
- const { stepKey, steps, stepIndex: currentStepIndex } = useEmbeddingSetup();
-
- const visibleSteps = steps.filter((step) => step.visibleInSidebar);
- const currentStepIndexInVisibleSteps = visibleSteps.findIndex(
- (step) => step.key === stepKey,
- );
-
- return (
- <Box
- component="aside"
- aria-label="Embedding Setup Sidebar"
- w="250px"
- pt="xl"
- p="md"
- style={{
- flexShrink: 0,
- display: "flex",
- flexDirection: "column",
- }}
- >
- <Flex mb="xl" direction="column" align="center">
- <Box h={39} w={39} mb="md">
- <LogoIcon />
- </Box>
- <Text fw="bold" size="2xl" mb="xl">
- {t`Embedded Analytics`}
- </Text>
- </Flex>
- <Box component="ol" style={{ position: "relative" }}>
- {steps.map((step: StepDefinition, index: number) => {
- if (!step.visibleInSidebar) {
- return null;
- }
- const indexInVisibleSteps = visibleSteps.findIndex(
- (visibleStep) => visibleStep.key === step.key,
- );
-
- const status = match({ index, indexInVisibleSteps })
- .when(
- ({ indexInVisibleSteps }) =>
- indexInVisibleSteps === currentStepIndexInVisibleSteps,
- () => "active" as const,
- )
- .when(
- ({ index }) => index < currentStepIndex,
- () => "done" as const,
- )
- .otherwise(() => "future" as const);
-
- return (
- <Step
- key={step.key}
- icon={step.icon}
- title={step.title}
- isLast={indexInVisibleSteps === visibleSteps.length - 1}
- status={status}
- />
- );
- })}
- </Box>
- <Center mt="auto" pt="xl" mb="xxl">
- <LanguageSelector />
- </Center>
- </Box>
- );
-};
-
-interface StepProps {
- title: string;
- status: "done" | "active" | "future";
- isLast: boolean;
- icon: IconName;
-}
-
-const Step = ({ title, status, isLast, icon }: StepProps) => {
- const uniqueId = useUniqueId("step-label");
- const { iconName, iconCssColor, circleBgCssColor, circleBorderCss } = match(
- status,
- )
- .with(
- "done",
- () =>
- ({
- iconName: "check",
- iconCssColor: "var(--mb-color-text-white)",
- circleBgCssColor: "#5CA040",
- circleBorderCss: "none",
- }) as const,
- )
- .with(
- "active",
- () =>
- ({
- iconName: icon,
- iconCssColor: "var(--mb-color-brand)",
- circleBgCssColor: "#fff",
- circleBorderCss: "2px solid var(--mb-color-brand)",
- }) as const,
- )
- .with(
- "future",
- () =>
- ({
- iconName: icon,
- iconCssColor: "var(--mb-color-text-light)",
- circleBgCssColor: "#fff",
- circleBorderCss: "2px solid var(--mb-color-border)",
- }) as const,
- )
- .exhaustive();
-
- return (
- <Flex
- component="li"
- aria-labelledby={uniqueId}
- aria-current={status === "active" ? "step" : undefined}
- style={{
- gap: 12,
- alignItems: "center",
- position: "relative",
- minHeight: ICON_SIZE,
- marginBottom: isLast ? 0 : STEP_GAP,
- }}
- >
- <Box
- style={{
- display: "flex",
- justifyContent: "center",
- alignItems: "center",
- position: "relative",
- height: ICON_SIZE,
- }}
- >
- {/* Vertical line */}
- {!isLast && (
- <Box
- style={{
- position: "absolute",
- top: ICON_SIZE / 2,
- left: "50%",
- width: 1,
- height: `calc(100% + ${STEP_GAP - ICON_SIZE / 2}px)`,
- background: "var(--mb-color-border)",
- transform: "translateX(-50%)",
- zIndex: 0,
- }}
- />
- )}
- {/* Icon circle */}
- <Box
- style={{
- width: ICON_SIZE,
- height: ICON_SIZE,
- borderRadius: "50%",
- background: circleBgCssColor,
- border: circleBorderCss,
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- zIndex: 1,
- }}
- >
- <Icon name={iconName} color={iconCssColor} size={16} />
- </Box>
- </Box>
- <Text c="text-primary" size="md" id={uniqueId}>
- {title}
- </Text>
- </Flex>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/index.ts b/frontend/src/metabase/setup/components/EmbeddingSetup/index.ts
deleted file mode 100644
index cb14a34a012..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/index.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export { WelcomeStep } from "./steps/WelcomeStep";
-export { DataConnectionStep } from "./steps/DataConnectionStep";
-export { TableSelectionStep } from "./steps/TableSelectionStep";
-export { ProcessingStep } from "./steps/ProcessingStep";
-export { FinalStep } from "./steps/FinalStep";
-export { DoneStep } from "./steps/DoneStep";
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DataConnectionStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DataConnectionStep.tsx
deleted file mode 100644
index ae249103df9..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DataConnectionStep.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-import { useCallback } from "react";
-import { push } from "react-router-redux";
-import { t } from "ttag";
-
-import { createDatabase } from "metabase/admin/databases/database";
-import { DatabaseForm } from "metabase/databases/components/DatabaseForm";
-import { useDispatch } from "metabase/lib/redux";
-import { Button, Stack, Text, Title } from "metabase/ui";
-import type { DatabaseData } from "metabase-types/api";
-
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-
-export const DataConnectionStep = () => {
- const dispatch = useDispatch();
- const { setDatabase, goToNextStep, trackEmbeddingSetupClick } =
- useEmbeddingSetup();
-
- const handleSubmit = async (databaseData: DatabaseData) => {
- const createdDatabase = await dispatch(createDatabase(databaseData));
- setDatabase(createdDatabase);
- goToNextStep();
- };
- const onCancel = useCallback(() => {
- trackEmbeddingSetupClick("add-data-later-or-skip");
- dispatch(push("/"));
- }, [dispatch, trackEmbeddingSetupClick]);
-
- const ContinueWithoutDataButton = useCallback(
- ({ onCancel }: { onCancel?: () => void }) => {
- return (
- <Button variant="subtle" c="text-secondary" onClick={onCancel}>
- {t`I'll add my data later`}
- </Button>
- );
- },
- [],
- );
-
- return (
- <Stack gap="xl">
- <Stack gap="md">
- <Title order={2}>{t`Connect to your data`}</Title>
- <Text size="lg">
- {t`Connect to your database to get started with embedding. We'll help you select tables to turn into models and dashboards.`}
- </Text>
- </Stack>
-
- <DatabaseForm
- onSubmit={handleSubmit}
- onEngineChange={() => {}}
- onCancel={onCancel}
- showSampleDatabase={false}
- ContinueWithoutDataSlot={ContinueWithoutDataButton}
- location="embedding_setup"
- />
- </Stack>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DoneStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DoneStep.tsx
deleted file mode 100644
index ee967957a7e..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/DoneStep.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-import { t } from "ttag";
-
-import { useDocsUrl } from "metabase/common/hooks";
-import { Anchor, Box, Button, Icon, Stack, Text, Title } from "metabase/ui";
-
-export const DoneStep = () => {
- const { url: authUrl } = useDocsUrl(
- "embedding/interactive-embedding-quick-start-guide",
- );
- const { url: appearanceUrl } = useDocsUrl("configuring-metabase/appearance");
- const { url: contentUrl } = useDocsUrl("dashboards/introduction");
-
- return (
- <Box>
- <Box mb="4rem">
- <Title order={2} fw="bold" mb="md">
- {t`You're on your way!`}
- </Title>
- <Text>
- {t`Now that you have a toy app with some starter content, you’re set up to go further.`}
- </Text>
- </Box>
- <Stack gap="3rem" mb="4rem">
- <ExternalLinkBlock
- href={authUrl}
- text={t`Next: Set up SSO`}
- description={t`Learn more about how to set up the right auth strategy so your users only see the data they’re supposed to.`}
- />
- <ExternalLinkBlock
- href={appearanceUrl}
- text={t`Later: Explore Theming`}
- description={t`Make your embeds match your apps look and feel.`}
- />
- <ExternalLinkBlock
- href={contentUrl}
- text={t`Later: Creating content for your embeds`}
- description={t`Evolve these starter dashboards or create new analysis.`}
- />
- </Stack>
- {/* This needs to be a client side navigation for a couple of reasons:
- - when we'll have the token step, we'll need to refresh the page to load the updated plugins
- - in /setup/embedding we're skipping rendering the DatabaseStatus component, but as soon as the user lands on /
- that will get rendered and shown, because we'll need the browser navigation anyway, this is a "cheap" solution to that as well */}
- <Button component="a" href="/" variant="filled">
- {t`Take me to Metabase`}
- </Button>
- </Box>
- );
-};
-
-const ExternalLinkBlock = ({
- href,
- text,
- description,
-}: {
- href: string;
- text: string;
- description: string;
-}) => {
- return (
- <Box>
- <Anchor
- href={href}
- target="_blank"
- rel="noopener"
- c="brand"
- fw="bold"
- size="xl"
- mb="sm"
- >
- {text}
- <Icon name="external" ml="sm" color="var(--mb-color-text-dark)" />
- </Anchor>
- <Text mt="xs" c="text-primary">
- {description}
- </Text>
- </Box>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/FinalStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/FinalStep.tsx
deleted file mode 100644
index 0c4b2ba76a1..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/FinalStep.tsx
+++ /dev/null
@@ -1,163 +0,0 @@
-import { useMemo } from "react";
-import { t } from "ttag";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-import { useDocsUrl } from "metabase/common/hooks";
-import { highlight } from "metabase/query_builder/components/expressions/HighlightExpression/utils";
-import {
- Box,
- Button,
- Center,
- Code,
- Group,
- Loader,
- Stack,
- Tabs,
- Text,
- Title,
-} from "metabase/ui";
-import type { Dashboard } from "metabase-types/api";
-
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-
-import type { StepProps } from "./embeddingSetupSteps";
-
-export const FinalStep = ({ nextStep }: StepProps) => {
- const { url: docsUrl } = useDocsUrl("embedding/interactive-embedding");
- const { createdDashboard2, trackEmbeddingSetupClick } = useEmbeddingSetup();
-
- const getEmbedCode = (url: string) => {
- return `<iframe src="${url}" width="800px" height="500px" />`;
- };
-
- const tabs = useMemo(
- () => [
- ...createdDashboard2.map((dashboard: Dashboard) => ({
- title: dashboard.name,
- url: `${window.location.origin}/dashboard/${dashboard.id}`,
- })),
- {
- title: t`Query Builder`,
- url: `${window.location.origin}/question/new`,
- },
- ],
- [createdDashboard2],
- );
-
- if (!createdDashboard2 || createdDashboard2.length === 0) {
- return (
- <Center h="500px">
- <Text>{t`No dashboards found`}</Text>
- </Center>
- );
- }
-
- return (
- <Stack gap="xl">
- <Group justify="space-between">
- <Stack gap="md">
- <Title order={2}>{t`Add to your app`}</Title>
- <Text size="md">
- {t`Copy the code into your application. You can also pick this up later.`}
- </Text>
- </Stack>
-
- <a href={docsUrl} target="_blank" rel="noreferrer">
- <Text c="brand">{t`Documentation`}</Text>
- </a>
- </Group>
-
- <Tabs
- defaultValue={tabs[0].url}
- // TODO: keepMounted={true} would keep them "in memory" but it also loads them all at the same time,
- // slowing down the load of the first
- >
- <Tabs.List>
- {tabs.map((tab) => (
- <Tabs.Tab key={tab.url} value={tab.url}>
- {tab.title}
- </Tabs.Tab>
- ))}
- </Tabs.List>
- {tabs.map((tab) => (
- <Tabs.Panel key={tab.url} value={tab.url}>
- <Box mt="md">
- <CodeSnippet
- code={getEmbedCode(tab.url)}
- onCopy={() => {
- trackEmbeddingSetupClick("snippet-copied");
- }}
- />
- </Box>
-
- {/* This shows a loader while the iframe is loading, it's ugly as it's a different loader than the one inside the iframe,
- but some times the iframe takes a second or two to "start" and in that time there's just a big white space in the page */}
- <Box my="md" style={{ position: "relative" }}>
- <Center
- w="100%"
- style={{
- position: "absolute",
- }}
- mt="xl"
- >
- <Loader />
- </Center>
- <iframe
- src={tab.url}
- style={{
- width: "100%",
- height: "600px",
- border: "none",
- zIndex: 2,
- position: "relative",
- }}
- title={tab.title}
- />
- </Box>
- </Tabs.Panel>
- ))}
- </Tabs>
-
- <Group justify="space-between" mt="xl">
- <Button
- variant="subtle"
- color="text-primary"
- onClick={() => {
- trackEmbeddingSetupClick("ill-do-this-later");
- nextStep();
- }}
- >
- {t`I'll do this later`}
- </Button>
-
- <Button variant="filled" onClick={nextStep}>
- {t`I see Metabase`}
- </Button>
- </Group>
- </Stack>
- );
-};
-
-export const CodeSnippet = ({
- code,
- onCopy,
-}: {
- code: string;
- onCopy?: () => void;
-}) => {
- return (
- <Group
- px="lg"
- py="md"
- bd="1px solid border"
- bg="bg-light"
- w="100%"
- style={{
- borderRadius: 8,
- }}
- >
- <Code flex={1} dangerouslySetInnerHTML={{ __html: highlight(code) }} />
- <CopyButton value={code} onCopy={onCopy} />
- </Group>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/ProcessingStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/ProcessingStep.tsx
deleted file mode 100644
index 70d26e45925..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/ProcessingStep.tsx
+++ /dev/null
@@ -1,142 +0,0 @@
-import { useCallback, useEffect, useState } from "react";
-import { t } from "ttag";
-
-import { useLazyGetXrayDashboardForModelQuery } from "metabase/api/automagic-dashboards";
-import { useCreateCardMutation } from "metabase/api/card";
-import { useSaveDashboardMutation } from "metabase/api/dashboard";
-import { useUpdateSettingsMutation } from "metabase/api/settings";
-import { useSetting } from "metabase/common/hooks";
-import { Box, Loader, Stack, Text, Title } from "metabase/ui";
-import type { Dashboard } from "metabase-types/api";
-
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-
-export const ProcessingStep = () => {
- const siteUrl = useSetting("site-url");
-
- const { goToNextStep } = useEmbeddingSetup();
-
- const [processingStep, setProcessingStep] = useState(0);
- const [error, setError] = useState<string | null>(null);
- const [updateSettings] = useUpdateSettingsMutation();
- const [createCard] = useCreateCardMutation();
- const [saveDashboard] = useSaveDashboardMutation();
- const [getXrayDashboardForModel] = useLazyGetXrayDashboardForModelQuery();
-
- const {
- database,
- selectedTables,
- processingStatus,
- setProcessingStatus,
- setCreatedDashboard,
- } = useEmbeddingSetup();
-
- const setupSettings = useCallback(async () => {
- await updateSettings({
- "embedding-homepage": "visible",
- "enable-embedding-interactive": true,
- "embedding-app-origins-interactive": `localhost:* ${siteUrl}`,
- "session-cookie-samesite": "none",
- });
- }, [updateSettings, siteUrl]);
-
- useEffect(() => {
- const process = async () => {
- const databaseId = database?.id;
- if (!databaseId || !selectedTables?.length) {
- setError("No database or tables selected");
- return;
- }
-
- try {
- setProcessingStatus(t`Setting up settings...`);
- await setupSettings();
- setProcessingStep((prev) => prev + 1);
-
- // Create models for each table
- setProcessingStatus(t`Creating models...`);
-
- const models = await Promise.all(
- selectedTables.map(async (table) => {
- const model = await createCard({
- name: table.display_name,
- type: "model",
- display: "table",
- visualization_settings: {},
- dataset_query: {
- type: "query",
- database: databaseId,
- query: { "source-table": table.id },
- },
- description: `A model created via the embedding setup flow`,
- }).unwrap();
- setProcessingStep((prev) => prev + 1);
- return model;
- }),
- );
-
- // Get the x-ray dashboard content (this doesn't save the dashboard yet)
- setProcessingStatus(t`Creating dashboards...`);
- const dashboardsContent = await Promise.all(
- models.map(async (model) => {
- const dashboardContent = await getXrayDashboardForModel({
- modelId: model.id,
- dashboard_load_id: Date.now(),
- }).unwrap();
- return dashboardContent;
- }),
- );
-
- // Save the dashboards one at the time, to avoid creating multiple "Automatically Generated Dashboards" collections
- const dashboards: Dashboard[] = [];
- for (const dashboard of dashboardsContent) {
- const savedDashboard = await saveDashboard(dashboard).unwrap();
- setProcessingStep((prev) => prev + 1);
- dashboards.push(savedDashboard);
- }
-
- setCreatedDashboard(dashboards);
-
- goToNextStep();
- } catch (err) {
- setError(err instanceof Error ? err.message : "An error occurred");
- }
- };
-
- process();
- }, [
- database?.id,
- selectedTables,
- setProcessingStatus,
- setCreatedDashboard,
- setupSettings,
- goToNextStep,
- createCard,
- saveDashboard,
- getXrayDashboardForModel,
- ]);
-
- if (error) {
- return (
- <Box ta="center" py="xl">
- <Text color="error">{error}</Text>
- </Box>
- );
- }
-
- const totalSteps = selectedTables?.length * 2 + 1 || 0;
- const progress = totalSteps > 0 ? (processingStep / totalSteps) * 100 : 0;
-
- return (
- <Box>
- <Title order={2} mb="lg">{t`Setting Up Your Analytics`}</Title>
- <Stack gap="lg">
- <Box ta="center">
- <Loader size="lg" />
- <Text mt="md">{t`${progress.toFixed(0)}% Complete`}</Text>
- </Box>
- <Text ta="center">{processingStatus}</Text>
- </Stack>
- </Box>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/TableSelectionStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/TableSelectionStep.tsx
deleted file mode 100644
index 2a16d09df14..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/TableSelectionStep.tsx
+++ /dev/null
@@ -1,271 +0,0 @@
-import { useCallback, useEffect, useMemo, useState } from "react";
-import { t } from "ttag";
-import { groupBy } from "underscore";
-
-import { databaseApi } from "metabase/api";
-import { useDispatch } from "metabase/lib/redux";
-import { isSyncInProgress } from "metabase/lib/syncing";
-import {
- Box,
- Button,
- Center,
- Checkbox,
- Group,
- Icon,
- Loader,
- Space,
- Stack,
- type StackProps,
- Text,
- TextInput,
- Title,
-} from "metabase/ui";
-import type { Table } from "metabase-types/api";
-
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-
-export const TableSelectionStep = () => {
- const [tables, setTables] = useState<Table[]>([]);
- const [isLoading, setIsLoading] = useState(false);
- const [error, setError] = useState<string | null>(null);
- const [search, setSearch] = useState("");
- const dispatch = useDispatch();
- const {
- database,
- selectedTables,
- setSelectedTables,
- setProcessingStatus,
- goToNextStep,
- } = useEmbeddingSetup();
-
- const getDatabaseTables = useCallback(async () => {
- const data = await dispatch(
- databaseApi.endpoints.getDatabaseMetadata.initiate(
- {
- id: database!.id!,
- },
- {
- forceRefetch: true,
- },
- ),
- ).unwrap();
- if (!data || !data.tables || data.tables.length === 0) {
- throw new Error("No tables found");
- }
- return data.tables as Table[];
- }, [database, dispatch]);
-
- const fetchTables = useCallback(async () => {
- const tables = await retry({
- fn: getDatabaseTables,
- maxTries: 10,
- retryDelay: 1000,
- onMaxTries: ({ maxTries }) => {
- setError(t`Failed to fetch tables after ${maxTries} attempts`);
- },
- });
- setTables(tables || []);
- }, [getDatabaseTables]);
-
- const waitForDbSync = useCallback(async () => {
- await retry({
- fn: async () => {
- const { data: databases } = await dispatch(
- databaseApi.endpoints.listDatabases.initiate(
- {},
- { forceRefetch: true },
- ),
- ).unwrap();
-
- const userDatabases =
- databases?.filter((database) => !database.is_sample) || [];
-
- if (userDatabases.length === 0) {
- throw new Error("No databases found");
- }
-
- if (userDatabases.some((database) => isSyncInProgress(database))) {
- throw new Error("Databases are syncing");
- }
- },
- maxTries: 60,
- retryDelay: 1000,
- onMaxTries: ({ maxTries }) => {
- setError(t`Failed to sync database after ${maxTries} attempts`);
- },
- });
- }, [dispatch]);
-
- useEffect(() => {
- const fetchData = async () => {
- setIsLoading(true);
- await waitForDbSync();
- await fetchTables();
- setIsLoading(false);
- };
- fetchData();
- }, [fetchTables, waitForDbSync]);
-
- const handleManualRefresh = () => {
- fetchTables();
- setError(null);
- };
-
- const handleTableToggle = (table: Table) => {
- if (selectedTables.some((t) => t.id === table.id)) {
- setSelectedTables(selectedTables.filter((t) => t.id !== table.id));
- } else {
- setSelectedTables([...selectedTables, table]);
- }
- };
-
- const handleSubmit = () => {
- setProcessingStatus("Creating models and dashboards...");
- goToNextStep();
- };
-
- const filteredTables = useMemo(() => {
- return tables.filter((table) => {
- const isSelected = selectedTables.some((t) => t.id === table.id);
- const isSearchMatch = table.name
- .toLowerCase()
- .includes(search.toLowerCase());
- return isSelected || isSearchMatch;
- });
- }, [tables, search, selectedTables]);
-
- const tablesBySchema = useMemo(
- () => groupBy(filteredTables, "schema"),
- [filteredTables],
- );
-
- if (isLoading) {
- return (
- <FullHeightContainer ta="center" py="xl">
- <Center>
- <Loader size="lg" />
- </Center>
- <Stack gap="md" mt="md">
- <Text>{t`Waiting for tables to be available. This may take a few minutes as we wait for the database to sync.`}</Text>
- </Stack>
- </FullHeightContainer>
- );
- }
-
- if (error) {
- return (
- <FullHeightContainer ta="center" py="xl">
- <Text color="error">{error}</Text>
- <Button variant="outline" mt="md" onClick={handleManualRefresh}>
- {t`Try Again`}
- </Button>
- </FullHeightContainer>
- );
- }
-
- const hasResults = filteredTables.length > 0;
-
- return (
- <FullHeightContainer>
- <Title order={2} mb="lg">{t`Select Tables to Embed`}</Title>
- <Text mb="xl">
- {t`Choose the tables that you want to turn into models and dashboards. These will be used to create your initial embedded analytics.`}
- </Text>
-
- <TextInput
- leftSection={<Icon name="search" />}
- placeholder={t`Search tables`}
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- size="md"
- mb="md"
- />
-
- {hasResults ? (
- <>
- <Stack gap="md">
- {Object.entries(tablesBySchema).map(([schema, tables]) => (
- <Box key={schema}>
- <Text fw={600} mb="md">
- {schema.charAt(0).toUpperCase() + schema.slice(1)}
- </Text>
- {tables.map((table) => (
- <Checkbox
- mb="md"
- key={table.id}
- label={table.name}
- checked={selectedTables.some((t) => t.id === table.id)}
- onChange={() => handleTableToggle(table)}
- />
- ))}
- </Box>
- ))}
- </Stack>
-
- <Space flex={1} />
- </>
- ) : (
- <Center flex={1}>
- <Text>{t`No tables found`}</Text>
- </Center>
- )}
-
- <Group justify="end" mt="xl">
- <Button onClick={handleSubmit} disabled={selectedTables.length === 0}>
- {t`Continue`}
- </Button>
- </Group>
- </FullHeightContainer>
- );
-};
-
-export const FullHeightContainer = ({
- children,
- ...props
-}: {
- children: React.ReactNode;
-} & StackProps) => {
- const yPadding = "8rem";
-
- const buffer = "2px";
-
- return (
- <Stack mih={`calc(100vh - ${yPadding} - ${buffer})`} {...props}>
- {children}
- </Stack>
- );
-};
-
-// Simple helper to retry if `fn` throws
-// We can't easily use RTK built in helpers because we need to retry when we don't find the tables
-const retry = async <T,>({
- fn,
- maxTries,
- retryDelay,
- onRetry,
- onMaxTries,
-}: {
- fn: () => Promise<T>;
- maxTries: number;
- retryDelay: number;
- onRetry?: ({
- error,
- retryCount,
- maxTries,
- }: {
- error: any;
- retryCount: number;
- maxTries: number;
- }) => void;
- onMaxTries?: ({ maxTries }: { maxTries: number }) => void;
-}) => {
- for (let i = 0; i < maxTries; i++) {
- try {
- return await fn();
- } catch (error) {
- onRetry?.({ error, retryCount: i, maxTries });
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
- }
- }
- onMaxTries?.({ maxTries });
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/UserCreationStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/UserCreationStep.tsx
deleted file mode 100644
index b013e5b7a5c..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/UserCreationStep.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { t } from "ttag";
-
-import { useUpdateSettingsMutation } from "metabase/api";
-import { useDispatch, useSelector } from "metabase/lib/redux";
-import { loadCurrentUser } from "metabase/redux/user";
-import { Box, Text, Title } from "metabase/ui";
-import type { UserInfo } from "metabase-types/store";
-
-import { submitUser } from "../../../actions";
-import { getIsHosted, getUser } from "../../../selectors";
-import { UserForm } from "../../UserForm";
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-
-export const UserCreationStep = () => {
- const { goToNextStep } = useEmbeddingSetup();
-
- const user = useSelector(getUser);
- const isHosted = useSelector(getIsHosted);
- const dispatch = useDispatch();
- const [updateSettings] = useUpdateSettingsMutation();
-
- const handleSubmit = async (user: UserInfo) => {
- await dispatch(submitUser(user)).unwrap();
- await dispatch(loadCurrentUser());
-
- // We want to set the embedding homepage visible if the user skips the rest of the flow.
- // This is the first place where we can do this, as we need the initial setup to be done.
- await updateSettings({ "embedding-homepage": "visible" });
- goToNextStep();
- };
-
- return (
- <Box>
- <Title order={2} mb="md">{t`What should we call you?`}</Title>
- <Text>{t`We know you’ve already created one of these.`}</Text>
- <Text>
- {t`We like to keep billing and product accounts separate so that you don’t have to share logins.`}
- </Text>
- <UserForm user={user} isHosted={isHosted} onSubmit={handleSubmit} />
- </Box>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/WelcomeStep.tsx b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/WelcomeStep.tsx
deleted file mode 100644
index 237e69d05f7..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/WelcomeStep.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import { Link } from "react-router";
-import { t } from "ttag";
-
-import { Box, Button, Space, Text, Title } from "metabase/ui";
-
-import { useEmbeddingSetup } from "../EmbeddingSetupContext";
-import type { StepProps } from "../steps/embeddingSetupSteps";
-
-export const WelcomeStep = ({ nextStep }: StepProps) => {
- const { trackEmbeddingSetupClick } = useEmbeddingSetup();
- return (
- <Box p="xl" style={{ borderRadius: 16 }} bg="white">
- <Title order={2} mb="lg">
- {t`Welcome to Metabase`}
- </Title>
-
- <Text size="lg" mb="md">
- {t`Let's get you up and running with a starting setup for embedded analytics. You'll get to add working starter content to your app based on your real data. This will give you a solid base to customize and keep building off of on your way to production.`}
- </Text>
-
- <Space h="xl" />
-
- <Title order={5} mb="xs">{t`Requirements:`}</Title>
- <Text size="lg">
- {t`Access to your app or a sample app you want to use to experiment.`}
- </Text>
-
- <Space h="xl" />
-
- <Button onClick={nextStep} variant="filled" mb="md" miw={"12rem"}>
- {t`Start`}
- </Button>
-
- <Space h="lg" />
-
- <Text color="text-secondary">
- <Link
- to="/"
- onClick={async () => {
- trackEmbeddingSetupClick("setup-up-manually");
- }}
- >{t`Set up manually`}</Link>
- </Text>
- </Box>
- );
-};
diff --git a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/embeddingSetupSteps.ts b/frontend/src/metabase/setup/components/EmbeddingSetup/steps/embeddingSetupSteps.ts
deleted file mode 100644
index 18cefe23598..00000000000
--- a/frontend/src/metabase/setup/components/EmbeddingSetup/steps/embeddingSetupSteps.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import { t } from "ttag";
-
-import type { IconName } from "metabase/ui";
-
-export interface StepDefinition {
- key: string;
- title: string;
- icon: IconName;
- visibleInSidebar: boolean;
-}
-
-export interface StepProps {
- nextStep: () => void;
- goToStep: (key: EmbeddingSetupStepKey) => void;
- stepKey: EmbeddingSetupStepKey; // Be aware that this is sent in the `embedding_setup_step_seen` simple event
- stepIndex: number;
- totalSteps: number;
-}
-
-export const STEPS = [
- {
- key: "welcome",
- get title() {
- return t`Welcome`;
- },
- icon: "home",
- visibleInSidebar: false,
- },
- {
- key: "user-creation",
- get title() {
- return t`Set up your account`;
- },
- icon: "person",
- visibleInSidebar: true,
- },
- {
- key: "data-connection",
- get title() {
- return t`Connect to your data`;
- },
- icon: "database",
- visibleInSidebar: true,
- },
- {
- key: "table-selection",
- get title() {
- return t`Generate starter content`;
- },
- icon: "bolt_filled",
- visibleInSidebar: true,
- },
- {
- key: "processing",
- get title() {
- return t`Processing`;
- },
- icon: "gear",
- visibleInSidebar: false,
- },
- {
- key: "add-to-your-app",
- get title() {
- return t`Add to your app`;
- },
- icon: "check",
- visibleInSidebar: true,
- },
- {
- key: "done",
- get title() {
- return t`Done`;
- },
- icon: "check",
- visibleInSidebar: false,
- },
-] as const satisfies StepDefinition[];
-
-export type EmbeddingSetupStepKey = (typeof STEPS)[number]["key"];
-
-export const getStepIndexByKey = (key: string): number => {
- const index = STEPS.findIndex((step) => step.key === key);
- return index === -1 ? 0 : index;
-};