Skip to content

Commit 65dc8e0

Browse files
committed
#RI-781 - Tree view
1 parent 3d7ea88 commit 65dc8e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1396
-865
lines changed
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 8 additions & 0 deletions
Loading

redisinsight/ui/src/components/instance-header/InstanceHeader.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import React, { useEffect, useState } from 'react'
2-
import { useDispatch, useSelector } from 'react-redux'
2+
import { useSelector } from 'react-redux'
33
import { useHistory } from 'react-router-dom'
44
import cx from 'classnames'
5-
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiToolTip, EuiSwitch, EuiSwitchEvent } from '@elastic/eui'
5+
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiToolTip } from '@elastic/eui'
66

77
import { Pages } from 'uiSrc/constants'
88
import { ConnectionType } from 'uiSrc/slices/interfaces'
99
import { connectedInstanceOverviewSelector, connectedInstanceSelector } from 'uiSrc/slices/instances'
1010
import ShortInstanceInfo from 'uiSrc/components/instance-header/components/ShortInstanceInfo'
1111
import DatabaseOverviewWrapper from 'uiSrc/components/database-overview/DatabaseOverviewWrapper'
12-
import { changeKeyViewType, keysSelector } from 'uiSrc/slices/keys'
13-
import { KeyViewType } from 'uiSrc/slices/interfaces/keys'
1412

1513
import styles from './styles.module.scss'
1614

@@ -23,13 +21,10 @@ const InstanceHeader = () => {
2321
connectionType = ConnectionType.Standalone,
2422
db = 0
2523
} = useSelector(connectedInstanceSelector)
26-
const { viewType } = useSelector(keysSelector)
2724
const { version } = useSelector(connectedInstanceOverviewSelector)
2825
const history = useHistory()
2926
const [windowDimensions, setWindowDimensions] = useState(0)
3027

