Skip to content

Commit 0b87e6d

Browse files
committed
feat(ui): collect telemetry on vector search page when clearing query
re #RI-7218
1 parent f44be1f commit 0b87e6d

File tree

7 files changed

+103
-4
lines changed

7 files changed

+103
-4
lines changed

redisinsight/ui/src/pages/vector-search/query/VectorSearchQuery.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,21 @@ describe('VectorSearchQuery', () => {
6666
eventData: { databaseId: INSTANCE_ID_MOCK },
6767
})
6868
})
69+
70+
it('should collect telemetry on query clear', () => {
71+
renderVectorSearchQueryComponent()
72+
73+
// Find and click the "Clear" button
74+
const clearButton = screen.getByTestId('btn-clear')
75+
expect(clearButton).toBeInTheDocument()
76+
77+
fireEvent.click(clearButton)
78+
79+
// Verify telemetry event was sent
80+
expect(sendEventTelemetry).toHaveBeenCalledWith({
81+
event: TelemetryEvent.SEARCH_CLEAR_EDITOR_CLICKED,
82+
eventData: { databaseId: INSTANCE_ID_MOCK },
83+
})
84+
})
6985
})
7086
})

redisinsight/ui/src/pages/vector-search/query/VectorSearchQuery.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ export const VectorSearchQuery = () => {
6363
})
6464
}
6565

