Skip to content

Commit 48420ba

Browse files
committed
#RI-6300 - Multiple delimiters in Tree view
1 parent a467516 commit 48420ba

File tree

12 files changed

+44
-28
lines changed

12 files changed

+44
-28
lines changed

redisinsight/ui/src/constants/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EuiComboBoxOptionOption } from '@elastic/eui'
22
import { KeyValueFormat, SortOrder } from './keys'
33

4-
export const DEFAULT_DELIMITER: EuiComboBoxOptionOption[] = [{ label: ':' }]
4+
export const DEFAULT_DELIMITER: EuiComboBoxOptionOption = { label: ':' }
55
export const DEFAULT_TREE_SORTING = SortOrder.ASC
66
export const DEFAULT_SHOW_HIDDEN_RECOMMENDATIONS = false
77

redisinsight/ui/src/helpers/constructKeysToTree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import { IKeyPropTypes } from 'uiSrc/constants/prop-types/keys'
33

44
interface Props {
55
items: IKeyPropTypes[]
6-
delimiter?: string
6+
delimiterPattern?: string
77
sorting?: SortOrder
88
}
99

1010
export const constructKeysToTree = (props: Props): any[] => {
11-
const { items: keys, delimiter = ':', sorting = 'ASC' } = props
12-
const keysSymbol = `keys${delimiter}keys`
11+
const { items: keys, delimiterPattern = ':', sorting = 'ASC' } = props
12+
const keysSymbol = `keys${delimiterPattern}keys`
1313
const tree: any = {}
1414

1515
keys.forEach((key: any) => {
1616
// eslint-disable-next-line prefer-object-spread
1717
let currentNode: any = tree
1818
const { nameString: name = '' } = key
19-
const nameSplitted = name.split(new RegExp(delimiter, 'g'))
19+
const nameSplitted = name.split(new RegExp(delimiterPattern, 'g'))
2020
const lastIndex = nameSplitted.length - 1
2121

2222
nameSplitted.forEach((value:any, index: number) => {
@@ -106,5 +106,5 @@ export const constructKeysToTree = (props: Props): any[] => {
106106
})
107107
}
108108

109-
return formatTreeData(tree, '', delimiter)
109+
return formatTreeData(tree, '', delimiterPattern)
110110
}

redisinsight/ui/src/helpers/tests/constructKeysToTree.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const constructKeysToTreeTests: any[] = [
1515
{ nameString: 'keys:2', type: 'hash', ttl: -1, size: 71 },
1616
{ nameString: 'keys_2', type: 'hash', ttl: -1, size: 71 },
1717
],
18-
delimiter: delimiterMock
18+
delimiterPattern: delimiterMock
1919
},
2020
constructKeysToTreeMockResult
2121
]