31-
const dispatch = useDispatch()
32-
3328
useEffect(() => {
3429
updateWindowDimensions()
3530
globalThis.addEventListener('resize', updateWindowDimensions)
@@ -46,10 +41,6 @@ const InstanceHeader = () => {
4641
history.push(Pages.home)
4742
}
4843

49-
const onChangeKeyViewType = (e: EuiSwitchEvent) => {
50-
dispatch(changeKeyViewType(!e.target.checked ? KeyViewType.List : KeyViewType.Tree))
51-
}
52-
5344
return (
5445
<div className={cx(styles.container)}>
5546
<EuiFlexGroup gutterSize="none" responsive={false}>
@@ -99,13 +90,6 @@ const InstanceHeader = () => {
9990
</EuiFlexGroup>
10091
</EuiToolTip>
10192
</div>
102-
<div style={{ paddingLeft: '10px' }}>
103-
<EuiSwitch
104-
label="Tree view"
105-
checked={viewType !== KeyViewType.List}
106-
onChange={(e) => onChangeKeyViewType(e)}
107-
/>
108-
</div>
10993
</div>
11094
</EuiFlexItem>
11195

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import { instance, mock } from 'ts-mockito'
3+
import { fireEvent, screen, render } from 'uiSrc/utils/test-utils'
4+
import ScanMore, { Props } from './KeysSummary'
5+
6+
const mockedProps = mock<Props>()
7+
8+
describe('ActionBar', () => {
9+
it('should render', () => {
10+
expect(render(<ScanMore {...instance(mockedProps)} />)).toBeTruthy()
11+
})
12+
13+
it('should call "onCloseActionBar"', () => {
14+
const handleClick = jest.fn()
15+
16+
const renderer = render(
17+
<ScanMore {...instance(mockedProps)} onCloseActionBar={handleClick} />
18+
)
19+
20+
expect(renderer).toBeTruthy()
21+
22+
fireEvent.click(screen.getByTestId('cancel-selecting'))
23+
expect(handleClick).toHaveBeenCalledTimes(1)
24+
})
25+
})
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React from 'react'
2+
import cx from 'classnames'
3+
import { EuiText, EuiTextColor } from '@elastic/eui'
4+
5+
import { numberWithSpaces } from 'uiSrc/utils/numbers'
6+
import ScanMore from '../scan-more'
7+
8+
import styles from './styles.module.scss'
9+
10+
export interface Props {
11+
loading: boolean
12+
items: any[]
13+
scanned?: number
14+
totalItemsCount?: number
15+
scanMoreStyle?: {
16+
[key: string]: string | number;
17+
}
18+
loadMoreItems?: (config: any) => void
19+
}
20+
21+
const KeysSummary = ({
22+
items,
23+
loading,
24+
scanned = 0,
25+
totalItemsCount = 0,
26+
scanMoreStyle,
27+
loadMoreItems,
28+
}: Props) => (
29+
<>
30+
{!!totalItemsCount && (
31+
<div className={styles.content}>
32+
{!!totalItemsCount && (
33+
<EuiText size="xs">
34+
{!!scanned && (
35+
<>
36+
<EuiTextColor className="eui-alignMiddle">
37+
<b>
38+
Results:&nbsp;
39+
<span data-testid="keys-number-of-results">{numberWithSpaces(items.length)}</span>
40+
{' '}
41+
key
42+
{items.length === 1 ? '' : 's'}
43+
.&nbsp;
44+
</b>
45+
<EuiTextColor color="subdued">
46+
Scanned
47+
{' '}
48+
<span data-testid="keys-number-of-scanned">{numberWithSpaces(scanned)}</span>
49+
{' '}
50+
/
51+
{' '}
52+
<span data-testid="keys-total">{numberWithSpaces(totalItemsCount)}</span>
53+
{' '}
54+
keys
55+
<span
56+
className={cx([styles.loading, { [styles.loadingShow]: loading }])}
57+
/>
58+
</EuiTextColor>
59+
</EuiTextColor>
60+
<ScanMore
61+
withAlert
62+
fill={false}
63+
style={scanMoreStyle}
64+
scanned={scanned}
65+
totalItemsCount={totalItemsCount}
66+
loading={loading}
67+
loadMoreItems={loadMoreItems}
68+
/>
69+
</>
70+
)}
71+
72+
{!scanned && (
73+
<EuiText size="xs">
74+
<b>
75+
Total:&nbsp;
76+
{numberWithSpaces(totalItemsCount)}
77+
</b>
78+
</EuiText>
79+
)}
80+
81+
</EuiText>
82+
)}
83+
</div>
84+
)}
85+
{loading && !totalItemsCount && (
86+
<EuiText size="xs">
87+
Scanning...
88+
</EuiText>
89+
)}
90+
</>
91+
)
92+
93+
export default KeysSummary
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import KeysSummary from './KeysSummary'
2+
3+
export default KeysSummary
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.loading {
2+
opacity: 0;
3+
}
4+
5+
.loadingShow {
6+
opacity: 1;
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react'
2+
import { instance, mock } from 'ts-mockito'
3+
import { fireEvent, screen, render } from 'uiSrc/utils/test-utils'
4+
import ScanMore, { Props } from './ScanMore'
5+
6+
const mockedProps = mock<Props>()
7+
8+
describe('ActionBar', () => {
9+
it('should render', () => {
10+
expect(render(<ScanMore {...instance(mockedProps)} />)).toBeTruthy()
11+
})
12+
13+
it('should call "onCloseActionBar"', () => {
14+
const handleClick = jest.fn()
15+
16+
const renderer = render(
17+
<ScanMore {...instance(mockedProps)} onCloseActionBar={handleClick} />
18+
)
19+
20+
expect(renderer).toBeTruthy()
21+
22+
fireEvent.click(screen.getByTestId('cancel-selecting'))
23+
expect(handleClick).toHaveBeenCalledTimes(1)
24+
})
25+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react'
2+
import { EuiButton, EuiIcon, EuiToolTip } from '@elastic/eui'
3+
4+
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
5+
import styles from './styles.module.scss'
6+
7+
export interface Props {
8+
withAlert?: boolean
9+
fill?: boolean
10+
loading: boolean
11+
scanned?: number
12+
totalItemsCount?: number
13+
style?: {
14+
[key: string]: string | number;
15+
}
16+
loadMoreItems?: (config: any) => void
17+
}
18+
19+
const WARNING_MESSAGE = 'Scanning additional keys may decrease performance and memory available.'
20+
21+
const ScanMore = ({
22+
fill = true,
23+
withAlert = true,
24+
scanned = 0,
25+
totalItemsCount = 0,
26+
loading,
27+
style,
28+
loadMoreItems,
29+
}: Props) => (
30+
<>
31+
{scanned < totalItemsCount && (
32+
<EuiButton
33+
fill={fill}
34+
size="s"
35+
color="secondary"
36+
style={style ?? { marginLeft: 25, height: 26 }}
37+
disabled={loading}
38+
className={styles.btn}
39+
onClick={() =>
40+
loadMoreItems?.({
41+
stopIndex: SCAN_COUNT_DEFAULT - 1,
42+
startIndex: 0,
43+
})}
44+
data-testid="scan-more"
45+
>
46+
{withAlert && (
47+
<EuiToolTip
48+
content={WARNING_MESSAGE}
49+
position="top"
50+
display="inlineBlock"
51+
>
52+
<EuiIcon type="alert" />
53+
</EuiToolTip>
54+
)}
55+
Scan more
56+
</EuiButton>
57+
)}
58+
</>
59+
)
60+
61+
export default ScanMore

0 commit comments

Comments
 (0)