Skip to content

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

Dependency diagnostics sidebar updates (#68825)

Alexander Polyankin0bacd6c5ca0e
diff --git a/e2e/support/helpers/e2e-dependency-helpers.ts b/e2e/support/helpers/e2e-dependency-helpers.ts
index 425a0f2f528..a79cb7a37c7 100644
--- a/e2e/support/helpers/e2e-dependency-helpers.ts
+++ b/e2e/support/helpers/e2e-dependency-helpers.ts
@@ -12,8 +12,8 @@ export const DependencyGraph = {
};
export const DependencyDiagnostics = {
- visitBreakingDependencies: () =>
- cy.visit("/data-studio/dependency-diagnostics/breaking"),
+ visitBrokenDependencies: () =>
+ cy.visit("/data-studio/dependency-diagnostics/broken"),
visitUnreferencedEntities: () =>
cy.visit("/data-studio/dependency-diagnostics/unreferenced"),
list: () => cy.findByTestId("dependency-list"),
@@ -25,11 +25,11 @@ export const DependencyDiagnostics = {
get: () => cy.findByTestId("dependency-list-sidebar"),
header: () => cy.findByTestId("dependency-list-sidebar-header"),
locationSection: () => cy.findByRole("region", { name: "Location" }),
- transformSection: () => cy.findByRole("region", { name: "Transform" }),
+ infoSection: () => cy.findByRole("region", { name: "Info" }),
+ errorsSection: (name: string) => cy.findByRole("region", { name }),
missingColumnsSection: () =>
cy.findByRole("region", { name: "Missing columns" }),
- creationSection: () =>
- cy.findByRole("region", { name: "Creator and last editor" }),
+ fieldsSection: () => cy.findByRole("region", { name: "Fields" }),
brokenDependentsSection: () =>
cy.findByRole("region", { name: "Broken dependents" }),
},
diff --git a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts
index 10e4d899d33..11a29243eb7 100644
--- a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts
@@ -90,7 +90,7 @@ describe("scenarios > dependencies > broken list", () => {
describe("analysis", () => {
it("should show broken dependencies", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
checkList({
visibleEntities: BROKEN_DEPENDENCIES,
hiddenEntities: BROKEN_DEPENDENTS,
@@ -100,13 +100,13 @@ describe("scenarios > dependencies > broken list", () => {
describe("sidebar", () => {
it("should show broken dependents", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
cy.log("table dependents");
H.DependencyDiagnostics.list().findByText(TABLE_DISPLAY_NAME).click();
checkSidebar({
- entityName: TABLE_DISPLAY_NAME,
- transformName: TABLE_TRANSFORM,
+ title: TABLE_DISPLAY_NAME,
+ transform: TABLE_TRANSFORM,
missingColumns: ["score", "status"],
brokenDependents: BROKEN_TABLE_DEPENDENTS,
});
@@ -114,7 +114,7 @@ describe("scenarios > dependencies > broken list", () => {
cy.log("question dependents");
H.DependencyDiagnostics.list().findByText(TABLE_BASED_QUESTION).click();
checkSidebar({
- entityName: TABLE_BASED_QUESTION,
+ title: TABLE_BASED_QUESTION,
missingColumns: ["PRICE"],
brokenDependents: BROKEN_QUESTION_DEPENDENTS,
});
@@ -122,7 +122,7 @@ describe("scenarios > dependencies > broken list", () => {
cy.log("model dependents");
H.DependencyDiagnostics.list().findByText(TABLE_BASED_MODEL).click();
checkSidebar({
- entityName: TABLE_BASED_MODEL,
+ title: TABLE_BASED_MODEL,
missingColumns: ["AMOUNT"],
brokenDependents: BROKEN_MODEL_DEPENDENTS,
});
@@ -131,7 +131,7 @@ describe("scenarios > dependencies > broken list", () => {
describe("search", () => {
it("should search for entities", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.searchInput().type(TABLE_DISPLAY_NAME);
checkList({
visibleEntities: [TABLE_DISPLAY_NAME],
@@ -142,7 +142,7 @@ describe("scenarios > dependencies > broken list", () => {
describe("filtering", () => {
it("should filter entities by type", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.filterButton().click();
H.popover().within(() => {
cy.findByText("Table").click();
@@ -188,7 +188,7 @@ describe("scenarios > dependencies > broken list", () => {
});
it("should filter entities by location", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.filterButton().click();
H.popover().within(() => {
cy.findByText("Include items in personal collections").click();
@@ -205,7 +205,7 @@ describe("scenarios > dependencies > broken list", () => {
describe("sorting", () => {
it("should sort by name", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.searchInput().type("test");
cy.log("sorted by name by default");
@@ -227,7 +227,7 @@ describe("scenarios > dependencies > broken list", () => {
});
it("should sort by location", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.searchInput().type("test");
cy.log("sorted by location ascending");
@@ -244,7 +244,7 @@ describe("scenarios > dependencies > broken list", () => {
});
it("should sort by dependents errors", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.searchInput().type("test");
cy.log("sorted by dependents errors ascending");
@@ -263,7 +263,7 @@ describe("scenarios > dependencies > broken list", () => {
});
it("should sort by dependents with errors", () => {
- H.DependencyDiagnostics.visitBreakingDependencies();
+ H.DependencyDiagnostics.visitBrokenDependencies();
H.DependencyDiagnostics.searchInput().type("test");
cy.log("sorted by dependents with errors ascending");
@@ -510,23 +510,23 @@ function checkList({
}
function checkSidebar({
- entityName,
- transformName,
+ title,
+ transform,
missingColumns,
brokenDependents,
}: {
- entityName: string;
- transformName?: string;
+ title: string;
+ transform?: string;
missingColumns?: string[];
brokenDependents?: string[];
}) {
H.DependencyDiagnostics.sidebar().within(() => {
H.DependencyDiagnostics.Sidebar.header()
- .findByText(entityName)
+ .findByText(title)
.should("be.visible");
- if (transformName) {
- H.DependencyDiagnostics.Sidebar.transformSection()
- .findByText(transformName)
+ if (transform) {
+ H.DependencyDiagnostics.Sidebar.infoSection()
+ .findByText(transform)
.should("exist");
}
if (missingColumns) {
diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
index 8968762b8d5..5a53b66bdd4 100644
--- a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
@@ -1,6 +1,8 @@
+import { USERS, WRITABLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
ADMIN_PERSONAL_COLLECTION_ID,
+ ADMIN_USER_ID,
FIRST_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
import type {
@@ -16,6 +18,10 @@ import { createMockParameter } from "metabase-types/api/mocks";
const { H } = cy;
const { ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;
+const DATABASE_NAME = "Writable Postgres12";
+const TABLE_NAME = "many_data_types";
+const TABLE_DISPLAY_NAME = "Many Data Types";
+const TABLE_DESCRIPTION = "This is a table with many data types";
const MODEL_FOR_QUESTION_DATA_SOURCE = "Model for question data source";
const MODEL_FOR_MODEL_DATA_SOURCE = "Model for model data source";
const MODEL_FOR_METRIC_DATA_SOURCE = "Model for metric data source";
@@ -37,6 +43,8 @@ const SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG =
"Snippet for native question card tag";
const SNIPPET_FOR_SNIPPET_TAG = "Snippet for snippet tag";
+const TABLE_NAMES = [TABLE_DISPLAY_NAME];
+
const MODEL_NAMES = [
MODEL_FOR_QUESTION_DATA_SOURCE,
MODEL_FOR_MODEL_DATA_SOURCE,
@@ -67,6 +75,7 @@ const SNIPPET_NAMES = [
];
const ENTITY_NAMES = [
+ ...TABLE_NAMES,
...MODEL_NAMES,
...SEGMENT_NAMES,
...METRIC_NAMES,
@@ -95,15 +104,17 @@ const MODELS_SORTED_BY_LOCATION = [
describe("scenarios > dependencies > unreferenced list", () => {
beforeEach(() => {
- H.restore();
+ H.restore("postgres-writable");
+ H.resetTestTable({ type: "postgres", table: TABLE_NAME });
cy.signInAsAdmin();
H.activateToken("bleeding-edge");
+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: TABLE_NAME });
cy.viewport(1600, 1400);
});
describe("analysis", () => {
it("should show unreferenced entities", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.list().within(() => {
ENTITY_NAMES.forEach((name) => {
@@ -113,7 +124,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should not show referenced entities", () => {
- createEntities({ withReferences: true });
+ setupEntities({ withReferences: true });
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.list().within(() => {
ENTITY_NAMES.forEach((name) => {
@@ -125,7 +136,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
describe("search", () => {
it("should search for entities", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.searchInput().type(
MODEL_FOR_QUESTION_DATA_SOURCE,
@@ -137,7 +148,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should search for entities with type filters", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.searchInput().type("tag");
checkList({
@@ -159,7 +170,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
describe("filters", () => {
it("should filter entities by type", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
checkList({ visibleEntities: ENTITY_NAMES });
@@ -189,7 +200,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should persist filter changes after page reload", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
checkList({ visibleEntities: MODEL_NAMES });
@@ -202,7 +213,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should filter by location", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
checkList({
visibleEntities: [
@@ -235,7 +246,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
describe("sorting", () => {
it("should sort by name", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.searchInput().type("Model for");
@@ -258,7 +269,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should sort by location", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.searchInput().type("Model for");
@@ -276,7 +287,7 @@ describe("scenarios > dependencies > unreferenced list", () => {
});
it("should persist sorting changes after page reload", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
H.DependencyDiagnostics.searchInput().type("Model for");
@@ -291,76 +302,97 @@ describe("scenarios > dependencies > unreferenced list", () => {
describe("sidebar", () => {
it("should show the sidebar for supported entities", () => {
- createEntities();
+ setupEntities();
H.DependencyDiagnostics.visitUnreferencedEntities();
+ H.DependencyDiagnostics.list().findByText(TABLE_DISPLAY_NAME).click();
+ checkSidebar({
+ title: TABLE_DISPLAY_NAME,
+ location: DATABASE_NAME,
+ description: TABLE_DESCRIPTION,
+ owner: `${USERS.admin.first_name} ${USERS.admin.last_name}`,
+ fields: ["ID", "UUID"],
+ });
+
H.DependencyDiagnostics.list()
.findByText(MODEL_FOR_QUESTION_DATA_SOURCE)
.click();
checkSidebar({
- entityName: MODEL_FOR_QUESTION_DATA_SOURCE,
- locationName: "Our analytics",
- creatorName: "Bobby Tables",
+ title: MODEL_FOR_QUESTION_DATA_SOURCE,
+ location: "Our analytics",
+ createdBy: "Bobby Tables",
+ fields: ["User ID"],
});
H.DependencyDiagnostics.list()
.findByText(MODEL_FOR_MODEL_DATA_SOURCE)
.click();
checkSidebar({
- entityName: MODEL_FOR_MODEL_DATA_SOURCE,
- locationName: "First collection",
- creatorName: "Bobby Tables",
+ title: MODEL_FOR_MODEL_DATA_SOURCE,
+ location: "First collection",
+ createdBy: "Bobby Tables",
});
H.DependencyDiagnostics.list()
.findByText(SEGMENT_FOR_QUESTION_FILTER)
.click();
checkSidebar({
- entityName: SEGMENT_FOR_QUESTION_FILTER,
- locationName: "Orders",
- creatorName: "Bobby Tables",
+ title: SEGMENT_FOR_QUESTION_FILTER,
+ location: "Orders",
+ createdBy: "Bobby Tables",
});
H.DependencyDiagnostics.list()
.findByText(METRIC_FOR_QUESTION_AGGREGATION)
.click();
checkSidebar({
- entityName: METRIC_FOR_QUESTION_AGGREGATION,
- locationName: "Our analytics",
- creatorName: "Bobby Tables",
+ title: METRIC_FOR_QUESTION_AGGREGATION,
+ location: "Our analytics",
+ createdBy: "Bobby Tables",
});
H.DependencyDiagnostics.list()
.findByText(METRIC_FOR_MODEL_AGGREGATION)
.click();
checkSidebar({
- entityName: METRIC_FOR_MODEL_AGGREGATION,
- locationName: "First collection",
- creatorName: "Bobby Tables",
+ title: METRIC_FOR_MODEL_AGGREGATION,
+ location: "First collection",
+ createdBy: "Bobby Tables",
});
H.DependencyDiagnostics.list()
.findByText(SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG)
.click();
checkSidebar({
- entityName: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,
- locationName: "SQL snippets",
- creatorName: "Bobby Tables",
+ title: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,
+ location: "SQL snippets",
+ createdBy: "Bobby Tables",
});
});
});
});
-function createEntities({
+function setupEntities({
withReferences = false,
}: { withReferences?: boolean } = {}) {
- createModelContent({ withReferences });
- createSegmentContent({ withReferences });
- createMetricContent({ withReferences });
- createSnippetContent({ withReferences });
+ setupTableContent();
+ setupModelContent({ withReferences });
+ setupSegmentContent({ withReferences });
+ setupMetricContent({ withReferences });
+ setupSnippetContent({ withReferences });
+}
+
+function setupTableContent() {
+ H.getTableId({ name: TABLE_NAME }).then((tableId) => {
+ cy.request("PUT", `/api/table/${tableId}`, {
+ display_name: TABLE_DISPLAY_NAME,
+ description: TABLE_DESCRIPTION,
+ owner_user_id: ADMIN_USER_ID,
+ });
+ });
}
-function createModelContent({
+function setupModelContent({
withReferences = false,
}: {
withReferences?: boolean;
@@ -456,7 +488,7 @@ function createModelContent({
});
}
-function createSegmentContent({
+function setupSegmentContent({
withReferences = false,
}: {
withReferences?: boolean;
@@ -514,7 +546,7 @@ function createSegmentContent({
});
}
-function createMetricContent({
+function setupMetricContent({
withReferences = false,
}: {
withReferences?: boolean;
@@ -572,7 +604,7 @@ function createMetricContent({
});
}
-function createSnippetContent({
+function setupSnippetContent({
withReferences = false,
}: {
withReferences?: boolean;
@@ -1039,28 +1071,42 @@ function checkListSorting({ visibleEntities }: { visibleEntities: string[] }) {
}
function checkSidebar({
- entityName,
- locationName,
- creatorName,
+ title,
+ location,
+ description,
+ owner,
+ createdBy,
+ fields = [],
}: {
- entityName: string;
- locationName?: string;
- creatorName?: string;
+ title: string;
+ location?: string;
+ description?: string;
+ owner?: string;
+ createdBy?: string;
+ fields?: string[];
}) {
+ const Sidebar = H.DependencyDiagnostics.Sidebar;
+
H.DependencyDiagnostics.sidebar().within(() => {
- H.DependencyDiagnostics.Sidebar.header()
- .findByText(entityName)
- .should("be.visible");
- if (locationName) {
- H.DependencyDiagnostics.Sidebar.locationSection()
- .findByText(locationName)
- .should("be.visible");
+ Sidebar.header().findByText(title).should("be.visible");
+ if (location) {
+ Sidebar.locationSection().findByText(location).should("be.visible");
}
- if (creatorName) {
- H.DependencyDiagnostics.Sidebar.creationSection().should(
- "contain.text",
- creatorName,
- );
+ if (description) {
+ Sidebar.infoSection().should("contain.text", description);
+ }
+ if (owner) {
+ Sidebar.infoSection().should("contain.text", owner);
+ }
+ if (createdBy) {
+ Sidebar.infoSection().should("contain.text", createdBy);
+ }
+ if (fields.length > 0) {
+ Sidebar.fieldsSection().within(() => {
+ fields.forEach((field) => {
+ cy.findByText(field).should("be.visible");
+ });
+ });
}
});
}
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
index 1ec98803208..42ed83281c5 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
@@ -148,13 +148,15 @@
(broken-cards-response {})))
(def ^:private entity-keys
- {:table [:name :description :display_name :db_id :db :schema :fields :transform]
+ {:table [:name :description :display_name :db_id :db :schema :fields :transform
+ :owner :owner_user_id :owner_email]
:card [:name :type :display :database_id :view_count :query_type
:created_at :creator :creator_id :description
:result_metadata :last-edit-info
:collection :collection_id :dashboard :dashboard_id :document :document_id]
:snippet [:name :description :created_at :creator :creator_id :collection :collection_id]
- :transform [:name :description :creator :table :last_run]
+ :transform [:name :description :creator :table :last_run
+ :owner :owner_user_id :owner_email]
:dashboard [:name :description :view_count
:created_at :creator :creator_id :last-edit-info
:collection :collection_id
@@ -293,10 +295,12 @@
:card_schema]
:dashboard [:id :name :description :created_at :creator_id :collection_id :view_count]
:document [:id :name :created_at :creator_id :collection_id :view_count]
- :table [:id :name :description :display_name :db_id :schema]
+ :table [:id :name :description :display_name :db_id :schema
+ :owner_user_id :owner_email]
:transform [:id :name :description :creator_id
;; :source has to be selected otherwise the BE won't know what DB it belongs to
- :source]
+ :source
+ :owner_user_id :owner_email]
:snippet [:id :name :description :created_at :creator_id :collection_id]
:sandbox [:id :table_id]
:segment [:id :name :description :created_at :creator_id :table_id]
@@ -546,9 +550,9 @@
(t2/hydrate :creator :dashboard :document [:collection :is_personal])
(->> (map collection.root/hydrate-root-collection))
(revisions/with-last-edit-info :card))
- :table (t2/hydrate entities :fields :db :transform)
+ :table (t2/hydrate entities :fields :db :transform :owner)
:transform (-> entities
- (t2/hydrate :creator :table-with-db-and-fields :last_run :collection)
+ (t2/hydrate :creator :table-with-db-and-fields :last_run :collection :owner)
(->> (map #(collection.root/hydrate-root-collection % (collection.root/hydrated-root-collection :transforms)))))
:dashboard (-> entities
(t2/hydrate :creator [:collection :is_personal])
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index 9306bdef067..bb489d6897c 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -2794,3 +2794,61 @@
card-ids (set (map :id response))]
(is (contains? card-ids (:id dependent-in-personal)))
(is (contains? card-ids (:id dependent-regular))))))))))))
+
+(deftest ^:sequential unreferenced-table-owner-test
+ (testing "GET /api/ee/dependencies/unreferenced - table owner is returned"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-model-cleanup [:model/Dependency]
+ (mt/with-temp [:model/Table {table1-id :id} {:name "User Owned Table - ownertest"
+ :owner_user_id (mt/user->id :crowberto)}
+ :model/Table {table2-id :id} {:name "Email Owned Table - ownertest"
+ :owner_email "[email protected]"}]
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/unreferenced"
+ :types "table" :query "ownertest"
+ :sort_column "name" :sort_direction "asc")]
+ (is (=? {:data [{:id table2-id
+ :type "table"
+ :data {:name "Email Owned Table - ownertest"
+ :owner {:email "[email protected]"}}}
+ {:id table1-id
+ :type "table"
+ :data {:name "User Owned Table - ownertest"
+ :owner {:id (mt/user->id :crowberto)
+ :email "[email protected]"}}}]}
+ response))))))))
+
+(deftest ^:sequential unreferenced-transform-owner-test
+ (testing "GET /api/ee/dependencies/unreferenced - transform owner is returned"
+ (mt/with-premium-features #{:dependencies}
+ (let [mp (mt/metadata-provider)
+ products (lib.metadata/table mp (mt/id :products))]
+ (mt/with-model-cleanup [:model/Dependency]
+ (mt/with-temp [:model/Transform {transform1-id :id} {:name "User Owned Transform - ownertest"
+ :owner_user_id (mt/user->id :crowberto)
+ :source {:type :query
+ :query (lib/query mp products)}
+ :target {:schema "PUBLIC"
+ :name "user_owned_transform_table"}}
+ :model/Transform {transform2-id :id} {:name "Email Owned Transform - ownertest"
+ :owner_email "[email protected]"
+ :source {:type :query
+ :query (lib/query mp products)}
+ :target {:schema "PUBLIC"
+ :name "email_owned_transform_table"}}]
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/unreferenced"
+ :types "transform" :query "ownertest"
+ :sort_column "name" :sort_direction "asc")]
+ (is (=? {:data [{:id transform2-id
+ :type "transform"
+ :data {:name "Email Owned Transform - ownertest"
+ :owner {:email "[email protected]"}}}
+ {:id transform1-id
+ :type "transform"
+ :data {:name "User Owned Transform - ownertest"
+ :owner {:id (mt/user->id :crowberto)
+ :email "[email protected]"}}}]}
+ response)))))))))
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
index 1c3b487e33c..258d856a2b0 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
@@ -11,7 +11,7 @@ import type {
DependencySortOptions,
} from "../../../types";
import {
- canHaveViewCount,
+ canNodeHaveViewCount,
getCardType,
getDependencyType,
} from "../../../utils";
@@ -63,7 +63,7 @@ export function getAvailableSortColumns(
return [
"name",
"location",
- ...(canHaveViewCount(getDependencyType(groupType))
+ ...(canNodeHaveViewCount(getDependencyType(groupType))
? ["view-count" as const]
: []),
];
@@ -72,7 +72,7 @@ export function getAvailableSortColumns(
export function getDefaultSortOptions(
groupType: DependencyGroupType,
): DependencySortOptions {
- return canHaveViewCount(getDependencyType(groupType))
+ return canNodeHaveViewCount(getDependencyType(groupType))
? { column: "view-count", direction: "desc" }
: { column: "name", direction: "asc" };
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
index 32cae5fe72d..f31d27b38e9 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
@@ -3,23 +3,28 @@ import { t } from "ttag";
import { EntityCreationInfo } from "metabase/common/components/EntityCreationInfo";
import { getColumnIcon } from "metabase/common/utils/columns";
import CS from "metabase/css/core/index.css";
-import { Box, FixedSizeIcon, Group, Stack, Title } from "metabase/ui";
+import { getUserName } from "metabase/lib/user";
+import { Box, FixedSizeIcon, Group, Stack, Text, Title } from "metabase/ui";
import * as Lib from "metabase-lib";
import type { DependencyEntry, DependencyNode } from "metabase-types/api";
import {
+ canNodeHaveOwner,
getNodeCreatedAt,
getNodeCreatedBy,
getNodeDescription,
+ getNodeFields,
+ getNodeFieldsLabelWithCount,
getNodeLastEditedAt,
getNodeLastEditedBy,
+ getNodeOwner,
} from "../../../../utils";
import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";
import { GraphExternalLink } from "../../GraphExternalLink";
import { GraphLink } from "../../GraphLink";
import S from "./PanelBody.module.css";
-import { getNodeFields, getNodeFieldsLabel, getNodeTableInfo } from "./utils";
+import { getNodeTableInfo } from "./utils";
type PanelBodyProps = {
node: DependencyNode;
@@ -30,6 +35,7 @@ export function PanelBody({ node, getGraphUrl }: PanelBodyProps) {
return (
<Stack className={S.body} p="lg" gap="lg">
<DescriptionSection node={node} />
+ <OwnerSection node={node} />
<CreatorAndLastEditorSection node={node} />
<TableSection node={node} getGraphUrl={getGraphUrl} />
<FieldsSection node={node} />
@@ -58,6 +64,25 @@ function DescriptionSection({ node }: SectionProps) {
);
}
+function OwnerSection({ node }: SectionProps) {
+ const canHaveOwner = canNodeHaveOwner(node.type);
+ if (!canHaveOwner) {
+ return null;
+ }
+
+ const owner = getNodeOwner(node);
+ return (
+ <Stack gap="xs" lh="1rem">
+ <Title order={6}>{t`Owner`}</Title>
+ {owner != null ? (
+ <Text lh="h4">{getUserName(owner)}</Text>
+ ) : (
+ <Text lh="h4" c="text-secondary">{t`No owner`}</Text>
+ )}
+ </Stack>
+ );
+}
+
function CreatorAndLastEditorSection({ node }: SectionProps) {
const createdAt = getNodeCreatedAt(node);
const createdBy = getNodeCreatedBy(node);
@@ -110,14 +135,14 @@ function TableSection({ node, getGraphUrl }: TableSectionProps) {
function FieldsSection({ node }: SectionProps) {
const fields = getNodeFields(node);
- if (fields.length === 0) {
+ if (fields == null) {
return null;
}
return (
<Stack gap="md" lh="1rem">
<Title className={CS.textWrap} order={6}>
- {getNodeFieldsLabel(fields.length)}
+ {getNodeFieldsLabelWithCount(fields.length)}
</Title>
{fields.map((field, fieldIndex) => {
const fieldTypeInfo = Lib.legacyColumnTypeInfo(field);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.unit.spec.tsx
new file mode 100644
index 00000000000..f0f3bc46a56
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.unit.spec.tsx
@@ -0,0 +1,158 @@
+import { Route } from "react-router";
+
+import { renderWithProviders, screen } from "__support__/ui";
+import * as Urls from "metabase/lib/urls";
+import type { DependencyEntry, DependencyNode } from "metabase-types/api";
+import {
+ createMockCardDependencyNode,
+ createMockCardDependencyNodeData,
+ createMockLastEditInfo,
+ createMockSandboxDependencyNode,
+ createMockTableDependencyNode,
+ createMockTableDependencyNodeData,
+ createMockTransformDependencyNode,
+ createMockTransformDependencyNodeData,
+ createMockUserInfo,
+} from "metabase-types/api/mocks";
+
+import { PanelBody } from "./PanelBody";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockCardDependencyNode() }: SetupOpts = {}) {
+ renderWithProviders(
+ <Route
+ path="/"
+ component={() => <PanelBody node={node} getGraphUrl={getGraphUrl} />}
+ />,
+ { withRouter: true, initialRoute: "/" },
+ );
+}
+
+function getGraphUrl(entry: DependencyEntry) {
+ return Urls.dependencyGraph({ entry });
+}
+
+describe("PanelBody", () => {
+ it("should display the description", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "My card description",
+ }),
+ }),
+ });
+ expect(screen.getByText("My card description")).toBeInTheDocument();
+ });
+
+ it("should display 'No description' when description is empty", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "",
+ }),
+ }),
+ });
+ expect(screen.getByText("No description")).toBeInTheDocument();
+ });
+
+ it("should display the owner for tables", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ owner: createMockUserInfo({
+ id: 1,
+ first_name: "Alice",
+ last_name: "Smith",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByText("Owner")).toBeInTheDocument();
+ expect(screen.getByText("Alice Smith")).toBeInTheDocument();
+ });
+
+ it("should display 'No owner' when owner is not set for tables", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ owner: undefined,
+ }),
+ }),
+ });
+ expect(screen.getByText("Owner")).toBeInTheDocument();
+ expect(screen.getByText("No owner")).toBeInTheDocument();
+ });
+
+ it("should display the owner for transforms", () => {
+ setup({
+ node: createMockTransformDependencyNode({
+ data: createMockTransformDependencyNodeData({
+ owner: createMockUserInfo({
+ id: 2,
+ first_name: "Dan",
+ last_name: "Lee",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByText("Owner")).toBeInTheDocument();
+ expect(screen.getByText("Dan Lee")).toBeInTheDocument();
+ });
+
+ it("should not display owner section for cards", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "Some description",
+ }),
+ }),
+ });
+ expect(screen.queryByText("Owner")).not.toBeInTheDocument();
+ });
+
+ it("should not display owner section for sandboxes", () => {
+ setup({
+ node: createMockSandboxDependencyNode(),
+ });
+ expect(screen.queryByText("Owner")).not.toBeInTheDocument();
+ });
+
+ it("should display creator info", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ creator: createMockUserInfo({
+ first_name: "Bob",
+ last_name: "Jones",
+ common_name: "Bob Jones",
+ }),
+ created_at: "2024-01-15T10:00:00Z",
+ }),
+ }),
+ });
+ expect(
+ screen.getByTestId("entity-creation-info-created"),
+ ).toHaveTextContent(/Bob Jones/);
+ });
+
+ it("should display last edited info", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ "last-edit-info": createMockLastEditInfo({
+ id: 2,
+ first_name: "Carol",
+ last_name: "White",
+ timestamp: "2024-02-20T15:00:00Z",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByTestId("entity-creation-info-edited")).toHaveTextContent(
+ /Carol White/,
+ );
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
index e4287495f31..4d8c5fc5068 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
@@ -1,11 +1,7 @@
-import { msgid, ngettext, t } from "ttag";
+import { t } from "ttag";
import * as Urls from "metabase/lib/urls";
-import type {
- DependencyEntry,
- DependencyNode,
- Field,
-} from "metabase-types/api";
+import type { DependencyEntry, DependencyNode } from "metabase-types/api";
import type { NodeTableInfo } from "./types";
@@ -53,29 +49,3 @@ export function getNodeTableInfo(
: null,
};
}
-
-export function getNodeFields(node: DependencyNode): Field[] {
- switch (node.type) {
- case "card":
- return node.data.result_metadata ?? [];
- case "table":
- return node.data.fields ?? [];
- case "transform":
- case "sandbox":
- return node.data.table?.fields ?? [];
- case "snippet":
- case "dashboard":
- case "document":
- case "segment":
- case "measure":
- return [];
- }
-}
-
-export function getNodeFieldsLabel(fieldCount: number) {
- return ngettext(
- msgid`${fieldCount} field`,
- `${fieldCount} fields`,
- fieldCount,
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
index 032936d04b7..8981a9f2cdd 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
@@ -55,7 +55,7 @@ export function DependencyList({
const [selectedEntry, setSelectedEntry] = useState<DependencyEntry>();
const useListGraphNodesQuery =
- mode === "breaking"
+ mode === "broken"
? useListBreakingGraphNodesQuery
: useListUnreferencedGraphNodesQuery;
@@ -193,6 +193,7 @@ export function DependencyList({
{selectedNode != null && (
<ListSidebar
node={selectedNode}
+ mode={mode}
containerWidth={containerWidth}
onResizeStart={startResizing}
onResizeStop={stopResizing}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
index 54f6396fa16..0224d5d1117 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
@@ -25,7 +25,7 @@ function getNameColumn(
): TreeTableColumnDef<DependencyNode> {
return {
id: "name" satisfies DependencySortColumn,
- header: mode === "breaking" ? t`Dependency` : t`Name`,
+ header: mode === "broken" ? t`Dependency` : t`Name`,
minWidth: 100,
enableSorting: true,
accessorFn: (node) => getNodeLabel(node),
@@ -93,13 +93,13 @@ export function getColumns(
return [
getNameColumn(mode),
getLocationColumn(),
- ...(mode === "breaking" ? [getDependentsErrorsColumn()] : []),
- ...(mode === "breaking" ? [getDependentsWithErrorsColumn()] : []),
+ ...(mode === "broken" ? [getDependentsErrorsColumn()] : []),
+ ...(mode === "broken" ? [getDependentsWithErrorsColumn()] : []),
];
}
export function getColumnWidths(mode: DependencyListMode): number[] {
- if (mode === "breaking") {
+ if (mode === "broken") {
return [0.3, 0.3, 0.3, 0.1];
} else {
return [0.5, 0.5];
@@ -134,7 +134,7 @@ export function getSortingOptions(
}
export function getNotFoundMessage(mode: DependencyListMode) {
- return mode === "breaking"
+ return mode === "broken"
? t`No broken dependencies found`
: t`No unreferenced entities found`;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
index 30628b9bac6..dfe042dedaa 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
@@ -13,7 +13,7 @@ export const ListHeader = memo(function ListHeader() {
const tabs: PaneHeaderTab[] = [
{
label: t`Broken dependencies`,
- to: Urls.breakingDependencies(),
+ to: Urls.brokenDependencies(),
icon: "broken_link",
},
{
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/SidebarDependentsSection.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/BrokenDependentsSection.module.css
similarity index 100%
rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/SidebarDependentsSection.module.css
rename to enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/BrokenDependentsSection.module.css
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/SidebarDependentsSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/BrokenDependentsSection.tsx
similarity index 97%
rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/SidebarDependentsSection.tsx
rename to enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/BrokenDependentsSection.tsx
index 351e2b49206..f74706ad9fa 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/SidebarDependentsSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/BrokenDependentsSection.tsx
@@ -43,20 +43,20 @@ import {
BROKEN_DEPENDENTS_SORT_COLUMNS,
} from "../../constants";
-import S from "./SidebarDependentsSection.module.css";
+import S from "./BrokenDependentsSection.module.css";
import {
getDefaultFilterOptions,
getDefaultSortOptions,
getListRequest,
} from "./utils";
-type SidebarDependentsSectionProps = {
+type BrokenDependentsSectionProps = {
node: DependencyNode;
};
-export function SidebarDependentsSection({
+export function BrokenDependentsSection({
node,
-}: SidebarDependentsSectionProps) {
+}: BrokenDependentsSectionProps) {
const count = getDependentErrorNodesCount(node.dependents_errors ?? []);
const [filterOptions, setFilterOptions] = useState<DependencyFilterOptions>(
getDefaultFilterOptions(),
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/index.ts
new file mode 100644
index 00000000000..2d754cef26c
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/index.ts
@@ -0,0 +1 @@
+export * from "./BrokenDependentsSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/utils.ts
similarity index 100%
rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/utils.ts
rename to enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/BrokenDependentsSection/utils.ts
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/SidebarErrorSection.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.module.css
similarity index 100%
rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/SidebarErrorSection.module.css
rename to enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.module.css
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.tsx
new file mode 100644
index 00000000000..56db668757e
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.tsx
@@ -0,0 +1,127 @@
+import { useClipboard } from "@mantine/hooks";
+import cx from "classnames";
+import { t } from "ttag";
+
+import { CopyButton } from "metabase/common/components/CopyButton";
+import CS from "metabase/css/core/index.css";
+import {
+ ActionIcon,
+ Badge,
+ Box,
+ Card,
+ FixedSizeIcon,
+ Group,
+ Stack,
+ Title,
+ Tooltip,
+} from "metabase/ui";
+import type { DependencyNode } from "metabase-types/api";
+
+import type { DependencyErrorGroup } from "../../../../types";
+import {
+ getDependencyErrorGroups,
+ getDependencyErrors,
+ getErrorTypeLabel,
+} from "../../../../utils";
+
+import S from "./ErrorsSection.module.css";
+
+type ErrorsSectionProps = {
+ node: DependencyNode;
+};
+
+export function ErrorsSection({ node }: ErrorsSectionProps) {
+ const errors = getDependencyErrors(node.dependents_errors ?? []);
+ const errorGroups = getDependencyErrorGroups(errors);
+
+ return (
+ <>
+ {errorGroups.map((group) => (
+ <ErrorGroupSection key={group.type} group={group} />
+ ))}
+ </>
+ );
+}
+
+type ErrorGroupSectionProps = {
+ group: DependencyErrorGroup;
+};
+
+function ErrorGroupSection({ group }: ErrorGroupSectionProps) {
+ const { type, errors } = group;
+ const count = errors.length;
+ const items = errors
+ .map((error) => error.detail)
+ .filter((detail) => detail != null);
+
+ return (
+ <ErrorList
+ title={getErrorTypeLabel(type, count)}
+ items={items}
+ aria-label={getErrorTypeLabel(type)}
+ />
+ );
+}
+
+type ErrorListProps = {
+ title: string;
+ items: string[];
+ "aria-label": string;
+};
+
+function ErrorList({ title, items, "aria-label": ariaLabel }: ErrorListProps) {
+ return (
+ <Stack role="region" aria-label={ariaLabel}>
+ <Group gap="sm" wrap="nowrap">
+ <Badge c="text-selected" bg="error">
+ {items.length}
+ </Badge>
+ <Title order={5}>{title}</Title>
+ </Group>
+ {items.length > 0 && (
+ <Card p={0} shadow="none" withBorder>
+ {items.map((item, itemIndex) => (
+ <ErrorListItem key={itemIndex} item={item} />
+ ))}
+ </Card>
+ )}
+ </Stack>
+ );
+}
+
+type ErrorListItemProps = {
+ item: string;
+};
+
+function ErrorListItem({ item }: ErrorListItemProps) {
+ const clipboard = useClipboard();
+
+ const handleClick = () => {
+ clipboard.copy(item);
+ };
+
+ return (
+ <Tooltip opened={clipboard.copied} label={t`Copied!`}>
+ <Group
+ className={cx(S.item, CS.hoverParent, CS.hoverVisibility)}
+ p="md"
+ justify="space-between"
+ wrap="nowrap"
+ onClick={handleClick}
+ >
+ <Box className={cx(CS.textWrap, CS.textMonospace)} fz="sm" lh="1rem">
+ {item}
+ </Box>
+ <CopyButton
+ className={CS.hoverChild}
+ value={item}
+ target={
+ <ActionIcon aria-label={t`Copy`}>
+ <FixedSizeIcon name="copy" />
+ </ActionIcon>
+ }
+ />
+ </Group>
+ </Tooltip>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.unit.spec.tsx
new file mode 100644
index 00000000000..33fb93e6039
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/ErrorsSection.unit.spec.tsx
@@ -0,0 +1,130 @@
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockAnalysisFindingError,
+ createMockCardDependencyNode,
+} from "metabase-types/api/mocks";
+
+import { ErrorsSection } from "./ErrorsSection";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockCardDependencyNode() }: SetupOpts = {}) {
+ renderWithProviders(<ErrorsSection node={node} />);
+}
+
+describe("ErrorsSection", () => {
+ it("should display missing columns errors", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COLUMN_A",
+ }),
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COLUMN_B",
+ }),
+ ],
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Missing columns" }),
+ ).toBeInTheDocument();
+ expect(screen.getByText("COLUMN_A")).toBeInTheDocument();
+ expect(screen.getByText("COLUMN_B")).toBeInTheDocument();
+ });
+
+ it("should display syntax errors", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "syntax-error",
+ error_detail: "unexpected token",
+ }),
+ ],
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Syntax errors" }),
+ ).toBeInTheDocument();
+ expect(screen.getByText("unexpected token")).toBeInTheDocument();
+ });
+
+ it("should display duplicate column errors", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "duplicate-column",
+ error_detail: "ID",
+ }),
+ ],
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Duplicate columns" }),
+ ).toBeInTheDocument();
+ expect(screen.getByText("ID")).toBeInTheDocument();
+ });
+
+ it("should display error count badges", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COL_1",
+ }),
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COL_2",
+ }),
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COL_3",
+ }),
+ ],
+ }),
+ });
+ expect(screen.getByText("3")).toBeInTheDocument();
+ });
+
+ it("should group errors by type", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "COL_A",
+ }),
+ createMockAnalysisFindingError({
+ error_type: "syntax-error",
+ error_detail: "bad syntax",
+ }),
+ ],
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Missing columns" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("region", { name: "Syntax errors" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should not render anything when there are no errors", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ dependents_errors: [],
+ }),
+ });
+ expect(
+ screen.queryByRole("region", { name: "Missing columns" }),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/index.ts
new file mode 100644
index 00000000000..fb622f1ba1a
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ErrorsSection/index.ts
@@ -0,0 +1 @@
+export * from "./ErrorsSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.module.css
new file mode 100644
index 00000000000..1b2f651934d
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.module.css
@@ -0,0 +1,5 @@
+.item {
+ &:not(:last-child) {
+ border-bottom: 1px solid var(--mb-color-border);
+ }
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.tsx
new file mode 100644
index 00000000000..6ba916baa88
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.tsx
@@ -0,0 +1,79 @@
+import cx from "classnames";
+import { t } from "ttag";
+
+import { getColumnIcon } from "metabase/common/utils/columns";
+import CS from "metabase/css/core/index.css";
+import {
+ Badge,
+ Box,
+ Card,
+ FixedSizeIcon,
+ Group,
+ Stack,
+ Title,
+} from "metabase/ui";
+import * as Lib from "metabase-lib";
+import type { DependencyNode, Field } from "metabase-types/api";
+
+import { getNodeFields, getNodeFieldsLabel } from "../../../../utils";
+
+import S from "./FieldsSection.module.css";
+
+type FieldsSectionProps = {
+ node: DependencyNode;
+};
+
+export function FieldsSection({ node }: FieldsSectionProps) {
+ const fields = getNodeFields(node);
+ if (fields == null) {
+ return null;
+ }
+
+ return (
+ <Stack role="region" aria-label={t`Fields`}>
+ <Group gap="sm" wrap="nowrap">
+ <Badge c="text-selected" bg="brand">
+ {fields.length}
+ </Badge>
+ <Title order={5}>{getNodeFieldsLabel(fields.length)}</Title>
+ </Group>
+ {fields.length > 0 && (
+ <Card p={0} shadow="none" withBorder>
+ {fields.map((field, fieldIndex) => (
+ <FieldListItem key={fieldIndex} field={field} />
+ ))}
+ </Card>
+ )}
+ </Stack>
+ );
+}
+
+type FieldListItemProps = {
+ field: Field;
+};
+
+function FieldListItem({ field }: FieldListItemProps) {
+ const fieldInfo = Lib.legacyColumnTypeInfo(field);
+ const fieldIcon = getColumnIcon(fieldInfo);
+
+ return (
+ <Stack className={S.item} p="md" gap="xs">
+ <Group gap="xs" wrap="nowrap">
+ <FixedSizeIcon name={fieldIcon} c="brand" />
+ <Box className={CS.textWrap} lh="1rem">
+ {field.display_name}
+ </Box>
+ </Group>
+ <Box
+ className={cx(CS.textWrap, CS.textMonospace)}
+ c="text-secondary"
+ ml="md"
+ pl="xs"
+ fz="sm"
+ lh="1rem"
+ >
+ {field.name}
+ </Box>
+ </Stack>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.unit.spec.tsx
new file mode 100644
index 00000000000..cd48526f79b
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/FieldsSection.unit.spec.tsx
@@ -0,0 +1,81 @@
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockField,
+ createMockSegmentDependencyNode,
+ createMockTableDependencyNode,
+ createMockTableDependencyNodeData,
+} from "metabase-types/api/mocks";
+
+import { FieldsSection } from "./FieldsSection";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockTableDependencyNode() }: SetupOpts = {}) {
+ renderWithProviders(<FieldsSection node={node} />);
+}
+
+describe("FieldsSection", () => {
+ it("should display the Fields region", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [createMockField({ name: "id", display_name: "ID" })],
+ }),
+ }),
+ });
+ expect(screen.getByRole("region", { name: "Fields" })).toBeInTheDocument();
+ });
+
+ it("should display field names", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [
+ createMockField({ name: "id", display_name: "ID" }),
+ createMockField({ name: "created_at", display_name: "Created At" }),
+ ],
+ }),
+ }),
+ });
+ expect(screen.getByText("ID")).toBeInTheDocument();
+ expect(screen.getByText("id")).toBeInTheDocument();
+ expect(screen.getByText("Created At")).toBeInTheDocument();
+ expect(screen.getByText("created_at")).toBeInTheDocument();
+ });
+
+ it("should display field count badge", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [
+ createMockField({ name: "id", display_name: "ID" }),
+ createMockField({ name: "name", display_name: "Name" }),
+ createMockField({ name: "email", display_name: "Email" }),
+ ],
+ }),
+ }),
+ });
+ expect(screen.getByText("3")).toBeInTheDocument();
+ });
+
+ it("should not render for an entity without fields", () => {
+ setup({ node: createMockSegmentDependencyNode() });
+ expect(
+ screen.queryByRole("region", { name: "Fields" }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("should display zero count when there are no fields", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [],
+ }),
+ }),
+ });
+ expect(screen.getByText("0")).toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/index.ts
new file mode 100644
index 00000000000..a2da318ab4c
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/FieldsSection/index.ts
@@ -0,0 +1 @@
+export * from "./FieldsSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.tsx
new file mode 100644
index 00000000000..0879df4b669
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.tsx
@@ -0,0 +1,119 @@
+import type { ReactNode } from "react";
+import { Link } from "react-router";
+import { t } from "ttag";
+
+import { DateTime } from "metabase/common/components/DateTime";
+import CS from "metabase/css/core/index.css";
+import * as Urls from "metabase/lib/urls";
+import { getUserName } from "metabase/lib/user";
+import { Anchor, Box, Card, FixedSizeIcon, Group, Stack } from "metabase/ui";
+import type { DependencyNode } from "metabase-types/api";
+
+import {
+ canNodeHaveOwner,
+ getNodeCreatedAt,
+ getNodeCreatedBy,
+ getNodeDescription,
+ getNodeLastEditedAt,
+ getNodeLastEditedBy,
+ getNodeOwner,
+ getNodeTransform,
+} from "../../../../utils";
+import S from "../ListSidebar.module.css";
+
+type InfoSectionProps = {
+ node: DependencyNode;
+};
+
+export function InfoSection({ node }: InfoSectionProps) {
+ const description = getNodeDescription(node);
+ const owner = getNodeOwner(node);
+ const canHaveOwner = canNodeHaveOwner(node.type);
+ const transform = getNodeTransform(node);
+ const createdBy = getNodeCreatedBy(node);
+ const createdAt = getNodeCreatedAt(node);
+ const editedBy = getNodeLastEditedBy(node);
+ const editedAt = getNodeLastEditedAt(node);
+
+ if (
+ description == null &&
+ !canHaveOwner &&
+ transform == null &&
+ (createdAt == null || createdBy == null) &&
+ (editedAt == null || editedBy == null)
+ ) {
+ return null;
+ }
+
+ return (
+ <Card p={0} shadow="none" withBorder role="region" aria-label={t`Info`}>
+ {description != null && (
+ <InfoSectionItem label={t`Description`}>
+ {description.length > 0 ? (
+ <Box className={CS.textWrap}>{description}</Box>
+ ) : (
+ <Box c="text-secondary">{t`No description`}</Box>
+ )}
+ </InfoSectionItem>
+ )}
+ {canHaveOwner && (
+ <InfoSectionItem label={t`Owner`}>
+ {owner != null ? (
+ <Box className={CS.textWrap}>{getUserName(owner)}</Box>
+ ) : (
+ <Box c="text-secondary">{t`No owner`}</Box>
+ )}
+ </InfoSectionItem>
+ )}
+ {transform != null && (
+ <InfoSectionItem label={t`Generated by`}>
+ <Anchor
+ component={Link}
+ className={CS.textWrap}
+ to={Urls.transform(transform.id)}
+ target="_blank"
+ >
+ <Group gap="sm" wrap="nowrap">
+ <FixedSizeIcon name="transform" />
+ {transform.name}
+ </Group>
+ </Anchor>
+ </InfoSectionItem>
+ )}
+ {createdBy != null && createdAt != null && (
+ <InfoSectionItem label={t`Created by`} date={createdAt}>
+ <Box className={CS.textWrap}>{getUserName(createdBy)}</Box>
+ </InfoSectionItem>
+ )}
+ {editedBy != null && editedAt != null && (
+ <InfoSectionItem label={t`Last edited by`} date={editedAt}>
+ <Box className={CS.textWrap}>{getUserName(editedBy)}</Box>
+ </InfoSectionItem>
+ )}
+ </Card>
+ );
+}
+
+type InfoSectionItemProps = {
+ label: string;
+ date?: string;
+ children?: ReactNode;
+};
+
+function InfoSectionItem({ label, date, children }: InfoSectionItemProps) {
+ return (
+ <Stack className={S.section} p="md" gap="xs">
+ <Box className={CS.textWrap} c="text-secondary" fz="sm" lh="h5">
+ {label}
+ </Box>
+ <Group lh="h4" justify="space-between" wrap="nowrap">
+ {children}
+ {date != null && (
+ <Box c="text-secondary">
+ <DateTime className={CS.textNoWrap} value={date} unit="day" />
+ </Box>
+ )}
+ </Group>
+ </Stack>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.unit.spec.tsx
new file mode 100644
index 00000000000..3cbec68b7aa
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/InfoSection.unit.spec.tsx
@@ -0,0 +1,159 @@
+import { Route } from "react-router";
+
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockCardDependencyNode,
+ createMockCardDependencyNodeData,
+ createMockLastEditInfo,
+ createMockSandboxDependencyNode,
+ createMockTableDependencyNode,
+ createMockTableDependencyNodeData,
+ createMockTransform,
+ createMockTransformDependencyNode,
+ createMockTransformDependencyNodeData,
+ createMockUserInfo,
+} from "metabase-types/api/mocks";
+
+import { InfoSection } from "./InfoSection";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockCardDependencyNode() }: SetupOpts = {}) {
+ renderWithProviders(
+ <Route path="/" component={() => <InfoSection node={node} />} />,
+ { withRouter: true, initialRoute: "/" },
+ );
+}
+
+describe("InfoSection", () => {
+ it("should display the Info region", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "Some description",
+ }),
+ }),
+ });
+ expect(screen.getByRole("region", { name: "Info" })).toBeInTheDocument();
+ });
+
+ it("should display the description", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "My card description",
+ }),
+ }),
+ });
+ expect(screen.getByText("My card description")).toBeInTheDocument();
+ });
+
+ it("should display 'No description' when description is empty", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: null,
+ }),
+ }),
+ });
+ expect(screen.getByText("No description")).toBeInTheDocument();
+ });
+
+ it("should display the owner for tables", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ owner: createMockUserInfo({
+ id: 1,
+ first_name: "Alice",
+ last_name: "Smith",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByText("Alice Smith")).toBeInTheDocument();
+ });
+
+ it("should display 'No owner' when owner is not set for tables", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ owner: undefined,
+ }),
+ }),
+ });
+ expect(screen.getByText("No owner")).toBeInTheDocument();
+ });
+
+ it("should display the transform link for tables with a transform", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ transform: createMockTransform({ id: 1, name: "My Transform" }),
+ }),
+ }),
+ });
+ expect(screen.getByText("My Transform")).toBeInTheDocument();
+ });
+
+ it("should display creator info", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ creator: createMockUserInfo({
+ first_name: "Bob",
+ last_name: "Jones",
+ common_name: "Bob Jones",
+ }),
+ created_at: "2024-01-15T10:00:00Z",
+ }),
+ }),
+ });
+ expect(screen.getByText("Bob Jones")).toBeInTheDocument();
+ expect(screen.getByText("Created by")).toBeInTheDocument();
+ });
+
+ it("should display last edited info", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ "last-edit-info": createMockLastEditInfo({
+ id: 2,
+ first_name: "Carol",
+ last_name: "White",
+ timestamp: "2024-02-20T15:00:00Z",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByText("Carol White")).toBeInTheDocument();
+ expect(screen.getByText("Last edited by")).toBeInTheDocument();
+ });
+
+ it("should not render for nodes without any info", () => {
+ setup({
+ node: createMockSandboxDependencyNode(),
+ });
+ expect(
+ screen.queryByRole("region", { name: "Info" }),
+ ).not.toBeInTheDocument();
+ });
+
+ it("should display owner label for transforms", () => {
+ setup({
+ node: createMockTransformDependencyNode({
+ data: createMockTransformDependencyNodeData({
+ owner: createMockUserInfo({
+ id: 2,
+ first_name: "Dan",
+ last_name: "Lee",
+ }),
+ }),
+ }),
+ });
+ expect(screen.getByText("Dan Lee")).toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/index.ts
new file mode 100644
index 00000000000..a8923b5ca21
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/InfoSection/index.ts
@@ -0,0 +1 @@
+export * from "./InfoSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
index 3abf38a5c3d..ee1fc9ca949 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
@@ -3,19 +3,20 @@ import { memo } from "react";
import { Stack } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
-import { getDependencyErrorGroups, getDependencyErrors } from "../../../utils";
+import type { DependencyListMode } from "../types";
+import { BrokenDependentsSection } from "./BrokenDependentsSection";
+import { ErrorsSection } from "./ErrorsSection";
+import { FieldsSection } from "./FieldsSection";
+import { InfoSection } from "./InfoSection";
import S from "./ListSidebar.module.css";
-import { SidebarCreationSection } from "./SidebarCreationSection";
-import { SidebarDependentsSection } from "./SidebarDependentsSection";
-import { SidebarErrorSection } from "./SidebarErrorSection";
+import { LocationSection } from "./LocationSection";
import { SidebarHeader } from "./SidebarHeader";
-import { SidebarLocationSection } from "./SidebarLocationSection";
import { SidebarResizableBox } from "./SidebarResizableBox";
-import { SidebarTransformSection } from "./SidebarTransformSection";
type ListSidebarProps = {
node: DependencyNode;
+ mode: DependencyListMode;
containerWidth: number;
onResizeStart: () => void;
onResizeStop: () => void;
@@ -24,14 +25,12 @@ type ListSidebarProps = {
export const ListSidebar = memo(function ListSidebar({
node,
+ mode,
containerWidth,
onResizeStart,
onResizeStop,
onClose,
}: ListSidebarProps) {
- const errors = getDependencyErrors(node.dependents_errors ?? []);
- const errorGroups = getDependencyErrorGroups(errors);
-
return (
<SidebarResizableBox
containerWidth={containerWidth}
@@ -47,18 +46,12 @@ export const ListSidebar = memo(function ListSidebar({
>
<Stack gap="lg">
<SidebarHeader node={node} onClose={onClose} />
- <SidebarLocationSection node={node} />
- <SidebarTransformSection node={node} />
- <SidebarCreationSection node={node} />
+ <LocationSection node={node} />
+ <InfoSection node={node} />
</Stack>
- {errorGroups.map((errorGroup) => (
- <SidebarErrorSection
- key={errorGroup.type}
- type={errorGroup.type}
- errors={errorGroup.errors}
- />
- ))}
- <SidebarDependentsSection node={node} />
+ {mode === "broken" && <ErrorsSection node={node} />}
+ {mode === "broken" && <BrokenDependentsSection node={node} />}
+ {mode === "unreferenced" && <FieldsSection node={node} />}
</Stack>
</SidebarResizableBox>
);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.unit.spec.tsx
new file mode 100644
index 00000000000..f23942d268a
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.unit.spec.tsx
@@ -0,0 +1,131 @@
+import { Route } from "react-router";
+
+import { setupListBrokenGraphNodesEndpoint } from "__support__/server-mocks";
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockAnalysisFindingError,
+ createMockCardDependencyNode,
+ createMockCardDependencyNodeData,
+ createMockTableDependencyNode,
+ createMockTableDependencyNodeData,
+} from "metabase-types/api/mocks";
+
+import type { DependencyListMode } from "../types";
+
+import { ListSidebar } from "./ListSidebar";
+
+type SetupOpts = {
+ node?: DependencyNode;
+ mode?: DependencyListMode;
+};
+
+function setup({
+ node = createMockCardDependencyNode(),
+ mode = "broken",
+}: SetupOpts = {}) {
+ const onResizeStart = jest.fn();
+ const onResizeStop = jest.fn();
+ const onClose = jest.fn();
+
+ setupListBrokenGraphNodesEndpoint([]);
+ renderWithProviders(
+ <Route
+ path="/"
+ component={() => (
+ <ListSidebar
+ node={node}
+ mode={mode}
+ containerWidth={1000}
+ onResizeStart={onResizeStart}
+ onResizeStop={onResizeStop}
+ onClose={onClose}
+ />
+ )}
+ />,
+ { withRouter: true, initialRoute: "/" },
+ );
+
+ return { onResizeStart, onResizeStop, onClose };
+}
+
+describe("ListSidebar", () => {
+ it("should render the sidebar container", () => {
+ setup();
+ expect(screen.getByTestId("dependency-list-sidebar")).toBeInTheDocument();
+ });
+
+ it("should render the sidebar header with node name", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ name: "Test Card" }),
+ }),
+ });
+ expect(screen.getByText("Test Card")).toBeInTheDocument();
+ });
+
+ it("should render the location section when available", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: { id: 1, name: "My Dashboard" },
+ }),
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Location" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should render the info section when available", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "A description",
+ }),
+ }),
+ });
+ expect(screen.getByRole("region", { name: "Info" })).toBeInTheDocument();
+ });
+
+ it("should render errors section in broken mode", () => {
+ setup({
+ mode: "broken",
+ node: createMockCardDependencyNode({
+ dependents_errors: [
+ createMockAnalysisFindingError({
+ error_type: "missing-column",
+ error_detail: "MISSING_COL",
+ }),
+ ],
+ }),
+ });
+ expect(screen.getByText("MISSING_COL")).toBeInTheDocument();
+ });
+
+ it("should render fields section in unreferenced mode", () => {
+ setup({
+ mode: "unreferenced",
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [],
+ }),
+ }),
+ });
+ expect(screen.getByRole("region", { name: "Fields" })).toBeInTheDocument();
+ });
+
+ it("should not render fields section in broken mode", () => {
+ setup({
+ mode: "broken",
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ fields: [],
+ }),
+ }),
+ });
+ expect(
+ screen.queryByRole("region", { name: "Fields" }),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/SidebarLocationSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.tsx
similarity index 90%
rename from enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/SidebarLocationSection.tsx
rename to enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.tsx
index 307bfdde0f9..bc953f77089 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/SidebarLocationSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.tsx
@@ -7,11 +7,11 @@ import type { DependencyNode } from "metabase-types/api";
import { getNodeLocationInfo } from "../../../../utils";
-type SidebarLocationSectionProps = {
+type LocationSectionProps = {
node: DependencyNode;
};
-export function SidebarLocationSection({ node }: SidebarLocationSectionProps) {
+export function LocationSection({ node }: LocationSectionProps) {
const locationInfo = getNodeLocationInfo(node);
if (locationInfo == null) {
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.unit.spec.tsx
new file mode 100644
index 00000000000..e6af040be03
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/LocationSection.unit.spec.tsx
@@ -0,0 +1,73 @@
+import { Route } from "react-router";
+
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockCardDependencyNode,
+ createMockCardDependencyNodeData,
+ createMockDatabase,
+ createMockTableDependencyNode,
+ createMockTableDependencyNodeData,
+ createMockTransformDependencyNode,
+} from "metabase-types/api/mocks";
+
+import { LocationSection } from "./LocationSection";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockCardDependencyNode() }: SetupOpts = {}) {
+ renderWithProviders(
+ <Route path="/" component={() => <LocationSection node={node} />} />,
+ { withRouter: true, initialRoute: "/" },
+ );
+}
+
+describe("LocationSection", () => {
+ it("should display the location region", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: { id: 1, name: "My Dashboard" },
+ }),
+ }),
+ });
+ expect(
+ screen.getByRole("region", { name: "Location" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should display the dashboard name for cards in a dashboard", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: { id: 1, name: "My Dashboard" },
+ }),
+ }),
+ });
+ expect(screen.getByText("My Dashboard")).toBeInTheDocument();
+ });
+
+ it("should display the database and schema for tables", () => {
+ setup({
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ db: createMockDatabase({ id: 1, name: "My Database" }),
+ schema: "public",
+ }),
+ }),
+ });
+ expect(screen.getByText("My Database")).toBeInTheDocument();
+ expect(screen.getByText("public")).toBeInTheDocument();
+ });
+
+ it("should not render for nodes without location", () => {
+ setup({
+ node: createMockTransformDependencyNode(),
+ });
+ expect(
+ screen.queryByRole("region", { name: "Location" }),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/index.ts
new file mode 100644
index 00000000000..724269fff73
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/LocationSection/index.ts
@@ -0,0 +1 @@
+export * from "./LocationSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/SidebarCreationSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/SidebarCreationSection.tsx
deleted file mode 100644
index 7b57a72abcb..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/SidebarCreationSection.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-import { t } from "ttag";
-
-import { DateTime } from "metabase/common/components/DateTime";
-import CS from "metabase/css/core/index.css";
-import { getUserName } from "metabase/lib/user";
-import { Box, Card, Group, Stack } from "metabase/ui";
-import type { DependencyNode } from "metabase-types/api";
-
-import {
- getNodeCreatedAt,
- getNodeCreatedBy,
- getNodeLastEditedAt,
- getNodeLastEditedBy,
-} from "../../../../utils";
-import S from "../ListSidebar.module.css";
-
-type SidebarCreationSectionProps = {
- node: DependencyNode;
-};
-
-export function SidebarCreationSection({ node }: SidebarCreationSectionProps) {
- const createdBy = getNodeCreatedBy(node);
- const createdAt = getNodeCreatedAt(node);
- const editedBy = getNodeLastEditedBy(node);
- const editedAt = getNodeLastEditedAt(node);
- const hasCreatedInfo = createdBy != null && createdAt != null;
- const hasEditedInfo = editedBy != null && editedAt != null;
-
- if (!hasCreatedInfo && !hasEditedInfo) {
- return null;
- }
-
- return (
- <Card
- p={0}
- shadow="none"
- withBorder
- role="region"
- aria-label={t`Creator and last editor`}
- >
- {createdBy != null && createdAt != null && (
- <UserSection
- label={t`Created by`}
- name={getUserName(createdBy)}
- date={createdAt}
- />
- )}
- {editedBy != null && editedAt != null && (
- <UserSection
- label={t`Last edited by`}
- name={getUserName(editedBy)}
- date={editedAt}
- />
- )}
- </Card>
- );
-}
-
-type UserSectionProps = {
- label: string;
- name: string | undefined;
- date: string;
-};
-
-function UserSection({ label, name, date }: UserSectionProps) {
- return (
- <Stack className={S.section} c="text-secondary" p="md" gap="xs">
- <Box className={CS.textWrap} fz="sm" lh="h5">
- {label}
- </Box>
- <Group lh="h4" justify="space-between" wrap="nowrap">
- <Box className={CS.textWrap} c="text-primary">
- {name}
- </Box>
- <DateTime className={CS.textNoWrap} value={date} unit="day" />
- </Group>
- </Stack>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/index.ts
deleted file mode 100644
index 608f16613f9..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./SidebarCreationSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/index.ts
deleted file mode 100644
index ca7719357d0..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./SidebarDependentsSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/SidebarErrorSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/SidebarErrorSection.tsx
deleted file mode 100644
index 672cdc5e2df..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/SidebarErrorSection.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-import { useClipboard } from "@mantine/hooks";
-import cx from "classnames";
-import { t } from "ttag";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-import CS from "metabase/css/core/index.css";
-import {
- ActionIcon,
- Badge,
- Box,
- Card,
- FixedSizeIcon,
- Group,
- Stack,
- Title,
- Tooltip,
-} from "metabase/ui";
-import type { AnalysisFindingErrorType } from "metabase-types/api";
-
-import type { DependencyError } from "../../../../types";
-import { getErrorTypeLabel } from "../../../../utils";
-
-import S from "./SidebarErrorSection.module.css";
-
-type SidebarErrorSectionProps = {
- type: AnalysisFindingErrorType;
- errors: DependencyError[];
-};
-
-export function SidebarErrorSection({
- type,
- errors,
-}: SidebarErrorSectionProps) {
- const count = errors.length;
- const title = getErrorTypeLabel(type, count);
- const details = errors
- .map((error) => error.detail)
- .filter((detail) => detail != null);
-
- return (
- <Stack role="region" aria-label={getErrorTypeLabel(type)}>
- <Group gap="sm" wrap="nowrap">
- <Badge c="text-selected" bg="error">
- {count}
- </Badge>
- <Title order={5}>{title}</Title>
- </Group>
- {details.length > 0 && (
- <Card p={0} shadow="none" withBorder>
- {details.map((detail, detailIndex) => (
- <ErrorItem key={detailIndex} detail={detail} />
- ))}
- </Card>
- )}
- </Stack>
- );
-}
-
-type ErrorItemProps = {
- detail: string;
-};
-
-function ErrorItem({ detail }: ErrorItemProps) {
- const clipboard = useClipboard();
-
- const handleClick = () => {
- clipboard.copy(detail);
- };
-
- return (
- <Tooltip opened={clipboard.copied} label={t`Copied!`}>
- <Group
- className={cx(S.item, CS.hoverParent, CS.hoverVisibility)}
- p="md"
- justify="space-between"
- wrap="nowrap"
- onClick={handleClick}
- >
- <Box className={cx(CS.textWrap, CS.textMonospace)} fz="sm" lh="1rem">
- {detail}
- </Box>
- <CopyButton
- className={CS.hoverChild}
- value={detail}
- target={
- <ActionIcon aria-label={t`Copy`}>
- <FixedSizeIcon name="copy" />
- </ActionIcon>
- }
- />
- </Group>
- </Tooltip>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/index.ts
deleted file mode 100644
index 16319473f0e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./SidebarErrorSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.unit.spec.tsx
new file mode 100644
index 00000000000..42f808fda3a
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.unit.spec.tsx
@@ -0,0 +1,71 @@
+import { Route } from "react-router";
+
+import { renderWithProviders, screen } from "__support__/ui";
+import type { DependencyNode } from "metabase-types/api";
+import {
+ createMockCardDependencyNode,
+ createMockCardDependencyNodeData,
+ createMockTransformDependencyNode,
+ createMockTransformDependencyNodeData,
+} from "metabase-types/api/mocks";
+
+import { SidebarHeader } from "./SidebarHeader";
+
+type SetupOpts = {
+ node?: DependencyNode;
+};
+
+function setup({ node = createMockCardDependencyNode() }: SetupOpts = {}) {
+ const onClose = jest.fn();
+ renderWithProviders(
+ <Route
+ path="/"
+ component={() => <SidebarHeader node={node} onClose={onClose} />}
+ />,
+ { withRouter: true, initialRoute: "/" },
+ );
+ return { onClose };
+}
+
+describe("SidebarHeader", () => {
+ it("should display the node name", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ name: "My Question" }),
+ }),
+ });
+ expect(screen.getByText("My Question")).toBeInTheDocument();
+ });
+
+ it("should display a close button", () => {
+ setup();
+ expect(screen.getByRole("button", { name: "Close" })).toBeInTheDocument();
+ });
+
+ it("should display a dependency graph link", () => {
+ setup();
+ expect(
+ screen.getByRole("link", { name: "View in dependency graph" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should display an external link for nodes with links", () => {
+ setup({
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ type: "question" }),
+ }),
+ });
+ expect(
+ screen.getByRole("link", { name: "View this question" }),
+ ).toBeInTheDocument();
+ });
+
+ it("should display the transform name", () => {
+ setup({
+ node: createMockTransformDependencyNode({
+ data: createMockTransformDependencyNodeData({ name: "My Transform" }),
+ }),
+ });
+ expect(screen.getByText("My Transform")).toBeInTheDocument();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/index.ts
deleted file mode 100644
index a1551331f29..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./SidebarLocationSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/SidebarTransformSection.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/SidebarTransformSection.tsx
deleted file mode 100644
index 406375d1e5e..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/SidebarTransformSection.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import { Link } from "react-router";
-import { t } from "ttag";
-
-import CS from "metabase/css/core/index.css";
-import * as Urls from "metabase/lib/urls";
-import { Anchor, Box, Card, FixedSizeIcon, Group, Stack } from "metabase/ui";
-import type { DependencyNode } from "metabase-types/api";
-
-import { getNodeTransform } from "../../../../utils";
-import S from "../ListSidebar.module.css";
-
-type SidebarTransformSectionProps = {
- node: DependencyNode;
-};
-
-export function SidebarTransformSection({
- node,
-}: SidebarTransformSectionProps) {
- const transform = getNodeTransform(node);
-
- if (transform == null) {
- return null;
- }
-
- return (
- <Card
- p={0}
- shadow="none"
- withBorder
- role="region"
- aria-label={t`Transform`}
- >
- <Stack className={S.section} c="text-secondary" p="md" gap="xs">
- <Box fz="sm" lh="h5">
- {t`Generated by`}
- </Box>
- <Box lh="h4" c="text-primary">
- <Anchor
- component={Link}
- className={CS.textWrap}
- to={Urls.transform(transform.id)}
- target="_blank"
- >
- <Group gap="sm" wrap="nowrap">
- <FixedSizeIcon name="transform" />
- {transform.name}
- </Group>
- {}
- </Anchor>
- </Box>
- </Stack>
- </Card>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/index.ts
deleted file mode 100644
index b1f23ea7a46..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformSection/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./SidebarTransformSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts
index 3b8d8071e19..e661edc4817 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts
@@ -1,4 +1,4 @@
-export type DependencyListMode = "breaking" | "unreferenced";
+export type DependencyListMode = "broken" | "unreferenced";
export type DependencyListParamsOptions = {
withSetLastUsedParams?: boolean;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
index 26c28144fd0..836a35470ef 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
@@ -10,7 +10,7 @@ import { BROKEN_GROUP_TYPES, UNREFERENCED_GROUP_TYPES } from "./constants";
import type { DependencyListMode } from "./types";
export function getAvailableGroupTypes(mode: DependencyListMode) {
- return mode === "breaking" ? BROKEN_GROUP_TYPES : UNREFERENCED_GROUP_TYPES;
+ return mode === "broken" ? BROKEN_GROUP_TYPES : UNREFERENCED_GROUP_TYPES;
}
export function getFilterOptions(
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/FilterOptionsPicker/FilterOptionsPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/FilterOptionsPicker/FilterOptionsPicker.tsx
index ed23cc091e1..d09b235f77f 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/FilterOptionsPicker/FilterOptionsPicker.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/FilterOptionsPicker/FilterOptionsPicker.tsx
@@ -40,6 +40,7 @@ export function FilterOptionsPicker({
<Popover opened={isOpened} onDismiss={close}>
<Popover.Target>
<Indicator
+ size={8}
offset={isCompact ? 6 : 12}
disabled={hasDefaultFilterOptions}
>
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx
index b60d76917d1..dabfb29d48e 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx
@@ -81,7 +81,7 @@ export function DependencyListPage({
export function BrokenDependencyListPage({
location,
}: DependencyListPageProps) {
- return <DependencyListPage mode="breaking" location={location} />;
+ return <DependencyListPage mode="broken" location={location} />;
}
export function UnreferencedDependencyListPage({
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.unit.spec.tsx
index 0cc0d1a6254..826bbb04164 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.unit.spec.tsx
@@ -51,7 +51,7 @@ type SetupOpts = {
};
function setup({
- mode = "breaking",
+ mode = "broken",
location = { query: {} },
nodes = [],
total,
@@ -59,7 +59,7 @@ function setup({
}: SetupOpts) {
const path = getPageUrl(mode, {});
- if (mode === "breaking") {
+ if (mode === "broken") {
setupListBreakingGraphNodesEndpoint(
createMockListBrokenGraphNodesResponse({
data: nodes,
@@ -129,7 +129,7 @@ describe("DependencyListPage", () => {
describe("URL parameters", () => {
it("should set the group_types parameter when not all types are selected", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: { group_types: ["table", "question", "model"] } },
});
@@ -146,7 +146,7 @@ describe("DependencyListPage", () => {
it("should not set the group_types parameter when all types are selected", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: { group_types: ["table", "question"] } },
});
@@ -161,7 +161,7 @@ describe("DependencyListPage", () => {
it("should set the include_personal_collections parameter when it is unchecked", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: { include_personal_collections: "true" } },
});
@@ -181,7 +181,7 @@ describe("DependencyListPage", () => {
it("should not set the include_personal_collections parameter when it is checked", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: { include_personal_collections: "false" } },
});
@@ -199,7 +199,7 @@ describe("DependencyListPage", () => {
it("should set the page parameter when navigating to the next page and it is not the first page", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
total: 50,
location: { query: {} },
@@ -213,7 +213,7 @@ describe("DependencyListPage", () => {
it("should set the page parameter when navigating to the previous page and it is not the first page", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
total: 50,
location: { query: { page: "2" } },
@@ -227,7 +227,7 @@ describe("DependencyListPage", () => {
it("should not set the page parameter when it is the first page", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: { page: "1" } },
total: 50,
@@ -305,7 +305,7 @@ describe("DependencyListPage", () => {
it("should update URL with last used parameters when there is no query string", async () => {
const { history } = setup({
- mode: "breaking",
+ mode: "broken",
nodes: CARD_NODES,
location: { query: {} },
lastUsedParams: { group_types: ["table", "question"] },
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
index 6d3c4dcd5bc..bec88515036 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts
@@ -21,8 +21,8 @@ export function getPageUrl(
mode: DependencyListMode,
params: Urls.DependencyListParams,
): string {
- return mode === "breaking"
- ? Urls.breakingDependencies(params)
+ return mode === "broken"
+ ? Urls.brokenDependencies(params)
: Urls.unreferencedDependencies(params);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
index 4c90ec0a65d..b5d948a27ca 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
@@ -13,8 +13,8 @@ export function getDataStudioDependencyRoutes() {
export function getDataStudioDependencyDiagnosticsRoutes() {
return (
<>
- <IndexRedirect to="breaking" />
- <Route path="breaking" component={BrokenDependencyListPage} />
+ <IndexRedirect to="broken" />
+ <Route path="broken" component={BrokenDependencyListPage} />
<Route path="unreferenced" component={UnreferencedDependencyListPage} />
</>
);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
index 5dced117cde..22b67080386 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
@@ -1,6 +1,7 @@
import { c, msgid, ngettext, t } from "ttag";
import * as Urls from "metabase/lib/urls";
+import type { NamedUser } from "metabase/lib/user";
import type { IconName } from "metabase/ui";
import visualizations from "metabase/visualizations";
import type {
@@ -12,9 +13,8 @@ import type {
DependencyId,
DependencyNode,
DependencyType,
- LastEditInfo,
+ Field,
Transform,
- UserInfo,
VisualizationDisplay,
} from "metabase-types/api";
@@ -333,6 +333,26 @@ export function getNodeLocationInfo(
}
}
+export function getNodeOwner(node: DependencyNode): NamedUser | null {
+ switch (node.type) {
+ case "table":
+ case "transform":
+ return node.data.owner ?? null;
+ default:
+ return null;
+ }
+}
+
+export function canNodeHaveOwner(type: DependencyType): boolean {
+ switch (type) {
+ case "table":
+ case "transform":
+ return true;
+ default:
+ return false;
+ }
+}
+
export function getNodeCreatedAt(node: DependencyNode): string | null {
switch (node.type) {
case "card":
@@ -343,13 +363,12 @@ export function getNodeCreatedAt(node: DependencyNode): string | null {
case "snippet":
case "transform":
return node.data.created_at;
- case "table":
- case "sandbox":
+ default:
return null;
}
}
-export function getNodeCreatedBy(node: DependencyNode): UserInfo | null {
+export function getNodeCreatedBy(node: DependencyNode): NamedUser | null {
switch (node.type) {
case "card":
case "dashboard":
@@ -359,8 +378,7 @@ export function getNodeCreatedBy(node: DependencyNode): UserInfo | null {
case "snippet":
case "transform":
return node.data.creator ?? null;
- case "table":
- case "sandbox":
+ default:
return null;
}
}
@@ -370,45 +388,28 @@ export function getNodeLastEditedAt(node: DependencyNode): string | null {
case "card":
case "dashboard":
return node.data["last-edit-info"]?.timestamp ?? null;
- case "segment":
- case "measure":
- case "table":
- case "transform":
- case "snippet":
- case "document":
- case "sandbox":
+ default:
return null;
}
}
-export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {
+export function getNodeLastEditedBy(node: DependencyNode): NamedUser | null {
switch (node.type) {
case "card":
case "dashboard":
return node.data["last-edit-info"] ?? null;
- case "segment":
- case "measure":
- case "table":
- case "transform":
- case "snippet":
- case "document":
- case "sandbox":
+ default:
return null;
}
}
-export function canHaveViewCount(type: DependencyType): boolean {
+export function canNodeHaveViewCount(type: DependencyType): boolean {
switch (type) {
case "card":
case "dashboard":
case "document":
return true;
- case "table":
- case "transform":
- case "snippet":
- case "sandbox":
- case "segment":
- case "measure":
+ default:
return false;
}
}
@@ -418,13 +419,8 @@ export function getNodeViewCount(node: DependencyNode): number | null {
case "card":
case "dashboard":
case "document":
- return node.data.view_count ?? null;
- case "table":
- case "measure":
- case "transform":
- case "snippet":
- case "sandbox":
- case "segment":
+ return node.data.view_count ?? 0;
+ default:
return null;
}
}
@@ -440,6 +436,36 @@ export function getNodeTransform(node: DependencyNode): Transform | null {
return null;
}
+export function getNodeFields(node: DependencyNode): Field[] | null {
+ switch (node.type) {
+ case "card":
+ return node.data.result_metadata ?? [];
+ case "table":
+ return node.data.fields ?? [];
+ case "transform":
+ case "sandbox":
+ return node.data.table?.fields ?? [];
+ case "snippet":
+ case "dashboard":
+ case "document":
+ case "segment":
+ case "measure":
+ return null;
+ }
+}
+
+export function getNodeFieldsLabel(fieldCount = 0) {
+ return fieldCount === 1 ? t`Field` : t`Fields`;
+}
+
+export function getNodeFieldsLabelWithCount(fieldCount: number) {
+ return ngettext(
+ msgid`${fieldCount} field`,
+ `${fieldCount} fields`,
+ fieldCount,
+ );
+}
+
export function getCardType(groupType: DependencyGroupType): CardType | null {
switch (groupType) {
case "question":
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
index 5651cd91308..cd6a5d7632d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
@@ -37,7 +37,7 @@ import type {
NodeLink,
} from "./types";
import {
- canHaveViewCount,
+ canNodeHaveViewCount,
getCardType,
getCardTypes,
getDependencyErrorGroups,
@@ -511,7 +511,7 @@ describe("getNodeLastEditedBy", () => {
});
});
-describe("canHaveViewCount", () => {
+describe("canNodeHaveViewCount", () => {
it.each<{ type: DependencyType; expected: boolean }>([
{ type: "card", expected: true },
{ type: "dashboard", expected: true },
@@ -523,7 +523,7 @@ describe("canHaveViewCount", () => {
{ type: "snippet", expected: false },
{ type: "sandbox", expected: false },
])("should return $expected for $type", ({ type, expected }) => {
- expect(canHaveViewCount(type)).toBe(expected);
+ expect(canNodeHaveViewCount(type)).toBe(expected);
});
});
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index 7a0e91bf629..f21a2c8eb16 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -68,11 +68,12 @@ export type TableDependencyNodeData = Pick<
| "db"
| "fields"
| "transform"
+ | "owner"
>;
export type TransformDependencyNodeData = Pick<
Transform,
- "name" | "description" | "table" | "creator" | "created_at"
+ "name" | "description" | "table" | "creator" | "created_at" | "owner"
>;
export type CardDependencyNodeData = Pick<
diff --git a/frontend/src/metabase-types/api/measure.ts b/frontend/src/metabase-types/api/measure.ts
index c7a0bd567e5..a71ad3c8091 100644
--- a/frontend/src/metabase-types/api/measure.ts
+++ b/frontend/src/metabase-types/api/measure.ts
@@ -17,6 +17,7 @@ export interface Measure {
created_at: string;
creator_id: number;
creator?: UserInfo;
+ updated_at: string;
}
export interface CreateMeasureRequest {
diff --git a/frontend/src/metabase-types/api/mocks/collection.ts b/frontend/src/metabase-types/api/mocks/collection.ts
index 0176291bc55..d987b5dff03 100644
--- a/frontend/src/metabase-types/api/mocks/collection.ts
+++ b/frontend/src/metabase-types/api/mocks/collection.ts
@@ -3,6 +3,7 @@ import type {
Collection,
CollectionEssentials,
CollectionItem,
+ LastEditInfo,
} from "metabase-types/api";
import { createMockEntityId } from "./entity-id";
@@ -82,6 +83,17 @@ export const createMockTransformsCollection = (
...opts,
});
+export const createMockLastEditInfo = (
+ opts?: Partial<LastEditInfo>,
+): LastEditInfo => ({
+ id: 1,
+ email: "[email protected]",
+ first_name: "Testy",
+ last_name: "Tableton",
+ timestamp: "2024-01-01T00:00:00Z",
+ ...opts,
+});
+
export const createMockSnippetsCollection = (
opts?: Partial<Collection>,
): Collection =>
diff --git a/frontend/src/metabase-types/api/mocks/measure.ts b/frontend/src/metabase-types/api/mocks/measure.ts
index 7b8ce006ac5..63baa006e74 100644
--- a/frontend/src/metabase-types/api/mocks/measure.ts
+++ b/frontend/src/metabase-types/api/mocks/measure.ts
@@ -11,6 +11,7 @@ export const createMockMeasure = (opts?: Partial<Measure>): Measure => ({
definition: createMockStructuredDatasetQuery(),
definition_description: "",
created_at: "2021-01-01T00:00:00Z",
+ updated_at: "2021-01-01T00:00:00Z",
creator_id: 1,
...opts,
});
diff --git a/frontend/src/metabase-types/api/mocks/segment.ts b/frontend/src/metabase-types/api/mocks/segment.ts
index 20e5a664cd9..b56130ac810 100644
--- a/frontend/src/metabase-types/api/mocks/segment.ts
+++ b/frontend/src/metabase-types/api/mocks/segment.ts
@@ -11,6 +11,7 @@ export const createMockSegment = (opts?: Partial<Segment>): Segment => ({
definition: createMockStructuredDatasetQuery(),
definition_description: "",
created_at: "2021-01-01T00:00:00Z",
+ updated_at: "2021-01-01T00:00:00Z",
creator_id: 1,
...opts,
});
diff --git a/frontend/src/metabase-types/api/segment.ts b/frontend/src/metabase-types/api/segment.ts
index 93fc25f1f3d..3c6b41909e4 100644
--- a/frontend/src/metabase-types/api/segment.ts
+++ b/frontend/src/metabase-types/api/segment.ts
@@ -18,6 +18,7 @@ export interface Segment {
created_at: string;
creator_id: number;
creator?: UserInfo;
+ updated_at: string;
}
export interface CreateSegmentRequest {
diff --git a/frontend/src/metabase-types/api/table.ts b/frontend/src/metabase-types/api/table.ts
index 818c6628875..06ee85f7660 100644
--- a/frontend/src/metabase-types/api/table.ts
+++ b/frontend/src/metabase-types/api/table.ts
@@ -6,7 +6,7 @@ import type { Field, FieldId } from "./field";
import type { Measure } from "./measure";
import type { Segment } from "./segment";
import type { Transform, TransformId } from "./transform";
-import type { UserId } from "./user";
+import type { UserId, UserInfo } from "./user";
export type ConcreteTableId = number;
export type VirtualTableId = string; // e.g. "card__17" where 17 is a card id
@@ -74,6 +74,7 @@ export type Table = {
data_layer: TableDataLayer | null;
owner_email: string | null;
owner_user_id: UserId | null;
+ owner?: TableOwner | null;
estimated_row_count?: number | null;
transform_id: TransformId | null; // readonly
view_count: number;
@@ -84,6 +85,11 @@ export type Table = {
collection?: Collection;
};
+export type TableOwner = Pick<
+ UserInfo,
+ "id" | "email" | "first_name" | "last_name"
+>;
+
export type SchemaName = string;
export interface Schema {
diff --git a/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx b/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx
index 6f0613363f7..4a0548f7759 100644
--- a/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx
+++ b/frontend/src/metabase/common/components/EntityCreationInfo/EntityCreationInfo.tsx
@@ -2,15 +2,14 @@ import { c, t } from "ttag";
import { DateTime } from "metabase/common/components/DateTime";
import CS from "metabase/css/core/index.css";
-import { getUserName } from "metabase/lib/user";
+import { type NamedUser, getUserName } from "metabase/lib/user";
import { Box, FixedSizeIcon, Group, Stack, Title } from "metabase/ui";
-import type { LastEditInfo, UserInfo } from "metabase-types/api";
type EntityCreationInfoProps = {
createdAt?: string | null;
- creator?: UserInfo | null;
+ creator?: NamedUser | null;
lastEditedAt?: string | null;
- lastEditor?: LastEditInfo | null;
+ lastEditor?: NamedUser | null;
withTitle?: boolean;
};
diff --git a/frontend/src/metabase/lib/urls/dependencies.ts b/frontend/src/metabase/lib/urls/dependencies.ts
index 5b232e3b8cd..a5955b6e477 100644
--- a/frontend/src/metabase/lib/urls/dependencies.ts
+++ b/frontend/src/metabase/lib/urls/dependencies.ts
@@ -78,8 +78,8 @@ function dependencyListQueryString({
return queryString.length > 0 ? `?${queryString}` : "";
}
-export function breakingDependencies(params?: DependencyListParams) {
- return `${dependencyDiagnostics()}/breaking${dependencyListQueryString(params)}`;
+export function brokenDependencies(params?: DependencyListParams) {
+ return `${dependencyDiagnostics()}/broken${dependencyListQueryString(params)}`;
}
export function unreferencedDependencies(params?: DependencyListParams) {
diff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.clj
index 540813627de..e9ae6a59101 100644
--- a/src/metabase/warehouse_schema/models/table.clj
+++ b/src/metabase/warehouse_schema/models/table.clj
@@ -340,6 +340,25 @@
:id
{:default false})))
+(methodical/defmethod t2/batched-hydrate [:model/Table :owner]
+ "Add owner (user) to a table. If owner_user_id is set, fetches the user.
+ If owner_email is set instead, returns a map with just the email."
+ [_model _k tables]
+ (if-not (seq tables)
+ tables
+ (let [owner-user-ids (into #{} (keep :owner_user_id) tables)
+ id->owner (when (seq owner-user-ids)
+ (t2/select-pk->fn identity [:model/User :id :email :first_name :last_name]
+ :id [:in owner-user-ids]))]
+ (for [table tables]
+ (assoc table :owner
+ (cond
+ (:owner_user_id table)
+ (get id->owner (:owner_user_id table))
+
+ (:owner_email table)
+ {:email (:owner_email table)}))))))
+
;;; ------------------------------------------------ SQL Permissions ------------------------------------------------
(mu/defmethod mi/visible-filter-clause :model/Table
diff --git a/test/metabase/warehouse_schema/models/table_test.clj b/test/metabase/warehouse_schema/models/table_test.clj
index 1eadf755906..0a1505689e9 100644
--- a/test/metabase/warehouse_schema/models/table_test.clj
+++ b/test/metabase/warehouse_schema/models/table_test.clj
@@ -563,6 +563,17 @@
(is (= coll2-id (-> hydrated second :collection :id)))
(is (nil? (-> hydrated (nth 2) :collection)))))))
+(deftest owner-hydration-test
+ (testing "hydrating :owner on a table with :owner_user_id"
+ (mt/with-temp [:model/Table table {:owner_user_id (mt/user->id :crowberto)}]
+ (is (=? {:owner {:id (mt/user->id :crowberto)
+ :email "[email protected]"}}
+ (t2/hydrate table :owner)))))
+ (testing "hydrating :owner on a table with :owner_email"
+ (mt/with-temp [:model/Table table {:owner_email "[email protected]"}]
+ (is (=? {:owner {:email "[email protected]"}}
+ (t2/hydrate table :owner))))))
+
;;; ---------------------------------------- can-read? permission tests ----------------------------------------
(deftest table-can-read?-with-view-data-and-create-queries-permission-test