Skip to content

Commit 384bdff

Browse files
authored
[RI-7069]: Replace EuiTabs with Tabs (#4625)
* RI-7069: use Tabs for HomeTabs * RI-7069: use Tabs for InstancesNavigationPopover * fix unit tests * use Tabs for InsightsPanel * Tabs for DatabaseAnalysis * fix tests * Tabs for AnalyticsTabs * Tabs for ChatsWrapper * Tabs for BulkActionsTabs * Tabs for Panel * Tabs for StreamTabs * Tabs for ManualConnectionForm * drop euiTab styles * temp: skip manual connection tests * fix failing tests * update tests * cleanup tests * update import path * update test selector
1 parent bf3ddfe commit 384bdff

File tree

42 files changed

+445
-1047
lines changed

Some content is hidden

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

42 files changed

+445
-1047
lines changed

redisinsight/ui/src/components/analytics-tabs/AnalyticsTabs.spec.tsx

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react'
22
import reactRouterDom from 'react-router-dom'
3-
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
43
import { ConnectionType } from 'uiSrc/slices/interfaces'
5-
import { act, fireEvent, render, screen } from 'uiSrc/utils/test-utils'
4+
import { fireEvent, render, screen } from 'uiSrc/utils/test-utils'
65
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
76
import AnalyticsTabs from './AnalyticsTabs'
87

@@ -32,13 +31,7 @@ describe('AnalyticsTabs', () => {
3231

3332
render(<AnalyticsTabs />)
3433

35-
await act(() => {
36-
fireEvent.click(
37-
screen.getByTestId(
38-
`analytics-tab-${AnalyticsViewTab.DatabaseAnalysis}`,
39-
),
40-
)
41-
})
34+
fireEvent.mouseDown(screen.getByText('Database Analysis'))
4235

4336
expect(pushMock).toHaveBeenCalledTimes(1)
4437
expect(pushMock).toHaveBeenCalledWith(
@@ -51,11 +44,7 @@ describe('AnalyticsTabs', () => {
5144

5245
render(<AnalyticsTabs />)
5346

54-
await act(() => {
55-
fireEvent.click(
56-
screen.getByTestId(`analytics-tab-${AnalyticsViewTab.SlowLog}`),
57-
)
58-
})
47+
fireEvent.mouseDown(screen.getByText('Slow Log'))
5948

6049
expect(pushMock).toHaveBeenCalledTimes(1)
6150
expect(pushMock).toHaveBeenCalledWith('/instanceId/analytics/slowlog')
@@ -69,20 +58,16 @@ describe('AnalyticsTabs', () => {
6958

7059
render(<AnalyticsTabs />)
7160

72-
expect(
73-
screen.getByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`),
74-
).toBeInTheDocument()
61+
expect(screen.getByText('Overview')).toBeInTheDocument()
7562
})
7663

7764
it('should not render cluster details tab when connectionType is not Cluster', async () => {
78-
const { queryByTestId } = render(<AnalyticsTabs />)
65+
const { queryByText } = render(<AnalyticsTabs />)
7966

80-
expect(
81-
queryByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`),
82-
).not.toBeInTheDocument()
67+
expect(queryByText('Overview')).not.toBeInTheDocument()
8368
})
8469

85-
it('should call History push with /cluster-details path when click on ClusterDetails tab ', async () => {
70+
it('should call History push with /cluster-details path when click on SlowLog tab ', async () => {
8671
const mockConnectionType = ConnectionType.Cluster
8772
;(connectedInstanceSelector as jest.Mock).mockReturnValueOnce({
8873
connectionType: mockConnectionType,
@@ -92,15 +77,9 @@ describe('AnalyticsTabs', () => {
9277

9378
render(<AnalyticsTabs />)
9479

95-
await act(() => {
96-
fireEvent.click(
97-
screen.getByTestId(`analytics-tab-${AnalyticsViewTab.ClusterDetails}`),
98-
)
99-
})
80+
fireEvent.mouseDown(screen.getByText('Slow Log'))
10081

10182
expect(pushMock).toHaveBeenCalledTimes(1)
102-
expect(pushMock).toHaveBeenCalledWith(
103-
'/instanceId/analytics/cluster-details',
104-
)
83+
expect(pushMock).toHaveBeenCalledWith('/instanceId/analytics/slowlog')
10584
})
10685
})

redisinsight/ui/src/components/analytics-tabs/AnalyticsTabs.tsx

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { useCallback, useEffect } from 'react'
2-
import { EuiTab, EuiTabs } from '@elastic/eui'
1+
import React, { useEffect, useMemo } from 'react'
32
import { useDispatch, useSelector } from 'react-redux'
43
import { useParams, useHistory } from 'react-router-dom'
54

@@ -18,7 +17,9 @@ import {
1817
import { renderOnboardingTourWithChild } from 'uiSrc/utils/onboarding'
1918
import { OnboardingSteps } from 'uiSrc/constants/onboarding'
2019
import { useConnectionType } from 'uiSrc/components/hooks/useConnectionType'
21-
import { analyticsViewTabs } from './constants'
20+
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
21+
import Tabs, { TabInfo } from 'uiSrc/components/base/layout/tabs'
22+
import { Text } from 'uiSrc/components/base/text'
2223

2324
const AnalyticsTabs = () => {
2425
const { viewTab } = useSelector(analyticsSettingsSelector)
@@ -39,7 +40,58 @@ const AnalyticsTabs = () => {
3940
}
4041
}, [])
4142

42-
const onSelectedTabChanged = (id: AnalyticsViewTab) => {
43+
const tabs: TabInfo[] = useMemo(() => {
44+
const visibleTabs: TabInfo[] = [
45+
{
46+
value: AnalyticsViewTab.DatabaseAnalysis,
47+
content: null,
48+
label: renderOnboardingTourWithChild(
49+
<Text>Database Analysis</Text>,
50+
{
51+
options: ONBOARDING_FEATURES?.ANALYTICS_DATABASE_ANALYSIS,
52+
anchorPosition: 'downLeft',
53+
},
54+
viewTab === AnalyticsViewTab.DatabaseAnalysis,
55+
AnalyticsViewTab.DatabaseAnalysis,
56+
),
57+
},
58+
{
59+
value: AnalyticsViewTab.SlowLog,
60+
content: null,
61+
label: renderOnboardingTourWithChild(
62+
<Text>Slow Log</Text>,
63+
{
64+
options: ONBOARDING_FEATURES?.ANALYTICS_SLOW_LOG,
65+
anchorPosition: 'downLeft',
66+
},
67+
viewTab === AnalyticsViewTab.SlowLog,
68+
AnalyticsViewTab.SlowLog,
69+
),
70+
},
71+
]
72+
73+
if (connectionType === ConnectionType.Cluster) {
74+
visibleTabs.unshift({
75+
value: AnalyticsViewTab.ClusterDetails,
76+
content: null,
77+
label: renderOnboardingTourWithChild(
78+
<Text>Overview</Text>,
79+
{
80+
options: ONBOARDING_FEATURES?.ANALYTICS_OVERVIEW,
81+
anchorPosition: 'downLeft',
82+
},
83+
viewTab === AnalyticsViewTab.ClusterDetails,
84+
AnalyticsViewTab.ClusterDetails,
85+
),
86+
})
87+
}
88+
89+
return visibleTabs
90+
}, [viewTab, connectionType])
91+
92+
const handleTabChange = (id: string) => {
93+
if (viewTab === id) return
94+
4395
if (id === AnalyticsViewTab.ClusterDetails) {
4496
history.push(Pages.clusterDetails(instanceId))
4597
}
@@ -49,40 +101,16 @@ const AnalyticsTabs = () => {
49101
if (id === AnalyticsViewTab.DatabaseAnalysis) {
50102
history.push(Pages.databaseAnalysis(instanceId))
51103
}
52-
dispatch(setAnalyticsViewTab(id))
104+
dispatch(setAnalyticsViewTab(id as AnalyticsViewTab))
53105
}
54106

55-
const renderTabs = useCallback(() => {
56-
const filteredAnalyticsViewTabs =
57-
connectionType === ConnectionType.Cluster
58-
? [...analyticsViewTabs]
59-
: [...analyticsViewTabs].filter(
60-
(tab) => tab.id !== AnalyticsViewTab.ClusterDetails,
61-
)
62-
63-
return filteredAnalyticsViewTabs.map(({ id, label, onboard }) =>
64-
renderOnboardingTourWithChild(
65-
<EuiTab
66-
isSelected={viewTab === id}
67-
onClick={() => onSelectedTabChanged(id)}
68-
key={id}
69-
data-testid={`analytics-tab-${id}`}
70-
>
71-
{label}
72-
</EuiTab>,
73-
{ options: onboard, anchorPosition: 'downLeft' },
74-
viewTab === id,
75-
id,
76-
),
77-
)
78-
}, [viewTab, connectionType])
79-
80107
return (
81-
<>
82-
<EuiTabs className="tabs-active-borders" data-test-subj="analytics-tabs">
83-
{renderTabs()}
84-
</EuiTabs>
85-
</>
108+
<Tabs
109+
tabs={tabs}
110+
value={viewTab}
111+
onChange={handleTabChange}
112+
data-testid="analytics-tabs"
113+
/>
86114
)
87115
}
88116

redisinsight/ui/src/components/analytics-tabs/constants.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Tabs, TabInfo } from '@redis-ui/components'
2+
3+
export default Tabs
4+
export type { TabInfo }

redisinsight/ui/src/components/home-tabs/HomeTabs.spec.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import React from 'react'
22
import reactRouterDom from 'react-router-dom'
33
import { cloneDeep } from 'lodash'
4-
import {
5-
render,
6-
screen,
7-
fireEvent,
8-
act,
9-
cleanup,
10-
mockedStore,
11-
} from 'uiSrc/utils/test-utils'
4+
import { render, screen, cleanup, mockedStore, fireEvent } from 'uiSrc/utils/test-utils'
125

136
import { Pages } from 'uiSrc/constants'
147
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
@@ -41,28 +34,36 @@ describe('HomeTabs', () => {
4134
expect(render(<HomeTabs />)).toBeTruthy()
4235
})
4336

44-
it('should show database instances tab active', () => {
37+
it('should show database instances tab active', async () => {
4538
reactRouterDom.useLocation = jest
4639
.fn()
4740
.mockReturnValue({ pathname: Pages.home })
4841

4942
render(<HomeTabs />)
5043

51-
expect(screen.getByTestId('home-tab-databases')).toHaveClass(
52-
'euiTab-isSelected',
44+
const tabs = await screen.findAllByRole('tab')
45+
46+
const databasesTab = tabs.find((tab) =>
47+
tab.getAttribute('id')?.endsWith('trigger-databases'),
5348
)
49+
50+
expect(databasesTab).toHaveAttribute('data-state', 'active')
5451
})
5552

56-
it('should show rdi instances tab active', () => {
53+
it('should show rdi instances tab active', async () => {
5754
reactRouterDom.useLocation = jest
5855
.fn()
5956
.mockReturnValue({ pathname: Pages.rdi })
6057

6158
render(<HomeTabs />)
6259

63-
expect(screen.getByTestId('home-tab-rdi-instances')).toHaveClass(
64-
'euiTab-isSelected',
60+
const tabs = await screen.findAllByRole('tab')
61+
62+
const rdiTab = tabs.find((tab) =>
63+
tab.getAttribute('id')?.endsWith('trigger-rdi-instances'),
6564
)
65+
66+
expect(rdiTab).toHaveAttribute('data-state', 'active')
6667
})
6768

6869
it('should call proper history push', () => {
@@ -74,11 +75,9 @@ describe('HomeTabs', () => {
7475

7576
render(<HomeTabs />)
7677

77-
act(() => {
78-
fireEvent.click(screen.getByTestId('home-tab-rdi-instances'))
79-
})
78+
fireEvent.mouseDown(screen.getByText('Redis Data Integration'))
8079

81-
expect(pushMock).toBeCalledWith(Pages.rdi)
80+
expect(pushMock).toHaveBeenCalledWith(Pages.rdi)
8281
})
8382

8483
it('should send proper telemetry', () => {
@@ -92,9 +91,7 @@ describe('HomeTabs', () => {
9291

9392
render(<HomeTabs />)
9493

95-
act(() => {
96-
fireEvent.click(screen.getByTestId('home-tab-rdi-instances'))
97-
})
94+
fireEvent.mouseDown(screen.getByText('Redis Data Integration'))
9895

9996
expect(sendEventTelemetry).toBeCalledWith({
10097
event: TelemetryEvent.INSTANCES_TAB_CHANGED,
@@ -114,7 +111,7 @@ describe('HomeTabs', () => {
114111
render(<HomeTabs />)
115112

116113
expect(
117-
screen.queryByTestId('home-tab-rdi-instances'),
114+
screen.queryByText('Redis Data Integration'),
118115
).not.toBeInTheDocument()
119116
})
120117
})

0 commit comments

Comments
 (0)