Skip to content

Commit 82541c8

Browse files
authored
Merge pull request #56 from RedisInsight/feature/RI-2063_command-groups
#RI-2063 - dynamically display command groups
2 parents 40d2512 + 04b2d67 commit 82541c8

File tree

10 files changed

+54
-107
lines changed

10 files changed

+54
-107
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import React from 'react'
22
import { render, screen, fireEvent } from 'uiSrc/utils/test-utils'
3-
4-
import { FILTER_GROUP_TYPE_OPTIONS } from './constants'
3+
import { GROUP_TYPES_DISPLAY } from 'uiSrc/constants'
54
import CliSearchFilter from './CliSearchFilter'
65

6+
const redisCommandsPath = 'uiSrc/slices/app/redis-commands'
7+
8+
const commandGroupsMock = ['list', 'hash', 'set']
9+
10+
jest.mock(redisCommandsPath, () => {
11+
const defaultState = jest.requireActual(redisCommandsPath).initialState
12+
return {
13+
...jest.requireActual(redisCommandsPath),
14+
appRedisCommandsSelector: jest.fn().mockReturnValue({
15+
...defaultState,
16+
commandGroups: commandGroupsMock
17+
}),
18+
}
19+
})
20+
721
describe('CliSearchFilter', () => {
822
it('should render', () => {
923
expect(render(<CliSearchFilter submitFilter={jest.fn()} />)).toBeTruthy()
@@ -12,9 +26,10 @@ describe('CliSearchFilter', () => {
1226
it('should call submitFilter after choose options', () => {
1327
const submitFilter = jest.fn()
1428
const { queryByText } = render(<CliSearchFilter submitFilter={submitFilter} />)
29+
const testGroup = commandGroupsMock[0]
1530
fireEvent.click(screen.getByTestId('select-filter-group-type'))
16-
fireEvent.click(queryByText(FILTER_GROUP_TYPE_OPTIONS[0].text) || document)
31+
fireEvent.click(queryByText((GROUP_TYPES_DISPLAY as any)[testGroup]) || document)
1732

18-
expect(submitFilter).toBeCalledWith(FILTER_GROUP_TYPE_OPTIONS[0].value)
33+
expect(submitFilter).toBeCalledWith(testGroup)
1934
})
2035
})

redisinsight/ui/src/components/cli/components/cli-search/CliSearchFilter/CliSearchFilter.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
} from '@elastic/eui'
1010
import { useSelector } from 'react-redux'
1111

12+
import { GROUP_TYPES_DISPLAY } from 'uiSrc/constants'
13+
import { appRedisCommandsSelector } from 'uiSrc/slices/app/redis-commands'
1214
import { cliSettingsSelector } from 'uiSrc/slices/cli/cli-settings'
13-
import { FILTER_GROUP_TYPE_OPTIONS } from 'uiSrc/components/cli/components/cli-search/CliSearchFilter/constants'
1415

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

@@ -20,6 +21,8 @@ export interface Props {
2021
}
2122

2223
const CliSearchFilter = ({ submitFilter, isLoading }: Props) => {
24+
const { commandGroups = [] } = useSelector(appRedisCommandsSelector)
25+
2326
const [isSelectOpen, setIsSelectOpen] = useState<boolean>(false)
2427
const [typeSelected, setTypeSelected] = useState<string>('')
2528

@@ -35,17 +38,22 @@ const CliSearchFilter = ({ submitFilter, isLoading }: Props) => {
3538
setTypeSelected('')
3639
}, [matchedCommand])
3740

38-
const options: EuiSuperSelectOption<string>[] = FILTER_GROUP_TYPE_OPTIONS.map(
41+
const groupOptions = [...commandGroups].sort().map((group: string) => ({
42+
text: (GROUP_TYPES_DISPLAY as any)[group] || group.replace(/_/g, ' '),
43+
value: group
44+
}))
45+
46+
const options: EuiSuperSelectOption<string>[] = groupOptions.map(
3947
(item) => {
4048
const { value, text } = item
4149
return {
4250
value,
4351
inputDisplay: (
44-
<EuiText className={styles.selectedType} size="s">
52+
<EuiText className={cx(styles.selectedType, 'text-capitalize')} size="s">
4553
{text}
4654
</EuiText>
4755
),
48-
dropdownDisplay: <EuiText>{text}</EuiText>,
56+
dropdownDisplay: <EuiText className="text-capitalize">{text}</EuiText>,
4957
'data-test-subj': `filter-option-group-type-${value}`,
5058
}
5159
}

redisinsight/ui/src/components/cli/components/cli-search/CliSearchFilter/constants.ts

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

redisinsight/ui/src/components/group-badge/GroupBadge.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EuiBadge, EuiText } from '@elastic/eui'
33
import { CommandGroup, KeyTypes, GROUP_TYPES_COLORS, GROUP_TYPES_DISPLAY } from 'uiSrc/constants'
44

55
export interface Props {
6-
type: KeyTypes | CommandGroup;
6+
type: KeyTypes | CommandGroup | string;
77
name?: string,
88
className?: string
99
}
@@ -15,7 +15,7 @@ const GroupBadge = ({ type, name = '', className = '' }: Props) => (
1515
data-testid={`badge-${type} ${name}`}
1616
>
1717
<EuiText style={{ color: 'var(--euiTextSubduedColorHover)' }} className="text-uppercase" size="xs">
18-
{GROUP_TYPES_DISPLAY[type] ?? type}
18+
{(GROUP_TYPES_DISPLAY as any)[type] ?? type.replace(/_/g, ' ')}
1919
</EuiText>
2020
</EuiBadge>
2121
)

redisinsight/ui/src/constants/keys.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const GROUP_TYPES_DISPLAY = Object.freeze({
2020
[KeyTypes.Hash]: 'Hash',
2121
[KeyTypes.List]: 'List',
2222
[KeyTypes.Set]: 'Set',
23-
[KeyTypes.ZSet]: 'Zset',
23+
[KeyTypes.ZSet]: 'Sorted Set',
2424
[KeyTypes.String]: 'String',
2525
[KeyTypes.ReJSON]: 'JSON',
2626
[KeyTypes.JSON]: 'JSON',
@@ -32,11 +32,12 @@ export const GROUP_TYPES_DISPLAY = Object.freeze({
3232
[CommandGroup.Connection]: 'Connection',
3333
[CommandGroup.Geo]: 'Geo',
3434
[CommandGroup.Generic]: 'Generic',
35-
[CommandGroup.PubSub]: 'PubSub',
35+
[CommandGroup.PubSub]: 'Pub/Sub',
3636
[CommandGroup.Scripting]: 'Scripting',
3737
[CommandGroup.Transactions]: 'Transactions',
38+
[CommandGroup.TimeSeries]: 'TimeSeries',
3839
[CommandGroup.Server]: 'Server',
39-
[CommandGroup.SortedSet]: 'ZSet',
40+
[CommandGroup.SortedSet]: 'Sorted Set',
4041
[CommandGroup.HyperLogLog]: 'HyperLogLog',
4142
})
4243

redisinsight/ui/src/pages/browser/components/add-key/constants/key-type-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const ADD_KEY_TYPE_OPTIONS = [
77
color: GROUP_TYPES_COLORS[KeyTypes.Hash],
88
},
99
{
10-
text: 'Zset',
10+
text: 'Sorted Set',
1111
value: KeyTypes.ZSet,
1212
color: GROUP_TYPES_COLORS[KeyTypes.ZSet],
1313
},

redisinsight/ui/src/pages/browser/components/filter-key-type/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const FILTER_KEY_TYPE_OPTIONS = [
1111
color: GROUP_TYPES_COLORS[KeyTypes.Hash],
1212
},
1313
{
14-
text: 'Zset',
14+
text: 'Sorted Set',
1515
value: KeyTypes.ZSet,
1616
color: GROUP_TYPES_COLORS[KeyTypes.ZSet],
1717
},

redisinsight/ui/src/slices/app/redis-commands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createSlice } from '@reduxjs/toolkit'
2+
import { uniqBy } from 'lodash'
23
import { apiService } from 'uiSrc/services'
3-
import { ApiEndpoints } from 'uiSrc/constants'
4+
import { ApiEndpoints, ICommand, ICommands } from 'uiSrc/constants'
45
import { getApiErrorMessage, isStatusSuccessful } from 'uiSrc/utils'
56
import { GetServerInfoResponse } from 'apiSrc/dto/server.dto'
67

@@ -11,7 +12,8 @@ export const initialState: StateAppRedisCommands = {
1112
loading: false,
1213
error: '',
1314
spec: {},
14-
commandsArray: []
15+
commandsArray: [],
16+
commandGroups: [],
1517
}
1618

1719
// A slice for recipes
@@ -22,10 +24,12 @@ const appRedisCommandsSlice = createSlice({
2224
getRedisCommands: (state) => {
2325
state.loading = true
2426
},
25-
getRedisCommandsSuccess: (state, { payload }) => {
27+
getRedisCommandsSuccess: (state, { payload }: { payload: ICommands }) => {
2628
state.loading = false
2729
state.spec = payload
2830
state.commandsArray = Object.keys(state.spec).sort()
31+
state.commandGroups = uniqBy(Object.values(payload), 'group')
32+
.map((item: ICommand) => item.group)
2933
},
3034
getRedisCommandsFailure: (state, { payload }) => {
3135
state.loading = false

redisinsight/ui/src/slices/interfaces/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export interface StateAppContext {
6060
export interface StateAppRedisCommands {
6161
loading: boolean;
6262
error: string;
63-
spec: ICommands,
64-
commandsArray: string[],
63+
spec: ICommands;
64+
commandsArray: string[];
65+
commandGroups: string[];
6566
}
6667

6768
export interface IPluginVisualization {

redisinsight/ui/src/slices/tests/app/redis-commands.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { cloneDeep } from 'lodash'
1+
import { cloneDeep, uniqBy } from 'lodash'
22
import { cleanup, initialStateDefault, mockedStore, } from 'uiSrc/utils/test-utils'
33
import { apiService } from 'uiSrc/services'
4-
import { MOCK_COMMANDS_SPEC } from 'uiSrc/constants'
4+
import { ICommand, MOCK_COMMANDS_SPEC } from 'uiSrc/constants'
55
import reducer, {
66
initialState,
77
getRedisCommands,
@@ -60,7 +60,9 @@ describe('slices', () => {
6060
const state = {
6161
...initialState,
6262
spec: data,
63-
commandsArray: Object.keys(data).sort()
63+
commandsArray: Object.keys(data).sort(),
64+
commandGroups: uniqBy(Object.values(data), 'group')
65+
.map((item: ICommand) => item.group)
6466
}
6567

6668
// Act

0 commit comments

Comments
 (0)