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
Move the entity icon slot into hooks (#81857)
Fraser81049d6069d2
diff --git a/enterprise/frontend/src/metabase-enterprise/collections/components/CollectionAuthorityLevelDisplay.tsx b/enterprise/frontend/src/metabase-enterprise/collections/components/CollectionAuthorityLevelDisplay.tsxindex 09da7cb167a..09edb3f7058 100644--- a/enterprise/frontend/src/metabase-enterprise/collections/components/CollectionAuthorityLevelDisplay.tsx+++ b/enterprise/frontend/src/metabase-enterprise/collections/components/CollectionAuthorityLevelDisplay.tsx@@ -2,7 +2,7 @@ import { useMemo } from "react";import { t } from "ttag";import type { ObjectWithModel } from "metabase/common/utils/icon";-import { PLUGIN_COLLECTIONS } from "metabase/plugins";+import { useGetIcon } from "metabase/hooks/use-icon";import { Group, Icon, Text } from "metabase/ui";import type { Collection } from "metabase-types/api";@@ -11,7 +11,7 @@ export const CollectionAuthorityLevelDisplay = ({}: {collection: Collection;}) => {- const getIcon = PLUGIN_COLLECTIONS.useGetIcon();+ const getIcon = useGetIcon();const iconProps = useMemo(() =>// Unjustified type cast. FIXMEdiff --git a/enterprise/frontend/src/metabase-enterprise/collections/index.tsx b/enterprise/frontend/src/metabase-enterprise/collections/index.tsxindex 223463f4a24..4cd051ecab3 100644--- a/enterprise/frontend/src/metabase-enterprise/collections/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/collections/index.tsx@@ -1,5 +1,6 @@import { t } from "ttag";+import { PLUGIN_ENTITY_ICON } from "metabase/hooks/plugins";import {PLUGIN_COLLECTIONS,PLUGIN_COLLECTION_COMPONENTS,@@ -41,7 +42,7 @@ export function initializePlugin() {PLUGIN_COLLECTIONS.isRegularCollection = isRegularCollection;PLUGIN_COLLECTIONS.REGULAR_COLLECTION = REGULAR_COLLECTION;PLUGIN_COLLECTIONS.AUTHORITY_LEVEL = AUTHORITY_LEVELS;- PLUGIN_COLLECTIONS.useGetIcon = useGetIcon;+ PLUGIN_ENTITY_ICON.useGetIcon = useGetIcon;PLUGIN_COLLECTIONS.getAuthorityLevelMenuItems = (collection: Collection,diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsxindex 1ccf90d1b06..70dff711e48 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx@@ -1,7 +1,7 @@import { c, t } from "ttag";import CS from "metabase/css/core/bordered.module.css";-import { PLUGIN_COLLECTIONS } from "metabase/plugins";+import { useGetIcon } from "metabase/hooks/use-icon";import { Box, Flex, Icon, Switch, Text } from "metabase/ui";import type { CollectionItem } from "metabase-types/api";@@ -18,7 +18,7 @@ export const CollectionSyncRow = ({onToggle,isReadOnly,}: CollectionSyncRowProps) => {- const getIcon = PLUGIN_COLLECTIONS.useGetIcon();+ const getIcon = useGetIcon();const canWrite = collection.can_write ?? false;const icon = getIcon({model: "collection",diff --git a/frontend/src/metabase/hooks/plugins.ts b/frontend/src/metabase/hooks/plugins.tsnew file mode 100644index 00000000000..8c5841dadd5--- /dev/null+++ b/frontend/src/metabase/hooks/plugins.ts@@ -0,0 +1,7 @@+import { definePluginSlot } from "metabase/plugins";++import { useGetIconBase } from "./use-icon";++export const PLUGIN_ENTITY_ICON = definePluginSlot(() => ({+ useGetIcon: () => useGetIconBase(),+}));diff --git a/frontend/src/metabase/hooks/use-icon.ts b/frontend/src/metabase/hooks/use-icon.tsindex 7828607b933..c38466c4093 100644--- a/frontend/src/metabase/hooks/use-icon.ts+++ b/frontend/src/metabase/hooks/use-icon.ts@@ -3,10 +3,12 @@ import { useCallback } from "react";import { PERSONAL_COLLECTIONS } from "metabase/common/collections/constants";import type { IconData, ObjectWithModel } from "metabase/common/utils/icon";import { modelIconMap } from "metabase/common/utils/icon";-import { PLUGIN_COLLECTIONS, PLUGIN_CUSTOM_VIZ } from "metabase/plugins";+import { PLUGIN_CUSTOM_VIZ } from "metabase/plugins";import { getIconForVisualizationType } from "metabase/viz-core";import type { VisualizationDisplay } from "metabase-types/api";+import { PLUGIN_ENTITY_ICON } from "./plugins";+export const useGetIconForVisualizationType = () => {const getCustomVizIcon = PLUGIN_CUSTOM_VIZ.useCustomVizPluginsIcon();@@ -72,4 +74,4 @@ export const useGetIconBase = () => {* relies mainly on the `model` property to determine the icon to return* also handle special collection icons and visualization types for cards*/-export const useGetIcon = () => PLUGIN_COLLECTIONS.useGetIcon();+export const useGetIcon = () => PLUGIN_ENTITY_ICON.useGetIcon();diff --git a/frontend/src/metabase/plugins/oss/collections.ts b/frontend/src/metabase/plugins/oss/collections.tsindex 648f54e6ccb..761985e9465 100644--- a/frontend/src/metabase/plugins/oss/collections.ts+++ b/frontend/src/metabase/plugins/oss/collections.ts@@ -6,7 +6,6 @@ import type {CollectionAuthorityLevelConfig,CollectionInstanceAnaltyicsConfig,} from "metabase/common/collections/types";-import { useGetIconBase } from "metabase/hooks/use-icon";import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";import type { IconProps } from "metabase/ui";import type {@@ -83,7 +82,6 @@ const getDefaultPluginCollections = () => ({_collection: Collection,_onUpdate: (collection: Collection, values: Partial<Collection>) => void,): React.ReactNode[] => [],- useGetIcon: () => useGetIconBase(),filterOutItemsFromInstanceAnalytics: <Item extends ItemWithCollection>(items: Item[],) => items,