Skip to content

Commit 397e8f1

Browse files
committed
RI-5905 enable telemetry for cloud auth users
1 parent 0950a64 commit 397e8f1

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

redisinsight/ui/src/components/config/Config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const Config = () => {
8080
if (cloudSsoFeature?.flag) {
8181
dispatch(fetchProfile())
8282
}
83-
}, [cloudSsoFeature])
83+
}, [cloudSsoFeature?.flag])
8484

8585
useEffect(() => {
8686
featuresHighlight()

redisinsight/ui/src/components/oauth/shared/oauth-agreement/OAuthAgreement.spec.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
screen,
1111
} from 'uiSrc/utils/test-utils'
1212
import { localStorageService } from 'uiSrc/services'
13-
import { setAgreement } from 'uiSrc/slices/oauth/cloud'
13+
import { oauthCloudPAgreementSelector, setAgreement } from 'uiSrc/slices/oauth/cloud'
1414
import { BrowserStorageItem } from 'uiSrc/constants'
15+
import { updateUserConfigSettings } from 'uiSrc/slices/user/user-settings'
1516
import OAuthAgreement from './OAuthAgreement'
1617

1718
let store: typeof mockedStore
@@ -33,6 +34,17 @@ jest.mock('uiSrc/services', () => ({
3334
},
3435
}))
3536

