Skip to content

Commit 1150094

Browse files
committed
RI-5905 create enableAnalyticsAction
1 parent 397e8f1 commit 1150094

File tree

8 files changed

+24
-80
lines changed

8 files changed

+24
-80
lines changed

redisinsight/api/src/constants/agreements-spec.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"disabled": false,
1010
"category": "privacy",
1111
"since": "1.0.1",
12-
"title": "Analytics",
13-
"label": "Enable Analytics",
14-
"description": "Select to help us make Redis Insight better. We aggregate anonymized user experience data and use it to fix bugs and improve experience for all users."
12+
"title": "Telemetry",
13+
"label": "Enable Telemetry",
14+
"description": "Select to help us make Redis Insight better. Telemetry helps us better understand how Redis Insight features are being used, improve experience for all users, and prioritize new features."
1515
},
1616
"notifications": {
1717
"defaultValue": false,

redisinsight/ui/src/components/consents-settings/ConsentsPrivacy/ConsentsPrivacy.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('ConsentsPrivacy', () => {
9191
})
9292
})
9393

94-
const expectedActions = [{}].fill(updateUserConfigSettings(), 0)
94+
const expectedActions = [updateUserConfigSettings()]
9595
expect(clearStoreActions(store.getActions().slice(0, expectedActions.length))).toEqual(
9696
clearStoreActions(expectedActions)
9797
)

redisinsight/ui/src/components/consents-settings/ConsentsPrivacy/ConsentsPrivacy.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ const ConsentsPrivacy = () => {
7474
return (
7575
<EuiForm component="form" onSubmit={formik.handleSubmit} data-testid="consents-settings-form">
7676
<div className={styles.consentsWrapper}>
77-
<EuiText size="s" className={styles.smallText} color="subdued">
78-
To optimize your experience, Redis Insight uses third-party tools.
79-
All data collected is anonymized and will not be used for any purpose without your consent.
80-
</EuiText>
81-
<EuiSpacer size="l" />
8277
<EuiTitle size="xs">
83-
<h4>Analytics</h4>
78+
<h4>Telemetry</h4>
8479
</EuiTitle>
8580
{
8681
privacyConsents

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

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

1817
let store: typeof mockedStore
@@ -34,17 +33,6 @@ jest.mock('uiSrc/services', () => ({
3433
},
3534
}))
3635

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-
4836
describe('OAuthAgreement', () => {
4937
it('should render', () => {
5038
expect(render(<OAuthAgreement />)).toBeTruthy()
@@ -71,19 +59,4 @@ describe('OAuthAgreement', () => {
7159
false,
7260
)
7361
})
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-
})
8962
})

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +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'
10+
import { enableUserAnalyticsAction } from 'uiSrc/slices/user/user-settings'
1111
import styles from './styles.module.scss'
1212

1313
export interface Props {
@@ -17,13 +17,12 @@ export interface Props {
1717
const OAuthAgreement = (props: Props) => {
1818
const { size = 'm' } = props
1919
const agreement = useSelector(oauthCloudPAgreementSelector)
20-
const config = useSelector(userSettingsConfigSelector)
2120

2221
const dispatch = useDispatch()
2322

2423
const handleCheck = (e: ChangeEvent<HTMLInputElement>) => {
25-
if (e.target.checked && !config?.agreements?.analytics) {
26-
dispatch(updateUserConfigSettingsAction({ agreements: { ...config?.agreements, analytics: true } }))
24+
if (e.target.checked) {
25+
dispatch(enableUserAnalyticsAction())
2726
}
2827
dispatch(setAgreement(e.target.checked))
2928
localStorageService.set(BrowserStorageItem.OAuthAgreement, e.target.checked)

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
33
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
4-
import { render, cleanup, clearStoreActions, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils'
4+
import { render, cleanup, 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'
87
import OAuthForm from './OAuthForm'
98

109
jest.mock('uiSrc/telemetry', () => ({
@@ -20,17 +19,6 @@ jest.mock('uiSrc/slices/oauth/cloud', () => ({
2019
oauthCloudPAgreementSelector: jest.fn().mockReturnValue(true),
2120
}))
2221

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-
3422
const onClick = jest.fn()
3523

3624
let store: typeof mockedStore
@@ -129,23 +117,4 @@ describe('OAuthForm', () => {
129117
fireEvent.click(screen.getByTestId('btn-submit'))
130118
})
131119
})
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-
})
151120
})

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState } from 'react'
2-
import { useDispatch, useSelector } from 'react-redux'
2+
import { useDispatch } 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'
7+
import { enableUserAnalyticsAction } from 'uiSrc/slices/user/user-settings'
88
import OAuthSsoForm from './components/oauth-sso-form'
99
import OAuthSocialButtons from '../oauth-social-buttons'
1010
import { Props as OAuthSocialButtonsProps } from '../oauth-social-buttons/OAuthSocialButtons'
@@ -25,17 +25,14 @@ const OAuthForm = ({
2525
const dispatch = useDispatch()
2626

2727
const [authStrategy, setAuthStrategy] = useState('')
28-
const config = useSelector(userSettingsConfigSelector)
2928

3029
const initOAuthProcess = (strategy: OAuthStrategy, action: string, data?: {}) => {
3130
dispatch(signIn())
3231
ipcAuth(strategy, action, data)
3332
}
3433

3534
const onSocialButtonClick = (authStrategy: OAuthStrategy) => {
36-
if (!config?.agreements?.analytics) {
37-
dispatch(updateUserConfigSettingsAction({ agreements: { ...config?.agreements, analytics: true } }))
38-
}
35+
dispatch(enableUserAnalyticsAction())
3936
setAuthStrategy(authStrategy)
4037
onClick?.(authStrategy)
4138

redisinsight/ui/src/slices/user/user-settings.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@ export function updateUserConfigSettingsAction(
182182
}
183183
}
184184
}
185+
186+
export function enableUserAnalyticsAction() {
187+
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
188+
const state = stateInit()
189+
const agreements = state?.user?.settings?.config?.agreements
190+
191+
if (agreements && !agreements.analytics) {
192+
dispatch(updateUserConfigSettingsAction({ agreements: { ...agreements, analytics: true } }))
193+
}
194+
}
195+
}

0 commit comments

Comments
 (0)