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
Register the use-icon spec's own visualizations from viz-core (#81844)
Fraser9ddee1f43498
diff --git a/frontend/lint/module-boundaries.mjs b/frontend/lint/module-boundaries.mjsindex 6354a259733..0b6e2f07eb3 100644--- a/frontend/lint/module-boundaries.mjs+++ b/frontend/lint/module-boundaries.mjs@@ -210,7 +210,7 @@ const elements = [createElement({ type: "shared", name: "forms" }),createElement({ type: "shared", name: "hoc" }),createElement({ type: "feature", name: "home" }),- createElement({ type: "shared", name: "hooks", enforceSharedTiers: false }),+ createElement({ type: "shared", name: "hooks" }),createElement({ type: "shared", name: "content-translation" }),createElement({ type: "shared", name: "metabot", enforceSharedTiers: false }),// The app-wide mirror of table and field metadata. Separate fromdiff --git a/frontend/src/metabase/hooks/use-icon.unit.spec.ts b/frontend/src/metabase/hooks/use-icon.unit.spec.tsindex db9cd8f6ab7..d5c2ec8d6e0 100644--- a/frontend/src/metabase/hooks/use-icon.unit.spec.ts+++ b/frontend/src/metabase/hooks/use-icon.unit.spec.ts@@ -1,12 +1,34 @@import { renderHook } from "@testing-library/react";-import { registerVisualizations as register } from "metabase/visualizations/register";+import {+ type VisualizationDefinition,+ registerVisualization,+ setDefaultVisualization,+} from "metabase/viz-core";+import type { IconName, VisualizationDisplay } from "metabase-types/api";import { useGetIcon } from "./use-icon";+// The hook only reads each registered visualization's iconName,+// so the spec registers stubs instead of the real chart modules from metabase/visualizations.+const createDefinition = (+ identifier: VisualizationDisplay,+ iconName: IconName,+): VisualizationDefinition => ({+ identifier,+ iconName,+ getUiName: () => identifier,+ checkRenderable: () => undefined,+});++const REGISTERED_DEFINITION = createDefinition("funnel", "rocket");+const DEFAULT_DEFINITION = createDefinition("table", "moon");+describe("useGetIcon", () => {beforeAll(() => {- register();+ // The registry resolves unknown display types to the default visualization.+ setDefaultVisualization(DEFAULT_DEFINITION);+ registerVisualization(REGISTERED_DEFINITION);});const createGetIcon = () => {@@ -73,68 +95,23 @@ describe("useGetIcon", () => {});describe("card display types", () => {- it("should return the default icon for an invalid display type", () => {- const getIcon = createGetIcon();- expect(- // @ts-expect-error testing invalid display type- getIcon({ model: "card", display: "pikachu" }),- ).toEqual({- name: "table2",- });- });-- it("should return the default icon for no display type", () => {+ it("should return the registered visualization's icon for a card", () => {const getIcon = createGetIcon();- expect(getIcon({ model: "card" })).toEqual({ name: "table2" });- });-- it("should return the correct icon for a card with a table chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "table" })).toEqual({- name: "table2",- });- });-- it("should return the correct icon for a card with a bar chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "bar" })).toEqual({- name: "bar",- });- });-- it("should return the correct icon for a card with a pie chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "pie" })).toEqual({- name: "pie",- });- });-- it("should return the correct icon for a card with a line chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "line" })).toEqual({- name: "line",- });- });-- it("should return the correct icon for a card with a row chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "row" })).toEqual({- name: "horizontal_bar",+ expect(getIcon({ model: "card", display: "funnel" })).toEqual({+ name: "rocket",});});- it("should return the correct icon for a card with a funnel chart", () => {+ it("should fall back to the default visualization's icon for an unknown display", () => {const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "funnel" })).toEqual({- name: "funnel",+ expect(getIcon({ model: "card", display: "scatter" })).toEqual({+ name: "moon",});});- it("should return the correct icon for a card with a map chart", () => {+ it("should return the default icon for no display type", () => {const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "map" })).toEqual({- name: "pinmap",- });+ expect(getIcon({ model: "card" })).toEqual({ name: "table2" });});it("should return the correct icon for a personal collection root", () => {@@ -165,12 +142,5 @@ describe("useGetIcon", () => {name: "group",});});-- it("should return the correct icon for a card with an object detail chart", () => {- const getIcon = createGetIcon();- expect(getIcon({ model: "card", display: "object" })).toEqual({- name: "document",- });- });});});diff --git a/frontend/src/metabase/plugins/oss/collections.ts b/frontend/src/metabase/plugins/oss/collections.tsindex 70ca20e6833..6e0efd15cd6 100644--- a/frontend/src/metabase/plugins/oss/collections.ts+++ b/frontend/src/metabase/plugins/oss/collections.ts@@ -81,7 +81,7 @@ const getDefaultPluginCollections = () => ({_collection: Collection,_onUpdate: (collection: Collection, values: Partial<Collection>) => void,): React.ReactNode[] => [],- useGetIcon: useGetIconBase,+ useGetIcon: () => useGetIconBase(),filterOutItemsFromInstanceAnalytics: <Item extends ItemWithCollection>(items: Item[],) => items,