From d84d54239ccc36e49f74fb81580bbfbe61032ea9 Mon Sep 17 00:00:00 2001 From: psjostrom Date: Fri, 18 Dec 2020 12:01:31 +0100 Subject: [PATCH 1/2] SDA-2571 Fixed triggering multiple BI calls --- src/app/screen-snippet-handler.ts | 15 ++++----------- src/app/window-handler.ts | 1 - 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 13a4effe..cd2163f5 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -52,6 +52,10 @@ class ScreenSnippet { if (isLinux) { this.captureUtil = '/usr/bin/gnome-screenshot'; } + + ipcMain.on('send-tracking-data-to-main', async (_event, eventData: { element: AnalyticsElements, type: ScreenSnippetActionTypes }) => { + analytics.track({ element: eventData.element, action_type: eventData.type }); + }); } /** @@ -116,7 +120,6 @@ class ScreenSnippet { windowHandler.closeSnippingToolWindow(); windowHandler.createSnippingToolWindow(this.outputFilePath, dimensions); this.uploadSnippet(webContents); - this.sendAnalytics(); return; } const { @@ -287,16 +290,6 @@ class ScreenSnippet { } }); } - - /** - * Send analytics data to analytics module - */ - private sendAnalytics() { - ipcMain.on('send-tracking-data-to-main', async (_event, eventData: { element: AnalyticsElements, type: ScreenSnippetActionTypes }) => { - analytics.track({element: eventData.element, action_type: eventData.type}); - }); - } - } const screenSnippet = new ScreenSnippet(); diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index 9e58f906..e201b7ab 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -1021,7 +1021,6 @@ export class WindowHandler { const scaleFactor = display.scaleFactor; const scaledImageDimensions = { height: Math.floor(snipDimensions.height / scaleFactor), width: Math.floor(snipDimensions.width / scaleFactor) }; logger.info('window-handler, createSnippingToolWindow: Image will open with scaled dimensions: ' + JSON.stringify(scaledImageDimensions)); - // const scaledImageDimensions = snipDimensions; const annotateAreaHeight = scaledImageDimensions.height > availableAnnotateAreaHeight ? availableAnnotateAreaHeight : From 3f08517ee229f962b8be4037cfd03ab8b79fb316 Mon Sep 17 00:00:00 2001 From: psjostrom Date: Fri, 18 Dec 2020 14:11:15 +0100 Subject: [PATCH 2/2] SDA-2571 Updated event variable name --- spec/annotateArea.spec.tsx | 6 +++--- spec/snippingTool.spec.tsx | 6 +++--- src/app/screen-snippet-handler.ts | 2 +- src/renderer/components/snipping-tool.tsx | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/annotateArea.spec.tsx b/spec/annotateArea.spec.tsx index 122dd2f3..325b44b5 100644 --- a/spec/annotateArea.spec.tsx +++ b/spec/annotateArea.spec.tsx @@ -148,7 +148,7 @@ describe('', () => { const path = wrapper.find('[data-testid="path0"]'); const expectedValue = { type: 'annotate_erased', element: 'screen_capture_annotate' }; path.simulate('click'); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); it('should send annotate_added_pen event when drawn with pen', () => { @@ -158,7 +158,7 @@ describe('', () => { const area = wrapper.find('[data-testid="annotate-area"]'); area.simulate('mousedown', { pageX: 2, pageY: 49 }); area.simulate('mouseup'); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); it('should send annotate_added_highlight event when drawn with highlight', () => { @@ -178,6 +178,6 @@ describe('', () => { const area = wrapper.find('[data-testid="annotate-area"]'); area.simulate('mousedown', { pageX: 2, pageY: 49 }); area.simulate('mouseup'); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); }); diff --git a/spec/snippingTool.spec.tsx b/spec/snippingTool.spec.tsx index 4aab3fcb..5f5ea1de 100644 --- a/spec/snippingTool.spec.tsx +++ b/spec/snippingTool.spec.tsx @@ -25,7 +25,7 @@ describe('Snipping Tool', () => { const spy = jest.spyOn(ipcRenderer, 'send'); const expectedValue = { type: 'screenshot_taken', element: 'screen_capture_annotate' }; mount(React.createElement(SnippingTool)); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); it('should send capture_sent BI event when clicking done', async () => { @@ -35,7 +35,7 @@ describe('Snipping Tool', () => { wrapper.find('[data-testid="done-button"]').simulate('click'); wrapper.update(); await waitForPromisesToResolve(); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); it('should send annotate_cleared BI event when clicking clear', async () => { @@ -45,7 +45,7 @@ describe('Snipping Tool', () => { wrapper.find('[data-testid="clear-button"]').simulate('click'); wrapper.update(); await waitForPromisesToResolve(); - expect(spy).toBeCalledWith('send-tracking-data-to-main', expectedValue); + expect(spy).toBeCalledWith('snippet-analytics-data', expectedValue); }); it('should render pen color picker when clicked on pen', () => { diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index cd2163f5..1122c239 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -53,7 +53,7 @@ class ScreenSnippet { this.captureUtil = '/usr/bin/gnome-screenshot'; } - ipcMain.on('send-tracking-data-to-main', async (_event, eventData: { element: AnalyticsElements, type: ScreenSnippetActionTypes }) => { + ipcMain.on('snippet-analytics-data', async (_event, eventData: { element: AnalyticsElements, type: ScreenSnippetActionTypes }) => { analytics.track({ element: eventData.element, action_type: eventData.type }); }); } diff --git a/src/renderer/components/snipping-tool.tsx b/src/renderer/components/snipping-tool.tsx index e9ad99fe..c3fdb4a7 100644 --- a/src/renderer/components/snipping-tool.tsx +++ b/src/renderer/components/snipping-tool.tsx @@ -52,7 +52,7 @@ const availableHighlightColors: IColor[] = [ const SNIPPING_TOOL_NAMESPACE = 'ScreenSnippet'; export const sendAnalyticsToMain = (element: AnalyticsElements, type: ScreenSnippetActionTypes): void => { - ipcRenderer.send('send-tracking-data-to-main', { element, type }); + ipcRenderer.send('snippet-analytics-data', { element, type }); }; const SnippingTool: React.FunctionComponent = ({ existingPaths }) => {