Commit 4d226c55 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'ph/340528/extensionRedisTracking' into 'master'

Added support for redis tracking to widget extensions

See merge request gitlab-org/gitlab!72901
parents b713de1a 042fa526
...@@ -8,6 +8,8 @@ import { ...@@ -8,6 +8,8 @@ import {
GlTooltipDirective, GlTooltipDirective,
GlIntersectionObserver, GlIntersectionObserver,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { once } from 'lodash';
import api from '~/api';
import { sprintf, s__, __ } from '~/locale'; import { sprintf, s__, __ } from '~/locale';
import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue'; import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue';
import { EXTENSION_ICON_CLASS } from '../../constants'; import { EXTENSION_ICON_CLASS } from '../../constants';
...@@ -102,8 +104,15 @@ export default { ...@@ -102,8 +104,15 @@ export default {
}); });
}, },
methods: { methods: {
triggerRedisTracking: once(function triggerRedisTracking() {
if (this.$options.expandEvent) {
api.trackRedisHllUserEvent(this.$options.expandEvent);
}
}),
toggleCollapsed() { toggleCollapsed() {
this.isCollapsed = !this.isCollapsed; this.isCollapsed = !this.isCollapsed;
this.triggerRedisTracking();
}, },
loadAllData() { loadAllData() {
if (this.fullData) return; if (this.fullData) return;
......
...@@ -12,6 +12,7 @@ export const registerExtension = (extension) => { ...@@ -12,6 +12,7 @@ export const registerExtension = (extension) => {
name: extension.name, name: extension.name,
props: extension.props, props: extension.props,
i18n: extension.i18n, i18n: extension.i18n,
expandEvent: extension.expandEvent,
computed: { computed: {
...Object.keys(extension.computed).reduce( ...Object.keys(extension.computed).reduce(
(acc, computedKey) => ({ (acc, computedKey) => ({
......
...@@ -11,6 +11,7 @@ export default { ...@@ -11,6 +11,7 @@ export default {
label: 'Issues', label: 'Issues',
loading: 'Loading issues...', loading: 'Loading issues...',
}, },
expandEvent: 'i_testing_load_performance_widget_total',
// Add an array of props // Add an array of props
// These then get mapped to values stored in the MR Widget store // These then get mapped to values stored in the MR Widget store
props: ['targetProjectFullPath', 'conflictsDocsPath'], props: ['targetProjectFullPath', 'conflictsDocsPath'],
......
...@@ -10,6 +10,7 @@ export default { ...@@ -10,6 +10,7 @@ export default {
label: s__('ciReport|Browser Performance'), label: s__('ciReport|Browser Performance'),
loading: s__('ciReport|Browser performance test metrics results are being parsed'), loading: s__('ciReport|Browser performance test metrics results are being parsed'),
}, },
expandEvent: 'i_testing_web_performance_widget_total',
computed: { computed: {
summary() { summary() {
const { improved, degraded, same } = this.collapsedData; const { improved, degraded, same } = this.collapsedData;
......
...@@ -9,6 +9,7 @@ export default { ...@@ -9,6 +9,7 @@ export default {
label: s__('ciReport|Load Performance'), label: s__('ciReport|Load Performance'),
loading: s__('ciReport|Load performance test metrics results are being parsed'), loading: s__('ciReport|Load performance test metrics results are being parsed'),
}, },
expandEvent: 'i_testing_load_performance_widget_total',
props: ['loadPerformance'], props: ['loadPerformance'],
computed: { computed: {
summary() { summary() {
......
...@@ -6,6 +6,7 @@ import VueApollo from 'vue-apollo'; ...@@ -6,6 +6,7 @@ import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { securityReportMergeRequestDownloadPathsQueryResponse } from 'jest/vue_shared/security_reports/mock_data'; import { securityReportMergeRequestDownloadPathsQueryResponse } from 'jest/vue_shared/security_reports/mock_data';
import api from '~/api';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { setFaviconOverlay } from '~/lib/utils/favicon'; import { setFaviconOverlay } from '~/lib/utils/favicon';
import notify from '~/lib/utils/notify'; import notify from '~/lib/utils/notify';
...@@ -23,6 +24,8 @@ import { faviconDataUrl, overlayDataUrl } from '../lib/utils/mock_data'; ...@@ -23,6 +24,8 @@ import { faviconDataUrl, overlayDataUrl } from '../lib/utils/mock_data';
import mockData from './mock_data'; import mockData from './mock_data';
import testExtension from './test_extension'; import testExtension from './test_extension';
jest.mock('~/api.js');
jest.mock('~/smart_interval'); jest.mock('~/smart_interval');
jest.mock('~/lib/utils/favicon'); jest.mock('~/lib/utils/favicon');
...@@ -904,6 +907,18 @@ describe('MrWidgetOptions', () => { ...@@ -904,6 +907,18 @@ describe('MrWidgetOptions', () => {
expect(wrapper.text()).toContain('Test extension summary count: 1'); expect(wrapper.text()).toContain('Test extension summary count: 1');
}); });
it('triggers trackRedisHllUserEvent API call', async () => {
await waitForPromises();
wrapper
.find('[data-testid="widget-extension"] [data-testid="toggle-button"]')
.trigger('click');
await Vue.nextTick();
expect(api.trackRedisHllUserEvent).toHaveBeenCalledWith('test_expand_event');
});
it('renders full data', async () => { it('renders full data', async () => {
await waitForPromises(); await waitForPromises();
......
...@@ -3,6 +3,7 @@ import { EXTENSION_ICONS } from '~/vue_merge_request_widget/constants'; ...@@ -3,6 +3,7 @@ import { EXTENSION_ICONS } from '~/vue_merge_request_widget/constants';
export default { export default {
name: 'WidgetTestExtension', name: 'WidgetTestExtension',
props: ['targetProjectFullPath'], props: ['targetProjectFullPath'],
expandEvent: 'test_expand_event',
computed: { computed: {
summary({ count, targetProjectFullPath }) { summary({ count, targetProjectFullPath }) {
return `Test extension summary count: ${count} & ${targetProjectFullPath}`; return `Test extension summary count: ${count} & ${targetProjectFullPath}`;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment