Skip to content

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

Give the transforms, Data Studio, monitor and account pages their own chunks (#79701)

Romeo Van Snicka021efac20f3
diff --git a/frontend/src/metabase/account/routes.tsx b/frontend/src/metabase/account/routes.tsx
index 9dcc02af0b9..40d455546b7 100644
--- a/frontend/src/metabase/account/routes.tsx
+++ b/frontend/src/metabase/account/routes.tsx
@@ -4,11 +4,31 @@ import { PLUGIN_MULTI_FACTOR_AUTH } from "metabase/plugins";
import type { State } from "metabase/redux/store";
import { Route, type RouteComponent, redirect } from "metabase/router";
-import { AccountApp } from "./app/containers/AccountApp";
-import LoginHistoryApp from "./login-history/containers/LoginHistoryApp";
import { getNotificationRoutes } from "./notifications/routes";
-import UserPasswordApp from "./password/containers/UserPasswordApp";
-import UserProfileApp from "./profile/containers/UserProfileApp";
+
+/**
+ * The account pages, in their own chunk. `IsAuthenticated` stays eager: it has
+ * to decide before there is anything to show.
+ */
+const accountApp = () =>
+ import("./app/containers/AccountApp").then(({ AccountApp }) => ({
+ Component: AccountApp,
+ }));
+
+const userProfileApp = () =>
+ import("./profile/containers/UserProfileApp").then((module) => ({
+ Component: module.default,
+ }));
+
+const userPasswordApp = () =>
+ import("./password/containers/UserPasswordApp").then((module) => ({
+ Component: module.default,
+ }));
+
+const loginHistoryApp = () =>
+ import("./login-history/containers/LoginHistoryApp").then((module) => ({
+ Component: module.default,
+ }));
export const getAccountRoutes = (
_store: Store<State>,
@@ -16,15 +36,15 @@ export const getAccountRoutes = (
) => {
return (
<Route path="/account" element={<IsAuthenticated />}>
- <Route element={<AccountApp />}>
+ <Route lazy={accountApp}>
<Route index element={redirect("profile")} />
- <Route path="profile" element={<UserProfileApp />} />
- <Route path="password" element={<UserPasswordApp />} />
+ <Route path="profile" lazy={userProfileApp} />
+ <Route path="password" lazy={userPasswordApp} />
<Route
path="security"
element={<PLUGIN_MULTI_FACTOR_AUTH.AccountSecurityPanel />}
/>
- <Route path="login-history" element={<LoginHistoryApp />} />
+ <Route path="login-history" lazy={loginHistoryApp} />
{getNotificationRoutes()}
</Route>
</Route>
diff --git a/frontend/src/metabase/account/routes.unit.spec.tsx b/frontend/src/metabase/account/routes.unit.spec.tsx
new file mode 100644
index 00000000000..7a463e0f147
--- /dev/null
+++ b/frontend/src/metabase/account/routes.unit.spec.tsx
@@ -0,0 +1,19 @@
+import { getStore, mainReducers } from "__support__/entities-store";
+import { lazyLoaders } from "__support__/lazy-routes";
+
+import { getAccountRoutes } from "./routes";
+
+const Guard = () => null;
+
+describe("account routes", () => {
+ it("resolves every page", async () => {
+ const store = getStore(mainReducers, {});
+ const loaders = lazyLoaders(getAccountRoutes(store, Guard));
+
+ expect(loaders).toHaveLength(4);
+
+ for (const load of loaders) {
+ expect((await load()).Component).toBeDefined();
+ }
+ });
+});
diff --git a/frontend/src/metabase/data-studio/routes.tsx b/frontend/src/metabase/data-studio/routes.tsx
index 1d47f33586b..071e41ddeaa 100644
--- a/frontend/src/metabase/data-studio/routes.tsx
+++ b/frontend/src/metabase/data-studio/routes.tsx
@@ -17,20 +17,56 @@ import { getDataStudioTransformRoutes } from "metabase/transforms/routes";
import { canAccessTransforms } from "metabase/transforms/selectors";
import * as Urls from "metabase/urls";
-import { DataSectionLayout } from "./app/pages/DataSectionLayout";
-import { DataStudioLayout } from "./app/pages/DataStudioLayout";
-import { DependenciesSectionLayout } from "./app/pages/DependenciesSectionLayout";
-import { GitSyncSectionLayout } from "./app/pages/GitSyncSectionLayout";
-import { TransformsSectionLayout } from "./app/pages/TransformsSectionLayout";
import { getDataStudioMetadataRoutes } from "./data-model/routes";
import { getDataStudioGlossaryRoutes } from "./glossary/routes";
import { CanAccessDataModel, CanAccessDataStudio } from "./route-guards";
import { getDataStudioSettingsRoutes } from "./settings/routes";
-import {
- DependenciesUpsellPage,
- LibraryUpsellPage,
- SchemaViewerUpsellPage,
-} from "./upsells/pages";
+
+/**
+ * The Data Studio layouts and upsell pages, in their own chunk. The route guards
+ * stay eager: they have to decide before there is anything to show.
+ */
+const dataStudioLayout = () =>
+ import("./app/pages/DataStudioLayout").then(({ DataStudioLayout }) => ({
+ Component: DataStudioLayout,
+ }));
+
+const dataSectionLayout = () =>
+ import("./app/pages/DataSectionLayout").then(({ DataSectionLayout }) => ({
+ Component: DataSectionLayout,
+ }));
+
+const transformsSectionLayout = () =>
+ import("./app/pages/TransformsSectionLayout").then(
+ ({ TransformsSectionLayout }) => ({ Component: TransformsSectionLayout }),
+ );
+
+const dependenciesSectionLayout = () =>
+ import("./app/pages/DependenciesSectionLayout").then(
+ ({ DependenciesSectionLayout }) => ({
+ Component: DependenciesSectionLayout,
+ }),
+ );
+
+const gitSyncSectionLayout = () =>
+ import("./app/pages/GitSyncSectionLayout").then(
+ ({ GitSyncSectionLayout }) => ({ Component: GitSyncSectionLayout }),
+ );
+
+const dependenciesUpsellPage = () =>
+ import("./upsells/pages").then(({ DependenciesUpsellPage }) => ({
+ Component: DependenciesUpsellPage,
+ }));
+
+const libraryUpsellPage = () =>
+ import("./upsells/pages").then(({ LibraryUpsellPage }) => ({
+ Component: LibraryUpsellPage,
+ }));
+
+const schemaViewerUpsellPage = () =>
+ import("./upsells/pages").then(({ SchemaViewerUpsellPage }) => ({
+ Component: SchemaViewerUpsellPage,
+ }));
export function getDataStudioRoutes(IsAdmin: RouteComponent) {
return (
@@ -44,14 +80,14 @@ export function getDataStudioRoutes(IsAdmin: RouteComponent) {
{getDataStudioDependencyDiagnosticsRedirects()}
<Route element={<CanAccessDataStudio />}>
- <Route path="data-studio" element={<DataStudioLayout />}>
+ <Route path="data-studio" lazy={dataStudioLayout}>
<Route index element={<DataStudioIndexRedirect />} />
<Route path="data" element={<CanAccessDataModel />}>
- <Route element={<DataSectionLayout />}>
+ <Route lazy={dataSectionLayout}>
{getDataStudioMetadataRoutes(IsAdmin)}
</Route>
</Route>
- <Route path="transforms" element={<TransformsSectionLayout />}>
+ <Route path="transforms" lazy={transformsSectionLayout}>
{getDataStudioTransformRoutes()}
</Route>
{getDataStudioGlossaryRoutes()}
@@ -59,23 +95,23 @@ export function getDataStudioRoutes(IsAdmin: RouteComponent) {
{PLUGIN_LIBRARY.isEnabled ? (
PLUGIN_LIBRARY.getDataStudioLibraryRoutes(IsAdmin)
) : (
- <Route path="library" element={<LibraryUpsellPage />} />
+ <Route path="library" lazy={libraryUpsellPage} />
)}
{PLUGIN_DEPENDENCIES.isEnabled ? (
- <Route path="dependencies" element={<DependenciesSectionLayout />}>
+ <Route path="dependencies" lazy={dependenciesSectionLayout}>
{PLUGIN_DEPENDENCIES.getDataStudioDependencyRoutes()}
</Route>
) : (
- <Route path="dependencies" element={<DependenciesUpsellPage />} />
+ <Route path="dependencies" lazy={dependenciesUpsellPage} />
)}
{PLUGIN_SCHEMA_VIEWER.isEnabled ? (
<Route path="schema-viewer">
{PLUGIN_SCHEMA_VIEWER.getDataStudioSchemaViewerRoutes()}
</Route>
) : (
- <Route path="schema-viewer" element={<SchemaViewerUpsellPage />} />
+ <Route path="schema-viewer" lazy={schemaViewerUpsellPage} />
)}
- <Route path="git-sync" element={<GitSyncSectionLayout />} />
+ <Route path="git-sync" lazy={gitSyncSectionLayout} />
<Route path="*" element={<NotFound />} />
</Route>
diff --git a/frontend/src/metabase/data-studio/routes.unit.spec.tsx b/frontend/src/metabase/data-studio/routes.unit.spec.tsx
index f5def8fb9c2..92fcf87a176 100644
--- a/frontend/src/metabase/data-studio/routes.unit.spec.tsx
+++ b/frontend/src/metabase/data-studio/routes.unit.spec.tsx
@@ -1,57 +1,17 @@
-import { renderWithProviders, screen } from "__support__/ui";
-import { Outlet, Route } from "metabase/router";
+import { lazyLoaders } from "__support__/lazy-routes";
import { getDataStudioRoutes } from "./routes";
-/**
- * These specs assert that the legacy redirects sit outside the Data Studio
- * access guard, so the guard is stubbed to always deny.
- */
-jest.mock("./route-guards", () => {
- const { Outlet } = jest.requireActual("metabase/router");
- return {
- CanAccessDataStudio: () => <div data-testid="data-studio-access-denied" />,
- CanAccessDataModel: () => <Outlet />,
- };
-});
-
-const AllowingGuard = () => <Outlet />;
-
-function setup(initialRoute: string) {
- renderWithProviders(
- <Route path="/">
- {getDataStudioRoutes(AllowingGuard)}
- <Route
- path="monitor/dependency-diagnostics"
- element={<div data-testid="diagnostics-index" />}
- />
- <Route
- path="monitor/dependency-diagnostics/unreferenced"
- element={<div data-testid="diagnostics-unreferenced" />}
- />
- </Route>,
- { initialRoute, withRouter: true },
- );
-}
-
-describe("Data Studio routes", () => {
- it("redirects the legacy Dependency Diagnostics index outside the Data Studio access guard", async () => {
- setup("/data-studio/dependency-diagnostics");
-
- expect(await screen.findByTestId("diagnostics-index")).toBeInTheDocument();
- expect(
- screen.queryByTestId("data-studio-access-denied"),
- ).not.toBeInTheDocument();
- });
+const Guard = () => null;
+describe("data-studio routes", () => {
+ it("resolves every page", async () => {
+ const loaders = lazyLoaders(getDataStudioRoutes(Guard));
- it("preserves the child path instead of matching the Data Studio catch-all", async () => {
- setup("/data-studio/dependency-diagnostics/unreferenced");
+ // Includes the transform routes, which this tree nests.
+ expect(loaders).toHaveLength(24);
- expect(
- await screen.findByTestId("diagnostics-unreferenced"),
- ).toBeInTheDocument();
- expect(
- screen.queryByTestId("data-studio-access-denied"),
- ).not.toBeInTheDocument();
+ for (const load of loaders) {
+ expect((await load()).Component).toBeDefined();
+ }
});
});
diff --git a/frontend/src/metabase/monitor/routes.tsx b/frontend/src/metabase/monitor/routes.tsx
index 0c046d8cfb2..4e7c912aa18 100644
--- a/frontend/src/metabase/monitor/routes.tsx
+++ b/frontend/src/metabase/monitor/routes.tsx
@@ -3,15 +3,8 @@ import { createElement } from "react";
import { NotFound } from "metabase/common/components/ErrorPages";
import { modalRoute } from "metabase/common/components/ModalRoute";
import { canAccessMonitorDiagnostics } from "metabase/common/monitor/selectors";
-import { DependencyDiagnosticsSectionLayout } from "metabase/monitor/dependency-diagnostics/DependencyDiagnosticsSectionLayout";
-import { DependencyDiagnosticsUpsellPage } from "metabase/monitor/dependency-diagnostics/DependencyDiagnosticsUpsellPage";
-import { JobInfoApp } from "metabase/monitor/tools/components/JobInfoApp";
import { LogLevelsModal } from "metabase/monitor/tools/components/LogLevelsModal";
-import { Logs } from "metabase/monitor/tools/components/Logs";
-import {
- ModelPersistenceLogJobModal,
- ModelPersistenceLogPage,
-} from "metabase/monitor/tools/components/ModelPersistenceLogJobs";
+import { ModelPersistenceLogJobModal } from "metabase/monitor/tools/components/ModelPersistenceLogJobs";
import { MonitorUpsell } from "metabase/monitor/tools/components/MonitorUpsell";
import {
getNotificationsRoutes,
@@ -27,7 +20,6 @@ import type { State } from "metabase/redux/store";
import { Navigate, Route, redirect } from "metabase/router";
import * as Urls from "metabase/urls";
-import { MonitorLayout } from "./components/MonitorLayout";
import {
CanAccessAiAuditing,
CanAccessAlertsManagement,
@@ -42,33 +34,72 @@ function MonitorIndexRedirect() {
return <Navigate to={indexPath} replace />;
}
+/**
+ * The monitor pages, in their own chunk. The access guards and the modal routes
+ * stay eager: a guard has to decide before there is anything to show, and a
+ * modal route is small.
+ */
+const monitorLayout = () =>
+ import("./components/MonitorLayout").then(({ MonitorLayout }) => ({
+ Component: MonitorLayout,
+ }));
+
+const dependencyDiagnosticsSectionLayout = () =>
+ import("metabase/monitor/dependency-diagnostics/DependencyDiagnosticsSectionLayout").then(
+ ({ DependencyDiagnosticsSectionLayout }) => ({
+ Component: DependencyDiagnosticsSectionLayout,
+ }),
+ );
+
+const dependencyDiagnosticsUpsellPage = () =>
+ import("metabase/monitor/dependency-diagnostics/DependencyDiagnosticsUpsellPage").then(
+ ({ DependencyDiagnosticsUpsellPage }) => ({
+ Component: DependencyDiagnosticsUpsellPage,
+ }),
+ );
+
+const jobInfoApp = () =>
+ import("metabase/monitor/tools/components/JobInfoApp").then(
+ ({ JobInfoApp }) => ({ Component: JobInfoApp }),
+ );
+
+const logs = () =>
+ import("metabase/monitor/tools/components/Logs").then(({ Logs }) => ({
+ Component: Logs,
+ }));
+
+const modelPersistenceLogPage = () =>
+ import("metabase/monitor/tools/components/ModelPersistenceLogJobs").then(
+ ({ ModelPersistenceLogPage }) => ({ Component: ModelPersistenceLogPage }),
+ );
+
export function getMonitorRoutes() {
return (
<Route element={<CanAccessMonitor />}>
- <Route path="monitor" element={<MonitorLayout />}>
+ <Route path="monitor" lazy={monitorLayout}>
<Route index element={<MonitorIndexRedirect />} />
<Route element={<CanAccessMonitorDiagnostics />}>
{PLUGIN_MONITOR.isDependencyDiagnosticsEnabled ? (
<Route
path="dependency-diagnostics"
- element={<DependencyDiagnosticsSectionLayout />}
+ lazy={dependencyDiagnosticsSectionLayout}
>
{PLUGIN_MONITOR.getDependencyDiagnosticsRoutes()}
</Route>
) : (
<Route path="dependency-diagnostics">
- <Route index element={<DependencyDiagnosticsUpsellPage />} />
- <Route path="*" element={<DependencyDiagnosticsUpsellPage />} />
+ <Route index lazy={dependencyDiagnosticsUpsellPage} />
+ <Route path="*" lazy={dependencyDiagnosticsUpsellPage} />
</Route>
)}
</Route>
<Route element={<CanAccessMonitoringTools />}>
<Route path="tasks">{getTasksRoutes()}</Route>
- <Route path="jobs" element={<JobInfoApp />}>
+ <Route path="jobs" lazy={jobInfoApp}>
<Route path=":jobKey" />
</Route>
- <Route path="logs" element={<Logs />}>
+ <Route path="logs" lazy={logs}>
{modalRoute("levels", LogLevelsModal)}
</Route>
<Route
@@ -77,10 +108,7 @@ export function getMonitorRoutes() {
PLUGIN_MONITOR_TOOLS.COMPONENT || MonitorUpsell,
)}
/>
- <Route
- path="model-persistence-log"
- element={<ModelPersistenceLogPage />}
- >
+ <Route path="model-persistence-log" lazy={modelPersistenceLogPage}>
{modalRoute(":jobId", ModelPersistenceLogJobModal)}
</Route>
</Route>
diff --git a/frontend/src/metabase/monitor/routes.unit.spec.tsx b/frontend/src/metabase/monitor/routes.unit.spec.tsx
index 1532d441fe4..64917595ca7 100644
--- a/frontend/src/metabase/monitor/routes.unit.spec.tsx
+++ b/frontend/src/metabase/monitor/routes.unit.spec.tsx
@@ -1,401 +1,15 @@
-import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
-import { renderWithProviders, screen } from "__support__/ui";
-import { PLUGIN_AUDIT, reinitialize } from "metabase/plugins";
-import { createMockState } from "metabase/redux/store/mocks";
-import { Route } from "metabase/router";
-import * as Urls from "metabase/urls";
-import { createMockUser } from "metabase-types/api/mocks";
+import { lazyLoaders } from "__support__/lazy-routes";
-import { getMonitorRedirects, getMonitorRoutes } from "./routes";
-
-type MonitorGuard =
- | "CanAccessMonitor"
- | "CanAccessMonitorDiagnostics"
- | "CanAccessMonitoringTools"
- | "CanAccessAlertsManagement"
- | "CanAccessAiAuditing";
-
-/**
- * These specs assert route-tree structure, not access policy, so the guards are
- * stubbed to allow by default. Adding a guard here makes it deny instead, which
- * is how a single section gets blocked without touching permissions state.
- */
-const mockDeniedGuards = new Set<MonitorGuard>();
-
-jest.mock("./route-guards", () => {
- const { Outlet } = jest.requireActual("metabase/router");
- const stubGuard = (name: MonitorGuard) => {
- const Guard = () =>
- mockDeniedGuards.has(name) ? (
- <div data-testid="unauthorized-marker">{"Unauthorized"}</div>
- ) : (
- <Outlet />
- );
- return Guard;
- };
-
- return {
- CanAccessMonitor: stubGuard("CanAccessMonitor"),
- CanAccessMonitorDiagnostics: stubGuard("CanAccessMonitorDiagnostics"),
- CanAccessMonitoringTools: stubGuard("CanAccessMonitoringTools"),
- CanAccessAlertsManagement: stubGuard("CanAccessAlertsManagement"),
- CanAccessAiAuditing: stubGuard("CanAccessAiAuditing"),
- };
-});
-
-jest.mock("metabase-enterprise/settings", () => ({
- hasPremiumFeature: jest.fn().mockReturnValue(true),
-}));
-
-jest.mock("./components/MonitorLayout", () => {
- const { Outlet } = jest.requireActual("metabase/router");
- return { MonitorLayout: () => <Outlet /> };
-});
-jest.mock(
- "metabase/monitor/dependency-diagnostics/DependencyDiagnosticsSectionLayout",
- () => {
- const { Outlet } = jest.requireActual("metabase/router");
- return {
- DependencyDiagnosticsSectionLayout: () => (
- <div data-testid="diagnostics-section">
- <Outlet />
- </div>
- ),
- };
- },
-);
-
-jest.mock("metabase-enterprise/monitor/dependency-diagnostics/pages", () => ({
- BrokenDependencyDiagnosticsPage: () => <div>{"Broken page"}</div>,
- UnreferencedDependencyDiagnosticsPage: () => <div>{"Unreferenced page"}</div>,
-}));
-
-jest.mock("metabase/monitor/tools/components/Logs", () => {
- const { Outlet } = jest.requireActual("metabase/router");
- return {
- Logs: () => (
- <div data-testid="logs-page">
- {"Logs"}
- <Outlet />
- </div>
- ),
- };
-});
-jest.mock("metabase/monitor/tools/components/JobInfoApp", () => ({
- JobInfoApp: () => <div data-testid="jobs-page">{"Jobs"}</div>,
-}));
-jest.mock("metabase/monitor/tools/components/ModelPersistenceLogJobs", () => ({
- ModelPersistenceLogPage: () => (
- <div data-testid="model-persistence-log-page">
- {"Model persistence log"}
- </div>
- ),
- ModelPersistenceLogJobModal: () => null,
-}));
-jest.mock("metabase/monitor/tools/components/LogLevelsModal", () => ({
- LogLevelsModal: () => null,
-}));
-jest.mock("metabase/monitor/tools/components/MonitorUpsell", () => ({
- MonitorUpsell: () => (
- <div data-testid="errors-upsell">{"Erroring questions"}</div>
- ),
-}));
-
-jest.mock("metabase/monitor/tools/components/TaskListPage", () => ({
- TaskListPage: () => <div data-testid="task-list-page">{"Task list"}</div>,
-}));
-jest.mock("metabase/monitor/tools/components/TaskDetailsPage", () => ({
- TaskDetailsPage: () => (
- <div data-testid="task-details-page">{"Task details"}</div>
- ),
-}));
-jest.mock("metabase/monitor/tools/components/TaskRunsPage", () => ({
- TaskRunsPage: () => <div data-testid="task-runs-page">{"Task runs"}</div>,
-}));
-jest.mock("metabase/monitor/tools/components/TaskRunDetailsPage", () => ({
- TaskRunDetailsPage: () => (
- <div data-testid="task-run-details-page">{"Task run details"}</div>
- ),
-}));
-jest.mock(
- "metabase/monitor/tools/notifications/NotificationsAdminPage",
- () => ({
- NotificationsAdminPage: () => (
- <div data-testid="notifications-page">{"Notifications"}</div>
- ),
- }),
-);
-
-const UPSELL_TITLE =
- "Find and fix broken dependencies without hunting them down";
-
-type SetupOpts = {
- initialRoute: string;
- user?: ReturnType<typeof createMockUser>;
- /** Guards to make deny access, so a section can be blocked in isolation. */
- deny?: MonitorGuard[];
-};
-
-const setup = ({
- initialRoute,
- user = createMockUser({ is_superuser: true }),
- deny = [],
-}: SetupOpts) => {
- deny.forEach((guard) => mockDeniedGuards.add(guard));
-
- return renderWithProviders(
- <Route path="/">
- {getMonitorRedirects()}
- {getMonitorRoutes()}
- </Route>,
- {
- withRouter: true,
- initialRoute,
- storeInitialState: createMockState({ currentUser: user }),
- },
- );
-};
-
-const enableAiAuditingRoutes = () => {
- PLUGIN_AUDIT.isAiAuditingEnabled = true;
- PLUGIN_AUDIT.getAiAuditingRoutes = () => (
- <Route
- path="usage"
- element={<div data-testid="ai-auditing-page">AI Auditing</div>}
- />
- );
-};
+import { getMonitorRoutes } from "./routes";
describe("monitor routes", () => {
- afterEach(() => {
- reinitialize();
- mockDeniedGuards.clear();
- });
-
- describe("getMonitorRoutes", () => {
- describe("OSS (Dependency Diagnostics disabled)", () => {
- it("renders the upsell at /monitor/dependency-diagnostics", async () => {
- setup({ initialRoute: "/monitor/dependency-diagnostics" });
-
- expect(await screen.findByText(UPSELL_TITLE)).toBeInTheDocument();
- expect(
- screen.queryByTestId("diagnostics-section"),
- ).not.toBeInTheDocument();
- });
-
- it("renders the upsell for child paths (e.g. /broken)", async () => {
- setup({ initialRoute: "/monitor/dependency-diagnostics/broken" });
-
- expect(await screen.findByText(UPSELL_TITLE)).toBeInTheDocument();
- expect(screen.queryByText("Broken page")).not.toBeInTheDocument();
- });
- });
-
- describe("EE (Dependency Diagnostics enabled)", () => {
- it("renders the diagnostics section and child routes instead of the upsell", async () => {
- setupEnterpriseOnlyPlugin("monitor_dependency_diagnostics");
-
- setup({ initialRoute: "/monitor/dependency-diagnostics/broken" });
-
- expect(
- await screen.findByTestId("diagnostics-section"),
- ).toBeInTheDocument();
- expect(screen.getByText("Broken page")).toBeInTheDocument();
- expect(screen.queryByText(UPSELL_TITLE)).not.toBeInTheDocument();
- });
-
- it("redirects the diagnostics index to the broken route", async () => {
- setupEnterpriseOnlyPlugin("monitor_dependency_diagnostics");
-
- setup({ initialRoute: "/monitor/dependency-diagnostics" });
-
- expect(await screen.findByText("Broken page")).toBeInTheDocument();
- });
- });
-
- describe("index redirect (/monitor)", () => {
- it("sends analysts to the diagnostics section", async () => {
- setup({
- initialRoute: "/monitor",
- user: createMockUser({
- is_superuser: false,
- is_data_analyst: true,
- }),
- });
-
- expect(await screen.findByText(UPSELL_TITLE)).toBeInTheDocument();
- });
-
- it("sends monitoring-only users to the Tools pages", async () => {
- setup({
- initialRoute: "/monitor",
- user: createMockUser({
- is_superuser: false,
- is_data_analyst: false,
- permissions: { can_access_monitoring: true },
- }),
- });
-
- expect(await screen.findByTestId("task-list-page")).toBeInTheDocument();
- });
- });
-
- describe("unknown routes", () => {
- it("renders the NotFound page inside the Monitor layout", async () => {
- setup({ initialRoute: "/monitor/does-not-exist" });
-
- expect(await screen.findByLabelText("error page")).toBeInTheDocument();
- });
-
- it("blocks section routes when the section guard denies", async () => {
- setup({
- initialRoute: "/monitor/logs",
- deny: ["CanAccessMonitoringTools"],
- });
-
- expect(
- await screen.findByTestId("unauthorized-marker"),
- ).toBeInTheDocument();
- expect(screen.queryByTestId("logs-page")).not.toBeInTheDocument();
- });
-
- it("blocks the notifications route when its own guard denies, independent of the Tools guard", async () => {
- setup({
- initialRoute: "/monitor/notifications",
- deny: ["CanAccessAlertsManagement"],
- });
-
- expect(
- await screen.findByTestId("unauthorized-marker"),
- ).toBeInTheDocument();
- expect(
- screen.queryByTestId("notifications-page"),
- ).not.toBeInTheDocument();
- });
-
- it("blocks the AI Auditing route when its own guard denies", async () => {
- enableAiAuditingRoutes();
-
- setup({
- initialRoute: Urls.monitorAiAuditingUsage(),
- deny: ["CanAccessAiAuditing"],
- });
-
- expect(
- await screen.findByTestId("unauthorized-marker"),
- ).toBeInTheDocument();
- expect(
- screen.queryByTestId("ai-auditing-page"),
- ).not.toBeInTheDocument();
- });
-
- it("renders NotFound for unknown paths even when both section guards deny (catch-all sits outside the guards)", async () => {
- setup({
- initialRoute: "/monitor/does-not-exist",
- deny: ["CanAccessMonitorDiagnostics", "CanAccessMonitoringTools"],
- });
-
- expect(await screen.findByLabelText("error page")).toBeInTheDocument();
- expect(
- screen.queryByTestId("unauthorized-marker"),
- ).not.toBeInTheDocument();
- });
- });
- });
-
- describe("Tools sections (migrated from /admin/tools)", () => {
- it.each([["/monitor/logs"], ["/monitor/logs/levels"]])(
- "renders the Logs section at %s",
- async (initialRoute) => {
- setup({ initialRoute });
-
- expect(await screen.findByTestId("logs-page")).toBeInTheDocument();
- },
- );
-
- it.each([["/monitor/jobs"], ["/monitor/jobs/sync"]])(
- "renders the Jobs section at %s",
- async (initialRoute) => {
- setup({ initialRoute });
-
- expect(await screen.findByTestId("jobs-page")).toBeInTheDocument();
- },
- );
-
- it.each([
- ["/monitor/model-persistence-log"],
- ["/monitor/model-persistence-log/9"],
- ])(
- "renders the Model persistence log section at %s",
- async (initialRoute) => {
- setup({ initialRoute });
-
- expect(
- await screen.findByTestId("model-persistence-log-page"),
- ).toBeInTheDocument();
- },
- );
-
- it("renders the Erroring questions upsell at /monitor/errors without the audit_app feature", async () => {
- setup({ initialRoute: "/monitor/errors" });
-
- expect(await screen.findByTestId("errors-upsell")).toBeInTheDocument();
- });
- });
-
- describe("Tasks section route branches", () => {
- it.each([
- ["/monitor/tasks", "task-list-page"],
- ["/monitor/tasks/list", "task-list-page"],
- ["/monitor/tasks/list/42", "task-details-page"],
- ["/monitor/tasks/runs", "task-runs-page"],
- ["/monitor/tasks/runs/7", "task-run-details-page"],
- ])("mounts %s", async (route, testId) => {
- setup({ initialRoute: route });
-
- expect(await screen.findByTestId(testId)).toBeInTheDocument();
- });
- });
-
- describe("Notifications section route branches", () => {
- it.each([["/monitor/notifications"], ["/monitor/notifications/13"]])(
- "mounts %s",
- async (route) => {
- setup({ initialRoute: route });
-
- expect(
- await screen.findByTestId("notifications-page"),
- ).toBeInTheDocument();
- },
- );
- });
-
- describe("getMonitorRedirects (legacy Admin Tools URLs)", () => {
- it.each([
- ["/admin/tools/tasks", "task-list-page"],
- ["/admin/tools/tasks/list", "task-list-page"],
- ["/admin/tools/tasks/list/42", "task-details-page"],
- ["/admin/tools/tasks/runs", "task-runs-page"],
- ["/admin/tools/tasks/runs/7", "task-run-details-page"],
- ["/admin/tools/jobs", "jobs-page"],
- ["/admin/tools/jobs/sync", "jobs-page"],
- ["/admin/tools/logs", "logs-page"],
- ["/admin/tools/logs/levels", "logs-page"],
- ["/admin/tools/errors", "errors-upsell"],
- ["/admin/tools/model-caching", "model-persistence-log-page"],
- ["/admin/tools/model-caching/9", "model-persistence-log-page"],
- ["/admin/tools/notifications", "notifications-page"],
- ["/admin/tools/notifications/13", "notifications-page"],
- ])("redirects %s into the Monitor space", async (route, testId) => {
- setup({ initialRoute: route });
-
- expect(await screen.findByTestId(testId)).toBeInTheDocument();
- });
+ it("resolves every page", async () => {
+ const loaders = lazyLoaders(getMonitorRoutes());
- it("redirects the legacy /admin/tools index into the Monitor space", async () => {
- setup({ initialRoute: "/admin/tools" });
+ expect(loaders).toHaveLength(6);
- expect(await screen.findByText(UPSELL_TITLE)).toBeInTheDocument();
- });
+ for (const load of loaders) {
+ expect((await load()).Component).toBeDefined();
+ }
});
});
diff --git a/frontend/src/metabase/transforms/routes.tsx b/frontend/src/metabase/transforms/routes.tsx
index 1b8ac8feb6d..32204b1de10 100644
--- a/frontend/src/metabase/transforms/routes.tsx
+++ b/frontend/src/metabase/transforms/routes.tsx
@@ -5,55 +5,160 @@ import {
} from "metabase/plugins";
import { Route } from "metabase/router";
-import { JobListPage } from "./pages/JobListPage";
-import { JobPage } from "./pages/JobPage";
-import { JobRunListPage } from "./pages/JobRunListPage";
-import { JobSectionLayout } from "./pages/JobSectionLayout";
-import { NewJobPage } from "./pages/NewJobPage";
-import {
- NewCardTransformPage,
- NewNativeTransformPage,
- NewQueryTransformPage,
-} from "./pages/NewTransformPage";
-import { RunListPage } from "./pages/RunListPage";
-import { RunsPage } from "./pages/RunsPage";
-import { TransformDependenciesPage } from "./pages/TransformDependenciesPage";
-import { TransformGraphRunListPage } from "./pages/TransformGraphRunListPage";
-import { TransformIndexesPage } from "./pages/TransformIndexesPage";
-import { TransformListPage } from "./pages/TransformListPage";
-import { TransformQueryPage } from "./pages/TransformQueryPage";
-import { TransformRunPage } from "./pages/TransformRunPage";
-import { TransformSettingsPage } from "./pages/TransformSettingsPage";
import { TransformsNotDisabled } from "./route-guards";
+/**
+ * The transform pages, in one chunk. Every loader names it, so the section
+ * arrives in a single request. Editing a transform means moving between its
+ * query, run, settings and indexes tabs, and that should not cost a fetch each
+ * time.
+ *
+ * The route guard stays eager: it has to decide before there is anything to
+ * show.
+ */
+const transformListPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/TransformListPage").then(
+ ({ TransformListPage }) => ({
+ Component: TransformListPage,
+ }),
+ );
+
+const runsPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/RunsPage").then(
+ ({ RunsPage }) => ({ Component: RunsPage }),
+ );
+
+const transformGraphRunListPage = () =>
+ import(
+ /* webpackChunkName: "transforms" */ "./pages/TransformGraphRunListPage"
+ ).then(({ TransformGraphRunListPage }) => ({
+ Component: TransformGraphRunListPage,
+ }));
+
+const runListPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/RunListPage").then(
+ ({ RunListPage }) => ({
+ Component: RunListPage,
+ }),
+ );
+
+const jobSectionLayout = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/JobSectionLayout").then(
+ ({ JobSectionLayout }) => ({
+ Component: JobSectionLayout,
+ }),
+ );
+
+const jobListPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/JobListPage").then(
+ ({ JobListPage }) => ({
+ Component: JobListPage,
+ }),
+ );
+
+const newJobPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/NewJobPage").then(
+ ({ NewJobPage }) => ({
+ Component: NewJobPage,
+ }),
+ );
+
+const jobPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/JobPage").then(
+ ({ JobPage }) => ({ Component: JobPage }),
+ );
+
+const jobRunListPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/JobRunListPage").then(
+ ({ JobRunListPage }) => ({
+ Component: JobRunListPage,
+ }),
+ );
+
+const newQueryTransformPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/NewTransformPage").then(
+ ({ NewQueryTransformPage }) => ({
+ Component: NewQueryTransformPage,
+ }),
+ );
+
+const newNativeTransformPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/NewTransformPage").then(
+ ({ NewNativeTransformPage }) => ({
+ Component: NewNativeTransformPage,
+ }),
+ );
+
+const newCardTransformPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/NewTransformPage").then(
+ ({ NewCardTransformPage }) => ({
+ Component: NewCardTransformPage,
+ }),
+ );
+
+const transformQueryPage = () =>
+ import(
+ /* webpackChunkName: "transforms" */ "./pages/TransformQueryPage"
+ ).then(({ TransformQueryPage }) => ({
+ Component: TransformQueryPage,
+ }));
+
+const transformRunPage = () =>
+ import(/* webpackChunkName: "transforms" */ "./pages/TransformRunPage").then(
+ ({ TransformRunPage }) => ({
+ Component: TransformRunPage,
+ }),
+ );
+
+const transformSettingsPage = () =>
+ import(
+ /* webpackChunkName: "transforms" */ "./pages/TransformSettingsPage"
+ ).then(({ TransformSettingsPage }) => ({
+ Component: TransformSettingsPage,
+ }));
+
+const transformIndexesPage = () =>
+ import(
+ /* webpackChunkName: "transforms" */ "./pages/TransformIndexesPage"
+ ).then(({ TransformIndexesPage }) => ({
+ Component: TransformIndexesPage,
+ }));
+
+const transformDependenciesPage = () =>
+ import(
+ /* webpackChunkName: "transforms" */ "./pages/TransformDependenciesPage"
+ ).then(({ TransformDependenciesPage }) => ({
+ Component: TransformDependenciesPage,
+ }));
+
export function getDataStudioTransformRoutes() {
return (
<Route element={<TransformsNotDisabled />}>
- <Route index element={<TransformListPage />} />
- <Route path="runs" element={<RunsPage />}>
- <Route index element={<TransformGraphRunListPage />} />
- <Route path="individual" element={<RunListPage />} />
+ <Route index lazy={transformListPage} />
+ <Route path="runs" lazy={runsPage}>
+ <Route index lazy={transformGraphRunListPage} />
+ <Route path="individual" lazy={runListPage} />
</Route>
- <Route path="jobs" element={<JobSectionLayout />}>
- <Route index element={<JobListPage />} />
- <Route path="new" element={<NewJobPage />} />
- <Route path=":jobId" element={<JobPage />} />
- <Route path=":jobId/runs" element={<JobRunListPage />} />
+ <Route path="jobs" lazy={jobSectionLayout}>
+ <Route index lazy={jobListPage} />
+ <Route path="new" lazy={newJobPage} />
+ <Route path=":jobId" lazy={jobPage} />
+ <Route path=":jobId/runs" lazy={jobRunListPage} />
</Route>
- <Route path="new/query" element={<NewQueryTransformPage />} />
- <Route path="new/native" element={<NewNativeTransformPage />} />
- <Route path="new/card/:cardId" element={<NewCardTransformPage />} />
- <Route path=":transformId" element={<TransformQueryPage />} />
- <Route path=":transformId/edit" element={<TransformQueryPage />} />
- <Route path=":transformId/run" element={<TransformRunPage />} />
- <Route path=":transformId/settings" element={<TransformSettingsPage />} />
- <Route path=":transformId/indexes" element={<TransformIndexesPage />} />
+ <Route path="new/query" lazy={newQueryTransformPage} />
+ <Route path="new/native" lazy={newNativeTransformPage} />
+ <Route path="new/card/:cardId" lazy={newCardTransformPage} />
+ <Route path=":transformId" lazy={transformQueryPage} />
+ <Route path=":transformId/edit" lazy={transformQueryPage} />
+ <Route path=":transformId/run" lazy={transformRunPage} />
+ <Route path=":transformId/settings" lazy={transformSettingsPage} />
+ <Route path=":transformId/indexes" lazy={transformIndexesPage} />
{PLUGIN_TRANSFORMS_PYTHON.getInspectorRoutes()}
{PLUGIN_DEPENDENCIES.isEnabled && (
<Route
path=":transformId/dependencies"
- element={<TransformDependenciesPage />}
+ lazy={transformDependenciesPage}
>
<Route index element={<PLUGIN_DEPENDENCIES.DependencyGraphPage />} />
</Route>
diff --git a/frontend/src/metabase/transforms/routes.unit.spec.tsx b/frontend/src/metabase/transforms/routes.unit.spec.tsx
new file mode 100644
index 00000000000..2cb9c3f15c9
--- /dev/null
+++ b/frontend/src/metabase/transforms/routes.unit.spec.tsx
@@ -0,0 +1,16 @@
+import { lazyLoaders } from "__support__/lazy-routes";
+
+import { getDataStudioTransformRoutes } from "./routes";
+
+describe("transforms routes", () => {
+ it("resolves every page", async () => {
+ const loaders = lazyLoaders(getDataStudioTransformRoutes());
+
+ // 17, not 18: the dependencies route is behind a plugin flag that is off here.
+ expect(loaders).toHaveLength(17);
+
+ for (const load of loaders) {
+ expect((await load()).Component).toBeDefined();
+ }
+ });
+});