From 2bfdc6eb7d344a44c20dd4790b7adaf103207b3e Mon Sep 17 00:00:00 2001 From: EvansA Date: Wed, 22 Feb 2023 12:39:02 +0300 Subject: [PATCH] Task: Add copy telemetry (#2419) --- src/app/views/App.tsx | 2 + .../views/common/copy/KeyboardCopyEvent.ts | 40 +++++++++++++++++++ .../adaptive-cards/AdaptiveCard.tsx | 2 +- .../headers/ResponseHeaders.tsx | 4 +- .../pivot-items/pivot-items.tsx | 10 ++--- .../snippets/snippets-helper.tsx | 2 + .../views/query-runner/request/auth/Auth.tsx | 2 +- .../query-runner/request/body/RequestBody.tsx | 2 +- src/telemetry/component-names.ts | 12 ++++++ src/telemetry/event-types.ts | 1 + 10 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/app/views/common/copy/KeyboardCopyEvent.ts diff --git a/src/app/views/App.tsx b/src/app/views/App.tsx index 0c939ed28..6af36e171 100644 --- a/src/app/views/App.tsx +++ b/src/app/views/App.tsx @@ -35,6 +35,7 @@ import { parse } from './query-runner/util/iframe-message-parser'; import { Sidebar } from './sidebar/Sidebar'; import { MainHeader } from './main-header/MainHeader'; import { removeSpinners } from '../..'; +import { KeyboardCopyEvent } from './common/copy/KeyboardCopyEvent'; export interface IAppProps { theme?: ITheme; @@ -87,6 +88,7 @@ class App extends Component { public componentDidMount = async () => { removeSpinners(); + KeyboardCopyEvent(); this.displayToggleButton(this.mediaQueryList); this.mediaQueryList.addListener(this.displayToggleButton); diff --git a/src/app/views/common/copy/KeyboardCopyEvent.ts b/src/app/views/common/copy/KeyboardCopyEvent.ts new file mode 100644 index 000000000..f7fa74de3 --- /dev/null +++ b/src/app/views/common/copy/KeyboardCopyEvent.ts @@ -0,0 +1,40 @@ +import { eventTypes, telemetry } from '../../../../telemetry'; +import { KEYBOARD_COPY_TABS } from '../../../../telemetry/component-names'; + +interface IComponentList { + [key: string]: string; +} +export const KeyboardCopyEvent = () => { + const componentList: IComponentList = KEYBOARD_COPY_TABS; + document.addEventListener('keydown', (event: KeyboardEvent) => { + if (event && (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'c') { + const targets = event.composedPath(); + const componentName = getComponentName(targets); + trackCopyEvent(componentName); + } + }); + + const getComponentName = (targets: EventTarget[]): string => { + const targetIds = targets.map((target: EventTarget) => { + return getTargetId(target); + }); + const filteredTargetIds = targetIds.filter((value) => value !== null)!; + const componentName = Object.keys(componentList).find(key => filteredTargetIds.includes(key)); + return componentName || ''; + } + + const getTargetId = (target: EventTarget) => { + if(target && target instanceof Element) { + return target.getAttribute('id'); + } + } + + const trackCopyEvent = (componentName: string) => { + if(!componentName) { return; } + telemetry.trackEvent(eventTypes.KEYBOARD_COPY_EVENT, + { + ComponentName: (KEYBOARD_COPY_TABS as IComponentList)[componentName], + trigger: 'Keyboard' + }); + } +} \ No newline at end of file diff --git a/src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx b/src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx index 5fd8c1e13..11bafaf91 100644 --- a/src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx +++ b/src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx @@ -157,7 +157,7 @@ const AdaptiveCard = (props: any) => { 'aria-controls': 'json-schema-tab' }} > -
+
{ if (headers) { return ( - <> +
- +
); } diff --git a/src/app/views/query-response/pivot-items/pivot-items.tsx b/src/app/views/query-response/pivot-items/pivot-items.tsx index 08d25f336..0a36e9d5d 100644 --- a/src/app/views/query-response/pivot-items/pivot-items.tsx +++ b/src/app/views/query-response/pivot-items/pivot-items.tsx @@ -73,7 +73,7 @@ export const GetPivotItems = () => { 'aria-controls': 'response-tab' }} > -
+
, { 'aria-controls': 'response-headers-tab' }} > -
+
]; if (mode === Mode.Complete) { @@ -102,7 +102,7 @@ export const GetPivotItems = () => { 'aria-controls': 'code-snippets-tab' }} > -
+
, { 'aria-controls': 'toolkit-tab' }} > -
+
, { {(theme) => ( // @ts-ignore -
+
diff --git a/src/app/views/query-runner/request/auth/Auth.tsx b/src/app/views/query-runner/request/auth/Auth.tsx index 6297af9dd..b0ad715d3 100644 --- a/src/app/views/query-runner/request/auth/Auth.tsx +++ b/src/app/views/query-runner/request/auth/Auth.tsx @@ -62,7 +62,7 @@ export function Auth(props: any) { target='_blank' />
- +
: