Skip to content

Commit c6586d2

Browse files
Merge pull request #1098 from RedisInsight/feature/RI-3377_Display_cluster_overview
Feature/ri 3377 display cluster overview
2 parents a6e5041 + 84f2a1c commit c6586d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1251
-92
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react'
2+
import reactRouterDom from 'react-router-dom'
3+
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
4+
import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils'
5+
import AnalyticsTabs from './AnalyticsTabs'
6+
7+
jest.mock('react-router-dom', () => ({
8+
...jest.requireActual('react-router-dom'),
9+
useHistory: () => ({
10+
push: jest.fn,
11+
}),
12+
}))
13+
14+
describe('StreamTabs', () => {
15+
it('should render', () => {
16+
expect(render(<AnalyticsTabs />)).toBeTruthy()
17+
})
18+
19+
it('click on clusterDetails tab should call History push with /cluster-details path ', async () => {
20+
const pushMock = jest.fn()
21+
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
22+
23+
render(<AnalyticsTabs />)
24+
25+
await act(() => {
26+
fireEvent.click(screen.getByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`))
27+
})
28+
29+
expect(pushMock).toHaveBeenCalledTimes(1)
30+
expect(pushMock).toHaveBeenCalledWith('/instanceId/cluster-details')
31+
})
32+
it('click on SlowLog tab should call History push with /slowlog path ', async () => {
33+
const pushMock = jest.fn()
34+
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
35+
36+
render(<AnalyticsTabs />)
37+
38+
await act(() => {
39+
fireEvent.click(screen.getByTestId(`analytics-tab-${AnalyticsViewTab.SlowLog}`))
40+
})
41+
42+
expect(pushMock).toHaveBeenCalledTimes(1)
43+
expect(pushMock).toHaveBeenCalledWith('/instanceId/slowlog')
44+
})
45+
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, { useCallback } from 'react'
2+
import { EuiTab, EuiTabs } from '@elastic/eui'
3+
import { useDispatch, useSelector } from 'react-redux'
4+
import { useParams, useHistory } from 'react-router-dom'
5+
6+
import { Pages } from 'uiSrc/constants'
7+
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
8+
import { analyticsSettingsSelector, setAnalyticsViewTab } from 'uiSrc/slices/analytics/settings'
9+
10+
import { analyticsViewTabs } from './constants'
11+
12+
const AnalyticsTabs = () => {
13+
const { viewTab } = useSelector(analyticsSettingsSelector)
14+
const history = useHistory()
15+
16+
const { instanceId } = useParams<{ instanceId: string }>()
17+
18+
const dispatch = useDispatch()
19+
20+
const onSelectedTabChanged = (id: AnalyticsViewTab) => {
21+
if (id === AnalyticsViewTab.ClusterDetails) {
22+
history.push(Pages.clusterDetails(instanceId))
23+
}
24+
if (id === AnalyticsViewTab.SlowLog) {
25+
history.push(Pages.slowLog(instanceId))
26+
}
27+
dispatch(setAnalyticsViewTab(id))
28+
}
29+
30+
const renderTabs = useCallback(() =>
31+
[...analyticsViewTabs].map(({ id, label }) => (
32+
<EuiTab
33+
isSelected={viewTab === id}
34+
onClick={() => onSelectedTabChanged(id)}
35+
key={id}
36+
data-testid={`analytics-tab-${id}`}
37+
>
38+
{label}
39+
</EuiTab>
40+
)), [viewTab])
41+
42+
return (
43+
<>
44+
<EuiTabs className="tabs-active-borders" data-test-subj="analytics-tabs">{renderTabs()}</EuiTabs>
45+
</>
46+
)
47+
}
48+
49+
export default AnalyticsTabs
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
2+
3+
interface AnalyticsTabs {
4+
id: AnalyticsViewTab,
5+
label: string,
6+
}
7+
8+
export const analyticsViewTabs: AnalyticsTabs[] = [
9+
{
10+
id: AnalyticsViewTab.ClusterDetails,
11+
label: 'Overview',
12+
},
13+
{
14+
id: AnalyticsViewTab.SlowLog,
15+
label: 'Slow Log',
16+
},
17+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import AnalyticsTabs from './AnalyticsTabs'
2+
3+
export default AnalyticsTabs

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ import {
1212
import WorkbenchPage from 'uiSrc/pages/workbench'
1313
import SlowLogPage from 'uiSrc/pages/slowLog'
1414
import PubSubPage from 'uiSrc/pages/pubSub'
15+
import ClusterDetailsPage from 'uiSrc/pages/clusterDetails'
16+
import AnalyticsPage from 'uiSrc/pages/analytics'
1517

1618
import COMMON_ROUTES from './commonRoutes'
1719

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+
1833
const INSTANCE_ROUTES: IRoute[] = [
1934
{
2035
pageName: PageNames.browser,
@@ -26,16 +41,16 @@ const INSTANCE_ROUTES: IRoute[] = [
2641
path: Pages.workbench(':instanceId'),
2742
component: WorkbenchPage,
2843
},
29-
{
30-
pageName: PageNames.slowLog,
31-
path: Pages.slowLog(':instanceId'),
32-
component: SlowLogPage,
33-
},
3444
{
3545
pageName: PageNames.pubSub,
3646
path: Pages.pubSub(':instanceId'),
3747
component: PubSubPage,
3848
},
49+
{
50+
path: Pages.analytics(':instanceId'),
51+
component: AnalyticsPage,
52+
routes: ANALYTICS_ROUTES,
53+
},
3954
]
4055

4156
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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ import PubSubSVG from 'uiSrc/assets/img/sidebar/pubsub.svg'
4141
import PubSubActiveSVG from 'uiSrc/assets/img/sidebar/pubsub_active.svg'
4242
import GithubSVG from 'uiSrc/assets/img/sidebar/github.svg'
4343
import Divider from 'uiSrc/components/divider/Divider'
44-
4544
import { BuildType } from 'uiSrc/constants/env'
45+
import { ConnectionType } from 'uiSrc/slices/interfaces'
46+
4647
import NotificationMenu from './components/notifications-center'
4748

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

5052
const workbenchPath = `/${PageNames.workbench}`
5153
const browserPath = `/${PageNames.browser}`
52-
const slowLogPath = `/${PageNames.slowLog}`
5354
const pubSubPath = `/${PageNames.pubSub}`
5455

5556
interface INavigations {
@@ -71,7 +72,7 @@ const NavigationMenu = () => {
7172
const [activePage, setActivePage] = useState(Pages.home)
7273
const [isHelpMenuActive, setIsHelpMenuActive] = useState(false)
7374

74-
const { id: connectedInstanceId = '' } = useSelector(connectedInstanceSelector)
75+
const { id: connectedInstanceId = '', connectionType } = useSelector(connectedInstanceSelector)
7576
const { isReleaseNotesViewed } = useSelector(appElectronInfoSelector)
7677
const { server } = useSelector(appInfoSelector)
7778

@@ -86,6 +87,10 @@ const NavigationMenu = () => {
8687
dispatch(setShortcutsFlyoutState(true))
8788
}
8889

90+
const isAnalyticsPath = (activePage: string) => !!ANALYTICS_ROUTES.find(
91+
({ path }) => (`/${last(path.split('/'))}` === activePage)
92+
)
93+
8994
const privateRoutes: INavigations[] = [
9095
{
9196
tooltipText: 'Browser',
@@ -116,12 +121,14 @@ const NavigationMenu = () => {
116121
},
117122
},
118123
{
119-
tooltipText: 'Slow Log',
120-
ariaLabel: 'SlowLog page button',
121-
onClick: () => handleGoPage(Pages.slowLog(connectedInstanceId)),
122-
dataTestId: 'slowlog-page-btn',
124+
tooltipText: 'Analysis tools',
125+
ariaLabel: 'Analysis tools',
126+
onClick: () => handleGoPage(connectionType === ConnectionType.Cluster
127+
? Pages.clusterDetails(connectedInstanceId)
128+
: Pages.slowLog(connectedInstanceId)),
129+
dataTestId: 'analytics-page-btn',
123130
connectedInstanceId,
124-
isActivePage: activePage === slowLogPath,
131+
isActivePage: isAnalyticsPath(activePage),
125132
getClassName() {
126133
return cx(styles.navigationButton, { [styles.active]: this.isActivePage })
127134
},

redisinsight/ui/src/constants/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ enum ApiEndpoints {
7272

7373
PUB_SUB = 'pub-sub',
7474
PUB_SUB_MESSAGES = 'pub-sub/messages',
75+
CLUSTER_DETAILS = 'cluster-details',
7576

7677
NOTIFICATIONS = 'notifications',
7778
NOTIFICATIONS_READ = 'notifications/read',

redisinsight/ui/src/constants/pages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export enum PageNames {
1515
browser = 'browser',
1616
slowLog = 'slowlog',
1717
pubSub = 'pub-sub',
18+
analytics = 'analytics',
19+
clusterDetails = 'cluster-details',
1820
}
1921

2022
const redisCloud = '/redis-cloud'
@@ -34,6 +36,8 @@ export const Pages = {
3436
sentinelDatabasesResult: `${sentinel}/databases-result`,
3537
browser: (instanceId: string) => `/${instanceId}/${PageNames.browser}`,
3638
workbench: (instanceId: string) => `/${instanceId}/${PageNames.workbench}`,
37-
slowLog: (instanceId: string) => `/${instanceId}/${PageNames.slowLog}`,
3839
pubSub: (instanceId: string) => `/${instanceId}/${PageNames.pubSub}`,
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}`,
3943
}

0 commit comments

Comments
 (0)