Skip to content

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

fix: library shows up in the model path incorrectly (#74185)

Maksym Yakubych3e75235c698b
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.tsx
index b280b0fe8f3..6b6f6d4eacd 100644
--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.tsx
@@ -14,6 +14,7 @@ import { ForwardRefLink } from "metabase/common/components/Link";
import { useToast } from "metabase/common/hooks";
import { deserializeCardFromQuery } from "metabase/common/utils/card";
import {
+ getCollectionLocationLabel,
getCollectionLocationParts,
getDatabaseLocationParts,
} from "metabase/common/utils/source-location";
@@ -406,7 +407,7 @@ const CardPill = ({ id, messageId }: { id: number; messageId?: string }) => {
iconName={iconName}
label={card?.name}
location={{
- parts: getCollectionLocationParts(card.collection?.name),
+ parts: [getCollectionLocationLabel(card.collection?.name)],
}}
messageId={messageId}
source={{
diff --git a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.unit.spec.tsx b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.unit.spec.tsx
index 14876c0eacb..0e1223959e0 100644
--- a/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.unit.spec.tsx
+++ b/frontend/src/metabase/metabot/components/MetabotChat/MetabotAgentDataSourcePills.unit.spec.tsx
@@ -10,6 +10,7 @@ import type {
} from "metabase-types/api";
import {
createMockCard,
+ createMockCollection,
createMockDatabase,
createMockTable,
} from "metabase-types/api/mocks";
@@ -330,6 +331,46 @@ describe("MetabotAgentDataSourcePills", () => {
);
});
+ it("does not show Library in a model source path for normal collections", async () => {
+ const sql = "SELECT * FROM {{#4-revenue_model}}";
+ const templateTags: TemplateTags = {
+ "#4-revenue_model": {
+ id: "1",
+ name: "#4-revenue_model",
+ "display-name": "Revenue Model",
+ type: "card",
+ "card-id": 4,
+ },
+ };
+ fetchMock.post(EXTRACT_SOURCES_ENDPOINT, {
+ tables: [],
+ card_ids: [4],
+ });
+ fetchMock.get(
+ "path:/api/card/4",
+ createMockCard({
+ id: 4,
+ name: "Revenue Model",
+ type: "model",
+ collection: createMockCollection({
+ id: 10,
+ name: "Marketing & Growth",
+ }),
+ }),
+ );
+ fetchMock.get("path:/api/database/1", DATABASE);
+
+ renderWithProviders(
+ <NavigateToTablePills path={createNativePath(sql, 1, templateTags)} />,
+ );
+
+ expect(
+ await screen.findByRole("link", { name: "Revenue Model" }),
+ ).toBeInTheDocument();
+ expect(screen.getByText("Marketing & Growth")).toBeInTheDocument();
+ expect(screen.queryByText("Library")).not.toBeInTheDocument();
+ });
+
it("shows source links without feedback buttons when message id is not provided", async () => {
setupNativeEndpoints();