Skip to content

Commit 6b1d576

Browse files
author
Roman.Sergeenko
committed
#RI-1756 - rework CLI & Command Helper
1 parent be97a69 commit 6b1d576

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

+462
-310
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 } = useSelector(cliSettingsSelector)
13+
const {
14+
isShowHelper,
15+
} = useSelector(cliSettingsSelector)
16+
17+
return (
18+
<div className={styles.groupComponentsWrapper}>
19+
<div className={styles.groupComponents}>
20+
{isShowCli && <CliWrapper />}
21+
{isShowHelper && (
22+
<div className={cx(styles.helperWrapper, { [styles.fullWidth]: !isShowCli })}>
23+
<CommandHelperWrapper />
24+
</div>
25+
)}
26+
</div>
27+
<BottomGroupMinimized />
28+
</div>
29+
)
30+
}
31+
32+
export default BottomGroupComponents
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3-
import { instance, mock } from 'ts-mockito'
43

5-
import { toggleCli, clearSearchingCommand } from 'uiSrc/slices/cli/cli-settings'
4+
import { toggleCli } from 'uiSrc/slices/cli/cli-settings'
65
import { fireEvent, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
7-
import CliHeaderMinimized, { Props } from './CliHeaderMinimized'
8-
9-
const mockedProps = mock<Props>()
6+
import BottomGroupMinimized from './BottomGroupMinimized'
107

118
describe('CliHeaderMinimized', () => {
129
it('should render', () => {
1310
expect(
14-
render(<CliHeaderMinimized {...instance(mockedProps)} />)
11+
render(<BottomGroupMinimized />)
1512
).toBeTruthy()
1613
})
1714

1815
it('should "toggleCli" & "clearSearchingCommand" actions be called after click "expand-cli" button', () => {
1916
const store = cloneDeep(mockedStore)
2017

21-
render(<CliHeaderMinimized {...instance(mockedProps)} />)
18+
render(<BottomGroupMinimized />)
2219
fireEvent.click(screen.getByTestId('expand-cli'))
2320

24-
const expectedActions = [toggleCli(), clearSearchingCommand()]
21+
const expectedActions = [toggleCli()]
2522
expect(store.getActions()).toEqual(expectedActions)
2623
})
2724
})
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-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: #364DA8 !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/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

redisinsight/ui/src/components/cli/components/cli-body/CliBodyWrapper.spec.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ describe('CliBodyWrapper', () => {
110110
)
111111
})
112112

113-
it('CliHelper should be opened by default', () => {
114-
render(<CliBodyWrapper />)
115-
116-
expect(screen.getByTestId('cli-helper')).toBeInTheDocument()
117-
})
118-
119113
// It's not possible to simulate events on contenteditable with testing-react-library,
120114
// or any testing library that uses js - dom, because of a limitation on js - dom itself.
121115
// https://github.com/testing-library/dom-testing-library/pull/235

redisinsight/ui/src/components/cli/components/cli-body/CliBodyWrapper.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ import { connectedInstanceSelector } from 'uiSrc/slices/instances'
2929
import { checkUnsupportedCommand, clearOutput } from 'uiSrc/utils/cliHelper'
3030
import { InitOutputText, ConnectionSuccessOutputText } from 'uiSrc/constants/cliOutput'
3131
import { SendClusterCommandDto } from 'apiSrc/modules/cli/dto/cli.dto'
32-
3332
import CliBody from './CliBody'
33+
3434
import styles from './CliBody/styles.module.scss'
35-
import CliHelperWrapper from '../cli-helper'
3635

3736
const CliBodyWrapper = () => {
3837
const cliClientUuid = sessionStorageService.get(BrowserStorageItem.cliClientUuid) ?? ''
@@ -45,7 +44,6 @@ const CliBodyWrapper = () => {
4544
const {
4645
errorClient: error,
4746
unsupportedCommands,
48-
isShowHelper,
4947
isEnteringCommand,
5048
isSearching,
5149
matchedCommand
@@ -147,7 +145,6 @@ const CliBodyWrapper = () => {
147145
setCommand={setCommand}
148146
onSubmit={handleSubmit}
149147
/>
150-
{isShowHelper && <CliHelperWrapper />}
151148
</section>
152149
)
153150
}

0 commit comments

Comments
 (0)