From 30fde3dfe92e7874e109cfa7b9c83cbb574f24c0 Mon Sep 17 00:00:00 2001 From: Naman Kumar Date: Thu, 24 Oct 2024 20:25:37 +0530 Subject: [PATCH] Remove onKeyPress on AccordionTrigger (#5993) context: https://sourcegraph.slack.com/archives/C05AGQYD528/p1729773000841009 Somehow `onKeyPress` causing an infinite loop of telemetry records. Also with the most recent changes the `context items opened` event is getting recorded even when the context menu is closed. This PR makes it so that the event is only getting recorded once. ## Test plan - Contact Piotr, even I don't know. ## Changelog --- .../chat/cells/contextCell/ContextCell.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vscode/webviews/chat/cells/contextCell/ContextCell.tsx b/vscode/webviews/chat/cells/contextCell/ContextCell.tsx index 62e7d69520f..cd92e841e28 100644 --- a/vscode/webviews/chat/cells/contextCell/ContextCell.tsx +++ b/vscode/webviews/chat/cells/contextCell/ContextCell.tsx @@ -99,12 +99,17 @@ export const ContextCell: FunctionComponent<{ ) const triggerAccordion = useCallback(() => { - setAccordionValue(prev => (prev ? '' : 'item-1')) - telemetryRecorder.recordEvent('cody.contextCell', 'opened', { - metadata: { - fileCount: new Set(usedContext.map(file => file.uri.toString())).size, - excludedAtContext: excludedContext.length, - }, + setAccordionValue(prev => { + if (!prev) { + telemetryRecorder.recordEvent('cody.contextCell', 'opened', { + metadata: { + fileCount: new Set(usedContext.map(file => file.uri.toString())).size, + excludedAtContext: excludedContext.length, + }, + }) + } + + return prev ? '' : 'item-1' }) }, [excludedContext.length, usedContext]) @@ -150,7 +155,6 @@ export const ContextCell: FunctionComponent<{ header={