Skip to content

Commit 1446990

Browse files
authored
Merge pull request #1119 from RedisInsight/feature/RI-3461_move-pipline-setting
#RI-3461 - move pipeline setting to workbench section, refactoring
2 parents 9a7290a + 2bb4564 commit 1446990

File tree

14 files changed

+213
-156
lines changed

14 files changed

+213
-156
lines changed

redisinsight/ui/src/components/advanced-settings/AdvancedSettings.tsx

Lines changed: 0 additions & 77 deletions
This file was deleted.

redisinsight/ui/src/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import InputFieldSentinel from './input-field-sentinel/InputFieldSentinel'
1010
import PageBreadcrumbs from './page-breadcrumbs/PageBreadcrumbs'
1111
import ContentEditable from './ContentEditable'
1212
import Config from './config'
13-
import AdvancedSettings from './advanced-settings/AdvancedSettings'
13+
import SettingItem from './settings-item/SettingItem'
1414
import { ConsentsSettings, ConsentsSettingsPopup, ConsentsPrivacy, ConsentsNotifications } from './consents-settings'
1515
import KeyboardShortcut from './keyboard-shortcut/KeyboardShortcut'
1616
import ShortcutsFlyout from './shortcuts-flyout/ShortcutsFlyout'
@@ -38,7 +38,7 @@ export {
3838
ConsentsSettingsPopup,
3939
ConsentsPrivacy,
4040
ConsentsNotifications,
41-
AdvancedSettings,
41+
SettingItem,
4242
KeyboardShortcut,
4343
MonitorConfig,
4444
PubSubConfig,
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
screen,
55
fireEvent,
66
} from 'uiSrc/utils/test-utils'
7-
import AdvancedSettingsItem from './AdvancedSettingsItem'
7+
import SettingItem from './SettingItem'
88

