1- import React , { FunctionComponent , useCallback , useMemo , useRef , useState } from 'react' ;
1+ import React , { FunctionComponent , useCallback , useMemo , useRef , useState , useEffect } from 'react' ;
22import { VscError , VscWarning , VscInfo , VscLightbulb , VscSearch , VscClose , VscSettingsGear } from 'react-icons/vsc' ;
33import { useModal } from '@ebay/nice-modal-react' ;
44import { DiagnosticSeverity } from '@asyncapi/parser' ;
@@ -11,6 +11,7 @@ import { debounce } from '../../helpers';
1111import { useDocumentsState , useSettingsState } from '../../state' ;
1212
1313import type { Diagnostic } from '@asyncapi/parser' ;
14+ import { trackEvent } from '@/helpers/analytics' ;
1415
1516interface ProblemsTabProps { }
1617
@@ -207,6 +208,10 @@ export const ProblemsTabContent: FunctionComponent<ProblemsTabProps> = () => {
207208 const [ search , setSearch ] = useState < string > ( '' ) ;
208209 const inputRef = useRef < HTMLInputElement > ( null ) ;
209210
211+ useEffect ( ( ) => {
212+ trackEvent ( 'Diagnostics' , 'panel_opened' , 'Problems tab opened' ) ;
213+ } , [ ] ) ;
214+
210215 const setActiveFn = useCallback ( ( severity : DiagnosticSeverity ) => {
211216 setActive ( acc => {
212217 if ( acc . some ( s => s === severity ) ) {
@@ -236,11 +241,19 @@ export const ProblemsTabContent: FunctionComponent<ProblemsTabProps> = () => {
236241 < SeverityButtons active = { active } setActive = { setActiveFn } />
237242 < div className = 'ml-2 flex-1 flex flex-row items-center justify-center rounded-md border border-transparent shadow-xs px-2 py-1 bg-gray-700 text-xs font-medium' >
238243 < VscSearch />
239- < input ref = { inputRef } placeholder = 'Filter diagnostics...' className = 'w-full bg-gray-700 border-transparent ml-2 focus:border-transparent focus:ring-0 focus:outline-none' onChange = { debounce ( ( e ) => setSearch ( e . target . value ) , 250 ) } />
244+ < input ref = { inputRef } placeholder = 'Filter diagnostics...' className = 'w-full bg-gray-700 border-transparent ml-2 focus:border-transparent focus:ring-0 focus:outline-none' onChange = { debounce ( ( e ) => {
245+ setSearch ( e . target . value )
246+ if ( e . target . value . length > 2 || e . target . value . length === 0 ) {
247+ trackEvent ( 'Diagnostics' , 'search' , `Search term: "${ e . target . value } "` ) ;
248+ }
249+ } , 250 ) } />
240250 < button type = 'button' className = { `hover:bg-gray-900 rounded-sm border border-transparent ${ search ? 'opacity-100' : 'opacity-0' } ` } onClick = { ( ) => {
241251 if ( inputRef . current ) {
242252 inputRef . current . value = '' ;
243253 }
254+ if ( search ) {
255+ trackEvent ( 'Diagnostics' , 'search_clear' , 'Search cleared' ) ;
256+ }
244257 setSearch ( '' ) ;
245258 } } >
246259 < VscClose />
@@ -250,7 +263,14 @@ export const ProblemsTabContent: FunctionComponent<ProblemsTabProps> = () => {
250263 < button
251264 type = "button"
252265 className = { 'justify-center border border-transparent shadow-xs px-2 py-1 ml-2 text-xs rounded-md font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-1 focus:ring-offset-1 focus:ring-gray-700' }
253- onClick = { ( ) => modal . show ( { activeTab : 'governance' } ) }
266+ onClick = { ( ) => {
267+ trackEvent (
268+ 'Diagnostics' ,
269+ 'settings_open' ,
270+ 'Opened governance settings'
271+ ) ;
272+ modal . show ( { activeTab : 'governance' } )
273+ } }
254274 >
255275 < VscSettingsGear className = 'w-4 h-4' />
256276 </ button >
@@ -274,14 +294,23 @@ export const ProblemsTabContent: FunctionComponent<ProblemsTabProps> = () => {
274294 < td className = "px-2 py-1 text-right" > < SeverityIcon severity = { severity } /> </ td >
275295 < td
276296 className = "px-2 py-1 cursor-pointer"
277- onClick = { ( ) =>
297+ onClick = { ( ) => {
298+ trackEvent ( 'Diagnostics' , 'diagnostic_click' , `Clicked on diagnostic at line ${ range . start . line + 1 } ` ) ;
278299 navigationSvc . scrollToEditorLine (
279300 range . start . line + 1 ,
280301 range . start . character + 1 ,
281302 )
282303 }
304+ }
283305 onKeyDown = { ( e ) => {
284306 if ( e . key === 'Enter' ) {
307+ trackEvent (
308+ 'Diagnostics' ,
309+ 'diagnostic_click' ,
310+ `Clicked on diagnostic at line ${
311+ range . start . line + 1
312+ } `
313+ ) ;
285314 navigationSvc . scrollToEditorLine (
286315 range . start . line + 1 ,
287316 range . start . character + 1 ,
0 commit comments