Skip to content

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

Fix unnecessary redirects on Models & Metrics pages (#64489)

Andersonbd1838423327
diff --git a/e2e/test/scenarios/metrics/browse.cy.spec.ts b/e2e/test/scenarios/metrics/browse.cy.spec.ts
index fa938ad0f15..fe5e309b0f6 100644
--- a/e2e/test/scenarios/metrics/browse.cy.spec.ts
+++ b/e2e/test/scenarios/metrics/browse.cy.spec.ts
@@ -197,7 +197,7 @@ describe("scenarios > browse > metrics", () => {
cy.get("@open").should("have.been.calledOnce");
cy.get("@open").should(
"have.been.calledWithMatch",
- /^\/question\/\d+-.*$/,
+ /^\/metric\/\d+-.*$/,
"_blank",
);
@@ -432,7 +432,7 @@ describe("scenarios > browse > metrics", () => {
findMetric(ORDERS_SCALAR_MODEL_METRIC.name).should("be.visible");
});
- it("should respect the user setting on wether or not to only show verified metrics", () => {
+ it("should respect the user setting on whether to only show verified metrics", () => {
cy.intercept("GET", "/api/session/properties", (req) => {
req.continue((res) => {
res.body["browse-filter-only-verified-metrics"] = true;
@@ -502,8 +502,6 @@ function verifyMetric(metric: StructuredQuestionDetailsWithName) {
cy.findByLabelText("Move, trash, and more…").click();
H.popover().findByText("Verify this metric").click();
- H.openNavigationSidebar();
-
H.navigationSidebar()
.findByRole("listitem", { name: "Browse metrics" })
.click();
@@ -515,8 +513,6 @@ function unverifyMetric(metric: StructuredQuestionDetailsWithName) {
cy.findByLabelText("Move, trash, and more…").click();
H.popover().findByText("Remove verification").click();
- H.openNavigationSidebar();
-
H.navigationSidebar()
.findByRole("listitem", { name: "Browse metrics" })
.click();
diff --git a/e2e/test/scenarios/onboarding/home/browse.cy.spec.ts b/e2e/test/scenarios/onboarding/home/browse.cy.spec.ts
index cb040449dd8..262e9baef50 100644
--- a/e2e/test/scenarios/onboarding/home/browse.cy.spec.ts
+++ b/e2e/test/scenarios/onboarding/home/browse.cy.spec.ts
@@ -61,7 +61,7 @@ describe("browse > models", () => {
cy.get("@open").should("have.been.calledOnce");
cy.get("@open").should(
"have.been.calledOnceWithExactly",
- `/question/${ORDERS_MODEL_ID}-orders-model`,
+ `/model/${ORDERS_MODEL_ID}-orders-model`,
"_blank",
);
});
diff --git a/frontend/src/metabase/browse/metrics/MetricsTable.tsx b/frontend/src/metabase/browse/metrics/MetricsTable.tsx
index 061d7574b99..b2eac9bd64e 100644
--- a/frontend/src/metabase/browse/metrics/MetricsTable.tsx
+++ b/frontend/src/metabase/browse/metrics/MetricsTable.tsx
@@ -189,7 +189,7 @@ function MetricRow({ metric }: { metric?: MetricResult }) {
}
const { id, name } = metric;
- const url = Urls.metric({ id, name });
+ const url = Urls.metric({ id, name, type: "metric" });
const subpathSafeUrl = Urls.getSubpathSafeUrl(url);
// TODO: metabase/metabse#47713
@@ -241,7 +241,9 @@ function NameCell({ metric }: { metric?: MetricResult }) {
>
<MaybeItemLink
to={
- metric ? Urls.metric({ id: metric.id, name: metric.name }) : undefined
+ metric
+ ? Urls.metric({ id: metric.id, name: metric.name, type: "metric" })
+ : undefined
}
style={{
// To align the icons with "Name" in the <th>
diff --git a/frontend/src/metabase/browse/metrics/tests/common.unit.spec.tsx b/frontend/src/metabase/browse/metrics/tests/common.unit.spec.tsx
index 85c45b32943..4c70d344f56 100644
--- a/frontend/src/metabase/browse/metrics/tests/common.unit.spec.tsx
+++ b/frontend/src/metabase/browse/metrics/tests/common.unit.spec.tsx
@@ -1,3 +1,5 @@
+import userEvent from "@testing-library/user-event";
+
import { screen, within } from "__support__/ui";
import { setup } from "./setup";
@@ -72,4 +74,22 @@ describe("BrowseMetrics (OSS)", () => {
within(table).getAllByTestId("path-for-collection: Alpha"),
).toHaveLength(3);
});
+
+ it("should render links that point directly to /metric/{id}-{slug} (metabase#55166)", async () => {
+ const { history } = setup({ metricCount: 5 });
+ const table = await screen.findByRole("table", {
+ name: /Table of metrics/,
+ });
+ expect(
+ within(table).getByRole("link", { name: /Metric 1/ }),
+ ).toHaveAttribute("href", "/metric/1-metric-1");
+ expect(
+ within(table).getByRole("link", { name: /Metric 2/ }),
+ ).toHaveAttribute("href", "/metric/2-metric-2");
+
+ expect(screen.queryByTestId("metric-detail-page")).not.toBeInTheDocument();
+ await userEvent.click(within(table).getByText("Metric 1"));
+ expect(screen.getByTestId("metric-detail-page")).toBeInTheDocument();
+ expect(history?.getCurrentLocation().pathname).toBe("/metric/1-metric-1");
+ });
});
diff --git a/frontend/src/metabase/browse/metrics/tests/setup.tsx b/frontend/src/metabase/browse/metrics/tests/setup.tsx
index b9ed5f5d737..25f4790d738 100644
--- a/frontend/src/metabase/browse/metrics/tests/setup.tsx
+++ b/frontend/src/metabase/browse/metrics/tests/setup.tsx
@@ -1,3 +1,5 @@
+import { Route } from "react-router";
+
import { setupEnterprisePlugins } from "__support__/enterprise";
import {
setupCardEndpoints,
@@ -259,5 +261,17 @@ export function setup({
setupCardQueryEndpoints(card, TEST_DATASET);
}
- return renderWithProviders(<BrowseMetrics />, { storeInitialState: state });
+ return renderWithProviders(
+ <>
+ <Route path="/" component={() => <BrowseMetrics />} />
+ <Route
+ path="/metric/:slug"
+ component={() => <div data-testid="metric-detail-page" />}
+ />
+ </>,
+ {
+ storeInitialState: state,
+ withRouter: true,
+ },
+ );
}
diff --git a/frontend/src/metabase/browse/models/BrowseModels.unit.spec.tsx b/frontend/src/metabase/browse/models/BrowseModels.unit.spec.tsx
index fe337f6359a..8ca032b231d 100644
--- a/frontend/src/metabase/browse/models/BrowseModels.unit.spec.tsx
+++ b/frontend/src/metabase/browse/models/BrowseModels.unit.spec.tsx
@@ -1,4 +1,5 @@
import userEvent from "@testing-library/user-event";
+import { Route } from "react-router";
import {
setupDatabasesEndpoints,
@@ -45,13 +46,23 @@ const setup = ({
setupSearchEndpoints(models.map((model) => createMockSearchResult(model)));
setupSettingsEndpoints([]);
setupRecentViewsEndpoints(mockRecentModels);
- return renderWithProviders(<BrowseModels />, {
- storeInitialState: {
- setup: createMockSetupState({
- locale: { name: "English", code: "en" },
- }),
+ return renderWithProviders(
+ <>
+ <Route path="/" component={() => <BrowseModels />} />
+ <Route
+ path="/model/:slug"
+ component={() => <div data-testid="model-detail-page" />}
+ />
+ </>,
+ {
+ storeInitialState: {
+ setup: createMockSetupState({
+ locale: { name: "English", code: "en" },
+ }),
+ },
+ withRouter: true,
},
- });
+ );
};
const collectionAlpha = createMockCollection({ id: 99, name: "Alpha" });
@@ -474,4 +485,33 @@ describe("BrowseModels", () => {
});
expect(recentModelsGrid).not.toBeInTheDocument();
});
+
+ it("should render links that point directly to /model/{id}-{slug} (metabase#55166)", async () => {
+ const { history } = setup({ modelCount: 25 });
+ const recentModelsGrid = await screen.findByRole("grid", {
+ name: /Recents/,
+ });
+ expect(
+ within(recentModelsGrid).getByRole("link", { name: /Model 1/ }),
+ ).toHaveAttribute("href", "/model/1-model-1");
+ expect(
+ within(recentModelsGrid).getByRole("link", { name: /Model 2/ }),
+ ).toHaveAttribute("href", "/model/2-model-2");
+
+ const modelsTable = await screen.findByRole("table", {
+ name: /Table of models/,
+ });
+
+ expect(
+ within(modelsTable).getByRole("link", { name: /Model 20/ }),
+ ).toHaveAttribute("href", "/model/20-model-20");
+ expect(
+ within(modelsTable).getByRole("link", { name: /Model 21/ }),
+ ).toHaveAttribute("href", "/model/21-model-21");
+
+ expect(screen.queryByTestId("model-detail-page")).not.toBeInTheDocument();
+ await userEvent.click(within(recentModelsGrid).getByText("Model 1"));
+ expect(screen.getByTestId("model-detail-page")).toBeInTheDocument();
+ expect(history?.getCurrentLocation().pathname).toBe("/model/1-model-1");
+ });
});
diff --git a/frontend/src/metabase/browse/models/ModelsTable.tsx b/frontend/src/metabase/browse/models/ModelsTable.tsx
index 9dc87b4a110..b289f3cfcd2 100644
--- a/frontend/src/metabase/browse/models/ModelsTable.tsx
+++ b/frontend/src/metabase/browse/models/ModelsTable.tsx
@@ -173,7 +173,7 @@ const ModelRow = ({ model }: { model?: ModelResult }) => {
}
const { id, name } = model;
- const url = Urls.model({ id, name });
+ const url = Urls.model({ id, name, type: "model" });
const subpathSafeUrl = Urls.getSubpathSafeUrl(url);
trackModelClick(model.id);
@@ -206,7 +206,11 @@ function NameCell({ model }: { model?: ModelResult }) {
return (
<ItemNameCell data-testid="model-name" aria-labelledby={headingId}>
<MaybeItemLink
- to={model ? Urls.model({ id: model.id, name: model.name }) : undefined}
+ to={
+ model
+ ? Urls.model({ id: model.id, name: model.name, type: "model" })
+ : undefined
+ }
style={{
// To align the icons with "Name" in the <th>
paddingInlineStart: "1.4rem",