Skip to content

Commit d7aa532

Browse files
committed
#RI-3377 - fix pr comments
1 parent 4330a91 commit d7aa532

File tree

10 files changed

+152
-23
lines changed

10 files changed

+152
-23
lines changed

redisinsight/ui/src/components/main-router/constants/defaultRoutes.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ import WorkbenchPage from 'uiSrc/pages/workbench'
1313
import SlowLogPage from 'uiSrc/pages/slowLog'
1414
import PubSubPage from 'uiSrc/pages/pubSub'
1515
import ClusterDetailsPage from 'uiSrc/pages/clusterDetails'
16+
import AnalyticsPage from 'uiSrc/pages/analytics'
1617

1718
import COMMON_ROUTES from './commonRoutes'
1819

20+
export const ANALYTICS_ROUTES: IRoute[] = [
21+
{
22+
pageName: PageNames.slowLog,
23+
path: Pages.slowLog(':instanceId'),
24+
component: SlowLogPage,
25+
},
26+
{
27+
pageName: PageNames.clusterDetails,
28+
path: Pages.clusterDetails(':instanceId'),
29+
component: ClusterDetailsPage,
30+
},
31+
]
32+
1933
const INSTANCE_ROUTES: IRoute[] = [
2034
{
2135
pageName: PageNames.browser,
@@ -27,21 +41,16 @@ const INSTANCE_ROUTES: IRoute[] = [
2741
path: Pages.workbench(':instanceId'),
2842
component: WorkbenchPage,
2943
},
30-
{
31-
pageName: PageNames.slowLog,
32-
path: Pages.slowLog(':instanceId'),
33-
component: SlowLogPage,
34-
},
35-
{
36-
pageName: PageNames.clusterDetails,
37-
path: Pages.clusterDetails(':instanceId'),
38-
component: ClusterDetailsPage,
39-
},
4044
{
4145
pageName: PageNames.pubSub,
4246
path: Pages.pubSub(':instanceId'),
4347
component: PubSubPage,
4448
},
49+
{
50+
path: Pages.analytics(':instanceId'),
51+
component: AnalyticsPage,
52+
routes: ANALYTICS_ROUTES,
53+
},
4554
]
4655

4756
const ROUTES: IRoute[] = [

redisinsight/ui/src/components/main-router/constants/redisStackRoutes.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,25 @@ import WorkbenchPage from 'uiSrc/pages/workbench'
66
import SlowLogPage from 'uiSrc/pages/slowLog'
77
import PubSubPage from 'uiSrc/pages/pubSub'
88
import EditConnection from 'uiSrc/pages/redisStack/components/edit-connection'
9+
import ClusterDetailsPage from 'uiSrc/pages/clusterDetails'
10+
import AnalyticsPage from 'uiSrc/pages/analytics'
911
import COMMON_ROUTES from './commonRoutes'
1012

13+
const ANALYTICS_ROUTES: IRoute[] = [
14+
{
15+
pageName: PageNames.slowLog,
16+
protected: true,
17+
path: Pages.slowLog(':instanceId'),
18+
component: SlowLogPage,
19+
},
20+
{
21+
pageName: PageNames.clusterDetails,
22+
protected: true,
23+
path: Pages.clusterDetails(':instanceId'),
24+
component: ClusterDetailsPage,
25+
},
26+
]
27+
1128
const INSTANCE_ROUTES: IRoute[] = [
1229
{
1330
pageName: PageNames.browser,
@@ -21,18 +38,18 @@ const INSTANCE_ROUTES: IRoute[] = [
2138
path: Pages.workbench(':instanceId'),
2239
component: WorkbenchPage,
2340
},
24-
{
25-
pageName: PageNames.slowLog,
26-
protected: true,
27-
path: Pages.slowLog(':instanceId'),
28-
component: SlowLogPage,
29-
},
3041
{
3142
pageName: PageNames.pubSub,
3243
protected: true,
3344
path: Pages.pubSub(':instanceId'),
3445
component: PubSubPage,
3546
},
47+
{
48+
path: Pages.analytics(':instanceId'),
49+
protected: true,
50+
component: AnalyticsPage,
51+
routes: ANALYTICS_ROUTES,
52+
},
3653
]
3754

3855
const ROUTES: IRoute[] = [

redisinsight/ui/src/components/navigation-menu/NavigationMenu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ import { ConnectionType } from 'uiSrc/slices/interfaces'
4646

4747
import NotificationMenu from './components/notifications-center'
4848

49+
import { ANALYTICS_ROUTES } from '../main-router/constants/defaultRoutes'
4950
import styles from './styles.module.scss'
5051

5152
const workbenchPath = `/${PageNames.workbench}`
5253
const browserPath = `/${PageNames.browser}`
53-
const slowLogPath = `/${PageNames.slowLog}`
54-
const clusterDetailsPath = `/${PageNames.clusterDetails}`
5554
const pubSubPath = `/${PageNames.pubSub}`
5655

5756
interface INavigations {
@@ -88,7 +87,9 @@ const NavigationMenu = () => {
8887
dispatch(setShortcutsFlyoutState(true))
8988
}
9089

91-
const isAnalyticsPath = (path: string) => path === slowLogPath || path === clusterDetailsPath
90+
const isAnalyticsPath = (activePage: string) => !!ANALYTICS_ROUTES.find(
91+
({ path }) => (`/${last(path.split('/'))}` === activePage)
92+
)
9293

9394
const privateRoutes: INavigations[] = [
9495
{

redisinsight/ui/src/constants/keys.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,5 @@ export enum KeyValueFormat {
172172
Msgpack = 'Msgpack',
173173
PHP = 'PHP Unserialize',
174174
JAVA = 'Java Object',
175-
Protobuf = 'Protobuf',
176-
Pickle = 'Pickle',
175+
Protobuf = 'Protobuf'
177176
}

redisinsight/ui/src/constants/pages.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum PageNames {
1515
browser = 'browser',
1616
slowLog = 'slowlog',
1717
pubSub = 'pub-sub',
18+
analytics = 'analytics',
1819
clusterDetails = 'cluster-details',
1920
}
2021

@@ -35,7 +36,8 @@ export const Pages = {
3536
sentinelDatabasesResult: `${sentinel}/databases-result`,
3637
browser: (instanceId: string) => `/${instanceId}/${PageNames.browser}`,
3738
workbench: (instanceId: string) => `/${instanceId}/${PageNames.workbench}`,
38-
slowLog: (instanceId: string) => `/${instanceId}/${PageNames.slowLog}`,
3939
pubSub: (instanceId: string) => `/${instanceId}/${PageNames.pubSub}`,
40-
clusterDetails: (instanceId: string) => `/${instanceId}/${PageNames.clusterDetails}`,
40+
analytics: (instanceId: string) => `/${instanceId}/${PageNames.analytics}`,
41+
slowLog: (instanceId: string) => `/${instanceId}/${PageNames.analytics}/${PageNames.slowLog}`,
42+
clusterDetails: (instanceId: string) => `/${instanceId}/${PageNames.analytics}/${PageNames.clusterDetails}`,
4143
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { cloneDeep } from 'lodash'
2+
import React from 'react'
3+
import { BrowserRouter } from 'react-router-dom'
4+
import { instance, mock } from 'ts-mockito'
5+
6+
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
7+
import AnalyticsPage, { Props } from './AnalyticsPage'
8+
9+
const mockedProps = mock<Props>()
10+
11+
let store: typeof mockedStore
12+
beforeEach(() => {
13+
cleanup()
14+
store = cloneDeep(mockedStore)
15+
store.clearActions()
16+
})
17+
18+
describe('AnalyticsPage', () => {
19+
it('should render', () => {
20+
expect(
21+
render(
22+
<BrowserRouter>
23+
<AnalyticsPage {...instance(mockedProps)} />
24+
</BrowserRouter>
25+
)
26+
).toBeTruthy()
27+
})
28+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { useEffect } from 'react'
2+
import { useSelector } from 'react-redux'
3+
import { useHistory, useParams, useLocation } from 'react-router-dom'
4+
import { Pages } from 'uiSrc/constants'
5+
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
6+
import { ConnectionType } from 'uiSrc/slices/interfaces'
7+
8+
import AnalyticsPageRouter from './AnalyticsPageRouter'
9+
10+
export interface Props {
11+
routes: any[];
12+
}
13+
14+
const AnalyticsPage = ({ routes = [] }: Props) => {
15+
const history = useHistory()
16+
const { instanceId } = useParams<{ instanceId: string }>()
17+
const { pathname } = useLocation()
18+
const { connectionType } = useSelector(connectedInstanceSelector)
19+
20+
useEffect(() => {
21+
if (pathname === Pages.analytics(instanceId)) {
22+
history.push(connectionType === ConnectionType.Cluster
23+
? Pages.clusterDetails(instanceId)
24+
: Pages.slowLog(instanceId))
25+
}
26+
}, [connectionType, instanceId, pathname])
27+
28+
return (
29+
<AnalyticsPageRouter routes={routes} />
30+
)
31+
}
32+
33+
export default AnalyticsPage
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import { render } from 'uiSrc/utils/test-utils'
3+
import AnalyticsPageRouter from './AnalyticsPageRouter'
4+
5+
const mockedRoutes = [
6+
{
7+
path: '/slowlog',
8+
},
9+
]
10+
11+
describe('AnalyticsPageRouter', () => {
12+
it('should render', () => {
13+
expect(
14+
render(<AnalyticsPageRouter routes={mockedRoutes} />, { withRouter: true })
15+
).toBeTruthy()
16+
})
17+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
import { Switch } from 'react-router-dom'
3+
import RouteWithSubRoutes from 'uiSrc/utils/routerWithSubRoutes'
4+
5+
export interface Props {
6+
routes: any[];
7+
}
8+
const InstancePageRouter = ({ routes }: Props) => (
9+
<Switch>
10+
{routes.map((route, i) => (
11+
// eslint-disable-next-line react/no-array-index-key
12+
<RouteWithSubRoutes key={i} {...route} />
13+
))}
14+
</Switch>
15+
)
16+
17+
export default React.memo(InstancePageRouter)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import AnalyticsPage from './AnalyticsPage'
2+
import AnalyticsPageRouter from './AnalyticsPageRouter'
3+
4+
export { AnalyticsPage, AnalyticsPageRouter }
5+
6+
export default AnalyticsPage

0 commit comments

Comments
 (0)