Skip to content

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

Add documents to broken card responses (#66638)

Alexander Polyankin4eea91f41dff
diff --git a/e2e/support/helpers/api/createDocument.ts b/e2e/support/helpers/api/createDocument.ts
index fee398f3618..39b421d3008 100644
--- a/e2e/support/helpers/api/createDocument.ts
+++ b/e2e/support/helpers/api/createDocument.ts
@@ -1,4 +1,6 @@
import type {
+ Card,
+ CardId,
Document,
DocumentContent,
RegularCollectionId,
@@ -8,12 +10,14 @@ export const createDocument = ({
name,
collection_id,
document,
+ cards,
alias,
idAlias,
}: {
name: string;
collection_id?: RegularCollectionId | null;
document: DocumentContent;
+ cards?: Record<CardId, Card>;
alias?: string;
idAlias?: string;
}): Cypress.Chainable<Cypress.Response<Document>> => {
@@ -24,6 +28,7 @@ export const createDocument = ({
name,
collection_id,
document,
+ cards,
})
.then((response) => {
if (alias) {
diff --git a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
index d1d9cc7f485..fb5772aadd1 100644
--- a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts
@@ -4,7 +4,6 @@ import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
import {
ADMIN_PERSONAL_COLLECTION_ID,
FIRST_COLLECTION_ID,
- ORDERS_DASHBOARD_ID,
SECOND_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
import type { IconName } from "metabase/ui";
@@ -12,6 +11,7 @@ import type {
CardId,
CardType,
CollectionId,
+ DashboardId,
DependencyId,
DependencyType,
NativeQuerySnippetId,
@@ -19,6 +19,7 @@ import type {
TableId,
TransformId,
} from "metabase-types/api";
+import { createMockCard } from "metabase-types/api/mocks";
const BASE_URL = "/data-studio/dependencies";
const TABLE_NAME = "scoreboard_actions";
@@ -49,6 +50,10 @@ const SEGMENT_BASED_QUESTION_NAME = "Segment-based question";
const SEGMENT_BASED_MODEL_NAME = "Segment-based model";
const SEGMENT_BASED_METRIC_NAME = "Segment-based metric";
const SEGMENT_BASED_SEGMENT_NAME = "Segment-based segment";
+const ROOT_COLLECTION_NAME = "Our analytics";
+const FIRST_COLLECTION_NAME = "First collection";
+const DASHBOARD_NAME = "Dashboard";
+const DOCUMENT_NAME = "Document";
describe("scenarios > dependencies > dependency graph", () => {
beforeEach(() => {
@@ -226,10 +231,12 @@ describe("scenarios > dependencies > dependency graph", () => {
itemTitle,
groupTitle,
dependentItemTitle,
+ dependentItemLocation,
}: {
itemTitle: string;
groupTitle: string;
dependentItemTitle: string;
+ dependentItemLocation?: string;
}) {
H.DependencyGraph.graph()
.findByLabelText(itemTitle)
@@ -237,8 +244,12 @@ describe("scenarios > dependencies > dependency graph", () => {
.click();
H.DependencyGraph.dependencyPanel()
.findByLabelText(dependentItemTitle)
- .findByText(dependentItemTitle)
- .click();
+ .within(() => {
+ if (dependentItemLocation) {
+ cy.findByText(dependentItemLocation).should("be.visible");
+ }
+ cy.findByText(dependentItemTitle).should("be.visible").click();
+ });
H.DependencyGraph.entryButton()
.findByText(dependentItemTitle)
.should("be.visible");
@@ -266,6 +277,7 @@ describe("scenarios > dependencies > dependency graph", () => {
itemTitle: TABLE_DISPLAY_NAME,
groupTitle: "1 model",
dependentItemTitle: TABLE_BASED_MODEL_NAME,
+ dependentItemLocation: ROOT_COLLECTION_NAME,
});
verifyPanelNavigation({
itemTitle: TABLE_DISPLAY_NAME,
@@ -479,6 +491,63 @@ describe("scenarios > dependencies > dependency graph", () => {
dependentItemTitle: SNIPPET_BASED_SNIPPET_NAME,
});
});
+
+ it("should display dependencies for a question in the root collection", () => {
+ getScoreboardTableId().then((tableId) => {
+ createTableBasedQuestion({ tableId });
+ visitGraphForEntity(tableId, "table");
+ });
+ verifyPanelNavigation({
+ itemTitle: TABLE_DISPLAY_NAME,
+ groupTitle: "1 question",
+ dependentItemTitle: TABLE_BASED_QUESTION_NAME,
+ dependentItemLocation: ROOT_COLLECTION_NAME,
+ });
+ });
+
+ it("should display dependencies for a question in a non-root collection", () => {
+ getScoreboardTableId().then((tableId) => {
+ createTableBasedQuestion({
+ tableId,
+ collectionId: FIRST_COLLECTION_ID,
+ });
+ visitGraphForEntity(tableId, "table");
+ });
+ verifyPanelNavigation({
+ itemTitle: TABLE_DISPLAY_NAME,
+ groupTitle: "1 question",
+ dependentItemTitle: TABLE_BASED_QUESTION_NAME,
+ dependentItemLocation: FIRST_COLLECTION_NAME,
+ });
+ });
+
+ it("should display dependencies for a question in a dashboard", () => {
+ getScoreboardTableId().then((tableId) => {
+ createDashboard().then(({ body: dashboard }) => {
+ createTableBasedQuestion({ tableId, dashboardId: dashboard.id });
+ visitGraphForEntity(tableId, "table");
+ });
+ });
+ verifyPanelNavigation({
+ itemTitle: TABLE_DISPLAY_NAME,
+ groupTitle: "1 question",
+ dependentItemTitle: TABLE_BASED_QUESTION_NAME,
+ dependentItemLocation: DASHBOARD_NAME,
+ });
+ });
+
+ it("should display dependencies for a question in a document", () => {
+ getScoreboardTableId().then((tableId) => {
+ createDocumentWithTableBasedQuestion({ tableId });
+ visitGraphForEntity(tableId, "table");
+ });
+ verifyPanelNavigation({
+ itemTitle: TABLE_DISPLAY_NAME,
+ groupTitle: "1 question",
+ dependentItemTitle: TABLE_BASED_QUESTION_NAME,
+ dependentItemLocation: DOCUMENT_NAME,
+ });
+ });
});
describe("dependent filtering", () => {
@@ -506,35 +575,37 @@ describe("scenarios > dependencies > dependency graph", () => {
it("should be able to filter questions", () => {
makeCollectionOfficial(FIRST_COLLECTION_ID);
getScoreboardTableId().then((tableId) => {
- createTableBasedQuestion({
- name: "Verified question",
- tableId,
- }).then(({ body: card }) => {
- verifyCard(card.id);
- });
- createTableBasedQuestion({
- name: "Question in dashboard",
- tableId,
- dashboardId: ORDERS_DASHBOARD_ID,
- });
- createTableBasedQuestion({
- name: "Question in root collection",
- tableId,
- });
- createTableBasedQuestion({
- name: "Question in official collection",
- tableId,
- collectionId: FIRST_COLLECTION_ID,
- });
- createTableBasedQuestion({
- name: "Question in regular collection",
- tableId,
- collectionId: SECOND_COLLECTION_ID,
- });
- createTableBasedQuestion({
- name: "Question in personal collection",
- tableId,
- collectionId: ADMIN_PERSONAL_COLLECTION_ID,
+ createDashboard().then(({ body: dashboard }) => {
+ createTableBasedQuestion({
+ name: "Verified question",
+ tableId,
+ }).then(({ body: card }) => {
+ verifyCard(card.id);
+ });
+ createTableBasedQuestion({
+ name: "Question in dashboard",
+ tableId,
+ dashboardId: dashboard.id,
+ });
+ createTableBasedQuestion({
+ name: "Question in root collection",
+ tableId,
+ });
+ createTableBasedQuestion({
+ name: "Question in official collection",
+ tableId,
+ collectionId: FIRST_COLLECTION_ID,
+ });
+ createTableBasedQuestion({
+ name: "Question in regular collection",
+ tableId,
+ collectionId: SECOND_COLLECTION_ID,
+ });
+ createTableBasedQuestion({
+ name: "Question in personal collection",
+ tableId,
+ collectionId: ADMIN_PERSONAL_COLLECTION_ID,
+ });
});
visitGraphForEntity(tableId, "table");
});
@@ -610,8 +681,8 @@ function createTableBasedCard({
name: string;
type: CardType;
tableId: TableId;
- collectionId?: number | null;
- dashboardId?: number | null;
+ collectionId?: CollectionId | null;
+ dashboardId?: DashboardId | null;
}) {
return H.createQuestion({
name,
@@ -633,8 +704,8 @@ function createTableBasedQuestion({
}: {
name?: string;
tableId: TableId;
- collectionId?: number | null;
- dashboardId?: number | null;
+ collectionId?: CollectionId | null;
+ dashboardId?: DashboardId | null;
}) {
return createTableBasedCard({
name,
@@ -1097,3 +1168,34 @@ function createSegmentBasedMetric({
segmentId,
});
}
+
+function createDashboard() {
+ return H.createDashboard({
+ name: DASHBOARD_NAME,
+ });
+}
+
+function createDocumentWithTableBasedQuestion({
+ tableId,
+}: {
+ tableId: TableId;
+}) {
+ return H.createDocument({
+ name: DOCUMENT_NAME,
+ document: [],
+ cards: {
+ "-1": createMockCard({
+ id: -1,
+ name: TABLE_BASED_QUESTION_NAME,
+ dataset_query: {
+ database: WRITABLE_DB_ID,
+ type: "query",
+ query: {
+ "source-table": tableId,
+ },
+ },
+ description: "Table based question",
+ }),
+ },
+ });
+}
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
index ff22fac7d11..3cdf9983fd6 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
@@ -19,7 +19,6 @@
[metabase.queries.schema :as queries.schema]
[metabase.revisions.core :as revisions]
[metabase.util.i18n :refer [tru]]
- [metabase.util.log :as log]
[metabase.util.malli.registry :as mr]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
@@ -36,21 +35,18 @@
(let [broken-card-ids (keys card)
broken-cards (when (seq broken-card-ids)
(-> (t2/select :model/Card :id [:in broken-card-ids])
- (t2/hydrate [:collection :effective_ancestors] :dashboard)))
+ (t2/hydrate [:collection :effective_ancestors] :dashboard :document)))
broken-transform-ids (keys transform)
broken-transforms (when (seq broken-transform-ids)
(t2/select :model/Transform :id [:in broken-transform-ids]))]
{:success (and (empty? broken-card-ids)
(empty? broken-transform-ids))
- :bad_cards (into [] (comp (filter (fn [card]
- (if (mi/can-read? card)
- card
- (do (log/debugf "Eliding broken card %d - not readable by the user" (:id card))
- nil))))
+ :bad_cards (into [] (comp (filter mi/can-read?)
(map (fn [card]
(-> card
collection.root/hydrate-root-collection
- (update :dashboard #(some-> % (select-keys [:id :name])))))))
+ (update :dashboard #(some-> % (select-keys [:id :name])))
+ (update :document #(some-> % (select-keys [:id :name])))))))
broken-cards)
:bad_transforms (into [] broken-transforms)}))
@@ -157,6 +153,7 @@
:created_at :creator :creator_id :description
:result_metadata :last-edit-info
:collection :collection_id :dashboard :dashboard_id
+ :document :document_id
:moderation_reviews]
:snippet [:name :description]
:transform [:name :description :creator :table]
@@ -174,6 +171,7 @@
(case (t2/model entity)
:model/Collection (select-keys entity [:id :name :authority_level :is_personal])
:model/Dashboard (select-keys entity [:id :name])
+ :model/Document (select-keys entity [:id :name])
entity))
(defn- entity-value [entity-type {:keys [id] :as entity} usages]
@@ -202,7 +200,7 @@
;; and others (like :last-edit-info, :view_count) are computed/added separately.
;; This map only lists the base database columns to SELECT.
(def ^:private entity-select-fields
- {:card [:id :name :description :type :display :database_id :collection_id :dashboard_id :result_metadata
+ {:card [:id :name :description :type :display :database_id :collection_id :dashboard_id :document_id :result_metadata
:created_at :creator_id
;; :card_schema always has to be selected
:card_schema]
@@ -368,7 +366,7 @@
(let [model (entity-model entity-type)
fields (entity-select-fields entity-type)]
(->> (cond-> (t2/select (into [model] fields) :id [:in entity-ids])
- (= entity-type :card) (-> (t2/hydrate :creator :dashboard [:collection :is_personal] :moderation_reviews)
+ (= entity-type :card) (-> (t2/hydrate :creator :dashboard :document [:collection :is_personal] :moderation_reviews)
(->> (map collection.root/hydrate-root-collection))
(revisions/with-last-edit-info :card))
(= entity-type :table) (t2/hydrate :fields :db)
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index f5e1c12f446..c43c690d376 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -69,6 +69,46 @@
(is (= {:bad_cards [], :bad_transforms [], :success true}
response))))))))
+(deftest check-card-hydrates-dashboard-and-document-test
+ (testing "POST /api/ee/dependencies/check_card hydrates dashboard and document for cards"
+ (mt/dataset test-data
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-current-user (mt/user->id :rasta)
+ (mt/with-temp [:model/User user {:email "[email protected]"}
+ :model/Dashboard dashboard {}
+ :model/Document document {}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency]
+ (let [metadata-provider (mt/metadata-provider)
+ ;; Create base card querying real orders table
+ base-card (card/create-card! (basic-card) user)
+ ;; Create dependent cards that filter on TOTAL
+ base-card-meta (lib.metadata/card metadata-provider (:id base-card))
+ dependent-query (let [q (lib/query metadata-provider base-card-meta)
+ cols (lib/filterable-columns q)
+ total-col (m/find-first #(= (:id %) (mt/id :orders :total)) cols)]
+ (lib/filter q (lib/> total-col 100)))
+ dashboard-card (card/create-card!
+ (merge (card-with-query "Dashboard card" dependent-query) {:dashboard_id (:id dashboard)})
+ user)
+ document-card (card/create-card!
+ (merge (card-with-query "Document card" dependent-query) {:document_id (:id document)})
+ user)
+ ;; Propose changing to products table (doesn't have TOTAL column, breaks downstream)
+ proposed-query (lib/query metadata-provider (lib.metadata/table metadata-provider (mt/id :products)))
+ proposed-card {:id (:id base-card)
+ :type :question
+ :dataset_query proposed-query
+ :result_metadata nil}]
+ (is (=? {:success false
+ :bad_cards [{:id (:id dashboard-card)
+ :dashboard_id (:id dashboard)
+ :dashboard (select-keys dashboard [:id :name])}
+ {:id (:id document-card)
+ :document_id (:id document)
+ :document (select-keys document [:id :name])}]
+ :bad_transforms []}
+ (mt/user-http-request :rasta :post 200 "ee/dependencies/check_card" proposed-card)))))))))))
+
(deftest check-card-removing-column-breaks-downstream-test
(testing "POST /api/ee/dependencies/check_card detects when removing a column breaks downstream cards"
(mt/dataset test-data
@@ -697,3 +737,68 @@
:type "card")]
(is (empty? (:edges response))
"Should have no edges when table is filtered out")))))))))))))
+
+(deftest graph-returns-dashboard-for-cards-test
+ (testing "Graph endpoints return dashboard data for cards in dashboards"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-current-user (mt/user->id :rasta)
+ (mt/with-model-cleanup [:model/Card :model/Dependency]
+ (mt/with-temp [:model/User user {:email "[email protected]"}
+ :model/Dashboard dashboard {:name "Test Dashboard"}]
+ (let [base-card (card/create-card! (basic-card "Base Card") user)
+ dashboard-card (card/create-card! (assoc (wrap-card base-card)
+ :dashboard_id (:id dashboard))
+ user)]
+ (testing "GET /api/ee/dependencies/graph returns dashboard with :id and :name"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph"
+ :id (:id dashboard-card)
+ :type :card)
+ card-node (first (filter #(= (:id %) (:id dashboard-card)) (:nodes response)))]
+ (is (= {:id (:id dashboard) :name "Test Dashboard"}
+ (get-in card-node [:data :dashboard])))
+ (is (= (:id dashboard)
+ (get-in card-node [:data :dashboard_id])))))
+ (testing "GET /api/ee/dependencies/graph/dependents returns dashboard with :id and :name"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
+ :id (:id base-card)
+ :type :card
+ :dependent_type :card
+ :dependent_card_type :question)
+ card-node (first (filter #(= (:id %) (:id dashboard-card)) response))]
+ (is (some? card-node))
+ (is (= {:id (:id dashboard) :name "Test Dashboard"}
+ (get-in card-node [:data :dashboard])))
+ (is (= (:id dashboard)
+ (get-in card-node [:data :dashboard_id]))))))))))))
+
+(deftest graph-returns-document-for-cards-test
+ (testing "Graph endpoints return document data for cards in documents"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-model-cleanup [:model/Card :model/Dependency]
+ (mt/with-temp [:model/User user {:email "[email protected]"}
+ :model/Document document {:name "Test Document"}]
+ (let [base-card (card/create-card! (basic-card "Base Card") user)
+ document-card (card/create-card! (assoc (wrap-card base-card)
+ :document_id (:id document))
+ user)]
+ (testing "GET /api/ee/dependencies/graph returns document with :id and :name"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph"
+ :id (:id document-card)
+ :type :card)
+ card-node (first (filter #(= (:id %) (:id document-card)) (:nodes response)))]
+ (is (= {:id (:id document) :name "Test Document"}
+ (get-in card-node [:data :document])))
+ (is (= (:id document)
+ (get-in card-node [:data :document_id])))))
+ (testing "GET /api/ee/dependencies/graph/dependents returns document with :id and :name"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
+ :id (:id base-card)
+ :type :card
+ :dependent_type :card
+ :dependent_card_type :question)
+ card-node (first (filter #(= (:id %) (:id document-card)) response))]
+ (is (some? card-node))
+ (is (= {:id (:id document) :name "Test Document"}
+ (get-in card-node [:data :document])))
+ (is (= (:id document)
+ (get-in card-node [:data :document_id])))))))))))
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.tsx
index 6e7ade773e9..1053dc7ccc2 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.tsx
@@ -162,32 +162,16 @@ function getItemLink(item: DependencyItem) {
function getItemDescription(item: DependencyItem) {
if (item.type === "card") {
- const { collection, dashboard } = item.card;
-
- if (collection != null) {
- const ancestors = collection.effective_ancestors ?? [];
- const breadcrumbs = [
- ...ancestors.map((ancestor) => ({
- title: ancestor.name,
- to: Urls.collection(ancestor),
- })),
- { title: collection.name, to: Urls.collection(collection) },
- ...(dashboard != null
- ? [{ title: dashboard.name, to: Urls.dashboard(dashboard) }]
- : []),
- ];
-
- return (
- <Group gap="sm" wrap="nowrap">
- <FixedSizeIcon
- c="text-secondary"
- name={dashboard != null ? "dashboard" : "collection"}
- flex="0 0 auto"
- />
- <BreadcrumbList items={breadcrumbs} />
- </Group>
- );
- }
+ return (
+ <Group gap="sm" wrap="nowrap">
+ <FixedSizeIcon
+ c="text-secondary"
+ name={getCardLinkIcon(item)}
+ flex="0 0 auto"
+ />
+ <BreadcrumbList items={getCardBreadcrumbs(item)} />
+ </Group>
+ );
}
if (item.type === "transform") {
@@ -201,6 +185,38 @@ function getItemDescription(item: DependencyItem) {
return null;
}
+function getCardBreadcrumbs(item: CardDependencyItem) {
+ const { collection, dashboard, document } = item.card;
+ if (collection == null) {
+ return [];
+ }
+
+ const ancestors = collection.effective_ancestors ?? [];
+ const breadcrumbs = ancestors.map((ancestor) => ({
+ title: ancestor.name,
+ to: Urls.collection(ancestor),
+ }));
+ breadcrumbs.push({ title: collection.name, to: Urls.collection(collection) });
+ if (dashboard != null) {
+ breadcrumbs.push({ title: dashboard.name, to: Urls.dashboard(dashboard) });
+ } else if (document != null) {
+ breadcrumbs.push({ title: document.name, to: Urls.document(document) });
+ }
+
+ return breadcrumbs;
+}
+
+function getCardLinkIcon(item: CardDependencyItem): IconName {
+ const { dashboard, document } = item.card;
+ if (dashboard != null) {
+ return "dashboard";
+ }
+ if (document != null) {
+ return "document";
+ }
+ return "collection";
+}
+
type BreadcrumbItem = {
title: string;
to: string;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.unit.spec.tsx
index bc96b0eea1f..594334caeed 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/CheckDependenciesForm/CheckDependenciesForm.unit.spec.tsx
@@ -174,6 +174,42 @@ describe("CheckDependenciesForm", () => {
).toHaveAttribute("href", "/dashboard/2-card-dashboard");
});
+ it("should display the document that the question belongs to", () => {
+ setup({
+ checkData: createMockCheckDependenciesResponse({
+ success: false,
+ bad_cards: [
+ createMockCard({
+ name: "Card",
+ type: "question",
+ collection: createMockCollection({
+ id: 1,
+ name: "First collection",
+ effective_ancestors: [
+ createMockCollection({ id: "root", name: "Our analytics" }),
+ ],
+ }),
+ document: {
+ id: 3,
+ name: "Card document",
+ },
+ }),
+ ],
+ }),
+ });
+ expect(screen.getByRole("link", { name: "Our analytics" })).toHaveAttribute(
+ "href",
+ "/collection/root",
+ );
+ expect(
+ screen.getByRole("link", { name: "First collection" }),
+ ).toHaveAttribute("href", "/collection/1-first-collection");
+ expect(screen.getByRole("link", { name: "Card document" })).toHaveAttribute(
+ "href",
+ "/document/3",
+ );
+ });
+
it("should display transforms", () => {
setup({
checkData: createMockCheckDependenciesResponse({
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
index 84a30a38187..000048799ee 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
@@ -230,6 +230,14 @@ export function getNodeLocationInfo(node: DependencyNode): NodeLink[] | null {
},
];
}
+ if (node.data.document != null) {
+ return [
+ {
+ label: node.data.document.name,
+ url: Urls.document(node.data.document),
+ },
+ ];
+ }
if (node.data.collection != null) {
return [
{
diff --git a/frontend/src/metabase-types/api/card.ts b/frontend/src/metabase-types/api/card.ts
index b5408c4305e..34abb08cf7a 100644
--- a/frontend/src/metabase-types/api/card.ts
+++ b/frontend/src/metabase-types/api/card.ts
@@ -13,7 +13,7 @@ import type {
DashboardTabId,
} from "./dashboard";
import type { Database, DatabaseId } from "./database";
-import type { DocumentId } from "./document";
+import type { Document, DocumentId } from "./document";
import type { BaseEntityId } from "./entity-id";
import type { Field } from "./field";
import type { ModerationReview } from "./moderation";
@@ -32,6 +32,7 @@ import type { SmartScalarComparison } from "./visualization-settings";
export type CardType = "model" | "question" | "metric";
export type CardDashboardInfo = Pick<Dashboard, "id" | "name">;
+export type CardDocumentInfo = Pick<Document, "id" | "name">;
export interface Card<Q extends DatasetQuery = DatasetQuery>
extends UnsavedCard<Q> {
@@ -60,7 +61,8 @@ export interface Card<Q extends DatasetQuery = DatasetQuery>
collection_position: number | null;
dashboard: CardDashboardInfo | null;
dashboard_id: DashboardId | null;
- document_id?: DocumentId;
+ document_id?: DocumentId | null;
+ document?: CardDocumentInfo | null;
dashboard_count: number | null;
parameter_usage_count?: number | null;
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index 105877deb55..d2ed1217b41 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -58,6 +58,8 @@ export type CardDependencyNodeData = Pick<
| "collection"
| "dashboard_id"
| "dashboard"
+ | "document_id"
+ | "document"
| "result_metadata"
| "creator"
| "created_at"
diff --git a/src/metabase/documents/models/document.clj b/src/metabase/documents/models/document.clj
index e12a002ebfb..00dc7181e3b 100644
--- a/src/metabase/documents/models/document.clj
+++ b/src/metabase/documents/models/document.clj
@@ -17,6 +17,10 @@
(methodical/defmethod t2/table-name :model/Document [_model] :document)
+(methodical/defmethod t2/model-for-automagic-hydration [#_model :default #_k :document]
+ [_original-model _k]
+ :model/Document)
+
(t2/deftransforms :model/Document
{:document mi/transform-json})