The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add a filter for personal collections; preserve filters in the URL, drop the broken dependencies page for now (#68008)
Alexander Polyankin3b5230611653
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.tsindex 269a1329f50..de86e797915 100644--- a/e2e/support/helpers/e2e-data-studio-helpers.ts+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts@@ -131,10 +131,8 @@ export const DataStudio = {libraryPage().findAllByTestId("collection-name").contains(name),},Tasks: {- visitBrokenEntities: () =>- cy.visit("/data-studio/dependency-diagnostics/broken"),visitUnreferencedEntities: () =>- cy.visit("/data-studio/dependency-diagnostics/unreferenced"),+ cy.visit("/data-studio/tasks/unreferenced"),list: () => cy.findByTestId("dependency-list"),searchInput: () => cy.findByTestId("dependency-list-search-input"),filterButton: () => cy.findByTestId("dependency-list-filter-button"),diff --git a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.tsdeleted file mode 100644index 57fbb23707b..00000000000--- a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts+++ /dev/null@@ -1,520 +0,0 @@-const { H } = cy;--import { WRITABLE_DB_ID } from "e2e/support/cypress_data";-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";-import type { CardId, CardType, FieldId, TableId } from "metabase-types/api";--const { ORDERS_ID, ORDERS, REVIEWS } = SAMPLE_DATABASE;--const WRITABLE_TABLE_NAME = "scoreboard_actions";--const VALID_CARD_COLUMN_ID = "Valid card column with id";-const VALID_CARD_COLUMN_NAME = "Valid card column with name";-const VALID_NATIVE_CARD = "Valid native card";-const VALID_SEGMENT = "Valid segment";-const VALID_METRIC = "Valid metric";--const VALID_ENTITY_NAMES = [- VALID_CARD_COLUMN_ID,- VALID_CARD_COLUMN_NAME,- VALID_NATIVE_CARD,- VALID_SEGMENT,- VALID_METRIC,-];--const CARD_COLUMN_ID_MISSING = "Card with a non-existing column with an id";-const CARD_COLUMN_WRONG_TABLE = "Card with a column on a wrong table";-const CARD_COLUMN_NAME_MISSING = "Card with a non-existing column with a name";-const NATIVE_CARD_COLUMN_MISSING = "Native card with a non-existing column";-const NATIVE_CARD_TABLE_ALIAS_MISSING =- "Native card with a missing table alias";-const NATIVE_CARD_SYNTAX_ERROR = "Native card with a syntax error";--const BROKEN_MBQL_CARD_NAMES = [- CARD_COLUMN_ID_MISSING,- CARD_COLUMN_WRONG_TABLE,- CARD_COLUMN_NAME_MISSING,-];--const BROKEN_MBQL_CARD_ERRORS = {- [CARD_COLUMN_ID_MISSING]: { "1 missing column": ["Unknown Field"] },- [CARD_COLUMN_WRONG_TABLE]: { "1 missing column": ["RATING"] },- [CARD_COLUMN_NAME_MISSING]: { "1 missing column": ["BAD_NAME"] },-};--const BROKEN_NATIVE_CARD_NAMES = [- NATIVE_CARD_COLUMN_MISSING,- NATIVE_CARD_TABLE_ALIAS_MISSING,- NATIVE_CARD_SYNTAX_ERROR,-];--const BROKEN_NATIVE_CARD_ERRORS = {- [NATIVE_CARD_COLUMN_MISSING]: { "1 missing column": ["RATING"] },- [NATIVE_CARD_TABLE_ALIAS_MISSING]: { "1 missing table alias": ["P"] },- [NATIVE_CARD_SYNTAX_ERROR]: { "1 syntax error": [] },-};--const BROKEN_CARD_NAMES = [- ...BROKEN_MBQL_CARD_NAMES,- ...BROKEN_NATIVE_CARD_NAMES,-];--const BROKEN_CARD_ERRORS = {- ...BROKEN_MBQL_CARD_ERRORS,- ...BROKEN_NATIVE_CARD_ERRORS,-};--const SEGMENT_COLUMN_ID_MISSING =- "Segment with a non-existing column with an id";-const BROKEN_SEGMENT_NAMES = [SEGMENT_COLUMN_ID_MISSING];--const TRANSFORM_COLUMN_ID_MISSING =- "Transform with a non-existing column with an id";-const TRANSFORM_COLUMN_WRONG_TABLE = "Transform with a column on a wrong table";-const TRANSFORM_CARD_COLUMN_MISSING =- "Native transform with a non-existing column";-const TRANSFORM_CARD_TABLE_ALIAS_MISSING =- "Native transform with a missing table alias";-const TRANSFORM_CARD_SYNTAX_ERROR = "Native transform with a syntax error";--const BROKEN_TRANSFORM_NAMES = [- TRANSFORM_COLUMN_ID_MISSING,- TRANSFORM_COLUMN_WRONG_TABLE,- TRANSFORM_CARD_COLUMN_MISSING,- TRANSFORM_CARD_TABLE_ALIAS_MISSING,- TRANSFORM_CARD_SYNTAX_ERROR,-];--const BROKEN_TRANSFORM_ERRORS = {- [TRANSFORM_COLUMN_ID_MISSING]: { "1 missing column": ["Unknown Field"] },- [TRANSFORM_COLUMN_WRONG_TABLE]: { "1 missing column": ["Unknown Field"] },- [TRANSFORM_CARD_COLUMN_MISSING]: { "1 missing column": ["rating"] },- [TRANSFORM_CARD_TABLE_ALIAS_MISSING]: { "1 missing table alias": ["P"] },- [TRANSFORM_CARD_SYNTAX_ERROR]: { "1 syntax error": [] },-};--describe("scenarios > dependencies > broken list", () => {- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();- H.activateToken("bleeding-edge");- H.resetTestTable({ type: "postgres", table: WRITABLE_TABLE_NAME });- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: WRITABLE_TABLE_NAME });- cy.viewport(1600, 1400);- });-- describe("analysis", () => {- it("should not show valid entities", () => {- createValidEntities();- createBrokenCards({ type: "question" });- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- VALID_ENTITY_NAMES.forEach((name) => {- cy.findByText(name).should("not.exist");- });- });- });-- it("should show broken questions", () => {- createBrokenCards({ type: "question" });- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- BROKEN_CARD_NAMES.forEach((name) => {- cy.findByText(name).should("be.visible");- });- });- });-- it("should show broken models", () => {- createBrokenCards({ type: "model" });- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- BROKEN_CARD_NAMES.forEach((name) => {- cy.findByText(name).should("be.visible");- });- });- });-- it("should show broken metrics", () => {- createBrokenCards({ type: "metric" });- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- BROKEN_MBQL_CARD_NAMES.forEach((name) => {- cy.findByText(name).should("be.visible");- });- });- });-- it("should show broken segments", () => {- createBrokenSegments();- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- BROKEN_SEGMENT_NAMES.forEach((name) => {- cy.findByText(name).should("be.visible");- });- });- });-- it("should show broken transforms", () => {- createBrokenTransforms();- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.list().within(() => {- BROKEN_TRANSFORM_NAMES.forEach((name) => {- cy.findByText(name).should("be.visible");- });- });- });- });-- describe("search", () => {- it("should search for entities", () => {- createBrokenCards({ type: "question" });- H.DataStudio.Tasks.visitBrokenEntities();- H.DataStudio.Tasks.searchInput().type(CARD_COLUMN_ID_MISSING);- checkList({- visibleEntities: [CARD_COLUMN_ID_MISSING],- hiddenEntities: [CARD_COLUMN_WRONG_TABLE],- });- });- });-- describe("filters", () => {- it("should filter entities by type", () => {- createBrokenCards({ type: "question" });- createBrokenSegments();- createBrokenTransforms();- H.DataStudio.Tasks.visitBrokenEntities();- checkList({- visibleEntities: [...BROKEN_CARD_NAMES, ...BROKEN_TRANSFORM_NAMES],- });-- H.DataStudio.Tasks.filterButton().click();- H.popover().findByText("Question").click();- checkList({- visibleEntities: [...BROKEN_CARD_NAMES],- hiddenEntities: [...BROKEN_TRANSFORM_NAMES],- });- });- });-- describe("sidebar", () => {- it("should show the sidebar for questions with error info", () => {- createBrokenCards({ type: "question" });- H.DataStudio.Tasks.visitBrokenEntities();- openSidebarAndCheckErrors(BROKEN_CARD_ERRORS);- });-- it("should show the sidebar for models with error info", () => {- createBrokenCards({ type: "model" });- H.DataStudio.Tasks.visitBrokenEntities();- openSidebarAndCheckErrors(BROKEN_CARD_ERRORS);- });-- it("should show the sidebar for metrics with error info", () => {- createBrokenCards({ type: "metric" });- H.DataStudio.Tasks.visitBrokenEntities();- openSidebarAndCheckErrors(BROKEN_MBQL_CARD_ERRORS);- });-- it("should show the sidebar for transforms with error info", () => {- createBrokenTransforms();- H.DataStudio.Tasks.visitBrokenEntities();- openSidebarAndCheckErrors(BROKEN_TRANSFORM_ERRORS);- });- });-});--function createValidEntities() {- createCardWithFieldIdRef({- name: VALID_CARD_COLUMN_ID,- type: "question",- tableId: ORDERS_ID,- fieldId: ORDERS.TOTAL,- });- createCardWithFieldNameRef({- name: VALID_CARD_COLUMN_NAME,- type: "model",- cardId: ORDERS_QUESTION_ID,- fieldName: "TOTAL",- baseType: "type/Float",- });- createNativeCard({- name: VALID_NATIVE_CARD,- type: "metric",- query: "SELECT ID, TOTAL FROM ORDERS",- });- createSegmentWithFieldIdRef({- name: VALID_SEGMENT,- tableId: ORDERS_ID,- fieldId: ORDERS.TOTAL,- });-}--function createBrokenCards({ type }: { type: CardType }) {- createCardWithFieldIdRef({- name: CARD_COLUMN_WRONG_TABLE,- type,- tableId: ORDERS_ID,- fieldId: REVIEWS.RATING,- });- createCardWithFieldIdRef({- name: CARD_COLUMN_ID_MISSING,- type,- tableId: ORDERS_ID,- fieldId: 1000,- });- createCardWithFieldNameRef({- name: CARD_COLUMN_NAME_MISSING,- type,- cardId: ORDERS_QUESTION_ID,- fieldName: "BAD_NAME",- baseType: "type/Integer",- });-- if (type !== "metric") {- createNativeCard({- name: NATIVE_CARD_COLUMN_MISSING,- type,- query: "SELECT ID, RATING FROM ORDERS",- });- createNativeCard({- name: NATIVE_CARD_TABLE_ALIAS_MISSING,- type,- query: "SELECT P.ID, P.PRICE FROM ORDERS",- });- createNativeCard({- name: NATIVE_CARD_SYNTAX_ERROR,- type,- query: "SELECT FROM",- });- }-}--function createBrokenSegments() {- createSegmentWithFieldIdRef({- name: SEGMENT_COLUMN_ID_MISSING,- tableId: ORDERS_ID,- fieldId: REVIEWS.RATING,- });-}--function createBrokenTransforms() {- H.getTableId({ name: WRITABLE_TABLE_NAME, databaseId: WRITABLE_DB_ID }).then(- (tableId) => {- createTransformWithFieldIdRef({- name: TRANSFORM_COLUMN_ID_MISSING,- tableId: tableId,- fieldId: 1000,- });- createTransformWithFieldIdRef({- name: TRANSFORM_COLUMN_WRONG_TABLE,- tableId: tableId,- fieldId: ORDERS.TOTAL,- });- createNativeTransform({- name: TRANSFORM_CARD_COLUMN_MISSING,- query: `SELECT RATING FROM "${WRITABLE_TABLE_NAME}"`,- });- createNativeTransform({- name: TRANSFORM_CARD_TABLE_ALIAS_MISSING,- query: `SELECT P.ID, P.PRICE FROM "${WRITABLE_TABLE_NAME}"`,- });- createNativeTransform({- name: TRANSFORM_CARD_SYNTAX_ERROR,- query: "SELECT FROM",- });- },- );-}--function createCardWithFieldIdRef({- name,- type,- tableId,- fieldId,-}: {- name: string;- type: CardType;- tableId: TableId;- fieldId: FieldId;-}) {- return H.createQuestion({- name,- type,- query: {- "source-table": tableId,- filter: ["not-null", ["field", fieldId, null]],- aggregation: [["count"]],- },- });-}--function createCardWithFieldNameRef({- name,- type,- cardId,- fieldName,- baseType,-}: {- name: string;- type: CardType;- cardId: CardId;- fieldName: string;- baseType: string;-}) {- return H.createQuestion({- name,- type,- query: {- "source-table": `card__${cardId}`,- filter: ["not-null", ["field", fieldName, { "base-type": baseType }]],- aggregation: [["count"]],- },- });-}--function createNativeCard({- name,- type,- query,-}: {- name: string;- type: CardType;- query: string;-}) {- return H.createNativeQuestion({- name,- type,- native: {- query,- },- });-}--function createSegmentWithFieldIdRef({- name,- tableId,- fieldId,-}: {- name: string;- tableId: TableId;- fieldId: FieldId;-}) {- return H.createSegment({- name,- table_id: tableId,- definition: {- "source-table": tableId,- filter: ["not-null", ["field", fieldId, null]],- },- });-}--function createTransformWithFieldIdRef({- name,- tableId,- fieldId,-}: {- name: string;- tableId: TableId;- fieldId: FieldId;-}) {- return H.createTransform({- name,- source: {- type: "query",- query: {- type: "query",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- filter: ["not-null", ["field", fieldId, null]],- },- },- },- target: {- type: "table",- database: WRITABLE_DB_ID,- name,- schema: "public",- },- });-}--function createNativeTransform({- name,- query,-}: {- name: string;- query: string;-}) {- return H.createTransform({- name,- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "native",- native: { query },- },- },- target: {- type: "table",- database: WRITABLE_DB_ID,- name,- schema: "public",- },- });-}--function checkList({- visibleEntities = [],- hiddenEntities = [],-}: {- visibleEntities?: string[];- hiddenEntities?: string[];-}) {- H.DataStudio.Tasks.list().within(() => {- visibleEntities.forEach((name) => {- cy.findByText(name).should("be.visible");- });- hiddenEntities.forEach((name) => {- cy.findByText(name).should("not.exist");- });- });-}--function checkSidebar({- entityName,- errors = {},-}: {- entityName: string;- locationName?: string;- creatorName?: string;- errors?: Record<string, string[]>;-}) {- H.DataStudio.Tasks.Sidebar.header()- .findByText(entityName)- .should("be.visible");-- Object.entries(errors).forEach(([label, errors]) => {- H.DataStudio.Tasks.Sidebar.errorInfo(label).within(() => {- errors.forEach((error) => {- cy.findByText(error).should("be.visible");- });- });- });-}--function openSidebarAndCheckErrors(- errors: Record<string, Record<string, string[]>>,-) {- Object.entries(errors).forEach(([entityName, errors]) => {- H.DataStudio.Tasks.list().findByText(entityName).click();- checkSidebar({- entityName,- errors,- });- });-}diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.tsindex 98f301e80cf..754e66acb5d 100644--- a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts+++ b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts@@ -1,7 +1,10 @@const { H } = cy;import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { FIRST_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";+import {+ ADMIN_PERSONAL_COLLECTION_ID,+ FIRST_COLLECTION_ID,+} from "e2e/support/cypress_sample_instance_data";import type {CardId,CollectionId,@@ -125,7 +128,7 @@ describe("scenarios > dependencies > unreferenced list", () => {});H.DataStudio.Tasks.filterButton().click();- H.popover().findByText("Model").click();+ H.popover().findByText("Snippet").click();checkList({visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG],hiddenEntities: [SNIPPET_FOR_SNIPPET_TAG],@@ -141,11 +144,11 @@ describe("scenarios > dependencies > unreferenced list", () => {H.DataStudio.Tasks.filterButton().click();H.popover().findByText("Model").click();- checkList({ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });+ checkList({ hiddenEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });H.popover().findByText("Segment").click();checkList({- visibleEntities: [+ hiddenEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG,SEGMENT_FOR_QUESTION_FILTER,],@@ -153,21 +156,45 @@ describe("scenarios > dependencies > unreferenced list", () => {H.popover().findByText("Metric").click();checkList({- visibleEntities: [+ hiddenEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG,SEGMENT_FOR_QUESTION_FILTER,METRIC_FOR_QUESTION_AGGREGATION,],});- H.popover().findByText("Snippet").click();+ H.popover().findByText("Model").click();+ checkList({ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });+ });++ it("should filter by location", () => {+ createEntities({ withPersonalCollection: true });+ H.DataStudio.Tasks.visitUnreferencedEntities();checkList({visibleEntities: [- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- SEGMENT_FOR_QUESTION_FILTER,- METRIC_FOR_QUESTION_AGGREGATION,+ MODEL_FOR_MODEL_DATA_SOURCE,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],+ });++ H.DataStudio.Tasks.filterButton().click();+ H.popover().findByText("Include items in personal collections").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ });++ H.popover().findByText("Include items in personal collections").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_MODEL_DATA_SOURCE,SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,],+ hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],});});});@@ -232,8 +259,9 @@ describe("scenarios > dependencies > unreferenced list", () => {function createEntities({withReferences = false,-}: { withReferences?: boolean } = {}) {- createModelContent({ withReferences });+ withPersonalCollection = false,+}: { withReferences?: boolean; withPersonalCollection?: boolean } = {}) {+ createModelContent({ withReferences, withPersonalCollection });createSegmentContent({ withReferences });createMetricContent({ withReferences });createSnippetContent({ withReferences });@@ -241,8 +269,10 @@ function createEntities({function createModelContent({withReferences = false,+ withPersonalCollection = false,}: {withReferences?: boolean;+ withPersonalCollection?: boolean;}) {createModelWithTableDataSource({name: MODEL_FOR_QUESTION_DATA_SOURCE,@@ -272,6 +302,9 @@ function createModelContent({createModelWithTableDataSource({name: MODEL_FOR_METRIC_DATA_SOURCE,tableId: ORDERS_ID,+ collectionId: withPersonalCollection+ ? ADMIN_PERSONAL_COLLECTION_ID+ : undefined,}).then(({ body: model }) => {if (withReferences) {createMetricWithModelDataSource({diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.cljindex 841acb17ead..873da0f0975 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj@@ -570,7 +570,28 @@(or (not= dependent_type :card)(= (-> % :data :type) dependent_card_type))))))))-(defn- unreferenced-query [entity-type card-types query include-archived-items]+(defn- personal-collection-filter+ "Returns a HoneySQL WHERE clause to exclude items in personal collections.+ Only applies to collection-based entities (card, dashboard, document, snippet).+ Returns nil for non-collection entities or when include-personal-collections is true."+ [entity-type include-personal-collections]+ (when-not include-personal-collections+ (case entity-type+ (:card :dashboard :document :snippet)+ (let [personal-ids (t2/select-pks-vec :model/Collection+ :personal_owner_id [:not= nil]+ :location "/")]+ (when (seq personal-ids)+ [:or+ [:= :entity.collection_id nil]+ [:and+ [:= :collection.personal_owner_id nil]+ (into [:and]+ (for [pid personal-ids]+ [:not-like :collection.location (str "/" pid "/%")]))]]))+ nil)))++(defn- unreferenced-query [entity-type card-types query include-archived-items include-personal-collections](let [table-name (case entity-type:card :report_card:table :metabase_table@@ -593,14 +614,19 @@[:and[:= :entity.active true][:= :entity.visibility_type nil]]- nil))]+ nil))+ personal-filter (personal-collection-filter entity-type include-personal-collections)+ needs-collection-join? (and (not include-personal-collections)+ (#{:card :dashboard :document :snippet} entity-type))]{:select [[[:inline (name entity-type)] :entity_type][:entity.id :entity_id][name-column :sort_key]]:from [[table-name :entity]]- :left-join [:dependency [:and- [:= :dependency.to_entity_id :entity.id]- [:= :dependency.to_entity_type [:inline (name entity-type)]]]]+ :left-join (cond-> [:dependency [:and+ [:= :dependency.to_entity_id :entity.id]+ [:= :dependency.to_entity_type [:inline (name entity-type)]]]]+ needs-collection-join?+ (conj :collection [:= :entity.collection_id :collection.id])):where (cond->> [:= :dependency.id nil](and (= entity-type :card)(seq card-types))@@ -610,7 +636,10 @@(conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]])archived-filter- (conj [:and archived-filter]))}))+ (conj [:and archived-filter])++ personal-filter+ (conj [:and personal-filter]))}))(def ^:private unreferenced-items-args[:map@@ -621,7 +650,8 @@(ms/enum-decode-keyword lib.schema.metadata/card-types)[:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]][:query {:optional true} :string]- [:archived {:optional true} :boolean]])+ [:archived {:optional true} :boolean]+ [:include_personal_collections {:optional true} :boolean]])(api.macros/defendpoint :get "/graph/unreferenced" :- [:sequential ::entity]"Returns a list of all unreferenced items in the instance.@@ -632,19 +662,22 @@- card_types: List of card types to include when filtering cards (e.g., [:question :model :metric])- query: Search string to filter by name or location- archived: Controls whether archived entities are included+ - include_personal_collections: Controls whether items in personal collections are included (default: false)Returns a list of unreferenced items, each with :id, :type, and :data fields."[_route-params- {:keys [types card_types query archived]+ {:keys [types card_types query archived include_personal_collections]:or {types (vec deps.dependency-types/dependency-types)- card_types (vec lib.schema.metadata/card-types)}} :- unreferenced-items-args]+ card_types (vec lib.schema.metadata/card-types)+ include_personal_collections false}} :- unreferenced-items-args](let [include-archived-items (if archived :all :exclude)graph-opts {:include-archived-items include-archived-items}selected-types (cond->> (if (sequential? types) types [types]);; Sandboxes don't support query filtering, so exclude them when a query is providedquery (remove #{:sandbox}))card-types (if (sequential? card_types) card_types [card_types])- union-queries (map #(unreferenced-query % card-types query include-archived-items) selected-types)+ union-queries (map #(unreferenced-query % card-types query include-archived-items include_personal_collections)+ selected-types)union-query {:union-all union-queries}all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))(map (fn [{:keys [entity_id entity_type]}]@@ -661,9 +694,10 @@(ms/enum-decode-keyword lib.schema.metadata/card-types)[:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]][:query {:optional true} :string]- [:archived {:optional true} :boolean]])+ [:archived {:optional true} :boolean]+ [:include_personal_collections {:optional true} :boolean]])-(defn- broken-query [entity-type card-types query include-archived-items]+(defn- broken-query [entity-type card-types query include-archived-items include-personal-collections](let [table-name (case entity-type:card :report_card:table :metabase_table@@ -686,14 +720,19 @@[:and[:= :entity.active true][:= :entity.visibility_type nil]]- nil))]+ nil))+ personal-filter (personal-collection-filter entity-type include-personal-collections)+ needs-collection-join? (and (not include-personal-collections)+ (#{:card :dashboard :document :snippet} entity-type))]{:select [[[:inline (name entity-type)] :entity_type][:entity.id :entity_id][name-column :sort_key]]:from [[table-name :entity]]- :left-join [:analysis_finding [:and- [:= :analysis_finding.analyzed_entity_id :entity.id]- [:= :analysis_finding.analyzed_entity_type (name entity-type)]]]+ :left-join (cond-> [:analysis_finding [:and+ [:= :analysis_finding.analyzed_entity_id :entity.id]+ [:= :analysis_finding.analyzed_entity_type (name entity-type)]]]+ needs-collection-join?+ (conj :collection [:= :entity.collection_id :collection.id])):where (cond->> [:= :analysis_finding.result false](and (= entity-type :card)(seq card-types))@@ -703,7 +742,10 @@(conj [:and [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")]])archived-filter- (conj [:and archived-filter]))}))+ (conj [:and archived-filter])++ personal-filter+ (conj [:and personal-filter]))}))(api.macros/defendpoint :get "/graph/broken" :- [:sequential ::entity]"Returns a list of all items with broken queries.@@ -713,19 +755,22 @@- `card_types`: List of card types to include when filtering cards (e.g., `[:question :model :metric]`)- `query`: Search string to filter by name or location- `archived`: Controls whether archived entities are included+ - `include_personal_collections`: Controls whether items in personal collections are included (default: false)Returns a list of broken items, each with `:id`, `:type`, `:data`, and `:error`s fields."[_route-params- {:keys [types card_types query archived]+ {:keys [types card_types query archived include_personal_collections]:or {types (vec deps.dependency-types/dependency-types)- card_types (vec lib.schema.metadata/card-types)}} :- broken-items-args]+ card_types (vec lib.schema.metadata/card-types)+ include_personal_collections false}} :- broken-items-args](let [include-archived-items (if archived :all :exclude)graph-opts {:include-archived-items include-archived-items}selected-types (cond->> (if (sequential? types) types [types]);; Sandboxes don't support query filtering, so exclude them when a query is providedquery (remove #{:sandbox}))card-types (if (sequential? card_types) card_types [card_types])- union-queries (map #(broken-query % card-types query include-archived-items) selected-types)+ union-queries (map #(broken-query % card-types query include-archived-items include_personal_collections)+ selected-types)union-query {:union-all union-queries}all-ids (->> (t2/query (assoc union-query :order-by [[:sort_key :asc]]))(map (fn [{:keys [entity_id entity_type]}]diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.cljindex d1249eb6650..2432d3db4d5 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj@@ -5,6 +5,7 @@[metabase-enterprise.dependencies.events][metabase-enterprise.dependencies.findings :as dependencies.findings][metabase-enterprise.dependencies.task.backfill :as dependencies.backfill]+ [metabase.collections.models.collection :as collection][metabase.events.core :as events][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]@@ -1484,3 +1485,88 @@measure-ids (set (map :id response))](is (contains? measure-ids unreffed-measure-id))(is (contains? measure-ids archived-measure-id)))))))))++(deftest ^:sequential unreferenced-personal-collection-card-test+ (testing "GET /api/ee/dependencies/graph/unreferenced with include_personal_collections parameter for cards"+ (mt/with-premium-features #{:dependencies}+ (binding [collection/*allow-deleting-personal-collections* true]+ (let [mp (mt/metadata-provider)+ products (lib.metadata/table mp (mt/id :products))]+ (mt/with-temp [:model/User {user-id :id} {}+ :model/Collection {personal-coll-id :id} {:personal_owner_id user-id+ :name "Test Personal Collection"}+ :model/Collection {sub-personal-coll-id :id} {:name "Sub Personal Collection"+ :location (format "/%d/" personal-coll-id)}+ :model/Card {card-in-personal :id} {:name "Card in Personal - personalcolltest"+ :type :question+ :collection_id personal-coll-id+ :dataset_query (lib/query mp products)}+ :model/Card {card-in-sub-personal :id} {:name "Card in Sub Personal - personalcolltest"+ :type :question+ :collection_id sub-personal-coll-id+ :dataset_query (lib/query mp products)}+ :model/Card {card-regular :id} {:name "Card Regular - personalcolltest"+ :type :question+ :dataset_query (lib/query mp products)}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (testing "include_personal_collections=false (default) excludes cards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=personalcolltest")+ card-ids (set (map :id response))]+ (is (not (contains? card-ids card-in-personal)))+ (is (not (contains? card-ids card-in-sub-personal)))+ (is (contains? card-ids card-regular))))+ (testing "include_personal_collections=true includes cards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=card&card_types=question&query=personalcolltest&include_personal_collections=true")+ card-ids (set (map :id response))]+ (is (contains? card-ids card-in-personal))+ (is (contains? card-ids card-in-sub-personal))+ (is (contains? card-ids card-regular))))))))))++(deftest ^:sequential unreferenced-personal-collection-dashboard-test+ (testing "GET /api/ee/dependencies/graph/unreferenced with include_personal_collections parameter for dashboards"+ (mt/with-premium-features #{:dependencies}+ (binding [collection/*allow-deleting-personal-collections* true]+ (mt/with-temp [:model/User {user-id :id} {}+ :model/Collection {personal-coll-id :id} {:personal_owner_id user-id+ :name "Test Personal Collection"}+ :model/Dashboard {dash-in-personal :id} {:name "Dashboard in Personal - personalcolltest"+ :collection_id personal-coll-id}+ :model/Dashboard {dash-regular :id} {:name "Dashboard Regular - personalcolltest"}]+ (while (#'dependencies.backfill/backfill-dependencies!))+ (testing "include_personal_collections=false (default) excludes dashboards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=personalcolltest")+ dashboard-ids (set (map :id response))]+ (is (not (contains? dashboard-ids dash-in-personal)))+ (is (contains? dashboard-ids dash-regular))))+ (testing "include_personal_collections=true includes dashboards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=dashboard&query=personalcolltest&include_personal_collections=true")+ dashboard-ids (set (map :id response))]+ (is (contains? dashboard-ids dash-in-personal))+ (is (contains? dashboard-ids dash-regular)))))))))++(deftest ^:sequential broken-personal-collection-card-test+ (testing "GET /api/ee/dependencies/graph/broken with include_personal_collections parameter"+ (mt/with-premium-features #{:dependencies}+ (binding [collection/*allow-deleting-personal-collections* true]+ (let [mp (mt/metadata-provider)]+ (mt/with-temp [:model/User {user-id :id} {}+ :model/Collection {personal-coll-id :id} {:personal_owner_id user-id+ :name "Test Personal Collection"}+ :model/Card {broken-in-personal :id} {:name "Broken Card in Personal - personalcollbrokentest"+ :type :question+ :collection_id personal-coll-id+ :dataset_query (lib/native-query mp "not a query")}+ :model/Card {broken-regular :id} {:name "Broken Card Regular - personalcollbrokentest"+ :type :question+ :dataset_query (lib/native-query mp "not a query")}]+ (while (> (dependencies.findings/analyze-batch! :card 50) 0))+ (testing "include_personal_collections=false (default) excludes broken cards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest")+ card-ids (set (map :id response))]+ (is (not (contains? card-ids broken-in-personal)))+ (is (contains? card-ids broken-regular))))+ (testing "include_personal_collections=true includes broken cards in personal collections"+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest&include_personal_collections=true")+ card-ids (set (map :id response))]+ (is (contains? card-ids broken-in-personal))+ (is (contains? card-ids broken-regular))))))))))diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsxindex 9caa7f5cd02..0a4f8226d6d 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx@@ -150,8 +150,8 @@ function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {<DataStudioTablabel={t`Dependency diagnostics`}icon="list"- to={Urls.dataStudioDependencyDiagnostics()}- isSelected={currentTab === "dependency-diagnostics"}+ to={Urls.dependencyTasks()}+ isSelected={currentTab === "tasks"}showLabel={isNavbarOpened}/>)}diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.tsindex a544c525187..f178e40e603 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.ts@@ -6,7 +6,7 @@ type TabName =| "transforms"| "jobs"| "runs"- | "dependency-diagnostics"+ | "tasks"| "dependencies"| "glossary";@@ -16,8 +16,8 @@ export const getCurrentTab = (pathname: string): TabName => {return "glossary";case pathname.startsWith(Urls.transformJobList()):return "jobs";- case pathname.startsWith(Urls.dataStudioDependencyDiagnostics()):- return "dependency-diagnostics";+ case pathname.startsWith(Urls.dependencyTasks()):+ return "tasks";case pathname.startsWith(Urls.dependencyGraph()):return "dependencies";case pathname.startsWith(Urls.dataStudioLibrary()):diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.unit.spec.tsindex 7d95447601e..87f3a4c9143 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/utils.unit.spec.ts@@ -2,28 +2,28 @@ import { getCurrentTab } from "./utils";describe("getCurrentTab", () => {it.each`- pathname | expectedTab- ${"/data-studio/glossary"} | ${"glossary"}- ${"/data-studio/glossary/some-path"} | ${"glossary"}- ${"/data-studio/transforms/jobs"} | ${"jobs"}- ${"/data-studio/transforms/jobs/123"} | ${"jobs"}- ${"/data-studio/transforms/jobs/new"} | ${"jobs"}- ${"/data-studio/dependencies"} | ${"dependencies"}- ${"/data-studio/dependencies?id=1&type=card"} | ${"dependencies"}- ${"/data-studio/dependency-diagnostics"} | ${"dependency-diagnostics"}- ${"/data-studio/dependency-diagnostics/broken"} | ${"dependency-diagnostics"}- ${"/data-studio/dependency-diagnostics/unreferenced"} | ${"dependency-diagnostics"}- ${"/data-studio/library"} | ${"library"}- ${"/data-studio/library/collections/123"} | ${"library"}- ${"/data-studio/library/metrics/456"} | ${"library"}- ${"/data-studio/transforms/runs"} | ${"runs"}- ${"/data-studio/transforms/runs?page=2"} | ${"runs"}- ${"/data-studio/transforms"} | ${"transforms"}- ${"/data-studio/transforms/123"} | ${"transforms"}- ${"/data-studio/transforms/new/query"} | ${"transforms"}- ${"/data-studio/data"} | ${"data"}- ${"/data-studio/data/database/1"} | ${"data"}- ${"/data-studio"} | ${"data"}+ pathname | expectedTab+ ${"/data-studio/glossary"} | ${"glossary"}+ ${"/data-studio/glossary/some-path"} | ${"glossary"}+ ${"/data-studio/transforms/jobs"} | ${"jobs"}+ ${"/data-studio/transforms/jobs/123"} | ${"jobs"}+ ${"/data-studio/transforms/jobs/new"} | ${"jobs"}+ ${"/data-studio/dependencies"} | ${"dependencies"}+ ${"/data-studio/dependencies?id=1&type=card"} | ${"dependencies"}+ ${"/data-studio/tasks"} | ${"tasks"}+ ${"/data-studio/tasks/broken"} | ${"tasks"}+ ${"/data-studio/tasks/unreferenced"} | ${"tasks"}+ ${"/data-studio/library"} | ${"library"}+ ${"/data-studio/library/collections/123"} | ${"library"}+ ${"/data-studio/library/metrics/456"} | ${"library"}+ ${"/data-studio/transforms/runs"} | ${"runs"}+ ${"/data-studio/transforms/runs?page=2"} | ${"runs"}+ ${"/data-studio/transforms"} | ${"transforms"}+ ${"/data-studio/transforms/123"} | ${"transforms"}+ ${"/data-studio/transforms/new/query"} | ${"transforms"}+ ${"/data-studio/data"} | ${"data"}+ ${"/data-studio/data/database/1"} | ${"data"}+ ${"/data-studio"} | ${"data"}`("should return '$expectedTab' for pathname '$pathname'",({ pathname, expectedTab }) => {diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsxindex 48e096b93e4..7581f6703f8 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/routes.tsx@@ -58,7 +58,7 @@ export function getDataStudioRoutes({getDataStudioSnippetRoutes()}</Route>{PLUGIN_DEPENDENCIES.isEnabled && (- <Route path="dependency-diagnostics" component={TasksSectionLayout}>+ <Route path="tasks" component={TasksSectionLayout}>{PLUGIN_DEPENDENCIES.getDataStudioTasksRoutes()}</Route>)}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsxindex 82ca8070032..c418771fc80 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx@@ -19,7 +19,11 @@ import {} from "metabase/ui";import type { DependencyNode } from "metabase-types/api";+import type { DependentGroup } from "../../../types";import {+ getDependencyGroupTitle,+ getDependentGroupLabel,+ getDependentGroups,getNodeIcon,getNodeLabel,getNodeTypeInfo,@@ -29,12 +33,6 @@ import { GraphContext } from "../GraphContext";import type { GraphSelection, NodeType } from "../types";import S from "./GraphNode.module.css";-import type { DependentGroup } from "./types";-import {- getDependencyGroupTitle,- getDependentGroupLabel,- getDependentGroups,-} from "./utils";type GraphNodeProps = NodeProps<NodeType>;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/types.tsdeleted file mode 100644index 8db2bedc247..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/types.ts+++ /dev/null@@ -1,6 +0,0 @@-import type { DependencyGroupType } from "metabase-types/api";--export type DependentGroup = {- type: DependencyGroupType;- count: number;-};diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.tsdeleted file mode 100644index 0049ac60302..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts+++ /dev/null@@ -1,95 +0,0 @@-import { c, msgid, ngettext, t } from "ttag";--import type { DependencyNode } from "metabase-types/api";--import type { DependentGroup } from "./types";--export function getDependentGroups(node: DependencyNode): DependentGroup[] {- const {- question = 0,- model = 0,- metric = 0,- table = 0,- transform = 0,- snippet = 0,- dashboard = 0,- document = 0,- sandbox = 0,- segment = 0,- measure = 0,- } = node.dependents_count ?? {};-- const groups: DependentGroup[] = [- { type: "question", count: question },- { type: "model", count: model },- { type: "metric", count: metric },- { type: "table", count: table },- { type: "transform", count: transform },- { type: "snippet", count: snippet },- { type: "dashboard", count: dashboard },- { type: "document", count: document },- { type: "sandbox", count: sandbox },- { type: "segment", count: segment },- { type: "measure", count: measure },- ];-- return groups.filter(({ count }) => count !== 0);-}--export function getDependencyGroupTitle(- node: DependencyNode,- groups: DependentGroup[],-) {- if (node.type === "sandbox") {- return t`Restricts table data`;- }- if (groups.length === 0) {- return t`Nothing uses this`;- }- if (node.type === "transform") {- return t`Generates`;- }- return t`Used by`;-}--export function getDependentGroupLabel({- type,- count,-}: DependentGroup): string {- switch (type) {- case "question":- return ngettext(msgid`${count} question`, `${count} questions`, count);- case "model":- return ngettext(msgid`${count} model`, `${count} models`, count);- case "metric":- return ngettext(msgid`${count} metric`, `${count} metrics`, count);- case "table":- return ngettext(msgid`${count} table`, `${count} tables`, count);- case "transform":- return ngettext(msgid`${count} transform`, `${count} transforms`, count);- case "snippet":- return ngettext(msgid`${count} snippet`, `${count} snippet`, count);- case "dashboard":- return ngettext(msgid`${count} dashboard`, `${count} dashboards`, count);- case "document":- return ngettext(msgid`${count} document`, `${count} documents`, count);- case "sandbox":- return ngettext(- msgid`${count} row and column security rule`,- `${count} row and column security rules`,- count,- );- case "segment":- return c("{0} is the number of segments").ngettext(- msgid`${count} segment`,- `${count} segments`,- count,- );- case "measure":- return c("{0} is the number of measures").ngettext(- msgid`${count} measure`,- `${count} measures`,- count,- );- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.tsindex 2cff342fb62..455cba0a446 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts@@ -1,6 +1,5 @@import type { Edge, Node } from "@xyflow/react";-import type { ColorName } from "metabase/lib/colors/types";import type {DependencyGroupType,DependencyId,@@ -8,20 +7,9 @@ import type {DependencyType,} from "metabase-types/api";-export type NodeId = string;export type EdgeId = string;export type NodeType = Node<DependencyNode>;-export type NodeTypeInfo = {- label: string;- color: ColorName;-};--export type NodeLink = {- label: string;- url: string;-};-export type GraphData = {nodes: NodeType[];edges: Edge[];diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.cssindex 0073571bccc..8e5ea292f02 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.css+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.module.css@@ -1,3 +1,4 @@.main {overflow: hidden;+ align-self: flex-start;}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsxindex 90a56cfe7a5..3206d79573d 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx@@ -1,93 +1,88 @@-import { useMemo } from "react";+import { useState } from "react";import { DelayedLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper/DelayedLoadingAndErrorWrapper";+import type * as Urls from "metabase/lib/urls";import { Center, Flex, Stack } from "metabase/ui";-import type {- DependencyEntry,- DependencyGroupType,- DependencyNode,-} from "metabase-types/api";+import {+ useListBrokenGraphNodesQuery,+ useListUnreferencedGraphNodesQuery,+} from "metabase-enterprise/api";+import type { DependencyEntry } from "metabase-types/api";-import type { DependencyFilterOptions } from "../../types";-import { isSameNode } from "../../utils";+import { getCardTypes, getDependencyTypes, isSameNode } from "../../utils";import S from "./DependencyList.module.css";import { ListBody } from "./ListBody";-import { ListEmptyState } from "./ListEmptyState";import { ListHeader } from "./ListHeader";import { ListSearchBar } from "./ListSearchBar";import { ListSidebar } from "./ListSidebar";+import type { DependencyListMode } from "./types";+import { getAvailableGroupTypes } from "./utils";type DependencyListProps = {- nodes: DependencyNode[];- selectedEntry: DependencyEntry | null;- searchValue: string;- filterOptions: DependencyFilterOptions;- availableGroupTypes: DependencyGroupType[];- notFoundMessage: string;- isLoading: boolean;- isFetching: boolean;- error: unknown;- withErrorsColumn?: boolean;- withDependentsCountColumn?: boolean;- onSelect: (entry: DependencyEntry | null) => void;- onSearchValueChange: (searchValue: string) => void;- onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+ mode: DependencyListMode;+ params: Urls.DependencyListParams;+ onParamsChange: (params: Urls.DependencyListParams) => void;};export function DependencyList({- nodes,- searchValue,- filterOptions,- availableGroupTypes,- notFoundMessage,- isLoading,- isFetching,- error,- selectedEntry,- withErrorsColumn = false,- withDependentsCountColumn = false,- onSelect,- onSearchValueChange,- onFilterOptionsChange,+ mode,+ params,+ onParamsChange,}: DependencyListProps) {- const selectedNode = useMemo(() => {- return selectedEntry != null+ const [selectedEntry, setSelectedEntry] = useState<DependencyEntry>();++ const useListGraphNodesQuery =+ mode === "broken"+ ? useListBrokenGraphNodesQuery+ : useListUnreferencedGraphNodesQuery;+ const availableGroupTypes = getAvailableGroupTypes(mode);++ const {+ data: nodes = [],+ isFetching,+ isLoading,+ error,+ } = useListGraphNodesQuery({+ query: params.query,+ types: getDependencyTypes(params.groupTypes ?? availableGroupTypes),+ card_types: getCardTypes(params.groupTypes ?? availableGroupTypes),+ include_personal_collections: params.includePersonalCollections,+ });++ const selectedNode =+ selectedEntry != null? nodes.find((node) => isSameNode(node, selectedEntry))- : null;- }, [nodes, selectedEntry]);+ : undefined;return (<Flex h="100%">- <Stack className={S.main} flex={1} px="3.5rem" py="md" gap="md">+ <Stack className={S.main} flex={1} px="3.5rem" pb="md" gap="md"><ListHeader /><ListSearchBar- searchValue={searchValue}- filterOptions={filterOptions}- availableGroupTypes={availableGroupTypes}+ mode={mode}+ params={params}hasLoader={isFetching && !isLoading}- onSearchValueChange={onSearchValueChange}- onFilterOptionsChange={onFilterOptionsChange}+ onParamsChange={onParamsChange}/>- {isLoading || error != null ? (+ {error != null ? (<Center flex={1}><DelayedLoadingAndErrorWrapper loading={isLoading} error={error} /></Center>- ) : nodes.length === 0 ? (- <Center flex={1}>- <ListEmptyState label={notFoundMessage} />- </Center>) : (<ListBodynodes={nodes}- withErrorsColumn={withErrorsColumn}- withDependentsCountColumn={withDependentsCountColumn}- onSelect={onSelect}+ mode={mode}+ isLoading={isLoading}+ onSelect={setSelectedEntry}/>)}</Stack>{selectedNode != null && (- <ListSidebar node={selectedNode} onClose={() => onSelect(null)} />+ <ListSidebar+ node={selectedNode}+ onClose={() => setSelectedEntry(undefined)}+ />)}</Flex>);diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsxindex a802242d8d5..bef138b6f40 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ListBody.tsx@@ -1,34 +1,34 @@import type { Row } from "@tanstack/react-table";import { memo, useCallback, useMemo } from "react";-import { Card, TreeTable, useTreeTableInstance } from "metabase/ui";+import {+ Card,+ TreeTable,+ TreeTableSkeleton,+ useTreeTableInstance,+} from "metabase/ui";import type { DependencyNode } from "metabase-types/api";import { getNodeId } from "../../../utils";+import { ListEmptyState } from "../ListEmptyState";+import type { DependencyListMode } from "../types";-import { getColumns } from "./utils";+import { getColumnWidths, getColumns, getNotFoundMessage } from "./utils";type ListBodyProps = {nodes: DependencyNode[];- withErrorsColumn?: boolean;- withDependentsCountColumn?: boolean;+ mode: DependencyListMode;+ isLoading?: boolean;onSelect: (node: DependencyNode) => void;};export const ListBody = memo(function ListBody({nodes,- withErrorsColumn = false,- withDependentsCountColumn = false,+ mode,+ isLoading = false,onSelect,}: ListBodyProps) {- const columns = useMemo(- () =>- getColumns({- withErrorsColumn,- withDependentsCountColumn,- }),- [withErrorsColumn, withDependentsCountColumn],- );+ const columns = useMemo(() => getColumns(mode), [mode]);const handleRowActivate = useCallback((row: Row<DependencyNode>) => onSelect(row.original),@@ -44,7 +44,15 @@ export const ListBody = memo(function ListBody({return (<Card flex={1} mih={0} p={0} withBorder data-testid="dependency-list">- <TreeTable instance={treeTableInstance} onRowClick={handleRowActivate} />+ {isLoading ? (+ <TreeTableSkeleton columnWidths={getColumnWidths(mode)} />+ ) : (+ <TreeTable+ instance={treeTableInstance}+ emptyState={<ListEmptyState label={getNotFoundMessage(mode)} />}+ onRowClick={handleRowActivate}+ />+ )}</Card>);});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.tsxindex 752bd3fe675..86e9c9cb662 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@@ -8,6 +8,7 @@ import {getNodeLabel,getNodeLocationInfo,} from "../../../utils";+import type { DependencyListMode } from "../types";import { ErrorsCell } from "./ErrorsCell";import { LocationCell } from "./LocationCell";@@ -73,19 +74,27 @@ function getNodeDependentsCountColumn(): TreeTableColumnDef<DependencyNode> {};}-type ColumnOptions = {- withErrorsColumn: boolean;- withDependentsCountColumn: boolean;-};--export function getColumns({- withErrorsColumn,- withDependentsCountColumn,-}: ColumnOptions): TreeTableColumnDef<DependencyNode>[] {+export function getColumns(+ mode: DependencyListMode,+): TreeTableColumnDef<DependencyNode>[] {return [getNodeNameColumn(),getNodeLocationColumn(),- ...(withErrorsColumn ? [getNodeErrorsColumn()] : []),- ...(withDependentsCountColumn ? [getNodeDependentsCountColumn()] : []),+ ...(mode === "broken" ? [getNodeErrorsColumn()] : []),+ ...(mode === "broken" ? [getNodeDependentsCountColumn()] : []),];}++export function getColumnWidths(mode: DependencyListMode): number[] {+ if (mode === "broken") {+ return [0.3, 0.3, 0.3, 0.1];+ } else {+ return [0.5, 0.5];+ }+}++export function getNotFoundMessage(mode: DependencyListMode) {+ 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.tsxindex 4b0ea1df57a..b67dc51d7df 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@@ -2,37 +2,29 @@ import { memo } from "react";import { t } from "ttag";import * as Urls from "metabase/lib/urls";-import { Stack, Title } from "metabase/ui";+import { DataStudioBreadcrumbs } from "metabase-enterprise/data-studio/common/components/DataStudioBreadcrumbs";import {+ PaneHeader,type PaneHeaderTab,PaneHeaderTabs,} from "metabase-enterprise/data-studio/common/components/PaneHeader";export const ListHeader = memo(function ListHeader() {const tabs: PaneHeaderTab[] = [- {- label: t`Broken entities`,- to: Urls.dataStudioBrokenEntities(),- icon: "list",- },{label: t`Unreferenced entities`,- to: Urls.dataStudioUnreferencedEntities(),+ to: Urls.unreferencedDependencies(),icon: "list",},];return (- <Stack gap="md">- <Title- order={1}- py="sm"- fz="sm"- lh="1rem"- fw="normal"- c="text-secondary"- >{t`Dependency diagnostics`}</Title>- <PaneHeaderTabs tabs={tabs} />- </Stack>+ <PaneHeader+ breadcrumbs={+ <DataStudioBreadcrumbs>{t`Dependency diagnostics`}</DataStudioBreadcrumbs>+ }+ tabs={<PaneHeaderTabs tabs={tabs} />}+ py={0}+ />);});diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsxindex 2b118dbd0b8..f0e78c144cd 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/FilterOptionsPicker.tsx@@ -1,23 +1,24 @@import { useDisclosure } from "@mantine/hooks";import { t } from "ttag";+import type * as Urls from "metabase/lib/urls";import { Box, Button, FixedSizeIcon, Popover, Stack } from "metabase/ui";-import type { DependencyGroupType } from "metabase-types/api";-import type { DependencyFilterOptions } from "../../../../types";+import type { DependencyListMode } from "../../types";+import { LocationFilterPicker } from "./LocationFilterPicker";import { TypeFilterPicker } from "./TypeFilterPicker";type FilterOptionsPickerProps = {- filterOptions: DependencyFilterOptions;- availableGroupTypes: DependencyGroupType[];- onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+ mode: DependencyListMode;+ params: Urls.DependencyListParams;+ onParamsChange: (params: Urls.DependencyListParams) => void;};export function FilterOptionsPicker({- filterOptions,- availableGroupTypes,- onFilterOptionsChange,+ mode,+ params,+ onParamsChange,}: FilterOptionsPickerProps) {const [isOpened, { toggle, close }] = useDisclosure();@@ -34,9 +35,9 @@ export function FilterOptionsPicker({</Popover.Target><Popover.Dropdown><FilterOptionsPopover- filterOptions={filterOptions}- availableGroupTypes={availableGroupTypes}- onFilterOptionsChange={onFilterOptionsChange}+ mode={mode}+ params={params}+ onParamsChange={onParamsChange}/></Popover.Dropdown></Popover>@@ -44,28 +45,25 @@ export function FilterOptionsPicker({}type FilterOptionsPopoverProps = {- filterOptions: DependencyFilterOptions;- availableGroupTypes: DependencyGroupType[];- onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+ mode: DependencyListMode;+ params: Urls.DependencyListParams;+ onParamsChange: (params: Urls.DependencyListParams) => void;};function FilterOptionsPopover({- filterOptions,- availableGroupTypes,- onFilterOptionsChange,+ mode,+ params,+ onParamsChange,}: FilterOptionsPopoverProps) {- const handleTypesChange = (groupTypes: DependencyGroupType[]) => {- onFilterOptionsChange({ ...filterOptions, groupTypes });- };-return (<Box w="20rem" p="md"><Stack><TypeFilterPicker- groupTypes={filterOptions.groupTypes ?? []}- availableGroupTypes={availableGroupTypes}- onChange={handleTypesChange}+ mode={mode}+ params={params}+ onParamsChange={onParamsChange}/>+ <LocationFilterPicker params={params} onParamsChange={onParamsChange} /></Stack></Box>);diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsxnew file mode 100644index 00000000000..ab629122975--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/LocationFilterPicker.tsx@@ -0,0 +1,35 @@+import type { ChangeEvent } from "react";+import { t } from "ttag";++import type * as Urls from "metabase/lib/urls";+import { Checkbox, Input, Stack } from "metabase/ui";++type LocationFilterPickerProps = {+ params: Urls.DependencyListParams;+ onParamsChange: (params: Urls.DependencyListParams) => void;+};++export function LocationFilterPicker({+ params,+ onParamsChange,+}: LocationFilterPickerProps) {+ const handleIncludeInPersonalCollectionsChange = (+ event: ChangeEvent<HTMLInputElement>,+ ) => {+ onParamsChange({+ ...params,+ includePersonalCollections: event.target.checked,+ });+ };++ return (+ <Input.Wrapper label={t`Location`}>+ <Stack gap="sm" mt="sm">+ <Checkbox+ label={t`Include items in personal collections`}+ onChange={handleIncludeInPersonalCollectionsChange}+ />+ </Stack>+ </Input.Wrapper>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/index.tsnew file mode 100644index 00000000000..41699b59226--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/LocationFilterPicker/index.ts@@ -0,0 +1 @@+export * from "./LocationFilterPicker";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsxindex 05bd81ad6b4..bb263d4388a 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/FilterOptionsPicker/TypeFilterPicker/TypeFilterPicker.tsx@@ -1,36 +1,43 @@-import { useMemo } from "react";+import { useState } from "react";import { t } from "ttag";+import type * as Urls from "metabase/lib/urls";import { Checkbox, Stack } from "metabase/ui";-import type { DependencyGroupType } from "metabase-types/api";import { getDependencyGroupTypeInfo } from "../../../../../utils";+import type { DependencyListMode } from "../../../types";+import { getAvailableGroupTypes } from "../../../utils";type TypeFilterPickerProps = {- groupTypes: DependencyGroupType[];- availableGroupTypes: DependencyGroupType[];- onChange: (groupTypes: DependencyGroupType[]) => void;+ mode: DependencyListMode;+ params: Urls.DependencyListParams;+ onParamsChange: (params: Urls.DependencyListParams) => void;};export function TypeFilterPicker({- groupTypes,- availableGroupTypes,- onChange,+ mode,+ params,+ onParamsChange,}: TypeFilterPickerProps) {- const groupOptions = useMemo(- () =>- availableGroupTypes.map((groupType) => ({- value: groupType,- label: getDependencyGroupTypeInfo(groupType).label,- })),- [availableGroupTypes],+ const availableGroupTypes = getAvailableGroupTypes(mode);++ // preserve selected options in state to allow to deselect all types+ // until the popover is closed+ const [groupTypes, setGroupTypes] = useState(+ params.groupTypes ?? availableGroupTypes,);- const handleChange = (value: string[]) => {+ const groupOptions = availableGroupTypes.map((groupType) => ({+ value: groupType,+ label: getDependencyGroupTypeInfo(groupType).label,+ }));++ const handleChange = (newValue: string[]) => {const newGroupTypes = availableGroupTypes.filter((groupType) =>- value.includes(groupType),+ newValue.includes(groupType),);- onChange(newGroupTypes);+ setGroupTypes(newGroupTypes);+ onParamsChange({ ...params, groupTypes: newGroupTypes });};return (diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsxindex b69caa8adf3..25735822517 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx@@ -1,34 +1,45 @@-import { type ChangeEvent, memo } from "react";+import { useDebouncedCallback } from "@mantine/hooks";+import { type ChangeEvent, memo, useState } from "react";import { t } from "ttag";+import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";+import type * as Urls from "metabase/lib/urls";import { Flex, Icon, Loader, TextInput } from "metabase/ui";-import type { DependencyGroupType } from "metabase-types/api";-import type { DependencyFilterOptions } from "../../../types";+import { getSearchQuery } from "../../../utils";+import type { DependencyListMode } from "../types";import { FilterOptionsPicker } from "./FilterOptionsPicker";type ListSearchBarProps = {- searchValue: string;- filterOptions: DependencyFilterOptions;- availableGroupTypes: DependencyGroupType[];+ mode: DependencyListMode;+ params: Urls.DependencyListParams;hasLoader: boolean;- onSearchValueChange: (searchValue: string) => void;- onFilterOptionsChange: (filterOptions: DependencyFilterOptions) => void;+ onParamsChange: (params: Urls.DependencyListParams) => void;};export const ListSearchBar = memo(function ListSearchBar({- searchValue,- filterOptions,- availableGroupTypes,+ mode,+ params,hasLoader,- onSearchValueChange,- onFilterOptionsChange,+ onParamsChange,}: ListSearchBarProps) {+ const [searchValue, setSearchValue] = useState(params.query ?? "");+const handleSearchChange = (event: ChangeEvent<HTMLInputElement>) => {- onSearchValueChange(event.target.value);+ const newSearchValue = event.target.value;+ setSearchValue(newSearchValue);+ handleSearchDebounce(newSearchValue);};+ const handleSearchDebounce = useDebouncedCallback(+ (newSearchValue: string) => {+ const newQuery = getSearchQuery(newSearchValue);+ onParamsChange({ ...params, query: newQuery });+ },+ SEARCH_DEBOUNCE_DURATION,+ );+return (<Flex gap="md" align="center"><TextInput@@ -41,9 +52,9 @@ export const ListSearchBar = memo(function ListSearchBar({onChange={handleSearchChange}/><FilterOptionsPicker- filterOptions={filterOptions}- availableGroupTypes={availableGroupTypes}- onFilterOptionsChange={onFilterOptionsChange}+ mode={mode}+ params={params}+ onParamsChange={onParamsChange}/></Flex>);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.tsxindex 545e601e72c..50a3d807dea 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@@ -5,6 +5,7 @@ import type { DependencyNode } from "metabase-types/api";import S from "./ListSidebar.module.css";import { SidebarCreationInfo } from "./SidebarCreationInfo";+import { SidebarDependentsInfo } from "./SidebarDependentsInfo";import { SidebarErrorInfo } from "./SidebarErrorInfo";import { SidebarHeader } from "./SidebarHeader";import { SidebarLocationInfo } from "./SidebarLocationInfo";@@ -32,6 +33,7 @@ export const ListSidebar = memo(function ListSidebar({<SidebarHeader node={node} onClose={onClose} /><SidebarCreationInfo node={node} /><SidebarLocationInfo node={node} />+ <SidebarDependentsInfo node={node} />{errorGroups.map((errorGroup) => (<SidebarErrorInfokey={errorGroup.type}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsxnew file mode 100644index 00000000000..aece5e692e6--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx@@ -0,0 +1,43 @@+import { ForwardRefLink } from "metabase/common/components/Link";+import * as Urls from "metabase/lib/urls";+import { Anchor, Card, Group, Icon, Stack, Title } from "metabase/ui";+import type { DependencyNode } from "metabase-types/api";++import {+ getDependencyGroupIcon,+ getDependencyGroupTitle,+ getDependentGroupLabel,+ getDependentGroups,+} from "../../../../utils";++type SidebarDependentsInfoProps = {+ node: DependencyNode;+};++export function SidebarDependentsInfo({ node }: SidebarDependentsInfoProps) {+ const groups = getDependentGroups(node);+ const title = getDependencyGroupTitle(node, groups);+ const link = Urls.dependencyGraph({ entry: node });++ if (groups.length === 0) {+ return null;+ }++ return (+ <Stack gap="sm" role="region" aria-label={title}>+ <Title order={4}>{title}</Title>+ <Card shadow="none" withBorder>+ <Stack gap="sm" lh="1rem">+ {groups.map((group, groupIndex) => (+ <Anchor key={groupIndex} component={ForwardRefLink} to={link}>+ <Group gap="sm" wrap="nowrap">+ <Icon name={getDependencyGroupIcon(group.type)} />+ {getDependentGroupLabel(group)}+ </Group>+ </Anchor>+ ))}+ </Stack>+ </Card>+ </Stack>+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/index.tsnew file mode 100644index 00000000000..ff946cb9c36--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/index.ts@@ -0,0 +1 @@+export * from "./SidebarDependentsInfo";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsxindex 9088d772f45..558c47c08cb 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx@@ -1,10 +1,9 @@import { t } from "ttag";import { ForwardRefLink } from "metabase/common/components/Link";-import { ActionIcon, FixedSizeIcon, Group, Title, Tooltip } from "metabase/ui";+import { ActionIcon, Anchor, FixedSizeIcon, Group } from "metabase/ui";import type { DependencyNode } from "metabase-types/api";-import { TOOLTIP_OPEN_DELAY_MS } from "../../../../constants";import { getNodeLabel, getNodeLink } from "../../../../utils";type SidebarHeaderProps = {@@ -20,28 +19,22 @@ export function SidebarHeader({ node, onClose }: SidebarHeaderProps) {gap="0.75rem"wrap="nowrap"align="start"+ justify="space-between"data-testid="dependency-list-sidebar-header">- <Title flex={1} order={3} lh="1.5rem">+ <Anchor+ component={ForwardRefLink}+ fz="h3"+ fw="bold"+ lh="1.5rem"+ to={link?.url ?? ""}+ target="_blank"+ >{getNodeLabel(node)}- </Title>- <Group gap="xs" wrap="nowrap">- {link != null && (- <Tooltip label={link.label} openDelay={TOOLTIP_OPEN_DELAY_MS}>- <ActionIcon- component={ForwardRefLink}- to={link.url}- target="_blank"- aria-label={link.label}- >- <FixedSizeIcon name="external" />- </ActionIcon>- </Tooltip>- )}- <ActionIcon aria-label={t`Close`} onClick={onClose}>- <FixedSizeIcon name="close" />- </ActionIcon>- </Group>+ </Anchor>+ <ActionIcon aria-label={t`Close`} onClick={onClose}>+ <FixedSizeIcon name="close" />+ </ActionIcon></Group>);}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.tsnew file mode 100644index 00000000000..a29f2671c08--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/types.ts@@ -0,0 +1 @@+export type DependencyListMode = "broken" | "unreferenced";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.tsnew file mode 100644index 00000000000..35e13c0475b--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts@@ -0,0 +1,23 @@+import type { DependencyGroupType } from "metabase-types/api";++import type { DependencyListMode } from "./types";++const BROKEN_GROUP_TYPES: DependencyGroupType[] = [+ "question",+ "model",+ "metric",+ "segment",+ "measure",+ "transform",+];++const UNREFERENCED_GROUP_TYPES: DependencyGroupType[] = [+ "model",+ "metric",+ "segment",+ "snippet",+];++export function getAvailableGroupTypes(mode: DependencyListMode) {+ return mode === "broken" ? BROKEN_GROUP_TYPES : UNREFERENCED_GROUP_TYPES;+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsxdeleted file mode 100644index e390dc27520..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/BrokenDependencyListPage.tsx+++ /dev/null@@ -1,74 +0,0 @@-import { useDebouncedValue } from "@mantine/hooks";-import { useState } from "react";-import { t } from "ttag";--import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";-import { useListBrokenGraphNodesQuery } from "metabase-enterprise/api";-import type {- DependencyEntry,- DependencyGroupType,- DependencyNode,-} from "metabase-types/api";--import { DependencyList } from "../../components/DependencyList";-import type { DependencyFilterOptions } from "../../types";-import { getCardTypes, getDependencyTypes, getSearchQuery } from "../../utils";--const EMPTY_NODES: DependencyNode[] = [];--export const AVAILABLE_GROUP_TYPES: DependencyGroupType[] = [- "question",- "model",- "metric",- "segment",- "transform",-];--export function BrokenDependencyListPage() {- const [searchValue, setSearchValue] = useState("");- const [searchQuery] = useDebouncedValue(- getSearchQuery(searchValue),- SEARCH_DEBOUNCE_DURATION,- );- const [filterOptions, setFilterOptions] = useState<DependencyFilterOptions>({- groupTypes: [],- });- const [selectedEntry, setSelectedEntry] = useState<DependencyEntry | null>(- null,- );-- const groupTypes =- filterOptions.groupTypes.length > 0- ? filterOptions.groupTypes- : AVAILABLE_GROUP_TYPES;-- const {- data: nodes = EMPTY_NODES,- isFetching,- isLoading,- error,- } = useListBrokenGraphNodesQuery({- query: searchQuery,- types: getDependencyTypes(groupTypes),- card_types: getCardTypes(groupTypes),- });-- return (- <DependencyList- nodes={nodes}- selectedEntry={selectedEntry}- searchValue={searchValue}- filterOptions={filterOptions}- availableGroupTypes={AVAILABLE_GROUP_TYPES}- notFoundMessage={t`No broken entities found`}- isLoading={isLoading}- isFetching={isFetching}- error={error}- withErrorsColumn={true}- withDependentsCountColumn={true}- onSelect={setSelectedEntry}- onSearchValueChange={setSearchValue}- onFilterOptionsChange={setFilterOptions}- />- );-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.tsdeleted file mode 100644index 75e03097579..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/BrokenDependencyListPage/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./BrokenDependencyListPage";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsxnew file mode 100644index 00000000000..4b73c9bd1b4--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/DependencyListPage.tsx@@ -0,0 +1,33 @@+import type { Location } from "history";+import { replace } from "react-router-redux";++import { useDispatch } from "metabase/lib/redux";+import * as Urls from "metabase/lib/urls";++import { DependencyList } from "../../components/DependencyList";++import type { DependencyListQueryParams } from "./types";+import { parseParams } from "./utils";++type DependencyListPageProps = {+ location: Location<DependencyListQueryParams>;+};++export function UnreferencedDependencyListPage({+ location,+}: DependencyListPageProps) {+ const params = parseParams(location.query);+ const dispatch = useDispatch();++ const handleParamsChange = (params: Urls.DependencyListParams) => {+ dispatch(replace(Urls.unreferencedDependencies(params)));+ };++ return (+ <DependencyList+ mode="unreferenced"+ params={params}+ onParamsChange={handleParamsChange}+ />+ );+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/index.tsnew file mode 100644index 00000000000..a426cf3ed59--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/index.ts@@ -0,0 +1 @@+export * from "./DependencyListPage";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.tsnew file mode 100644index 00000000000..4f190b6519b--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/types.ts@@ -0,0 +1,7 @@+export type DependencyListQueryParams = {+ query?: unknown;+ groupTypes?: unknown;+ selectedId?: unknown;+ selectedType?: unknown;+ includePersonalCollections?: unknown;+};diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.tsnew file mode 100644index 00000000000..3472cd6e060--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyListPage/utils.ts@@ -0,0 +1,18 @@+import type * as Urls from "metabase/lib/urls";+import { DEPENDENCY_GROUP_TYPES } from "metabase-types/api";++import { parseBoolean, parseEnum, parseList, parseString } from "../../utils";++import type { DependencyListQueryParams } from "./types";++export function parseParams(+ params: DependencyListQueryParams,+): Urls.DependencyListParams {+ return {+ query: parseString(params.query),+ groupTypes: parseList(params.groupTypes, (item) =>+ parseEnum(item, DEPENDENCY_GROUP_TYPES),+ ),+ includePersonalCollections: parseBoolean(params.includePersonalCollections),+ };+}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsxdeleted file mode 100644index 71317856727..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/UnreferencedDependencyListPage.tsx+++ /dev/null@@ -1,71 +0,0 @@-import { useDebouncedValue } from "@mantine/hooks";-import { useState } from "react";-import { t } from "ttag";--import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";-import { useListUnreferencedGraphNodesQuery } from "metabase-enterprise/api";-import type {- DependencyEntry,- DependencyGroupType,- DependencyNode,-} from "metabase-types/api";--import { DependencyList } from "../../components/DependencyList";-import type { DependencyFilterOptions } from "../../types";-import { getCardTypes, getDependencyTypes, getSearchQuery } from "../../utils";--const EMPTY_NODES: DependencyNode[] = [];--export const AVAILABLE_GROUP_TYPES: DependencyGroupType[] = [- "model",- "metric",- "segment",- "snippet",-];--export function UnreferencedDependencyListPage() {- const [searchValue, setSearchValue] = useState("");- const [searchQuery] = useDebouncedValue(- getSearchQuery(searchValue),- SEARCH_DEBOUNCE_DURATION,- );- const [filterOptions, setFilterOptions] = useState<DependencyFilterOptions>({- groupTypes: [],- });- const [selectedEntry, setSelectedEntry] = useState<DependencyEntry | null>(- null,- );-- const groupTypes =- filterOptions.groupTypes.length > 0- ? filterOptions.groupTypes- : AVAILABLE_GROUP_TYPES;-- const {- data: nodes = EMPTY_NODES,- isFetching,- isLoading,- error,- } = useListUnreferencedGraphNodesQuery({- query: searchQuery,- types: getDependencyTypes(groupTypes),- card_types: getCardTypes(groupTypes),- });-- return (- <DependencyList- nodes={nodes}- selectedEntry={selectedEntry}- searchValue={searchValue}- filterOptions={filterOptions}- availableGroupTypes={AVAILABLE_GROUP_TYPES}- notFoundMessage={t`No unreferenced entities found`}- isLoading={isLoading}- isFetching={isFetching}- error={error}- onSelect={setSelectedEntry}- onSearchValueChange={setSearchValue}- onFilterOptionsChange={setFilterOptions}- />- );-}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.tsdeleted file mode 100644index d76e5ec6f4a..00000000000--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/UnreferencedDependencyListPage/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./UnreferencedDependencyListPage";diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsxindex 8a4287dc564..bce30e937d2 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx@@ -1,8 +1,7 @@import { IndexRedirect, IndexRoute, Route } from "react-router";-import { BrokenDependencyListPage } from "./pages/BrokenDependencyListPage";import { DependencyGraphPage } from "./pages/DependencyGraphPage";-import { UnreferencedDependencyListPage } from "./pages/UnreferencedDependencyListPage";+import { UnreferencedDependencyListPage } from "./pages/DependencyListPage";export function getDataStudioDependencyRoutes() {return <IndexRoute component={DependencyGraphPage} />;@@ -11,8 +10,7 @@ export function getDataStudioDependencyRoutes() {export function getDataStudioTasksRoutes() {return (<>- <IndexRedirect to="broken" />- <Route path="broken" component={BrokenDependencyListPage} />+ <IndexRedirect to="unreferenced" /><Route path="unreferenced" component={UnreferencedDependencyListPage} /></>);diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/types.tsindex 8cb1353dc10..df0d568b376 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts@@ -19,11 +19,12 @@ export type NodeLocationInfo = {links: NodeLink[];};+export type DependentGroup = {+ type: DependencyGroupType;+ count: number;+};+export type DependencyErrorInfo = {label: string;detail: string | null;};--export type DependencyFilterOptions = {- groupTypes: DependencyGroupType[];-};diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.tsindex b6e7de16230..f8b627126f4 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts@@ -1,4 +1,4 @@-import { msgid, ngettext, t } from "ttag";+import { c, msgid, ngettext, t } from "ttag";import * as Urls from "metabase/lib/urls";import type { IconName } from "metabase/ui";@@ -20,6 +20,7 @@ import type {import type {DependencyErrorInfo,DependencyGroupTypeInfo,+ DependentGroup,NodeId,NodeLink,NodeLocationInfo,@@ -502,6 +503,13 @@ export function getDependencyGroupTypeInfo(}}+export function getDependencyGroupIcon(groupType: DependencyGroupType) {+ const type = getDependencyType(groupType);+ const cardType = getCardType(groupType);++ return getNodeIconWithType(type, cardType ?? undefined);+}+export function getNodeTypeInfo(node: DependencyNode): DependencyGroupTypeInfo {// For SQL questions, return a special labelif (@@ -530,6 +538,96 @@ export function getCardTypes(groupTypes: DependencyGroupType[]): CardType[] {return Array.from(new Set(cardTypes));}+export function getDependentGroups(node: DependencyNode): DependentGroup[] {+ const {+ question = 0,+ model = 0,+ metric = 0,+ table = 0,+ transform = 0,+ snippet = 0,+ dashboard = 0,+ document = 0,+ sandbox = 0,+ segment = 0,+ measure = 0,+ } = node.dependents_count ?? {};++ const groups: DependentGroup[] = [+ { type: "question", count: question },+ { type: "model", count: model },+ { type: "metric", count: metric },+ { type: "table", count: table },+ { type: "transform", count: transform },+ { type: "snippet", count: snippet },+ { type: "dashboard", count: dashboard },+ { type: "document", count: document },+ { type: "sandbox", count: sandbox },+ { type: "segment", count: segment },+ { type: "measure", count: measure },+ ];++ return groups.filter(({ count }) => count !== 0);+}++export function getDependencyGroupTitle(+ node: DependencyNode,+ groups: DependentGroup[],+) {+ if (node.type === "sandbox") {+ return t`Restricts table data`;+ }+ if (groups.length === 0) {+ return t`Nothing uses this`;+ }+ if (node.type === "transform") {+ return t`Generates`;+ }+ return t`Used by`;+}++export function getDependentGroupLabel({+ type,+ count,+}: DependentGroup): string {+ switch (type) {+ case "question":+ return ngettext(msgid`${count} question`, `${count} questions`, count);+ case "model":+ return ngettext(msgid`${count} model`, `${count} models`, count);+ case "metric":+ return ngettext(msgid`${count} metric`, `${count} metrics`, count);+ case "table":+ return ngettext(msgid`${count} table`, `${count} tables`, count);+ case "transform":+ return ngettext(msgid`${count} transform`, `${count} transforms`, count);+ case "snippet":+ return ngettext(msgid`${count} snippet`, `${count} snippet`, count);+ case "dashboard":+ return ngettext(msgid`${count} dashboard`, `${count} dashboards`, count);+ case "document":+ return ngettext(msgid`${count} document`, `${count} documents`, count);+ case "sandbox":+ return ngettext(+ msgid`${count} row and column security rule`,+ `${count} row and column security rules`,+ count,+ );+ case "segment":+ return c("{0} is the number of segments").ngettext(+ msgid`${count} segment`,+ `${count} segments`,+ count,+ );+ case "measure":+ return c("{0} is the number of measures").ngettext(+ msgid`${count} measure`,+ `${count} measures`,+ count,+ );+ }+}+export function getDependencyErrorTypeLabel(type: DependencyErrorType): string {switch (type) {case "validate/missing-column":@@ -630,6 +728,21 @@ export function getDependencyErrorInfo(};}+export function parseString(value: unknown): string | undefined {+ return typeof value === "string" ? value : undefined;+}++export function parseBoolean(value: unknown): boolean | undefined {+ switch (value) {+ case "true":+ return true;+ case "false":+ return false;+ default:+ return undefined;+ }+}+export function parseEnum<T extends string>(value: unknown,items: readonly T[],@@ -641,6 +754,18 @@ export function parseEnum<T extends string>(return item != null ? item : undefined;}+export function parseList<T>(+ value: unknown,+ parseItem: (item: unknown) => T | undefined,+): T[] | undefined {+ if (value != null) {+ const array = Array.isArray(value) ? value : [value];+ return array.map(parseItem).filter((item) => item != null);+ } else {+ return undefined;+ }+}+export function getSearchQuery(searchValue: string): string | undefined {const searchQuery = searchValue.trim();return searchQuery.length > 0 ? searchQuery : undefined;diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.tsindex 5c2a76ad54f..9f9bfee5c57 100644--- a/frontend/src/metabase-types/api/dependencies.ts+++ b/frontend/src/metabase-types/api/dependencies.ts@@ -283,10 +283,12 @@ export type ListBrokenGraphNodesRequest = {types?: DependencyType[];card_types?: CardType[];query?: string;+ include_personal_collections?: boolean;};export type ListUnreferencedGraphNodesRequest = {types?: DependencyType[];card_types?: CardType[];query?: string;+ include_personal_collections?: boolean;};diff --git a/frontend/src/metabase/lib/urls/data-studio.ts b/frontend/src/metabase/lib/urls/data-studio.tsindex c4ffa0765cd..e9967e77105 100644--- a/frontend/src/metabase/lib/urls/data-studio.ts+++ b/frontend/src/metabase/lib/urls/data-studio.ts@@ -308,15 +308,3 @@ export function newDataStudioSegment(tableId: TableId) {export function dataStudioSegmentDependencies(segmentId: SegmentId) {return `${dataStudioSegment(segmentId)}/dependencies`;}--export function dataStudioDependencyDiagnostics() {- return `${ROOT_URL}/dependency-diagnostics`;-}--export function dataStudioBrokenEntities() {- return `${dataStudioDependencyDiagnostics()}/broken`;-}--export function dataStudioUnreferencedEntities() {- return `${dataStudioDependencyDiagnostics()}/unreferenced`;-}diff --git a/frontend/src/metabase/lib/urls/dependencies.ts b/frontend/src/metabase/lib/urls/dependencies.tsindex aaff7bdc0fe..4e4b785ad88 100644--- a/frontend/src/metabase/lib/urls/dependencies.ts+++ b/frontend/src/metabase/lib/urls/dependencies.ts@@ -1,6 +1,8 @@-import type { DependencyEntry } from "metabase-types/api";+import type { DependencyEntry, DependencyGroupType } from "metabase-types/api";-const BASE_URL = `/data-studio/dependencies`;+const BASE_URL = `/data-studio`;+const GRAPH_URL = `${BASE_URL}/dependencies`;+const TASKS_URL = `${BASE_URL}/tasks`;export type DependencyGraphParams = {entry?: DependencyEntry;@@ -9,7 +11,7 @@ export type DependencyGraphParams = {export function dependencyGraph({entry,- baseUrl = BASE_URL,+ baseUrl = GRAPH_URL,}: DependencyGraphParams = {}) {const searchParams = new URLSearchParams();if (entry != null) {@@ -19,3 +21,46 @@ export function dependencyGraph({const queryString = searchParams.toString();return queryString.length > 0 ? `${baseUrl}?${queryString}` : baseUrl;}++export function dependencyTasks() {+ return TASKS_URL;+}++export type DependencyListParams = {+ query?: string;+ groupTypes?: DependencyGroupType[];+ includePersonalCollections?: boolean;+};++function dependencyListQueryString({+ query,+ groupTypes,+ includePersonalCollections,+}: DependencyListParams = {}) {+ const searchParams = new URLSearchParams();+ if (query != null) {+ searchParams.set("query", query);+ }+ if (groupTypes != null) {+ groupTypes.forEach((groupType) => {+ searchParams.append("groupTypes", groupType);+ });+ }+ if (includePersonalCollections != null) {+ searchParams.set(+ "includePersonalCollections",+ String(includePersonalCollections),+ );+ }++ const queryString = searchParams.toString();+ return queryString.length > 0 ? `?${queryString}` : "";+}++export function brokenDependencies(params?: DependencyListParams) {+ return `${dependencyTasks()}/broken${dependencyListQueryString(params)}`;+}++export function unreferencedDependencies(params?: DependencyListParams) {+ return `${dependencyTasks()}/unreferenced${dependencyListQueryString(params)}`;+}