99
jest.mock('uiSrc/slices/user/user-settings', () => ({
1010
...jest.requireActual('uiSrc/slices/user/user-settings'),
@@ -28,24 +28,24 @@ const mockedProps = {
2828
label: 'Keys to Scan:',
2929
}
3030

31-
describe('AdvancedSettingsItem', () => {
31+
describe('SettingItem', () => {
3232
it('should render', () => {
33-
expect(render(<AdvancedSettingsItem {...mockedProps} />)).toBeTruthy()
33+
expect(render(<SettingItem {...mockedProps} />)).toBeTruthy()
3434
})
3535

3636
it('should render keys to scan value', () => {
37-
render(<AdvancedSettingsItem {...mockedProps} />)
37+
render(<SettingItem {...mockedProps} />)
3838
expect(screen.getByTestId(/keys-to-scan-value/)).toHaveTextContent('10000')
3939
})
4040

4141
it('should render keys to scan input after click value', () => {
42-
render(<AdvancedSettingsItem {...mockedProps} />)
42+
render(<SettingItem {...mockedProps} />)
4343
fireEvent.click(screen.getByTestId(/keys-to-scan-value/))
4444
expect(screen.getByTestId(/keys-to-scan-input/)).toBeInTheDocument()
4545
})
4646

4747
it('should change keys to scan input properly', () => {
48-
render(<AdvancedSettingsItem {...mockedProps} />)
48+
render(<SettingItem {...mockedProps} />)
4949
fireEvent.click(screen.getByTestId(/keys-to-scan-value/))
5050
fireEvent.change(
5151
screen.getByTestId(/keys-to-scan-input/),
@@ -57,7 +57,7 @@ describe('AdvancedSettingsItem', () => {
5757
})
5858

5959
it('should properly apply changes', () => {
60-
render(<AdvancedSettingsItem {...mockedProps} />)
60+
render(<SettingItem {...mockedProps} />)
6161

6262
fireEvent.click(screen.getByTestId(/keys-to-scan-value/))
6363
fireEvent.change(
@@ -71,7 +71,7 @@ describe('AdvancedSettingsItem', () => {
7171
})
7272

7373
it('should properly decline changes', async () => {
74-
render(<AdvancedSettingsItem {...mockedProps} />)
74+
render(<SettingItem {...mockedProps} />)
7575
fireEvent.click(screen.getByTestId(/keys-to-scan-value/))
7676

7777
fireEvent.change(

redisinsight/ui/src/components/advanced-settings/AdvancedSettingsItem.tsx renamed to redisinsight/ui/src/components/settings-item/SettingItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface Props {
2525
validation: (value: string) => string,
2626
}
2727

28-
const AdvancedSettingsItem = (props: Props) => {
28+
const SettingItem = (props: Props) => {
2929
const { initValue, title, summary, testid, placeholder, label, onApply, validation = (val: string) => val } = props
3030

3131
const [value, setValue] = useState<string>(initValue)
@@ -117,4 +117,4 @@ const AdvancedSettingsItem = (props: Props) => {
117117
)
118118
}
119119

120-
export default AdvancedSettingsItem
120+
export default SettingItem
File renamed without changes.

redisinsight/ui/src/pages/settings/SettingsPage.spec.tsx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
import { fireEvent } from '@testing-library/react'
2-
import { cloneDeep } from 'lodash'
31
import React from 'react'
4-
import { setWorkbenchCleanUp } from 'uiSrc/slices/user/user-settings'
5-
import { cleanup, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
2+
import { render } from 'uiSrc/utils/test-utils'
63
import SettingsPage from './SettingsPage'
74

8-
let store: typeof mockedStore
9-
beforeEach(() => {
10-
cleanup()
11-
store = cloneDeep(mockedStore)
12-
store.clearActions()
13-
})
14-
15-
165
describe('SettingsPage', () => {
176
it('should render', () => {
187
expect(render(<SettingsPage />)).toBeTruthy()
@@ -51,15 +40,4 @@ describe('SettingsPage', () => {
5140
).toBeInTheDocument()
5241
expect(render(<SettingsPage />)).toBeTruthy()
5342
})
54-
55-
it('should call proper actions after click on switch wb clear mode', () => {
56-
render(<SettingsPage />)
57-
58-
const afterRenderActions = [...store.getActions()]
59-
60-
fireEvent.click(screen.getByTestId('switch-workbench-cleanup'))
61-
62-
expect(store.getActions())
63-
.toEqual([...afterRenderActions, setWorkbenchCleanUp(true)])
64-
})
6543
})

redisinsight/ui/src/pages/settings/SettingsPage.tsx

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ import {
1414
EuiSpacer,
1515
EuiText,
1616
EuiCallOut,
17-
EuiSwitch,
1817
} from '@elastic/eui'
1918
import { useDispatch, useSelector } from 'react-redux'
2019

2120
import { setTitle } from 'uiSrc/utils'
2221
import { THEMES } from 'uiSrc/constants'
2322
import { useDebouncedEffect } from 'uiSrc/services'
24-
import { ConsentsNotifications, ConsentsPrivacy, AdvancedSettings } from 'uiSrc/components'
23+
import { ConsentsNotifications, ConsentsPrivacy } from 'uiSrc/components'
2524
import { sendEventTelemetry, sendPageViewTelemetry, TelemetryEvent, TelemetryPageView } from 'uiSrc/telemetry'
2625
import { appAnalyticsInfoSelector } from 'uiSrc/slices/app/info'
2726
import { ThemeContext } from 'uiSrc/contexts/themeContext'
2827
import {
2928
fetchUserConfigSettings,
3029
fetchUserSettingsSpec,
31-
setWorkbenchCleanUp,
3230
userSettingsSelector,
33-
userSettingsWBSelector,
3431
} from 'uiSrc/slices/user/user-settings'
3532

33+
import { AdvancedSettings, WorkbenchSettings } from './components'
34+
3635
import styles from './styles.module.scss'
3736

3837
const SettingsPage = () => {
@@ -41,7 +40,6 @@ const SettingsPage = () => {
4140

4241
const [loading, setLoading] = useState(false)
4342
const { loading: settingsLoading } = useSelector(userSettingsSelector)
44-
const { cleanup } = useSelector(userSettingsWBSelector)
4543
const { identified: analyticsIdentified } = useSelector(appAnalyticsInfoSelector)
4644

4745
const dispatch = useDispatch()
@@ -74,17 +72,6 @@ const SettingsPage = () => {
7472
})
7573
}
7674

77-
const onSwitchWbCleanUp = (val: boolean) => {
78-
dispatch(setWorkbenchCleanUp(val))
79-
sendEventTelemetry({
80-
event: TelemetryEvent.SETTINGS_WORKBENCH_EDITOR_CLEAR_CHANGED,
81-
eventData: {
82-
currentValue: !val,
83-
newValue: val,
84-
}
85-
})
86-
}
87-
8875
const Appearance = () => (
8976
<>
9077
<EuiForm component="form">
@@ -118,28 +105,18 @@ const SettingsPage = () => {
118105
</div>
119106
)
120107

121-
const WorkbenchSettings = () => (
122-
<>
123-
<EuiForm component="form">
124-
<EuiTitle size="xs">
125-
<h4>Editor Cleanup</h4>
126-
</EuiTitle>
127-
<EuiSpacer size="m" />
128-
<EuiFormRow>
129-
<EuiSwitch
130-
label="Clear the Editor when running the code"
131-
checked={cleanup}
132-
onChange={(e) => onSwitchWbCleanUp(e.target.checked)}
133-
className={styles.switchOption}
134-
data-testid="switch-workbench-cleanup"
135-
/>
136-
</EuiFormRow>
137-
<EuiSpacer size="l" />
138-
</EuiForm>
139-
</>
108+
const WorkbenchSettingsGroup = () => (
109+
<div>
110+
{loading && (
111+
<div className={styles.cover}>
112+
<EuiLoadingSpinner size="xl" />
113+
</div>
114+
)}
115+
<WorkbenchSettings />
116+
</div>
140117
)
141118

142-
const AdvancedSettingsNavGroup = () => (
119+
const AdvancedSettingsGroup = () => (
143120
<div>
144121
{loading && (
145122
<div className={styles.cover}>
@@ -148,7 +125,7 @@ const SettingsPage = () => {
148125
)}
149126
<EuiCallOut className={styles.warning}>
150127
<EuiText size="s" className={styles.smallText}>
151-
These settings should only be changed if you understand their impact.
128+
Advanced settings should only be changed if you understand their impact.
152129
</EuiText>
153130
</EuiCallOut>
154131
<AdvancedSettings />
@@ -189,7 +166,7 @@ const SettingsPage = () => {
189166
initialIsOpen={false}
190167
data-test-subj="accordion-workbench-settings"
191168
>
192-
{WorkbenchSettings()}
169+
{WorkbenchSettingsGroup()}
193170
</EuiCollapsibleNavGroup>
194171
<EuiCollapsibleNavGroup
195172
isCollapsible
@@ -198,7 +175,7 @@ const SettingsPage = () => {
198175
initialIsOpen={false}
199176
data-test-subj="accordion-advanced-settings"
200177
>
201-
{AdvancedSettingsNavGroup()}
178+
{AdvancedSettingsGroup()}
202179
</EuiCollapsibleNavGroup>
203180
</EuiPageContentBody>
204181
</EuiPageBody>

redisinsight/ui/src/components/advanced-settings/AdvancedSettings.spec.tsx renamed to redisinsight/ui/src/pages/settings/components/advanced-settings/AdvancedSettings.spec.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ describe('AdvancedSettings', () => {
2020
it('should render', () => {
2121
expect(render(<AdvancedSettings />)).toBeTruthy()
2222
})
23+
2324
it('should Keys-to-scan-value render ', () => {
2425
render(<AdvancedSettings />)
2526

2627
expect(screen.getByTestId(/keys-to-scan-value/)).toBeInTheDocument()
2728
})
28-
it('should pipeline-bunch render ', () => {
29-
render(<AdvancedSettings />)
30-
31-
expect(screen.getByTestId(/pipeline-bunch/)).toBeInTheDocument()
32-
})
3329
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { EuiSpacer } from '@elastic/eui'
2+
import React from 'react'
3+
import { useDispatch, useSelector } from 'react-redux'
4+
5+
import { validateCountNumber } from 'uiSrc/utils'
6+
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
7+
import { SettingItem } from 'uiSrc/components'
8+
import { updateUserConfigSettingsAction, userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'
9+
10+
const AdvancedSettings = () => {
11+
const { scanThreshold = '' } = useSelector(userSettingsConfigSelector) ?? {}
12+
13+
const dispatch = useDispatch()
14+
15+
const handleApplyKeysToScanChanges = (value: string) => {
16+
// eslint-disable-next-line no-nested-ternary
17+
const data = value ? (+value < SCAN_COUNT_DEFAULT ? SCAN_COUNT_DEFAULT : +value) : null
18+
19+
dispatch(
20+
updateUserConfigSettingsAction(
21+
{ scanThreshold: data },
22+
)
23+
)
24+
}
25+
26+
return (
27+
<>
28+
<SettingItem
29+
initValue={scanThreshold.toString()}
30+
onApply={handleApplyKeysToScanChanges}
31+
validation={validateCountNumber}
32+
title="Keys to Scan in Browser"
33+
summary="Sets the amount of keys to scan per one iteration. Filtering by pattern per a large number of keys may decrease performance."
34+
testid="keys-to-scan"
35+
placeholder="10 000"
36+
label="Keys to Scan:"
37+
/>
38+
<EuiSpacer size="m" />
39+
</>
40+
)
41+
}
42+
43+
export default AdvancedSettings
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AdvancedSettings from './AdvancedSettings'
2+
3+
export default AdvancedSettings

0 commit comments

Comments
 (0)