Skip to content

Commit 2cdbbf4

Browse files
committed
#RI-6331 - add telemetry event
1 parent 4f1a522 commit 2cdbbf4

File tree

2 files changed

+75
-30
lines changed

2 files changed

+75
-30
lines changed

redisinsight/ui/src/components/navigation-menu/components/create-cloud/CreateCloud.spec.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ import { cleanup, mockedStore, render, fireEvent } from 'uiSrc/utils/test-utils'
55
import { setSSOFlow } from 'uiSrc/slices/instances/cloud'
66
import { OAuthSocialAction, OAuthSocialSource } from 'uiSrc/slices/interfaces'
77
import { setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
8+
import { appFeatureFlagsFeaturesSelector } from 'uiSrc/slices/app/features'
9+
import { sendEventTelemetry } from 'uiSrc/telemetry'
10+
import { HELP_LINKS } from 'uiSrc/pages/home/constants'
811
import CreateCloud from './CreateCloud'
912

13+
jest.mock('uiSrc/telemetry', () => ({
14+
...jest.requireActual('uiSrc/telemetry'),
15+
sendEventTelemetry: jest.fn(),
16+
}))
17+
1018
jest.mock('uiSrc/slices/app/features', () => ({
1119
...jest.requireActual('uiSrc/slices/app/features'),
1220
appFeatureFlagsFeaturesSelector: jest.fn().mockReturnValue({
@@ -39,4 +47,25 @@ describe('CreateCloud', () => {
3947
setSocialDialogState(OAuthSocialSource.NavigationMenu)
4048
])
4149
})
50+
51+
it('should call proper telemetry when sso is disabled', () => {
52+
const sendEventTelemetryMock = jest.fn();
53+
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock);
54+
(appFeatureFlagsFeaturesSelector as jest.Mock).mockReturnValueOnce({
55+
cloudSso: {
56+
flag: false
57+
}
58+
})
59+
const { container } = render(<CreateCloud />)
60+
const createCloudLink = container.querySelector('[data-test-subj="create-cloud-nav-link"]')
61+
62+
fireEvent.click(createCloudLink as Element)
63+
64+
expect(sendEventTelemetry).toBeCalledWith({
65+
event: HELP_LINKS.cloud.event,
66+
eventData: {
67+
source: OAuthSocialSource.NavigationMenu
68+
}
69+
})
70+
})
4271
})

redisinsight/ui/src/components/navigation-menu/components/create-cloud/CreateCloud.tsx

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,53 @@ import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
88
import CloudIcon from 'uiSrc/assets/img/oauth/cloud_centered.svg?react'
99

1010
import { getUtmExternalLink } from 'uiSrc/utils/links'
11+
import { sendEventTelemetry } from 'uiSrc/telemetry'
12+
import { HELP_LINKS } from 'uiSrc/pages/home/constants'
1113
import styles from '../../styles.module.scss'
1214

13-
const CreateCloud = () => (
14-
<EuiToolTip
15-
content="Create FREE Redis Cloud database"
16-
position="right"
17-
>
18-
<span className={cx(styles.iconNavItem)}>
19-
<OAuthSsoHandlerDialog>
20-
{(ssoCloudHandlerClick) => (
21-
<EuiLink
22-
external={false}
23-
onClick={(e) => {
24-
ssoCloudHandlerClick(e,
25-
{ source: OAuthSocialSource.NavigationMenu, action: OAuthSocialAction.Create })
26-
}}
27-
className={styles.cloudLink}
28-
href={getUtmExternalLink(EXTERNAL_LINKS.tryFree, { campaign: 'navigation_menu' })}
29-
target="_blank"
30-
data-test-subj="create-cloud-nav-link"
31-
>
32-
<EuiIcon
33-
className={styles.cloudIcon}
34-
type={CloudIcon}
35-
data-testid="cloud-db-icon"
36-
/>
37-
</EuiLink>
38-
)}
39-
</OAuthSsoHandlerDialog>
40-
</span>
41-
</EuiToolTip>
42-
)
15+
const CreateCloud = () => {
16+
const onCLickLink = (isSSOEnabled: boolean) => {
17+
if (isSSOEnabled) return
18+
19+
sendEventTelemetry({
20+
event: HELP_LINKS.cloud.event,
21+
eventData: {
22+
source: OAuthSocialSource.NavigationMenu
23+
}
24+
})
25+
}
26+
27+
return (
28+
<EuiToolTip
29+
content="Create FREE Redis Cloud database"
30+
position="right"
31+
>
32+
<span className={cx(styles.iconNavItem)}>
33+
<OAuthSsoHandlerDialog>
34+
{(ssoCloudHandlerClick, isSSOEnabled) => (
35+
<EuiLink
36+
external={false}
37+
onClick={(e) => {
38+
onCLickLink(isSSOEnabled)
39+
ssoCloudHandlerClick(e,
40+
{ source: OAuthSocialSource.NavigationMenu, action: OAuthSocialAction.Create })
41+
}}
42+
className={styles.cloudLink}
43+
href={getUtmExternalLink(EXTERNAL_LINKS.tryFree, { campaign: 'navigation_menu' })}
44+
target="_blank"
45+
data-test-subj="create-cloud-nav-link"
46+
>
47+
<EuiIcon
48+
className={styles.cloudIcon}
49+
type={CloudIcon}
50+
data-testid="cloud-db-icon"
51+
/>
52+
</EuiLink>
53+
)}
54+
</OAuthSsoHandlerDialog>
55+
</span>
56+
</EuiToolTip>
57+
)
58+
}
4359

4460
export default CreateCloud

0 commit comments

Comments
 (0)