Skip to content

Commit 6b215bd

Browse files
committed
RI-6371 move func to utils, made sort case insensitive
1 parent 9534a3c commit 6b215bd

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

redisinsight/ui/src/components/instance-header/components/instances-navigation-popover/InstancesNavigationPopover.tsx

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { EuiFieldText, EuiIcon, EuiPopover, EuiSpacer, EuiTab, EuiTabs, EuiText
33
import cx from 'classnames'
44
import { useSelector } from 'react-redux'
55
import { useHistory, useParams } from 'react-router-dom'
6-
import { orderBy } from 'lodash'
76
import { instancesSelector as rdiInstancesSelector } from 'uiSrc/slices/rdi/instances'
87
import { instancesSelector as dbInstancesSelector } from 'uiSrc/slices/instances/instances'
98
import Divider from 'uiSrc/components/divider/Divider'
@@ -12,8 +11,8 @@ import Down from 'uiSrc/assets/img/Down.svg?react'
1211
import Search from 'uiSrc/assets/img/Search.svg'
1312
import { Instance, RdiInstance } from 'uiSrc/slices/interfaces'
1413
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
15-
import { getDbIndex } from 'uiSrc/utils'
1614
import { localStorageService } from 'uiSrc/services'
15+
import { filterAndSort } from 'uiSrc/utils'
1716
import InstancesList from './components/instances-list'
1817
import styles from './styles.module.scss'
1918

@@ -40,35 +39,6 @@ const InstancesNavigationPopover = ({ name }: Props) => {
4039
const history = useHistory()
4140

4241
useEffect(() => {
43-
const filterAndSort = (
44-
arr: Instance[] | RdiInstance[],
45-
search: string,
46-
sort: { field: string, direction: 'asc' | 'desc' }
47-
): (Instance | RdiInstance
48-
)[] => {
49-
if (!arr?.length) return arr
50-
const filtered = arr.filter((instance) => {
51-
const label = `${instance.name} ${getDbIndex(instance.db)}`
52-
return label.toLowerCase?.().includes(search)
53-
})
54-
55-
const sortingFunc = (ins) => {
56-
if (sort.field === 'lastConnection') {
57-
return ins.lastConnection ? -new Date(`${ins.lastConnection}`) : -Infinity
58-
}
59-
if (sort.field === 'host') {
60-
return `${ins.host}:${ins.port}`
61-
}
62-
return sort.field
63-
}
64-
65-
return orderBy(
66-
filtered,
67-
sortingFunc,
68-
sort.direction
69-
)
70-
}
71-
7242
const dbSort = localStorageService.get(BrowserStorageItem.instancesSorting) ?? {
7343
field: 'lastConnection',
7444
direction: 'asc'

redisinsight/ui/src/utils/instance/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import getUrl from './getUrlInstance'
22

33
export * from './instanceModules'
44
export * from './instanceOptions'
5+
export * from './instanceNavigation'
56

67
export {
78
getUrl
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { orderBy } from 'lodash'
2+
import { Instance, RdiInstance } from 'uiSrc/slices/interfaces'
3+
import { getDbIndex } from '../longNames'
4+
5+
export const filterAndSort = (
6+
arr: Instance[] | RdiInstance[],
7+
search: string,
8+
sort: { field: string, direction: 'asc' | 'desc' }
9+
): (Instance | RdiInstance
10+
)[] => {
11+
if (!arr?.length) return arr
12+
const filtered = arr.filter((instance) => {
13+
const label = `${instance.name} ${getDbIndex(instance.db)}`
14+
return label.toLowerCase?.().includes(search.toLowerCase())
15+
})
16+
17+
const sortingFunc = (ins) => {
18+
if (sort.field === 'lastConnection') {
19+
return ins.lastConnection ? -new Date(`${ins.lastConnection}`) : -Infinity
20+
}
21+
if (sort.field === 'host') {
22+
return `${ins.host}:${ins.port}`
23+
}
24+
return sort.field
25+
}
26+
27+
return orderBy(
28+
filtered,
29+
sortingFunc,
30+
sort.direction
31+
)
32+
}

0 commit comments

Comments
 (0)