Skip to content

Commit 9d933c9

Browse files
committed
#RI-6294 - fix key view event
1 parent 9d9d8db commit 9d933c9

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/KeyDetails.spec.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
33
import { cloneDeep } from 'lodash'
4-
import { cleanup, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
4+
import { cleanup, mockedStore, render, screen, act } from 'uiSrc/utils/test-utils'
55

66
import { defaultSelectedKeyAction, setSelectedKeyRefreshDisabled } from 'uiSrc/slices/browser/keys'
7+
import { stringToBuffer } from 'uiSrc/utils'
8+
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
9+
import { apiService } from 'uiSrc/services'
10+
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
711
import KeyDetails, { Props as KeyDetailsProps } from './KeyDetails'
812

13+
jest.mock('uiSrc/telemetry', () => ({
14+
...jest.requireActual('uiSrc/telemetry'),
15+
sendEventTelemetry: jest.fn(),
16+
}))
17+
918
const mockedProps = mock<KeyDetailsProps>()
1019

1120
let store: typeof mockedStore
@@ -47,4 +56,23 @@ describe('KeyDetails', () => {
4756

4857
expect(screen.getByTestId('select-key-message')).toBeInTheDocument()
4958
})
59+
60+
it('should call proper telemetry after open key details', async () => {
61+
const sendEventTelemetryMock = jest.fn();
62+
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock)
63+
apiService.post = jest.fn().mockResolvedValueOnce({ status: 200, data: { length: 1, type: 'hash' } })
64+
65+
await act(async () => {
66+
render(<KeyDetails {...instance(mockedProps)} keyProp={stringToBuffer('key')} />)
67+
})
68+
69+
expect(sendEventTelemetry).toBeCalledWith({
70+
event: TelemetryEvent.BROWSER_KEY_VALUE_VIEWED,
71+
eventData: {
72+
databaseId: INSTANCE_ID_MOCK,
73+
length: 1,
74+
keyType: 'hash'
75+
}
76+
})
77+
})
5078
})

redisinsight/ui/src/pages/browser/modules/key-details/KeyDetails.tsx

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect } from 'react'
2-
import { isNull, isUndefined } from 'lodash'
2+
import { isNull } from 'lodash'
33
import { useDispatch, useSelector } from 'react-redux'
44
import { useParams } from 'react-router-dom'
55
import cx from 'classnames'
@@ -45,33 +45,34 @@ const KeyDetails = (props: Props) => {
4545
const { viewType } = useSelector(keysSelector)
4646
const { loading, error = '', data } = useSelector(selectedKeySelector)
4747
const isKeySelected = !isNull(useSelector(selectedKeyDataSelector))
48-
const { type: keyType, length: keyLength } = useSelector(selectedKeyDataSelector) ?? {
49-
type: KeyTypes.String,
50-
}
48+
const { type: keyType } = useSelector(selectedKeyDataSelector) ?? { type: KeyTypes.String }
5149

5250
const dispatch = useDispatch()
5351

5452
useEffect(() => {
55-
if (keyProp === null) {
56-
return
57-
}
58-
if (keyProp?.data) {
59-
sendEventTelemetry({
60-
event: getBasedOnViewTypeEvent(
61-
viewType,
62-
TelemetryEvent.BROWSER_KEY_VALUE_VIEWED,
63-
TelemetryEvent.TREE_VIEW_KEY_VALUE_VIEWED
64-
),
65-
eventData: {
66-
keyType,
67-
databaseId: instanceId,
68-
length: keyLength,
69-
}
70-
})
71-
}
72-
// Restore key details from context in future
73-
// (selectedKey.data?.name !== keyProp)
74-
dispatch(fetchKeyInfo(keyProp))
53+
if (keyProp === null) return
54+
55+
dispatch(fetchKeyInfo(
56+
keyProp,
57+
undefined,
58+
(data) => {
59+
if (!data) return
60+
61+
sendEventTelemetry({
62+
event: getBasedOnViewTypeEvent(
63+
viewType,
64+
TelemetryEvent.BROWSER_KEY_VALUE_VIEWED,
65+
TelemetryEvent.TREE_VIEW_KEY_VALUE_VIEWED
66+
),
67+
eventData: {
68+
keyType: data.type,
69+
databaseId: instanceId,
70+
length: data.length,
71+
}
72+
})
73+
}
74+
))
75+
7576
dispatch(setSelectedKeyRefreshDisabled(false))
7677
}, [keyProp])
7778

redisinsight/ui/src/pages/browser/modules/key-details/components/hash-details/HashDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const HashDetails = (props: Props) => {
6868
className={styles.showTtlCheckbox}
6969
checked={showTtl}
7070
onChange={(e) => handleSelectShow(e.target.checked)}
71-
data-testId="test-check-ttl"
71+
data-testid="test-check-ttl"
7272
/>
7373
<Divider
7474
className={styles.divider}

redisinsight/ui/src/pages/rdi/instance/components/header/components/buttons/deploy-pipeline-button/DeployPipelineButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const DeployPipelineButton = ({ loading, disabled }: Props) => {
110110
className={cx(styles.resetPipelineCheckbox, { [styles.checked]: resetPipeline })}
111111
checked={resetPipeline}
112112
onChange={(e) => handleSelectReset(e.target.checked)}
113-
data-testId="reset-pipeline-checkbox"
113+
data-testid="reset-pipeline-checkbox"
114114
/>
115115

116116
<EuiToolTip

redisinsight/ui/src/slices/browser/keys.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export function fetchPatternKeysAction(
519519
sourceKeysFetch = CancelToken.source()
520520

521521
const state = stateInit()
522-
const scanThreshold = state.user.settings.config?.scanThreshold || SCAN_COUNT_DEFAULT;
522+
const scanThreshold = state.user.settings.config?.scanThreshold || SCAN_COUNT_DEFAULT
523523
const { search: match, filter: type } = state.browser.keys
524524
const { encoding } = state.app.info
525525

@@ -594,7 +594,7 @@ export function fetchMorePatternKeysAction(oldKeys: IKeyPropTypes[] = [], cursor
594594
sourceKeysFetch = CancelToken.source()
595595

596596
const state = stateInit()
597-
const scanThreshold = state.user.settings.config?.scanThreshold ?? SCAN_COUNT_DEFAULT;
597+
const scanThreshold = state.user.settings.config?.scanThreshold ?? SCAN_COUNT_DEFAULT
598598
const { search: match, filter: type } = state.browser.keys
599599
const { encoding } = state.app.info
600600
const { data, status } = await apiService.post(
@@ -643,7 +643,11 @@ export function fetchMorePatternKeysAction(oldKeys: IKeyPropTypes[] = [], cursor
643643
}
644644

645645
// Asynchronous thunk action
646-
export function fetchKeyInfo(key: RedisResponseBuffer, resetData?: boolean) {
646+
export function fetchKeyInfo(
647+
key: RedisResponseBuffer,
648+
resetData?: boolean,
649+
onSuccess?: (data: Nullable<IKeyPropTypes>) => void
650+
) {
647651
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
648652
dispatch(defaultSelectedKeyAction())
649653

@@ -662,6 +666,7 @@ export function fetchKeyInfo(key: RedisResponseBuffer, resetData?: boolean) {
662666
if (isStatusSuccessful(status)) {
663667
dispatch(loadKeyInfoSuccess(data))
664668
dispatch(updateSelectedKeyRefreshTime(Date.now()))
669+
onSuccess?.(data)
665670
}
666671

667672
if (data.type === KeyTypes.Hash) {

0 commit comments

Comments
 (0)