37+
jest.mock('uiSrc/slices/user/user-settings', () => ({
38+
...jest.requireActual('uiSrc/slices/user/user-settings'),
39+
userSettingsConfigSelector: jest.fn().mockReturnValue({
40+
agreements: {
41+
eula: true,
42+
version: '1.0.1',
43+
analytics: false,
44+
},
45+
})
46+
}))
47+
3648
describe('OAuthAgreement', () => {
3749
it('should render', () => {
3850
expect(render(<OAuthAgreement />)).toBeTruthy()
@@ -59,4 +71,19 @@ describe('OAuthAgreement', () => {
5971
false,
6072
)
6173
})
74+
75+
it('should update settings when checkbox checked if analytics is set to false', () => {
76+
(oauthCloudPAgreementSelector as jest.Mock).mockReturnValueOnce(false)
77+
78+
render(<OAuthAgreement />)
79+
80+
const el = screen.getByTestId('oauth-agreement-checkbox') as HTMLInputElement
81+
expect(el.checked).toBe(false)
82+
fireEvent.click(el)
83+
84+
const expectedActions = [{}].fill(updateUserConfigSettings(), 0)
85+
expect(clearStoreActions(store.getActions().slice(0, expectedActions.length))).toEqual(
86+
clearStoreActions(expectedActions)
87+
)
88+
})
6289
})

redisinsight/ui/src/components/oauth/shared/oauth-agreement/OAuthAgreement.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { localStorageService } from 'uiSrc/services'
77
import { BrowserStorageItem } from 'uiSrc/constants'
88
import { setAgreement, oauthCloudPAgreementSelector } from 'uiSrc/slices/oauth/cloud'
99

10+
import { updateUserConfigSettingsAction, userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'
1011
import styles from './styles.module.scss'
1112

1213
export interface Props {
@@ -16,10 +17,14 @@ export interface Props {
1617
const OAuthAgreement = (props: Props) => {
1718
const { size = 'm' } = props
1819
const agreement = useSelector(oauthCloudPAgreementSelector)
20+
const config = useSelector(userSettingsConfigSelector)
1921

2022
const dispatch = useDispatch()
2123

2224
const handleCheck = (e: ChangeEvent<HTMLInputElement>) => {
25+
if (e.target.checked && !config?.agreements?.analytics) {
26+
dispatch(updateUserConfigSettingsAction({ agreements: { ...config?.agreements, analytics: true } }))
27+
}
2328
dispatch(setAgreement(e.target.checked))
2429
localStorageService.set(BrowserStorageItem.OAuthAgreement, e.target.checked)
2530
}
@@ -63,6 +68,9 @@ const OAuthAgreement = (props: Props) => {
6368
<li className={styles.listItem}>
6469
that Redis Insight will generate Redis Cloud API account and user keys, and store them locally on your machine
6570
</li>
71+
<li className={styles.listItem}>
72+
Analytics will be enabled to aggregate anonymized user data to improve user experience. You can disable it anytime on the Settings page.
73+
</li>
6674
</ul>
6775
</div>
6876
)

redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
33
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
4-
import { render, cleanup, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
4+
import { render, cleanup, clearStoreActions, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
55
import { OAuthStrategy } from 'uiSrc/slices/interfaces'
66
import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth'
7+
import { updateUserConfigSettings, userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'
78
import OAuthForm from './OAuthForm'
89

910
jest.mock('uiSrc/telemetry', () => ({
@@ -19,6 +20,17 @@ jest.mock('uiSrc/slices/oauth/cloud', () => ({
1920
oauthCloudPAgreementSelector: jest.fn().mockReturnValue(true),
2021
}))
2122

23+
jest.mock('uiSrc/slices/user/user-settings', () => ({
24+
...jest.requireActual('uiSrc/slices/user/user-settings'),
25+
userSettingsConfigSelector: jest.fn().mockReturnValue({
26+
agreements: {
27+
eula: true,
28+
version: '1.0.1',
29+
analytics: true,
30+
},
31+
})
32+
}))
33+
2234
const onClick = jest.fn()
2335

2436
let store: typeof mockedStore
@@ -117,4 +129,23 @@ describe('OAuthForm', () => {
117129
fireEvent.click(screen.getByTestId('btn-submit'))
118130
})
119131
})
132+
133+
it('should updaten analytics if analytics is set to false', () => {
134+
(userSettingsConfigSelector as jest.Mock).mockReturnValueOnce({
135+
agreements: {
136+
eula: true,
137+
version: '1.0.1',
138+
analytics: false,
139+
},
140+
})
141+
142+
render(<OAuthForm>{(children) => (<>{children}</>)}</OAuthForm>)
143+
144+
fireEvent.click(screen.getByTestId('google-oauth'))
145+
146+
const expectedActions = [{}].fill(updateUserConfigSettings(), 0)
147+
expect(clearStoreActions(store.getActions().slice(0, expectedActions.length))).toEqual(
148+
clearStoreActions(expectedActions)
149+
)
150+
})
120151
})

redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React, { useState } from 'react'
2-
import { useDispatch } from 'react-redux'
2+
import { useDispatch, useSelector } from 'react-redux'
33
import { signIn } from 'uiSrc/slices/oauth/cloud'
44
import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces'
55
import { ipcAuth } from 'uiSrc/electron/utils'
66
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
7+
import { updateUserConfigSettingsAction, userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'
78
import OAuthSsoForm from './components/oauth-sso-form'
89
import OAuthSocialButtons from '../oauth-social-buttons'
910
import { Props as OAuthSocialButtonsProps } from '../oauth-social-buttons/OAuthSocialButtons'
@@ -24,13 +25,17 @@ const OAuthForm = ({
2425
const dispatch = useDispatch()
2526

2627
const [authStrategy, setAuthStrategy] = useState('')
28+
const config = useSelector(userSettingsConfigSelector)
2729

2830
const initOAuthProcess = (strategy: OAuthStrategy, action: string, data?: {}) => {
2931
dispatch(signIn())
3032
ipcAuth(strategy, action, data)
3133
}
3234

3335
const onSocialButtonClick = (authStrategy: OAuthStrategy) => {
36+
if (!config?.agreements?.analytics) {
37+
dispatch(updateUserConfigSettingsAction({ agreements: { ...config?.agreements, analytics: true } }))
38+
}
3439
setAuthStrategy(authStrategy)
3540
onClick?.(authStrategy)
3641

0 commit comments

Comments
 (0)