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
Show view_count for models and metrics in dependencies (#68588)
Alexander Polyankin0bd69823a434
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.tsindex d4b64a33f0c..1c3b487e33c 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@@ -63,14 +63,16 @@ export function getAvailableSortColumns(return ["name","location",- ...(canHaveViewCount(groupType) ? ["view-count" as const] : []),+ ...(canHaveViewCount(getDependencyType(groupType))+ ? ["view-count" as const]+ : []),];}export function getDefaultSortOptions(groupType: DependencyGroupType,): DependencySortOptions {- return canHaveViewCount(groupType)+ return canHaveViewCount(getDependencyType(groupType))? { column: "view-count", direction: "desc" }: { column: "name", direction: "asc" };}diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.tsindex 6204d1d8e82..3ac3ee2f077 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts@@ -396,17 +396,13 @@ export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {}}-export function canHaveViewCount(groupType: DependencyGroupType): boolean {- switch (groupType) {- case "question":+export function canHaveViewCount(type: DependencyType): boolean {+ switch (type) {+ case "card":case "dashboard":case "document":return true;- // view_count is not calculated property for models and metrics since- // they are typically not run directlycase "table":- case "model":- case "metric":case "transform":case "snippet":case "sandbox":@@ -419,11 +415,6 @@ export function canHaveViewCount(groupType: DependencyGroupType): boolean {export function getNodeViewCount(node: DependencyNode): number | null {switch (node.type) {case "card":- // view_count is not calculated property for models and metrics since- // they are typically not run directly- return node.data.type === "question"- ? (node.data.view_count ?? null)- : null;case "dashboard":case "document":return node.data.view_count ?? null;diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.tsindex b43c4300554..5651cd91308 100644--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts@@ -14,8 +14,10 @@ import {createMockCardDependencyNodeData,createMockCollection,createMockDashboardDependencyNode,+ createMockDashboardDependencyNodeData,createMockDatabase,createMockDocumentDependencyNode,+ createMockDocumentDependencyNodeData,createMockMeasureDependencyNode,createMockSandboxDependencyNode,createMockSegmentDependencyNode,@@ -35,6 +37,7 @@ import type {NodeLink,} from "./types";import {+ canHaveViewCount,getCardType,getCardTypes,getDependencyErrorGroups,@@ -508,51 +511,64 @@ describe("getNodeLastEditedBy", () => {});});-describe("getNodeViewCount", () => {- it("should return view count for question", () => {- const node = createMockCardDependencyNode({- data: createMockCardDependencyNodeData({- type: "question",- view_count: 100,- }),- });- expect(getNodeViewCount(node)).toBe(100);+describe("canHaveViewCount", () => {+ it.each<{ type: DependencyType; expected: boolean }>([+ { type: "card", expected: true },+ { type: "dashboard", expected: true },+ { type: "document", expected: true },+ { type: "table", expected: false },+ { type: "transform", expected: false },+ { type: "segment", expected: false },+ { type: "measure", expected: false },+ { type: "snippet", expected: false },+ { type: "sandbox", expected: false },+ ])("should return $expected for $type", ({ type, expected }) => {+ expect(canHaveViewCount(type)).toBe(expected);});+});- it("should return null for model", () => {- const node = createMockCardDependencyNode({- data: createMockCardDependencyNodeData({- type: "model",- view_count: 100,+describe("getNodeViewCount", () => {+ it.each<{ node: DependencyNode; expected: number | null }>([+ {+ node: createMockCardDependencyNode({+ data: createMockCardDependencyNodeData({+ type: "question",+ view_count: 100,+ }),}),- });- expect(getNodeViewCount(node)).toBeNull();- });-- it("should return view count for dashboard", () => {- const node = createMockDashboardDependencyNode({- data: {- name: "Dashboard",- description: null,- created_at: "2020-01-01T00:00:00Z",- collection_id: null,- moderation_reviews: [],- view_count: 50,- "last-edit-info": {- id: 1,- email: "[email protected]",- first_name: "Test",- last_name: "User",- timestamp: "2020-01-01T00:00:00Z",- },- },- });- expect(getNodeViewCount(node)).toBe(50);- });-- it("should return null for table", () => {- const node = createMockTableDependencyNode();- expect(getNodeViewCount(node)).toBeNull();+ expected: 100,+ },+ {+ node: createMockCardDependencyNode({+ data: createMockCardDependencyNodeData({+ type: "model",+ view_count: 100,+ }),+ }),+ expected: 100,+ },+ {+ node: createMockDashboardDependencyNode({+ data: createMockDashboardDependencyNodeData({+ view_count: 50,+ }),+ }),+ expected: 50,+ },+ {+ node: createMockDocumentDependencyNode({+ data: createMockDocumentDependencyNodeData({+ view_count: 25,+ }),+ }),+ expected: 25,+ },+ {+ node: createMockTableDependencyNode(),+ expected: null,+ },+ ])("should return view count for $node.type", ({ node, expected }) => {+ expect(getNodeViewCount(node)).toBe(expected);});});