Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('BulkActions', () => {
eventData: {
databaseId: 'instanceId',
action: BulkActionsType.Delete,
search: '',
match: '*',
filterType: 'hash'
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { BulkActionsType } from 'uiSrc/constants'
import { keysSelector } from 'uiSrc/slices/browser/keys'
import { getMatchType, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { DEFAULT_SEARCH_MATCH } from 'uiSrc/constants/api'

import BulkUpload from './BulkUpload'
import BulkDelete from './BulkDelete'
Expand All @@ -41,16 +42,12 @@ const BulkActions = (props: Props) => {
const dispatch = useDispatch()

useEffect(() => {
let matchValue = '*'
if (search !== '*' && !!search) {
matchValue = getMatchType(search)
}
sendEventTelemetry({
event: TelemetryEvent.BULK_ACTIONS_OPENED,
eventData: {
databaseId: instanceId,
filterType: filter,
match: matchValue,
match: (search && search !== DEFAULT_SEARCH_MATCH) ? getMatchType(search) : DEFAULT_SEARCH_MATCH,
}
})
}, [])
Expand All @@ -71,7 +68,7 @@ const BulkActions = (props: Props) => {
}

if (type === BulkActionsType.Delete) {
eventData.search = search
eventData.match = (search && search !== DEFAULT_SEARCH_MATCH) ? getMatchType(search) : DEFAULT_SEARCH_MATCH
eventData.filterType = filter
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,70 @@
import React from 'react'
import { mock } from 'ts-mockito'
import { render } from 'uiSrc/utils/test-utils'

import { fireEvent, render, screen } from 'uiSrc/utils/test-utils'
import { BulkActionsType } from 'uiSrc/constants'
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import BulkActionsTabs, { Props } from './BulkActionsTabs'

const mockedProps = {
...mock<Props>(),
}

jest.mock('uiSrc/telemetry', () => ({
...jest.requireActual('uiSrc/telemetry'),
sendEventTelemetry: jest.fn(),
}))

jest.mock('uiSrc/slices/browser/bulkActions', () => ({
...jest.requireActual('uiSrc/slices/browser/bulkActions'),
selectedBulkActionsSelector: jest.fn().mockReturnValue({
type: 'delete'
}),
}))

jest.mock('uiSrc/slices/browser/keys', () => ({
...jest.requireActual('uiSrc/slices/browser/keys'),
keysSelector: jest.fn().mockReturnValue({
filter: 'set',
search: 'dawkmdk*'
}),
}))

describe('BulkActionsTabs', () => {
it('should render', () => {
expect(render(<BulkActionsTabs {...mockedProps} />)).toBeTruthy()
})

it('should call proper telemetry events', async () => {
const sendEventTelemetryMock = jest.fn();
(sendEventTelemetry as jest.Mock).mockImplementation(() => sendEventTelemetryMock)

render(<BulkActionsTabs {...mockedProps} onChangeType={jest.fn()} />)

fireEvent.click(screen.getByTestId('bulk-action-tab-upload'))

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.BULK_ACTIONS_OPENED,
eventData: {
databaseId: '',
action: BulkActionsType.Upload,
}
});

(sendEventTelemetry as jest.Mock).mockRestore()

fireEvent.click(screen.getByTestId('bulk-action-tab-delete'))

expect(sendEventTelemetry).toBeCalledWith({
event: TelemetryEvent.BULK_ACTIONS_OPENED,
eventData: {
databaseId: '',
action: BulkActionsType.Delete,
match: 'PATTERN',
filterType: 'set'
}
});

(sendEventTelemetry as jest.Mock).mockRestore()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { useSelector } from 'react-redux'
import { BulkActionsType } from 'uiSrc/constants'
import { selectedBulkActionsSelector } from 'uiSrc/slices/browser/bulkActions'

import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { getMatchType, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
import { DEFAULT_SEARCH_MATCH } from 'uiSrc/constants/api'
import { keysSelector } from 'uiSrc/slices/browser/keys'

import { bulkActionsTypeTabs } from '../constants/bulk-type-options'
import styles from './styles.module.scss'

Expand All @@ -17,16 +20,23 @@ export interface Props {
const BulkActionsTabs = (props: Props) => {
const { onChangeType } = props
const { id: instanceId } = useSelector(connectedInstanceSelector)
const { filter, search } = useSelector(keysSelector)
const { type } = useSelector(selectedBulkActionsSelector)

const onSelectedTabChanged = (id: BulkActionsType) => {
const eventData: Record<string, any> = {
databaseId: instanceId,
action: id
}

if (id === BulkActionsType.Delete) {
eventData.match = (search && search !== DEFAULT_SEARCH_MATCH) ? getMatchType(search) : DEFAULT_SEARCH_MATCH
eventData.filterType = filter
}

sendEventTelemetry({
event: TelemetryEvent.BULK_ACTIONS_SWITCHED,
eventData: {
databaseId: instanceId,
prevValue: type,
currentValue: id
}
event: TelemetryEvent.BULK_ACTIONS_OPENED,
eventData
})
onChangeType(id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const BulkUpload = (props: Props) => {
const onStartAgain = () => {
dispatch(setBulkUploadStartAgain())
setFiles(null)
setIsSubmitDisabled(true)
}

const handleUploadWarning = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
import { fireEvent } from '@testing-library/react'
import { cleanup, mockedStore, render, waitFor, screen, clearStoreActions } from 'uiSrc/utils/test-utils'
import { KeysStoreData, KeyViewType, SearchMode } from 'uiSrc/slices/interfaces/keys'
import { deleteSelectedKey, keysSelector, setLastBatchKeys } from 'uiSrc/slices/browser/keys'
import { deleteKey, keysSelector, setLastBatchKeys } from 'uiSrc/slices/browser/keys'
import { apiService } from 'uiSrc/services'
import KeyList from './KeyList'

Expand Down Expand Up @@ -196,7 +196,7 @@ describe('KeyList', () => {
fireEvent.click(screen.getByTestId('submit-delete-key'))

const expectedActions = [
deleteSelectedKey()
deleteKey()
]
expect(clearStoreActions(store.getActions().slice(-1))).toEqual(clearStoreActions(expectedActions))
})
Expand Down
2 changes: 0 additions & 2 deletions redisinsight/ui/src/telemetry/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ export enum TelemetryEvent {
BULK_ACTIONS_WARNING = 'BULK_ACTIONS_WARNING',
BULK_ACTIONS_CANCELLED = 'BULK_ACTIONS_CANCELLED',
BULK_ACTIONS_STARTED = 'BULK_ACTIONS_STARTED',
BULK_ACTIONS_STOPPED = 'BULK_ACTIONS_STOPPED',
BULK_ACTIONS_SWITCHED = 'BULK_ACTIONS_SWITCHED',

DATABASE_ANALYSIS_STARTED = 'DATABASE_ANALYSIS_STARTED',
DATABASE_ANALYSIS_HISTORY_VIEWED = 'DATABASE_ANALYSIS_HISTORY_VIEWED',
Expand Down