Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

4 changes: 2 additions & 2 deletions redisinsight/ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import InputFieldSentinel from './input-field-sentinel/InputFieldSentinel'
import PageBreadcrumbs from './page-breadcrumbs/PageBreadcrumbs'
import ContentEditable from './ContentEditable'
import Config from './config'
import AdvancedSettings from './advanced-settings/AdvancedSettings'
import SettingItem from './settings-item/SettingItem'
import { ConsentsSettings, ConsentsSettingsPopup, ConsentsPrivacy, ConsentsNotifications } from './consents-settings'
import KeyboardShortcut from './keyboard-shortcut/KeyboardShortcut'
import ShortcutsFlyout from './shortcuts-flyout/ShortcutsFlyout'
Expand Down Expand Up @@ -38,7 +38,7 @@ export {
ConsentsSettingsPopup,
ConsentsPrivacy,
ConsentsNotifications,
AdvancedSettings,
SettingItem,
KeyboardShortcut,
MonitorConfig,
PubSubConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
screen,
fireEvent,
} from 'uiSrc/utils/test-utils'
import AdvancedSettingsItem from './AdvancedSettingsItem'
import SettingItem from './SettingItem'

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

describe('AdvancedSettingsItem', () => {
describe('SettingItem', () => {
it('should render', () => {
expect(render(<AdvancedSettingsItem {...mockedProps} />)).toBeTruthy()
expect(render(<SettingItem {...mockedProps} />)).toBeTruthy()
})

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

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

it('should change keys to scan input properly', () => {
render(<AdvancedSettingsItem {...mockedProps} />)
render(<SettingItem {...mockedProps} />)
fireEvent.click(screen.getByTestId(/keys-to-scan-value/))
fireEvent.change(
screen.getByTestId(/keys-to-scan-input/),
Expand All @@ -57,7 +57,7 @@ describe('AdvancedSettingsItem', () => {
})

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

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

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

fireEvent.change(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Props {
validation: (value: string) => string,
}

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

const [value, setValue] = useState<string>(initValue)
Expand Down Expand Up @@ -117,4 +117,4 @@ const AdvancedSettingsItem = (props: Props) => {
)
}

export default AdvancedSettingsItem
export default SettingItem
24 changes: 1 addition & 23 deletions redisinsight/ui/src/pages/settings/SettingsPage.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { fireEvent } from '@testing-library/react'
import { cloneDeep } from 'lodash'
import React from 'react'
import { setWorkbenchCleanUp } from 'uiSrc/slices/user/user-settings'
import { cleanup, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
import { render } from 'uiSrc/utils/test-utils'
import SettingsPage from './SettingsPage'

let store: typeof mockedStore
beforeEach(() => {
cleanup()
store = cloneDeep(mockedStore)
store.clearActions()
})


describe('SettingsPage', () => {
it('should render', () => {
expect(render(<SettingsPage />)).toBeTruthy()
Expand Down Expand Up @@ -51,15 +40,4 @@ describe('SettingsPage', () => {
).toBeInTheDocument()
expect(render(<SettingsPage />)).toBeTruthy()
})

it('should call proper actions after click on switch wb clear mode', () => {
render(<SettingsPage />)

const afterRenderActions = [...store.getActions()]

fireEvent.click(screen.getByTestId('switch-workbench-cleanup'))

expect(store.getActions())
.toEqual([...afterRenderActions, setWorkbenchCleanUp(true)])
})
})
55 changes: 16 additions & 39 deletions redisinsight/ui/src/pages/settings/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ import {
EuiSpacer,
EuiText,
EuiCallOut,
EuiSwitch,
} from '@elastic/eui'
import { useDispatch, useSelector } from 'react-redux'

import { setTitle } from 'uiSrc/utils'
import { THEMES } from 'uiSrc/constants'
import { useDebouncedEffect } from 'uiSrc/services'
import { ConsentsNotifications, ConsentsPrivacy, AdvancedSettings } from 'uiSrc/components'
import { ConsentsNotifications, ConsentsPrivacy } from 'uiSrc/components'
import { sendEventTelemetry, sendPageViewTelemetry, TelemetryEvent, TelemetryPageView } from 'uiSrc/telemetry'
import { appAnalyticsInfoSelector } from 'uiSrc/slices/app/info'
import { ThemeContext } from 'uiSrc/contexts/themeContext'
import {
fetchUserConfigSettings,
fetchUserSettingsSpec,
setWorkbenchCleanUp,
userSettingsSelector,
userSettingsWBSelector,
} from 'uiSrc/slices/user/user-settings'

import { AdvancedSettings, WorkbenchSettings } from './components'

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

const SettingsPage = () => {
Expand All @@ -41,7 +40,6 @@ const SettingsPage = () => {

const [loading, setLoading] = useState(false)
const { loading: settingsLoading } = useSelector(userSettingsSelector)
const { cleanup } = useSelector(userSettingsWBSelector)
const { identified: analyticsIdentified } = useSelector(appAnalyticsInfoSelector)

const dispatch = useDispatch()
Expand Down Expand Up @@ -74,17 +72,6 @@ const SettingsPage = () => {
})
}

const onSwitchWbCleanUp = (val: boolean) => {
dispatch(setWorkbenchCleanUp(val))
sendEventTelemetry({
event: TelemetryEvent.SETTINGS_WORKBENCH_EDITOR_CLEAR_CHANGED,
eventData: {
currentValue: !val,
newValue: val,
}
})
}

const Appearance = () => (
<>
<EuiForm component="form">
Expand Down Expand Up @@ -118,28 +105,18 @@ const SettingsPage = () => {
</div>
)

const WorkbenchSettings = () => (
<>
<EuiForm component="form">
<EuiTitle size="xs">
<h4>Editor Cleanup</h4>
</EuiTitle>
<EuiSpacer size="m" />
<EuiFormRow>
<EuiSwitch
label="Clear the Editor when running the code"
checked={cleanup}
onChange={(e) => onSwitchWbCleanUp(e.target.checked)}
className={styles.switchOption}
data-testid="switch-workbench-cleanup"
/>
</EuiFormRow>
<EuiSpacer size="l" />
</EuiForm>
</>
const WorkbenchSettingsGroup = () => (
<div>
{loading && (
<div className={styles.cover}>
<EuiLoadingSpinner size="xl" />
</div>
)}
<WorkbenchSettings />
</div>
)

const AdvancedSettingsNavGroup = () => (
const AdvancedSettingsGroup = () => (
<div>
{loading && (
<div className={styles.cover}>
Expand All @@ -148,7 +125,7 @@ const SettingsPage = () => {
)}
<EuiCallOut className={styles.warning}>
<EuiText size="s" className={styles.smallText}>
These settings should only be changed if you understand their impact.
Advanced settings should only be changed if you understand their impact.
</EuiText>
</EuiCallOut>
<AdvancedSettings />
Expand Down Expand Up @@ -189,7 +166,7 @@ const SettingsPage = () => {
initialIsOpen={false}
data-test-subj="accordion-workbench-settings"
>
{WorkbenchSettings()}
{WorkbenchSettingsGroup()}
</EuiCollapsibleNavGroup>
<EuiCollapsibleNavGroup
isCollapsible
Expand All @@ -198,7 +175,7 @@ const SettingsPage = () => {
initialIsOpen={false}
data-test-subj="accordion-advanced-settings"
>
{AdvancedSettingsNavGroup()}
{AdvancedSettingsGroup()}
</EuiCollapsibleNavGroup>
</EuiPageContentBody>
</EuiPageBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ describe('AdvancedSettings', () => {
it('should render', () => {
expect(render(<AdvancedSettings />)).toBeTruthy()
})

it('should Keys-to-scan-value render ', () => {
render(<AdvancedSettings />)

expect(screen.getByTestId(/keys-to-scan-value/)).toBeInTheDocument()
})
it('should pipeline-bunch render ', () => {
render(<AdvancedSettings />)

expect(screen.getByTestId(/pipeline-bunch/)).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { EuiSpacer } from '@elastic/eui'
import React from 'react'
import { useDispatch, useSelector } from 'react-redux'

import { validateCountNumber } from 'uiSrc/utils'
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
import { SettingItem } from 'uiSrc/components'
import { updateUserConfigSettingsAction, userSettingsConfigSelector } from 'uiSrc/slices/user/user-settings'

const AdvancedSettings = () => {
const { scanThreshold = '' } = useSelector(userSettingsConfigSelector) ?? {}

const dispatch = useDispatch()

const handleApplyKeysToScanChanges = (value: string) => {
// eslint-disable-next-line no-nested-ternary
const data = value ? (+value < SCAN_COUNT_DEFAULT ? SCAN_COUNT_DEFAULT : +value) : null

dispatch(
updateUserConfigSettingsAction(
{ scanThreshold: data },
)
)
}

return (
<>
<SettingItem
initValue={scanThreshold.toString()}
onApply={handleApplyKeysToScanChanges}
validation={validateCountNumber}
title="Keys to Scan in Browser"
summary="Sets the amount of keys to scan per one iteration. Filtering by pattern per a large number of keys may decrease performance."
testid="keys-to-scan"
placeholder="10 000"
label="Keys to Scan:"
/>
<EuiSpacer size="m" />
</>
)
}

export default AdvancedSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AdvancedSettings from './AdvancedSettings'

export default AdvancedSettings
7 changes: 7 additions & 0 deletions redisinsight/ui/src/pages/settings/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import AdvancedSettings from './advanced-settings'
import WorkbenchSettings from './workbench-settings'

export {
AdvancedSettings,
WorkbenchSettings
}
Loading