1- import type { AttributeValue } from '@opentelemetry/api' ;
21import type { QuickInputButton } from 'vscode' ;
32import { commands , Uri } from 'vscode' ;
43import { getAvatarUri } from '../../avatars' ;
@@ -29,7 +28,7 @@ import {
2928 UnpinQuickInputButton ,
3029 UnsnoozeQuickInputButton ,
3130} from '../../commands/quickCommand.buttons' ;
32- import type { Source , Sources } from '../../constants' ;
31+ import type { LaunchpadTelemetryContext , Source , Sources } from '../../constants' ;
3332import { Commands , previewBadge } from '../../constants' ;
3433import type { Container } from '../../container' ;
3534import type { QuickPickItemOfT } from '../../quickpicks/items/common' ;
@@ -91,7 +90,7 @@ interface Context {
9190 items : FocusItem [ ] ;
9291 title : string ;
9392 collapsed : Map < FocusGroup , boolean > ;
94- telemetryContext : Record < string , AttributeValue | null | undefined > | undefined ;
93+ telemetryContext : LaunchpadTelemetryContext | undefined ;
9594}
9695
9796interface GroupedFocusItem extends FocusItem {
@@ -126,7 +125,7 @@ const instanceCounter = getScopedCounter();
126125@command ( )
127126export class FocusCommand extends QuickCommand < State > {
128127 private readonly source : Source ;
129- private readonly telemetryContext : Record < string , any > | undefined ;
128+ private readonly telemetryContext : LaunchpadTelemetryContext | undefined ;
130129
131130 // TODO: Hidden is a hack for now to avoid telemetry when this gets loaded in the hidden group of the git commands
132131 constructor ( container : Container , args ?: FocusCommandArgs , hidden : boolean = false ) {
@@ -145,7 +144,7 @@ export class FocusCommand extends QuickCommand<State> {
145144 if ( this . container . telemetry . enabled && ! hidden ) {
146145 this . telemetryContext = {
147146 instance : instanceCounter . next ( ) ,
148- 'initialState.group' : args ?. state ?. initialGroup ?? null ,
147+ 'initialState.group' : args ?. state ?. initialGroup ,
149148 'initialState.selectTopItem' : args ?. state ?. selectTopItem ?? false ,
150149 } ;
151150
@@ -205,7 +204,7 @@ export class FocusCommand extends QuickCommand<State> {
205204 this . container . telemetry . sendEvent (
206205 opened ? 'launchpad/steps/connect' : 'launchpad/opened' ,
207206 {
208- ...context . telemetryContext ,
207+ ...context . telemetryContext ! ,
209208 connected : false ,
210209 } ,
211210 this . source ,
@@ -236,7 +235,7 @@ export class FocusCommand extends QuickCommand<State> {
236235 this . container . telemetry . sendEvent (
237236 opened ? 'launchpad/steps/main' : 'launchpad/opened' ,
238237 {
239- ...context . telemetryContext ,
238+ ...context . telemetryContext ! ,
240239 connected : true ,
241240 } ,
242241 this . source ,
@@ -349,7 +348,7 @@ export class FocusCommand extends QuickCommand<State> {
349348 this . container . telemetry . sendEvent (
350349 'launchpad/groupToggled' ,
351350 {
352- ...context . telemetryContext ,
351+ ...context . telemetryContext ! ,
353352 group : ui ,
354353 collapsed : collapsed ,
355354 } ,
@@ -915,7 +914,7 @@ export class FocusCommand extends QuickCommand<State> {
915914 this . container . telemetry . sendEvent (
916915 action === 'select' ? 'launchpad/steps/details' : 'launchpad/action' ,
917916 {
918- ...context . telemetryContext ,
917+ ...context . telemetryContext ! ,
919918 action : action ,
920919 'item.id' : getFocusItemIdHash ( item ) ,
921920 'item.type' : item . type ,
@@ -927,8 +926,8 @@ export class FocusCommand extends QuickCommand<State> {
927926 'item.updatedDate' : item . updatedDate . getTime ( ) ,
928927 'item.isNew' : item . isNew ,
929928
930- 'item.comments.count' : item . commentCount ,
931- 'item.upvotes.count' : item . upvoteCount ,
929+ 'item.comments.count' : item . commentCount ?? undefined ,
930+ 'item.upvotes.count' : item . upvoteCount ?? undefined ,
932931
933932 'item.pr.codeSuggestionCount' : item . codeSuggestionsCount ,
934933 'item.pr.isDraft' : item . isDraft ,
@@ -944,7 +943,7 @@ export class FocusCommand extends QuickCommand<State> {
944943 'item.pr.hasConflicts' : item . hasConflicts ,
945944
946945 'item.pr.reviews.count' : item . reviews ?. length ?? undefined ,
947- 'item.pr.reviews.decision' : item . reviewDecision ,
946+ 'item.pr.reviews.decision' : item . reviewDecision ?? undefined ,
948947 'item.pr.reviews.changeRequestCount' : item . changeRequestReviewCount ?? undefined ,
949948
950949 'item.viewer.isAuthor' : item . viewer . isAuthor ,
@@ -971,18 +970,22 @@ async function updateContextItems(container: Container, context: Context, option
971970}
972971
973972function updateTelemetryContext ( context : Context ) {
973+ if ( context . telemetryContext == null ) return ;
974+
974975 const grouped = countFocusItemGroups ( context . items ) ;
975976
976- context . telemetryContext = {
977+ const updatedContext : NonNullable < ( typeof context ) [ ' telemetryContext' ] > = {
977978 ...context . telemetryContext ,
978979 'items.count' : context . items . length ,
979980 'groups.count' : grouped . size ,
980981 } ;
981982
982983 for ( const [ group , count ] of grouped ) {
983- context . telemetryContext [ `groups.${ group } .count` ] = count ;
984- context . telemetryContext [ `groups.${ group } .collapsed` ] = context . collapsed . get ( group ) ;
984+ updatedContext [ `groups.${ group } .count` ] = count ;
985+ updatedContext [ `groups.${ group } .collapsed` ] = context . collapsed . get ( group ) ;
985986 }
987+
988+ context . telemetryContext = updatedContext ;
986989}
987990
988991function isFocusTargetActionQuickPickItem ( item : any ) : item is QuickPickItemOfT < FocusTargetAction > {
0 commit comments