1- import { Fragment , useEffect , useMemo } from 'react' ;
1+ import { Fragment , useEffect , useMemo , useRef } from 'react' ;
22
33import Feature from 'sentry/components/acl/feature' ;
44import { FeatureBadge } from 'sentry/components/core/badge/featureBadge' ;
@@ -10,6 +10,7 @@ import {useLocation} from 'sentry/utils/useLocation';
1010import useOrganization from 'sentry/utils/useOrganization' ;
1111import useProjects from 'sentry/utils/useProjects' ;
1212import { useGetSavedQueries } from 'sentry/views/explore/hooks/useGetSavedQueries' ;
13+ import { canUseMetricsUI } from 'sentry/views/explore/metrics/metricsFlags' ;
1314import { PRIMARY_NAV_GROUP_CONFIG } from 'sentry/views/nav/primary/config' ;
1415import { SecondaryNav } from 'sentry/views/nav/secondary/secondary' ;
1516import { ExploreSavedQueryNavItems } from 'sentry/views/nav/secondary/sections/explore/exploreSavedQueryNavItems' ;
@@ -38,23 +39,32 @@ export function ExploreSecondaryNav() {
3839 [ projects ]
3940 ) ;
4041
41- const hasMetricsSupportedPlatform = projects . some ( project => {
42- const platform = project . platform || 'unknown' ;
43- return Array . from ( limitedMetricsSupportPrefixes ) . some ( prefix =>
44- platform . startsWith ( prefix )
45- ) ;
46- } ) ;
42+ const metricsSupportedPlatformNameRef = useRef < string | undefined > ( undefined ) ;
43+
44+ if ( ! metricsSupportedPlatformNameRef . current ) {
45+ const metricsSupportedPlatform = projects . find ( project => {
46+ const platform = project . platform || 'unknown' ;
47+ return Array . from ( limitedMetricsSupportPrefixes ) . find ( prefix =>
48+ platform . startsWith ( prefix )
49+ ) ;
50+ } ) ;
51+ metricsSupportedPlatformNameRef . current = metricsSupportedPlatform ?. slug ;
52+ }
53+
54+ const hasMetricsSupportedPlatform = ! ! metricsSupportedPlatformNameRef . current ;
4755
4856 useEffect ( ( ) => {
4957 if ( userPlatforms . length === 0 ) {
5058 return ;
5159 }
5260 trackAnalytics ( 'metrics.nav.rendered' , {
5361 organization,
54- metrics_tab_visible : hasMetricsSupportedPlatform ,
55- platforms : userPlatforms ,
62+ has_feature_flag : canUseMetricsUI ( organization ) ,
63+ has_metrics_supported_platform : hasMetricsSupportedPlatform ,
64+ metrics_supported_platform_name : metricsSupportedPlatformNameRef . current ,
65+ metrics_tab_visible : hasMetricsSupportedPlatform && canUseMetricsUI ( organization ) ,
5666 } ) ;
57- } , [ organization , hasMetricsSupportedPlatform , userPlatforms ] ) ;
67+ } , [ organization , hasMetricsSupportedPlatform , userPlatforms . length ] ) ;
5868
5969 return (
6070 < Fragment >
0 commit comments