1
- import { type MouseEventHandler , useCallback } from 'react' ;
1
+ import type { MouseEventHandler } from 'react' ;
2
2
import { css , type Theme } from '@emotion/react' ;
3
3
import styled from '@emotion/styled' ;
4
4
@@ -12,6 +12,7 @@ import {isLinkActive, makeLinkPropsFromTo} from 'sentry/components/nav/utils';
12
12
import { Tooltip } from 'sentry/components/tooltip' ;
13
13
import { IconDefaultsProvider } from 'sentry/icons/useIconDefaults' ;
14
14
import { space } from 'sentry/styles/space' ;
15
+ import type { Organization } from 'sentry/types/organization' ;
15
16
import { trackAnalytics } from 'sentry/utils/analytics' ;
16
17
import normalizeUrl from 'sentry/utils/url/normalizeUrl' ;
17
18
import { useLocation } from 'sentry/utils/useLocation' ;
@@ -43,6 +44,13 @@ interface SidebarButtonProps {
43
44
onClick ?: MouseEventHandler < HTMLElement > ;
44
45
}
45
46
47
+ function recordPrimaryItemClick ( analyticsKey : string , organization : Organization ) {
48
+ trackAnalytics ( 'navigation.primary_item_clicked' , {
49
+ item : analyticsKey ,
50
+ organization,
51
+ } ) ;
52
+ }
53
+
46
54
export function SidebarItem ( {
47
55
children,
48
56
...props
@@ -63,10 +71,6 @@ export function SidebarMenu({
63
71
forceLabel,
64
72
} : SidebarItemDropdownProps ) {
65
73
const organization = useOrganization ( ) ;
66
- const recordAnalytics = useCallback (
67
- ( ) => trackAnalytics ( 'growth.clicked_sidebar' , { item : analyticsKey , organization} ) ,
68
- [ organization , analyticsKey ]
69
- ) ;
70
74
const { layout} = useNavContext ( ) ;
71
75
72
76
const showLabel = forceLabel || layout === NavLayout . MOBILE ;
@@ -82,7 +86,7 @@ export function SidebarMenu({
82
86
{ ...props }
83
87
aria-label = { showLabel ? undefined : label }
84
88
onClick = { event => {
85
- recordAnalytics ( ) ;
89
+ recordPrimaryItemClick ( analyticsKey , organization ) ;
86
90
props . onClick ?.( event ) ;
87
91
} }
88
92
isMobile = { layout === NavLayout . MOBILE }
@@ -115,17 +119,12 @@ export function SidebarLink({
115
119
const { layout} = useNavContext ( ) ;
116
120
const showLabel = forceLabel || layout === NavLayout . MOBILE ;
117
121
118
- const recordAnalytics = useCallback (
119
- ( ) => trackAnalytics ( 'growth.clicked_sidebar' , { item : analyticsKey , organization} ) ,
120
- [ organization , analyticsKey ]
121
- ) ;
122
-
123
122
return (
124
123
< SidebarItem >
125
124
< Tooltip title = { label } disabled = { showLabel } position = "right" skipWrapper >
126
125
< NavLink
127
126
{ ...linkProps }
128
- onClick = { recordAnalytics }
127
+ onClick = { ( ) => recordPrimaryItemClick ( analyticsKey , organization ) }
129
128
aria-selected = { isActive }
130
129
aria-current = { isActive ? 'page' : undefined }
131
130
aria-label = { showLabel ? undefined : label }
@@ -157,7 +156,7 @@ export function SidebarButton({
157
156
isMobile = { layout === NavLayout . MOBILE }
158
157
aria-label = { showLabel ? undefined : label }
159
158
onClick = { ( e : React . MouseEvent < HTMLElement > ) => {
160
- trackAnalytics ( 'growth.clicked_sidebar' , { item : analyticsKey , organization} ) ;
159
+ recordPrimaryItemClick ( analyticsKey , organization ) ;
161
160
buttonProps . onClick ?.( e ) ;
162
161
onClick ?.( e ) ;
163
162
} }
0 commit comments