@@ -20,6 +20,14 @@ import './GlobalHeaderDropdown.scss'
2020// Types
2121import GlobalHeaderTypeAheadMenu from 'src/identity/components/GlobalHeader/GlobalHeaderDropdown/GlobalHeaderTypeAheadMenu'
2222
23+ // Eventing
24+ import {
25+ MainMenuEventPrefix ,
26+ multiOrgTag ,
27+ TypeAheadEventPrefix ,
28+ } from 'src/identity/events/multiOrgEvents'
29+ import { event } from 'src/cloud/utils/reporting'
30+
2331export interface MainMenuItem {
2432 name : string
2533 iconFont : string
@@ -34,20 +42,22 @@ export interface TypeAheadMenuItem {
3442export interface Props extends StandardFunctionProps {
3543 defaultButtonText ?: string
3644 defaultTestID ?: string
37- dropdownButtonSize ?: ComponentSize
3845 dropdownButtonIcon ?: IconFont
46+ dropdownButtonSize ?: ComponentSize
3947 dropdownMenuStyle ?: React . CSSProperties
4048 dropdownMenuTheme ?: DropdownMenuTheme
41- mainMenuHeaderText ?: string
49+ mainMenuEventPrefix ?: MainMenuEventPrefix
4250 mainMenuHeaderIcon ?: IconFont
51+ mainMenuHeaderText ?: string
4352 mainMenuOptions : MainMenuItem [ ]
4453 mainMenuTestID ?: string
4554 onlyRenderSubmenu ?: boolean
4655 testID ?: string
47- typeAheadSelectedOption ?: TypeAheadMenuItem
48- typeAheadMenuOptions : TypeAheadMenuItem [ ]
56+ typeAheadEventPrefix : TypeAheadEventPrefix
4957 typeAheadInputPlaceholder ?: string
58+ typeAheadMenuOptions : TypeAheadMenuItem [ ]
5059 typeAheadOnSelectOption ?: ( item : TypeAheadMenuItem | null ) => void
60+ typeAheadSelectedOption ?: TypeAheadMenuItem
5161 typeAheadTestID ?: string
5262}
5363
@@ -80,46 +90,63 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
8090 const {
8191 defaultButtonText,
8292 defaultTestID,
83- dropdownButtonSize,
8493 dropdownButtonIcon,
94+ dropdownButtonSize,
8595 } = this . props
8696 const { selectedItem} = this . state
8797 return (
8898 < Dropdown . Button
8999 active = { active }
100+ className = "global-header--dropdown-button"
90101 onClick = { onClick }
91102 size = { dropdownButtonSize }
92- trailingIcon = { dropdownButtonIcon || IconFont . DoubleCaretVertical }
93- className = "global-header--dropdown-button"
94103 testID = { defaultTestID }
104+ trailingIcon = { dropdownButtonIcon || IconFont . DoubleCaretVertical }
95105 >
96106 { selectedItem ?. name || defaultButtonText }
97107 </ Dropdown . Button >
98108 )
99109 }
100110
111+ private sendMainMenuEvent = ( menuItem : string ) => ( ) => {
112+ const { mainMenuEventPrefix} = this . props
113+ event ( `${ mainMenuEventPrefix } ${ menuItem } .clicked` , multiOrgTag )
114+ }
115+
101116 private toggleShowTypeAheadMenu = ( ) => {
117+ const { mainMenuEventPrefix} = this . props
102118 const { showTypeAheadMenu} = this . state
119+ // 'Clicked the switch button' event only emitted when opening the typeahead.
120+ if ( ! showTypeAheadMenu ) {
121+ event ( `${ mainMenuEventPrefix } Switch.clicked` , multiOrgTag )
122+ }
103123 this . setState ( { showTypeAheadMenu : ! showTypeAheadMenu } )
104124 }
105125
106126 private renderMainMenuOptions = ( ) => {
107127 const { mainMenuOptions} = this . props
108128 return (
109129 < div >
110- { mainMenuOptions . map ( value => {
111- const iconEl = < Icon glyph = { value . iconFont } className = "button-icon" />
112- const textEl = < span > { value . name } </ span >
130+ { mainMenuOptions . map ( menuItem => {
131+ const iconEl = (
132+ < Icon glyph = { menuItem . iconFont } className = "button-icon" />
133+ )
134+ const textEl = < span > { menuItem . name } </ span >
113135 return (
114- < Dropdown . HrefItem
115- key = { value . name }
116- href = { value . href }
117- className = "global-header--align-center"
118- testID = { `${ this . props . mainMenuTestID } -${ value . name } ` }
136+ < div
137+ onClick = { this . sendMainMenuEvent ( menuItem . name ) }
138+ key = { `eventWrapper.${ menuItem . name } ` }
119139 >
120- { iconEl }
121- { textEl }
122- </ Dropdown . HrefItem >
140+ < Dropdown . HrefItem
141+ className = "global-header--align-center"
142+ key = { menuItem . name }
143+ href = { menuItem . href }
144+ testID = { `${ this . props . mainMenuTestID } -${ menuItem . name } ` }
145+ >
146+ { iconEl }
147+ { textEl }
148+ </ Dropdown . HrefItem >
149+ </ div >
123150 )
124151 } ) }
125152 </ div >
@@ -130,29 +157,31 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
130157 const { typeAheadMenuOptions} = this . props
131158 const { selectedItem} = this . state
132159 const {
160+ dropdownMenuStyle,
161+ typeAheadEventPrefix,
133162 typeAheadInputPlaceholder,
134163 typeAheadOnSelectOption,
135- dropdownMenuStyle,
136164 } = this . props
137165 return (
138166 < GlobalHeaderTypeAheadMenu
139- typeAheadPlaceHolder = { typeAheadInputPlaceholder }
140- typeAheadMenuOptions = { typeAheadMenuOptions }
167+ defaultSelectedItem = { selectedItem }
141168 onSelectOption = { typeAheadOnSelectOption }
142169 style = { dropdownMenuStyle }
143- defaultSelectedItem = { selectedItem }
144170 testID = { this . props . typeAheadTestID }
171+ typeAheadEventPrefix = { typeAheadEventPrefix }
172+ typeAheadMenuOptions = { typeAheadMenuOptions }
173+ typeAheadPlaceHolder = { typeAheadInputPlaceholder }
145174 />
146175 )
147176 }
148177
149178 private renderMenu = ( ) => {
150179 const {
151- mainMenuHeaderText,
152- dropdownMenuTheme = DropdownMenuTheme . None ,
153180 dropdownMenuStyle,
154- typeAheadMenuOptions,
181+ dropdownMenuTheme = DropdownMenuTheme . None ,
182+ mainMenuHeaderText,
155183 onlyRenderSubmenu = false ,
184+ typeAheadMenuOptions,
156185 } = this . props
157186 const { showTypeAheadMenu} = this . state
158187
@@ -210,8 +239,8 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
210239 return (
211240 < Dropdown
212241 { ...dropdownProps }
213- disableAutoFocus
214242 button = { this . dropdownButton }
243+ disableAutoFocus
215244 menu = { this . renderMenu }
216245 testID = { this . props . testID }
217246 />
0 commit comments