1
- import React , { useState } from 'react'
2
1
import {
3
2
EuiBasicTableColumn ,
3
+ EuiButtonEmpty ,
4
4
EuiInMemoryTable ,
5
5
EuiTextColor ,
6
6
EuiToolTip ,
7
- EuiButtonEmpty ,
8
7
PropertySort
9
8
} from '@elastic/eui'
9
+ import cx from 'classnames'
10
10
import { isNull } from 'lodash'
11
- import { useParams , useHistory } from 'react-router-dom '
11
+ import React , { useState } from 'react'
12
12
import { useDispatch , useSelector } from 'react-redux'
13
- import cx from 'classnames'
13
+ import { useHistory , useParams } from 'react-router-dom'
14
+ import { GroupBadge } from 'uiSrc/components'
15
+ import { Pages } from 'uiSrc/constants'
16
+ import { SCAN_COUNT_DEFAULT , SCAN_TREE_COUNT_DEFAULT } from 'uiSrc/constants/api'
17
+ import {
18
+ resetBrowserTree ,
19
+ setBrowserKeyListDataLoaded ,
20
+ setBrowserSelectedKey ,
21
+ setBrowserTreeDelimiter
22
+ } from 'uiSrc/slices/app/context'
23
+ import {
24
+ changeSearchMode ,
25
+ fetchKeys ,
26
+ keysSelector ,
27
+ resetKeysData ,
28
+ setFilter ,
29
+ setSearchMatch
30
+ } from 'uiSrc/slices/browser/keys'
31
+ import { KeyViewType , SearchMode } from 'uiSrc/slices/interfaces/keys'
14
32
15
33
import {
16
34
formatBytes ,
17
35
formatLongName ,
36
+ HighlightType ,
37
+ isBigKey ,
38
+ stringToBuffer ,
18
39
truncateNumberToDuration ,
19
40
truncateNumberToFirstUnit ,
20
- truncateTTLToSeconds ,
21
- stringToBuffer
41
+ truncateTTLToSeconds
22
42
} from 'uiSrc/utils'
23
43
import { numberWithSpaces } from 'uiSrc/utils/numbers'
24
- import { GroupBadge } from 'uiSrc/components'
25
- import { setFilter , setSearchMatch , resetKeysData , fetchKeys , keysSelector , changeSearchMode } from 'uiSrc/slices/browser/keys'
26
- import { SCAN_COUNT_DEFAULT , SCAN_TREE_COUNT_DEFAULT } from 'uiSrc/constants/api'
27
- import { KeyViewType , SearchMode } from 'uiSrc/slices/interfaces/keys'
28
- import { setBrowserKeyListDataLoaded , setBrowserSelectedKey , resetBrowserTree , setBrowserTreeDelimiter } from 'uiSrc/slices/app/context'
29
- import { Pages } from 'uiSrc/constants'
30
44
import { Key } from 'apiSrc/modules/database-analysis/models/key'
31
45
32
46
import styles from './styles.module.scss'
@@ -54,7 +68,7 @@ const Table = (props: Props) => {
54
68
dispatch ( setBrowserTreeDelimiter ( delimiter ) )
55
69
dispatch ( setFilter ( null ) )
56
70
dispatch ( setSearchMatch ( name , SearchMode . Pattern ) )
57
- dispatch ( resetKeysData ( ) )
71
+ dispatch ( resetKeysData ( SearchMode . Pattern ) )
58
72
dispatch ( fetchKeys (
59
73
SearchMode . Pattern ,
60
74
'0' ,
@@ -96,7 +110,7 @@ const Table = (props: Props) => {
96
110
truncateText : true ,
97
111
render : ( name : string ) => {
98
112
const tooltipContent = formatLongName ( name )
99
- const cellContent = name . substring ( 0 , 200 )
113
+ const cellContent = ( name as string ) . substring ( 0 , 200 )
100
114
return (
101
115
< div data-testid = "top-keys-table-name" className = { cx ( styles . delimiter , 'truncateText' ) } >
102
116
< EuiToolTip
@@ -159,16 +173,25 @@ const Table = (props: Props) => {
159
173
width : '9%' ,
160
174
sortable : true ,
161
175
align : 'right' ,
162
- render : ( value : number ) => {
176
+ render : ( value : number , { type } ) => {
163
177
const [ number , size ] = formatBytes ( value , 3 , true )
164
-
178
+ const isHighlight = isBigKey ( type , HighlightType . Memory , value )
165
179
return (
166
180
< EuiToolTip
167
- content = { `${ numberWithSpaces ( value ) } B` }
181
+ content = { (
182
+ < >
183
+ { isHighlight ? ( < > Consider splitting it into multiple keys< br /> </ > ) : null }
184
+ { numberWithSpaces ( value ) } B
185
+ </ >
186
+ ) }
187
+ anchorClassName = { cx ( { [ styles . highlight ] : isHighlight } ) }
168
188
data-testid = "usedMemory-tooltip"
169
189
>
170
190
< >
171
- < span className = { styles . count } data-testid = { `nsp-usedMemory-value=${ value } ` } >
191
+ < span
192
+ className = { styles . count }
193
+ data-testid = { `nsp-usedMemory-value=${ value } ${ isHighlight ? '-highlighted' : '' } ` }
194
+ >
172
195
{ number }
173
196
</ span >
174
197
< span className = { styles . valueUnit } > { size } </ span >
@@ -183,18 +206,26 @@ const Table = (props: Props) => {
183
206
width : '15%' ,
184
207
sortable : ( { length } ) => length ?? - 1 ,
185
208
align : 'right' ,
186
- render : ( value : number , { name } ) => {
209
+ render : ( value : number , { name, type } ) => {
187
210
if ( isNull ( value ) ) {
188
211
return (
189
212
< EuiTextColor color = "subdued" style = { { maxWidth : '100%' } } data-testid = { `length-empty-${ name } ` } >
190
213
-
191
214
</ EuiTextColor >
192
215
)
193
216
}
217
+
218
+ const isHighlight = isBigKey ( type , HighlightType . Length , value )
194
219
return (
195
- < span className = { styles . count } data-testid = { `length-value-${ name } ` } >
196
- { numberWithSpaces ( value ) }
197
- </ span >
220
+ < EuiToolTip
221
+ content = { isHighlight ? 'Consider splitting it into multiple keys' : '' }
222
+ anchorClassName = { cx ( { [ styles . highlight ] : isHighlight } ) }
223
+ data-testid = "usedMemory-tooltip"
224
+ >
225
+ < span className = { styles . count } data-testid = { `length-value-${ name } ${ isHighlight ? '-highlighted' : '' } ` } >
226
+ { numberWithSpaces ( value ) }
227
+ </ span >
228
+ </ EuiToolTip >
198
229
)
199
230
}
200
231
} ,
0 commit comments