1
- import { keys } from '@elastic/eui'
1
+ import { EuiButtonIcon , EuiToolTip , keys } from '@elastic/eui'
2
2
import React , { useEffect , useState } from 'react'
3
3
import { useDispatch , useSelector } from 'react-redux'
4
4
import cx from 'classnames'
5
5
6
+ import { useParams } from 'react-router-dom'
6
7
import MultiSearch from 'uiSrc/components/multi-search/MultiSearch'
7
8
import { SCAN_COUNT_DEFAULT , SCAN_TREE_COUNT_DEFAULT } from 'uiSrc/constants/api'
8
9
import { replaceSpaces } from 'uiSrc/utils'
9
10
import {
11
+ changeExactMatch ,
10
12
deleteSearchHistoryAction ,
11
13
fetchKeys ,
12
14
fetchSearchHistoryAction ,
@@ -15,13 +17,11 @@ import {
15
17
setFilter ,
16
18
setSearchMatch
17
19
} from 'uiSrc/slices/browser/keys'
18
- import { SearchMode , KeyViewType , SearchHistoryItem } from 'uiSrc/slices/interfaces/keys'
19
- import {
20
- redisearchHistorySelector ,
21
- redisearchSelector
22
- } from 'uiSrc/slices/browser/redisearch'
20
+ import { KeyViewType , SearchHistoryItem , SearchMode } from 'uiSrc/slices/interfaces/keys'
21
+ import { redisearchHistorySelector , redisearchSelector } from 'uiSrc/slices/browser/redisearch'
23
22
24
23
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
24
+ import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
25
25
import styles from './styles.module.scss'
26
26
27
27
const placeholders = {
@@ -31,7 +31,7 @@ const placeholders = {
31
31
32
32
const SearchKeyList = ( ) => {
33
33
const { id } = useSelector ( connectedInstanceSelector )
34
- const { search, viewType, searchMode } = useSelector ( keysSelector )
34
+ const { search, viewType, searchMode, exactMatch } = useSelector ( keysSelector )
35
35
const { search : redisearchQuery , selectedIndex } = useSelector ( redisearchSelector )
36
36
const { data : rediSearchHistory , loading : rediSearchHistoryLoading } = useSelector ( redisearchHistorySelector )
37
37
const { data : searchHistory , loading : searchHistoryLoading } = useSelector ( keysSearchHistorySelector )
@@ -40,6 +40,7 @@ const SearchKeyList = () => {
40
40
const [ disableSubmit , setDisableSubmit ] = useState ( false )
41
41
42
42
const dispatch = useDispatch ( )
43
+ const { instanceId } = useParams < { instanceId : string } > ( )
43
44
44
45
useEffect ( ( ) => {
45
46
if ( id ) {
@@ -114,6 +115,23 @@ const SearchKeyList = () => {
114
115
handleApply ( '' )
115
116
}
116
117
118
+ const handleChangeExactMatch = ( ) => {
119
+ sendEventTelemetry ( {
120
+ event : TelemetryEvent . BROWSER_FILTER_PER_PATTERN_CLICKED ,
121
+ eventData : {
122
+ databaseId : instanceId ,
123
+ view : viewType ,
124
+ previous : exactMatch ? 'Exact' : 'Pattern' ,
125
+ current : exactMatch ? 'Pattern' : 'Exact' ,
126
+ }
127
+ } )
128
+ dispatch ( changeExactMatch ( ! exactMatch ) )
129
+
130
+ if ( value ) {
131
+ handleApply ( )
132
+ }
133
+ }
134
+
117
135
return (
118
136
< div className = { cx ( styles . container , { [ styles . redisearchMode ] : searchMode === SearchMode . Redisearch } ) } >
119
137
< MultiSearch
@@ -130,6 +148,24 @@ const SearchKeyList = () => {
130
148
onApply : handleApplySuggestion ,
131
149
onDelete : handleDeleteSuggestions ,
132
150
} }
151
+ optionalButton = { searchMode === SearchMode . Pattern ? (
152
+ < EuiToolTip
153
+ title = "Exact Search"
154
+ content = { exactMatch ? 'Disable to see keys matching your pattern' : 'Enable to see keys that exactly match your pattern' }
155
+ position = "bottom"
156
+ >
157
+ < EuiButtonIcon
158
+ display = "empty"
159
+ iconType = "bullseye"
160
+ color = "primary"
161
+ size = "xs"
162
+ onClick = { handleChangeExactMatch }
163
+ aria-label = "exact match button"
164
+ className = { cx ( styles . exactSearchIcon , { [ styles . disabled ] : ! exactMatch } ) }
165
+ data-testid = "exact-match-button"
166
+ />
167
+ </ EuiToolTip >
168
+ ) : null }
133
169
disableSubmit = { disableSubmit }
134
170
placeholder = { placeholders [ searchMode ] }
135
171
className = { styles . input }
0 commit comments