66+
const onQueryClear = () => {
67+
sendEventTelemetry({
68+
event: TelemetryEvent.SEARCH_CLEAR_EDITOR_CLICKED,
69+
eventData: {
70+
databaseId: instanceId,
71+
},
72+
})
73+
}
74+
6675
return (
6776
<CreateIndexWrapper direction="column" justify="between">
6877
<HeaderActions />
@@ -78,6 +87,7 @@ export const VectorSearchQuery = () => {
7887
onSubmit={onQuerySubmit}
7988
onQueryChangeMode={onQueryChangeMode}
8089
onChangeGroupMode={onChangeGroupMode}
90+
onClear={onQueryClear}
8191
queryProps={{ useLiteActions: true }}
8292
/>
8393
</ResizablePanel>

redisinsight/ui/src/pages/workbench/components/query/Query/Query.spec.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { cloneDeep } from 'lodash'
22
import React from 'react'
33
import { instance, mock } from 'ts-mockito'
4-
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
4+
import {
5+
cleanup,
6+
fireEvent,
7+
mockedStore,
8+
render,
9+
screen,
10+
waitFor,
11+
} from 'uiSrc/utils/test-utils'
512
import Query, { Props } from './Query'
613

714
const mockedProps = mock<Props>()
@@ -36,4 +43,30 @@ describe('Query', () => {
3643
it('should render', () => {
3744
expect(render(<Query {...instance(mockedProps)} />)).toBeTruthy()
3845
})
46+
47+
it('should call onClear when clear button is clicked', async () => {
48+
const props: Props = {
49+
...instance(mockedProps),
50+
query: 'test query',
51+
useLiteActions: true,
52+
setQuery: jest.fn(),
53+
onClear: jest.fn(),
54+
}
55+
56+
render(<Query {...props} />)
57+
58+
// Ensure we start with the query input populated
59+
const queryInput = screen.getByTestId('monaco')
60+
expect(queryInput).toHaveValue(props.query)
61+
62+
// Find the clear button and click it
63+
const clearButton = screen.getByTestId('btn-clear')
64+
expect(clearButton).toBeInTheDocument()
65+
66+
fireEvent.click(clearButton)
67+
68+
// Verify that the onClear function was called and the query input is cleared
69+
expect(props.setQuery).toHaveBeenCalled()
70+
expect(props.onClear).toHaveBeenCalled()
71+
})
3972
})

redisinsight/ui/src/pages/workbench/components/query/Query/Query.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export interface Props {
8888
onKeyDown?: (e: React.KeyboardEvent, script: string) => void
8989
onQueryChangeMode: () => void
9090
onChangeGroupMode: () => void
91+
onClear?: () => void
9192
}
9293

9394
let execHistoryPos: number = 0
@@ -109,6 +110,7 @@ const Query = (props: Props) => {
109110
setQueryEl = () => {},
110111
onQueryChangeMode = () => {},
111112
onChangeGroupMode = () => {},
113+
onClear = () => {},
112114
} = props
113115
let contribution: Nullable<ISnippetController> = null
114116
const [isDedicatedEditorOpen, setIsDedicatedEditorOpen] = useState(false)
@@ -479,6 +481,11 @@ const Query = (props: Props) => {
479481
onSubmit(value)
480482
}
481483

484+
const handleClear = () => {
485+
setQuery('')
486+
onClear?.()
487+
}
488+
482489
const handleSuggestions = (
483490
editor: monacoEditor.editor.IStandaloneCodeEditor,
484491
command?: Nullable<IMonacoQuery>,
@@ -746,7 +753,7 @@ const Query = (props: Props) => {
746753
<QueryLiteActions
747754
isLoading={isLoading}
748755
onSubmit={handleSubmit}
749-
onClear={() => setQuery('')}
756+
onClear={handleClear}
750757
/>
751758
) : (
752759
<>

redisinsight/ui/src/pages/workbench/components/query/QueryWrapper.spec.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { cloneDeep } from 'lodash'
22
import React from 'react'
33
import { instance, mock } from 'ts-mockito'
4-
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
4+
import {
5+
cleanup,
6+
fireEvent,
7+
mockedStore,
8+
render,
9+
screen,
10+
} from 'uiSrc/utils/test-utils'
511
import QueryWrapper, { Props } from './QueryWrapper'
612

713
const mockedProps = mock<Props>()
@@ -45,4 +51,28 @@ describe('QueryWrapper', () => {
4551

4652
expect(render(<QueryWrapper {...instance(mockedProps)} />)).toBeTruthy()
4753
})
54+
55+
it('should call onClear callback when clear button is clicked', () => {
56+
const props: Props = {
57+
...instance(mockedProps),
58+
queryProps: {
59+
useLiteActions: true,
60+
},
61+
query: 'test query',
62+
onClear: jest.fn(),
63+
}
64+
65+
render(<QueryWrapper {...props} />)
66+
67+
// Ensure we start with the query input populated
68+
const queryInput = screen.getByTestId('monaco')
69+
expect(queryInput).toHaveValue(props.query)
70+
71+
// Find the clear button and click it
72+
const clearButton = screen.getByTestId('btn-clear')
73+
fireEvent.click(clearButton)
74+
75+
// Verify that the onClear function was called and the query input is cleared
76+
expect(props.onClear).toHaveBeenCalled()
77+
})
4878
})

redisinsight/ui/src/pages/workbench/components/query/QueryWrapper.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface Props {
2828
onSubmit: (value?: string) => void
2929
onQueryChangeMode: () => void
3030
onChangeGroupMode: () => void
31+
onClear?: () => void
3132
}
3233

3334
const QueryWrapper = (props: Props) => {
@@ -41,6 +42,7 @@ const QueryWrapper = (props: Props) => {
4142
onSubmit,
4243
onQueryChangeMode,
4344
onChangeGroupMode,
45+
onClear,
4446
queryProps = {},
4547
} = props
4648
const { loading: isCommandsLoading } = useSelector(appRedisCommandsSelector)
@@ -84,6 +86,7 @@ const QueryWrapper = (props: Props) => {
8486
onSubmit={onSubmit}
8587
onQueryChangeMode={onQueryChangeMode}
8688
onChangeGroupMode={onChangeGroupMode}
89+
onClear={onClear}
8790
{...queryProps}
8891
/>
8992
)

redisinsight/ui/src/telemetry/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export enum TelemetryEvent {
362362
SEARCH_RESULTS_EXPANDED = 'SEARCH_RESULTS_EXPANDED',
363363
SEARCH_CLEAR_RESULT_CLICKED = 'SEARCH_CLEAR_RESULT_CLICKED',
364364
SEARCH_CLEAR_ALL_RESULTS_CLICKED = 'SEARCH_CLEAR_ALL_RESULTS_CLICKED',
365-
// SEARCH_CLEAR_EDITOR_CLICKED = 'SEARCH_CLEAR_EDITOR_CLICKED',
365+
SEARCH_CLEAR_EDITOR_CLICKED = 'SEARCH_CLEAR_EDITOR_CLICKED',
366366
// SEARCH_MANAGE_INDEXES_DRAWER_OPENED = 'SEARCH_MANAGE_INDEXES_DRAWER_OPENED',
367367
// SEARCH_MANAGE_INDEXES_DRAWER_CLOSED = 'SEARCH_MANAGE_INDEXES_DRAWER_CLOSED',
368368
// SEARCH_MANAGE_INDEX_DETAILS_OPENED = 'SEARCH_MANAGE_INDEX_DETAILS_OPENED',

0 commit comments

Comments
 (0)