redisinsight/ui/src/pages/browser/components/key-tree/KeyTree.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const KeyTree = forwardRef((props: Props, ref) => {
6969
const [items, setItems] = useState<IKeyPropTypes[]>(parseKeyNames(keysState.keys ?? []))
7070

7171
// escape regexp symbols and join and transform to regexp
72-
const delimiter = comboBoxToArray(treeViewDelimiter)
72+
const delimiterPattern = comboBoxToArray(treeViewDelimiter)
7373
.map(escapeRegExp)
7474
.join('|')
7575

@@ -92,8 +92,8 @@ const KeyTree = forwardRef((props: Props, ref) => {
9292
// open all parents for selected key
9393
const openSelectedKey = (selectedKeyName: Nullable<string> = '') => {
9494
if (selectedKeyName) {
95-
const parts = selectedKeyName.split(delimiter)
96-
const parents = parts.map((_, index) => parts.slice(0, index + 1).join(delimiter) + delimiter)
95+
const parts = selectedKeyName.split(delimiterPattern)
96+
const parents = parts.map((_, index) => parts.slice(0, index + 1).join(delimiterPattern) + delimiterPattern)
9797

9898
// remove key name from parents
9999
parents.pop()
@@ -116,7 +116,7 @@ const KeyTree = forwardRef((props: Props, ref) => {
116116
}
117117

118118
setItems(parseKeyNames(keysState.keys))
119-
}, [keysState.lastRefreshTime, delimiter, sorting])
119+
}, [keysState.lastRefreshTime, delimiterPattern, sorting])
120120

121121
useEffect(() => {
122122
openSelectedKey(selectedKeyName)
@@ -194,7 +194,7 @@ const KeyTree = forwardRef((props: Props, ref) => {
194194
<VirtualTree
195195
items={items}
196196
loadingIcon={TreeViewSVG}
197-
delimiter={delimiter}
197+
delimiterPattern={delimiterPattern}
198198
sorting={sorting}
199199
deleting={deleting}
200200
statusSelected={selectedKeyName}

redisinsight/ui/src/pages/browser/components/key-tree/KeyTreeSettings/KeyTreeSettings.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ let store: typeof mockedStore
2424
const APPLY_BTN = 'tree-view-apply-btn'
2525
const TREE_SETTINGS_TRIGGER_BTN = 'tree-view-settings-btn'
2626
const SORTING_SELECT = 'tree-view-sorting-select'
27-
const DELIMITER_INPUT = 'tree-view-delimiter-input'
2827
const SORTING_DESC_ITEM = 'tree-view-sorting-item-DESC'
2928

3029
beforeEach(() => {
@@ -130,7 +129,7 @@ describe('KeyTreeDelimiter', () => {
130129
event: TelemetryEvent.TREE_VIEW_DELIMITER_CHANGED,
131130
eventData: {
132131
databaseId: INSTANCE_ID_MOCK,
133-
from: comboBoxToArray(DEFAULT_DELIMITER),
132+
from: comboBoxToArray([DEFAULT_DELIMITER]),
134133
to: [value],
135134
}
136135
})
@@ -164,7 +163,7 @@ describe('KeyTreeDelimiter', () => {
164163
})
165164

166165
const expectedActions = [
167-
setBrowserTreeDelimiter(DEFAULT_DELIMITER),
166+
setBrowserTreeDelimiter([DEFAULT_DELIMITER]),
168167
resetBrowserTree(),
169168
]
170169

redisinsight/ui/src/pages/browser/components/key-tree/KeyTreeSettings/KeyTreeSettings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const sortOptions = [SortOrder.ASC, SortOrder.DESC].map((value) => ({
4242
const KeyTreeSettings = ({ loading }: Props) => {
4343
const { instanceId = '' } = useParams<{ instanceId: string }>()
4444
const {
45-
treeViewDelimiter = DEFAULT_DELIMITER,
45+
treeViewDelimiter = [DEFAULT_DELIMITER],
4646
treeViewSort = DEFAULT_TREE_SORTING,
4747
} = useSelector(appContextDbConfig)
4848
const [sorting, setSorting] = useState<SortOrder>(treeViewSort)
@@ -86,7 +86,7 @@ const KeyTreeSettings = ({ loading }: Props) => {
8686

8787
const handleApply = () => {
8888
if (!isEqual(delimiters, treeViewDelimiter)) {
89-
const delimitersValue = delimiters.length ? delimiters : DEFAULT_DELIMITER
89+
const delimitersValue = delimiters.length ? delimiters : [DEFAULT_DELIMITER]
9090

9191
dispatch(setBrowserTreeDelimiter(delimitersValue))
9292
sendEventTelemetry({

redisinsight/ui/src/pages/browser/components/virtual-tree/VirtualTree.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import styles from './styles.module.scss'
2727

2828
export interface Props {
2929
items: IKeyPropTypes[]
30-
delimiter: string
30+
delimiterPattern: string
3131
loadingIcon?: string
3232
loading: boolean
3333
deleting: boolean
@@ -52,7 +52,7 @@ export const KEYS = 'keys'
5252
const VirtualTree = (props: Props) => {
5353
const {
5454
items,
55-
delimiter,
55+
delimiterPattern,
5656
loadingIcon = 'empty',
5757
statusOpen = {},
5858
statusSelected,
@@ -103,13 +103,13 @@ const VirtualTree = (props: Props) => {
103103
nodes.current = []
104104
elements.current = {}
105105
rerender({})
106-
runWebworker?.({ items: [], delimiter, sorting })
106+
runWebworker?.({ items: [], delimiterPattern, sorting })
107107
return
108108
}
109109

110110
setConstructingTree(true)
111-
runWebworker?.({ items, delimiter, sorting })
112-
}, [items, delimiter])
111+
runWebworker?.({ items, delimiterPattern, sorting })
112+
}, [items, delimiterPattern])
113113

114114
const handleUpdateSelected = useCallback((name: RedisString) => {
115115
onStatusSelected?.(name)
@@ -190,7 +190,7 @@ const VirtualTree = (props: Props) => {
190190
size: node.size,
191191
type: node.type,
192192
fullName: node.fullName,
193-
shortName: node.nameString?.split(new RegExp(delimiter, 'g')).pop(),
193+
shortName: node.nameString?.split(new RegExp(delimiterPattern, 'g')).pop(),
194194
nestingLevel,
195195
deleting,
196196
path: node.path,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const initialState: StateAppContext = {
3838
contextRdiInstanceId: '',
3939
lastPage: '',
4040
dbConfig: {
41-
treeViewDelimiter: DEFAULT_DELIMITER,
41+
treeViewDelimiter: [DEFAULT_DELIMITER],
4242
treeViewSort: DEFAULT_TREE_SORTING,
4343
slowLogDurationUnit: DEFAULT_SLOWLOG_DURATION_UNIT,
4444
showHiddenRecommendations: DEFAULT_SHOW_HIDDEN_RECOMMENDATIONS,
@@ -127,7 +127,7 @@ const appContextSlice = createSlice({
127127
state.workspace = payload || AppWorkspace.Databases
128128
},
129129
setDbConfig: (state, { payload }) => {
130-
state.dbConfig.treeViewDelimiter = payload?.treeViewDelimiter ?? DEFAULT_DELIMITER
130+
state.dbConfig.treeViewDelimiter = payload?.treeViewDelimiter ?? [DEFAULT_DELIMITER]
131131
state.dbConfig.treeViewSort = payload?.treeViewSort ?? DEFAULT_TREE_SORTING
132132
state.dbConfig.slowLogDurationUnit = payload?.slowLogDurationUnit ?? DEFAULT_SLOWLOG_DURATION_UNIT
133133
state.dbConfig.showHiddenRecommendations = payload?.showHiddenRecommendations

redisinsight/ui/src/utils/common.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EuiComboBoxOptionOption } from '@elastic/eui'
21
import { IpcInvokeEvent } from 'uiSrc/electron/constants'
32

43
const baseApiUrl = process.env.RI_BASE_API_URL
@@ -51,5 +50,3 @@ export const openNewWindowDatabase = (location: string) => {
5150
{ location },
5251
)
5352
}
54-
55-
export const comboBoxToArray = (items: EuiComboBoxOptionOption[]) => [...items].map(({ label }) => label)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { comboBoxToArray } from 'uiSrc/utils'
2+
3+
const getOutputForFormatToTextTests: any[] = [
4+
[[], []],
5+
[[{ label: '123' }, { label: 'test' }], ['123', 'test']],
6+
[[{ label1: '123' }], []],
7+
[[{ label: '123' }, { label: 'test' }], ['123', 'test']],
8+
]
9+
10+
describe('formatToText', () => {
11+
it.each(getOutputForFormatToTextTests)('for input: %s (reply), should be output: %s',
12+
(reply, expected) => {
13+
const result = comboBoxToArray(reply)
14+
expect(result).toEqual(expected)
15+
})
16+
})

0 commit comments

Comments
 (0)