Skip to content

Commit 24c6867

Browse files
authored
Merge pull request #115 from RedisInsight/feature/RI-1756_rework-cli-ch
#RI-1756 - rework CLI & Command Helper
2 parents 977f30f + a374a6b commit 24c6867

Some content is hidden

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

59 files changed

+574
-333
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { cloneDeep } from 'lodash'
2+
import React from 'react'
3+
4+
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
5+
import { toggleCli, toggleCliHelper } from 'uiSrc/slices/cli/cli-settings'
6+
7+
import BottomGroupComponents from './BottomGroupComponents'
8+
9+
jest.mock('uiSrc/slices/cli/cli-settings', () => ({
10+
...jest.requireActual('uiSrc/slices/cli/cli-settings'),
11+
cliSettingsSelector: jest.fn().mockReturnValue({
12+
isShowCli: true,
13+
isShowHelper: true
14+
}),
15+
}))
16+
17+
let store: typeof mockedStore
18+
beforeEach(() => {
19+
cleanup()
20+
store = cloneDeep(mockedStore)
21+
store.clearActions()
22+
})
23+
24+
const commandHelperId = 'command-helper'
25+
const cliId = 'cli'
26+
27+
describe('BottomGroupComponents', () => {
28+
it('should render', () => {
29+
expect(
30+
render(<BottomGroupComponents />)
31+
).toBeTruthy()
32+
})
33+
34+
it('should render Cli when isShowCli truthy', () => {
35+
render(<BottomGroupComponents />)
36+
expect(screen.getByTestId(cliId)).toBeInTheDocument()
37+
})
38+
39+
it('should render Command Helper when isShowHelper truthy', () => {
40+
render(<BottomGroupComponents />)
41+
expect(screen.getByTestId(commandHelperId)).toBeInTheDocument()
42+
})
43+
44+
it('should not to close command helper after closing cli', () => {
45+
render(<BottomGroupComponents />)
46+
fireEvent.click(screen.getByTestId('collapse-cli'))
47+
const expectedActions = [toggleCli()]
48+
expect(store.getActions()).toEqual(expect.arrayContaining(expectedActions))
49+
50+
expect(screen.getByTestId('command-helper')).toBeInTheDocument()
51+
})
52+
53+
it('should not to close cli after closing command-helper', () => {
54+
render(<BottomGroupComponents />)
55+
fireEvent.click(screen.getByTestId('close-command-helper'))
56+
57+
const expectedActions = [toggleCliHelper()]
58+
expect(store.getActions()).toEqual(expect.arrayContaining(expectedActions))
59+
60+
expect(screen.getByTestId('cli')).toBeInTheDocument()
61+
})
62+
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
import { useSelector } from 'react-redux'
3+
import cx from 'classnames'
4+
import { cliSettingsSelector } from 'uiSrc/slices/cli/cli-settings'
5+
import CliWrapper from 'uiSrc/components/cli/CliWrapper'
6+
import CommandHelperWrapper from 'uiSrc/components/command-helper/CommandHelperWrapper'
7+
import BottomGroupMinimized from './components/bottom-group-minimized/BottomGroupMinimized'
8+
9+
import styles from './styles.module.scss'
10+
11+
const BottomGroupComponents = () => {
12+
const { isShowCli, isShowHelper } = useSelector(cliSettingsSelector)
13+
14+
return (
15+
<div className={styles.groupComponentsWrapper}>
16+
<div className={styles.groupComponents}>
17+
{isShowCli && <CliWrapper />}
18+
{isShowHelper && (
19+
<div className={cx(styles.helperWrapper, { [styles.fullWidth]: !isShowCli })}>
20+
<CommandHelperWrapper />
21+
</div>
22+
)}
23+
</div>
24+
<BottomGroupMinimized />
25+
</div>
26+
)
27+
}
28+
29+
export default BottomGroupComponents
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react'
2+
import { cloneDeep } from 'lodash'
3+
4+
import { toggleCli, toggleCliHelper } from 'uiSrc/slices/cli/cli-settings'
5+
import { cleanup, fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
6+
import BottomGroupMinimized from './BottomGroupMinimized'
7+
8+
let store: typeof mockedStore
9+
beforeEach(() => {
10+
cleanup()
11+
store = cloneDeep(mockedStore)
12+
store.clearActions()
13+
})
14+
15+
describe('BottomGroupMinimized', () => {
16+
it('should render', () => {
17+
expect(
18+
render(<BottomGroupMinimized />)
19+
).toBeTruthy()
20+
})
21+
22+
it('should "toggleCli" action be called after click "expand-cli" button', () => {
23+
render(<BottomGroupMinimized />)
24+
fireEvent.click(screen.getByTestId('expand-cli'))
25+
26+
const expectedActions = [toggleCli()]
27+
expect(store.getActions()).toEqual(expectedActions)
28+
})
29+
30+
it('should "toggleCliHelper" action be called after click "expand-command-helper" button', () => {
31+
render(<BottomGroupMinimized />)
32+
fireEvent.click(screen.getByTestId('expand-command-helper'))
33+
34+
const expectedActions = [toggleCliHelper()]
35+
expect(store.getActions()).toEqual(expectedActions)
36+
})
37+
})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react'
2+
import cx from 'classnames'
3+
import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui'
4+
import { useDispatch, useSelector } from 'react-redux'
5+
import { useParams } from 'react-router-dom'
6+
7+
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
8+
import { toggleCli, toggleCliHelper, cliSettingsSelector } from 'uiSrc/slices/cli/cli-settings'
9+
10+
import styles from '../../styles.module.scss'
11+
12+
const BottomGroupMinimized = () => {
13+
const { isShowHelper, isShowCli } = useSelector(cliSettingsSelector)
14+
const { instanceId = '' } = useParams<{ instanceId: string }>()
15+
const dispatch = useDispatch()
16+
17+
const handleExpandCli = () => {
18+
sendEventTelemetry({
19+
event: TelemetryEvent.CLI_OPENED,
20+
eventData: {
21+
databaseId: instanceId
22+
}
23+
})
24+
dispatch(toggleCli())
25+
}
26+
27+
const handleExpandHelper = () => {
28+
sendEventTelemetry({
29+
event: isShowHelper ? TelemetryEvent.COMMAND_HELPER_COLLAPSED : TelemetryEvent.COMMAND_HELPER_EXPANDED,
30+
eventData: {
31+
databaseId: instanceId
32+
}
33+
})
34+
dispatch(toggleCliHelper())
35+
}
36+
37+
return (
38+
<div className={styles.containerMinimized}>
39+
<EuiFlexGroup
40+
gutterSize="none"
41+
alignItems="center"
42+
responsive={false}
43+
style={{ height: '100%' }}
44+
>
45+
<EuiFlexItem
46+
className={styles.componentBadgeItem}
47+
grow={false}
48+
onClick={handleExpandCli}
49+
data-testid="expand-cli"
50+
>
51+
<EuiBadge className={cx(styles.componentBadge, { [styles.active]: isShowCli })}>
52+
<EuiIcon type="console" size="m" />
53+
<span>CLI</span>
54+
</EuiBadge>
55+
</EuiFlexItem>
56+
<EuiFlexItem
57+
className={styles.componentBadgeItem}
58+
grow={false}
59+
onClick={handleExpandHelper}
60+
data-testid="expand-command-helper"
61+
>
62+
<EuiBadge className={cx(styles.componentBadge, { [styles.active]: isShowHelper })}>
63+
<EuiIcon type="documents" size="m" />
64+
<span>Command Helper</span>
65+
</EuiBadge>
66+
</EuiFlexItem>
67+
</EuiFlexGroup>
68+
</div>
69+
)
70+
}
71+
72+
export default BottomGroupMinimized
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import BottomGroupMinimized from './BottomGroupMinimized'
2+
3+
export default BottomGroupMinimized
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.groupComponentsWrapper {
2+
flex-grow: 1;
3+
height: 100%;
4+
padding: 0 16px;
5+
}
6+
7+
.groupComponents {
8+
display: flex;
9+
flex-grow: 1;
10+
height: calc(100% - 26px);
11+
}
12+
13+
.containerMinimized {
14+
height: 26px;
15+
line-height: 26px;
16+
border: 1px solid var(--euiColorLightShade);
17+
}
18+
19+
.componentBadgeItem {
20+
margin: 0 2px;
21+
cursor: pointer;
22+
user-select: none;
23+
24+
:global {
25+
.euiBadge__text, .euiBadge__content {
26+
cursor: pointer !important;
27+
}
28+
29+
.euiBadge__text {
30+
display: flex;
31+
align-items: center;
32+
}
33+
34+
.euiIcon {
35+
margin-right: 4px;
36+
}
37+
}
38+
}
39+
40+
.componentBadge {
41+
background-color: transparent !important;
42+
color: var(--euiTextSubduedColor) !important;
43+
height: 18px !important;
44+
border: none !important;
45+
46+
&:hover {
47+
background-color: var(--buttonIconPrimaryHover) !important;
48+
}
49+
50+
&.active {
51+
background-color: var(--hoverInListColorDarken) !important;
52+
color: var(--euiColorPrimary) !important;
53+
}
54+
}
55+
56+
57+
.helperWrapper {
58+
width: 100%;
59+
max-width: 360px;
60+
&.fullWidth {
61+
max-width: 100%;
62+
}
63+
}

redisinsight/ui/src/components/cli/Cli/Cli.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CliBodyWrapper from 'uiSrc/components/cli/components/cli-body'
55
import styles from './styles.module.scss'
66

77
const CLI = () => (
8-
<div className={styles.container}>
8+
<div className={styles.container} data-testid="cli">
99
<div className={styles.main}>
1010
<CliHeader />
1111
<CliBodyWrapper />

redisinsight/ui/src/components/cli/Cli/styles.module.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
.container {
66
height: 100%;
77
width: 100%;
8-
padding-left: 16px;
9-
padding-right: 16px;
108
}
119

1210
.main {

redisinsight/ui/src/components/cli/CliWrapper.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cloneDeep } from 'lodash'
22
import React from 'react'
3-
import { clearSearchingCommand, setCliEnteringCommand } from 'uiSrc/slices/cli/cli-settings'
3+
import { processCliClient, setCliEnteringCommand } from 'uiSrc/slices/cli/cli-settings'
44
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
55
import CliWrapper from './CliWrapper'
66

@@ -35,7 +35,7 @@ describe('CliWrapper', () => {
3535

3636
unmount()
3737

38-
const expectedActions = [clearSearchingCommand(), setCliEnteringCommand()]
38+
const expectedActions = [processCliClient(), setCliEnteringCommand()]
3939
expect(store.getActions().slice(-2)).toEqual(expectedActions)
4040
})
4141
})

redisinsight/ui/src/components/cli/components/cli-body/CliBody/styles.module.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
color: var(--textColorShade);
2424

2525
border-top: 1px solid var(--euiColorLightShade);
26-
border-right: 1px solid var(--euiColorLightShade);
2726

2827
z-index: 10;
2928

0 commit comments

Comments
 (0)