Skip to content

Commit f93a9a7

Browse files
authored
[RI-7064] Replace EuiPopover with RiPopover (#4671)
* RI-7064: replace EuiPopup init * replace EuiPopup with RiPopup * fix some unit tests * skip some unit tests * remove EuiPopover reference * fix tests * fix onboarding popover
1 parent 6d9f45f commit f93a9a7

File tree

76 files changed

+378
-271
lines changed

Some content is hidden

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

76 files changed

+378
-271
lines changed

redisinsight/ui/src/components/auto-refresh/AutoRefresh.spec.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
screen,
77
render,
88
act,
9+
waitForRiPopoverVisible,
910
} from 'uiSrc/utils/test-utils'
1011
import { localStorageService } from 'uiSrc/services'
1112
import AutoRefresh, { Props } from './AutoRefresh'
@@ -77,7 +78,8 @@ describe('AutoRefresh', () => {
7778
it('refresh text should contain "Auto-refresh" time with enabled auto-refresh', async () => {
7879
render(<AutoRefresh {...instance(mockedProps)} displayText />)
7980

80-
fireEvent.click(screen.getByTestId('auto-refresh-config-btn'))
81+
await userEvent.click(screen.getByTestId('auto-refresh-config-btn'))
82+
await waitForRiPopoverVisible()
8183
await userEvent.click(screen.getByTestId('auto-refresh-switch'))
8284

8385
expect(screen.getByTestId('refresh-message-label')).toHaveTextContent(
@@ -158,7 +160,8 @@ describe('AutoRefresh', () => {
158160
const onRefresh = jest.fn()
159161
render(<AutoRefresh {...instance(mockedProps)} onRefresh={onRefresh} />)
160162

161-
fireEvent.click(screen.getByTestId('auto-refresh-config-btn'))
163+
await userEvent.click(screen.getByTestId('auto-refresh-config-btn'))
164+
await waitForRiPopoverVisible()
162165
await userEvent.click(screen.getByTestId('auto-refresh-switch'))
163166
fireEvent.click(screen.getByTestId('refresh-rate'))
164167

@@ -264,7 +267,8 @@ describe('AutoRefresh', () => {
264267
<AutoRefresh {...instance(mockedProps)} onRefresh={onRefresh} />,
265268
)
266269

267-
fireEvent.click(screen.getByTestId('auto-refresh-config-btn'))
270+
await userEvent.click(screen.getByTestId('auto-refresh-config-btn'))
271+
await waitForRiPopoverVisible()
268272
await userEvent.click(screen.getByTestId('auto-refresh-switch'))
269273
fireEvent.click(screen.getByTestId('refresh-rate'))
270274
fireEvent.change(screen.getByTestId(INLINE_ITEM_EDITOR), {

redisinsight/ui/src/components/auto-refresh/AutoRefresh.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react'
2-
import { EuiIcon, EuiPopover } from '@elastic/eui'
2+
import { EuiIcon } from '@elastic/eui'
33
import cx from 'classnames'
44
import { ChevronDownIcon, RefreshIcon } from 'uiSrc/components/base/icons'
55
import {
@@ -14,7 +14,7 @@ import { BrowserStorageItem } from 'uiSrc/constants'
1414
import { IconButton } from 'uiSrc/components/base/forms/buttons'
1515
import { ColorText } from 'uiSrc/components/base/text'
1616
import { SwitchInput } from 'uiSrc/components/base/inputs'
17-
import { RiTooltip } from 'uiSrc/components'
17+
import { RiPopover, RiTooltip } from 'uiSrc/components/base'
1818
import {
1919
DEFAULT_REFRESH_RATE,
2020
DURATION_FIRST_REFRESH_TIME,
@@ -245,7 +245,7 @@ const AutoRefresh = ({
245245
/>
246246
</RiTooltip>
247247

248-
<EuiPopover
248+
<RiPopover
249249
ownFocus={false}
250250
anchorPosition="downRight"
251251
isOpen={isPopoverOpen}
@@ -309,7 +309,7 @@ const AutoRefresh = ({
309309
</>
310310
)}
311311
</div>
312-
</EuiPopover>
312+
</RiPopover>
313313
</div>
314314
)
315315
}

redisinsight/ui/src/components/base/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import { HorizontalRule, LoadingContent } from './layout'
44
export { ExternalLink, HorizontalRule, LoadingContent }
55

66
export * from './tooltip'
7+
export * from './popover'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react'
2+
import { Popover } from '@redis-ui/components'
3+
4+
import { RiPopoverProps } from './types'
5+
import { anchorPositionMap, panelPaddingSizeMap } from './config'
6+
7+
export const RiPopover = ({
8+
isOpen,
9+
closePopover,
10+
children,
11+
ownFocus,
12+
button,
13+
anchorPosition,
14+
panelPaddingSize,
15+
anchorClassName,
16+
panelClassName,
17+
maxWidth = '100%',
18+
...props
19+
}: RiPopoverProps) => (
20+
<Popover
21+
{...props}
22+
open={isOpen}
23+
onClickOutside={closePopover}
24+
content={children}
25+
// Props passed to the children wrapper:
26+
className={panelClassName}
27+
maxWidth={maxWidth}
28+
style={{
29+
padding: panelPaddingSize && panelPaddingSizeMap[panelPaddingSize],
30+
}}
31+
autoFocus={ownFocus}
32+
placement={anchorPosition && anchorPositionMap[anchorPosition]?.placement}
33+
align={anchorPosition && anchorPositionMap[anchorPosition]?.align}
34+
>
35+
<span className={anchorClassName}>{button}</span>
36+
</Popover>
37+
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export const anchorPositionMap = {
2+
upCenter: {
3+
placement: 'top',
4+
align: 'center',
5+
},
6+
upLeft: {
7+
placement: 'top',
8+
align: 'start',
9+
},
10+
upRight: {
11+
placement: 'top',
12+
align: 'end',
13+
},
14+
downCenter: {
15+
placement: 'bottom',
16+
align: 'center',
17+
},
18+
downLeft: {
19+
placement: 'bottom',
20+
align: 'start',
21+
},
22+
downRight: {
23+
placement: 'bottom',
24+
align: 'end',
25+
},
26+
leftCenter: {
27+
placement: 'left',
28+
align: 'center',
29+
},
30+
leftUp: {
31+
placement: 'left',
32+
align: 'start',
33+
},
34+
leftDown: {
35+
placement: 'left',
36+
align: 'end',
37+
},
38+
rightCenter: {
39+
placement: 'right',
40+
align: 'center',
41+
},
42+
rightUp: {
43+
placement: 'right',
44+
align: 'start',
45+
},
46+
rightDown: {
47+
placement: 'right',
48+
align: 'end',
49+
},
50+
} as const
51+
52+
export const panelPaddingSizeMap = {
53+
l: 24,
54+
m: 18,
55+
s: 8,
56+
none: 0,
57+
} as const
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './RiPopover'
2+
export * from './types'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { type PopoverProps } from '@redis-ui/components'
2+
3+
import { anchorPositionMap, panelPaddingSizeMap } from './config'
4+
5+
type AnchorPosition = keyof typeof anchorPositionMap
6+
7+
type PanelPaddingSize = keyof typeof panelPaddingSizeMap
8+
9+
export type RiPopoverProps = Omit<
10+
PopoverProps,
11+
| 'open'
12+
| 'onClickOutside'
13+
| 'autoFocus'
14+
| 'content'
15+
| 'className'
16+
| 'placement'
17+
| 'align'
18+
> & {
19+
isOpen?: PopoverProps['open']
20+
closePopover?: PopoverProps['onClickOutside']
21+
ownFocus?: PopoverProps['autoFocus']
22+
button: PopoverProps['content']
23+
anchorPosition?: AnchorPosition
24+
panelPaddingSize?: PanelPaddingSize
25+
anchorClassName?: string
26+
panelClassName?: string
27+
'data-testid'?: string
28+
}

redisinsight/ui/src/components/inline-item-editor/InlineItemEditor.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { ChangeEvent, Ref, useEffect, useRef, useState } from 'react'
22
import { capitalize } from 'lodash'
33
import cx from 'classnames'
4-
import { EuiFieldText, EuiForm, EuiPopover, keys } from '@elastic/eui'
4+
import { EuiFieldText, EuiForm, keys } from '@elastic/eui'
55

6-
import { RiTooltip } from 'uiSrc/components'
6+
import { RiPopover, RiTooltip } from 'uiSrc/components/base'
77
import { FlexItem } from 'uiSrc/components/base/layout/flex'
88
import { WindowEvent } from 'uiSrc/components/base/utils/WindowEvent'
99
import { FocusTrap } from 'uiSrc/components/base/utils/FocusTrap'
@@ -250,13 +250,12 @@ const InlineItemEditor = (props: Props) => {
250250
/>
251251
{!approveByValidation && ApplyBtn}
252252
{approveByValidation && (
253-
<EuiPopover
253+
<RiPopover
254254
anchorPosition="leftCenter"
255255
isOpen={isShowApprovePopover}
256256
closePopover={() => setIsShowApprovePopover(false)}
257257
anchorClassName={styles.popoverAnchor}
258258
panelClassName={cx(styles.popoverPanel)}
259-
className={styles.popoverWrapper}
260259
button={ApplyBtn}
261260
>
262261
<div
@@ -289,7 +288,7 @@ const InlineItemEditor = (props: Props) => {
289288
</DestructiveButton>
290289
</div>
291290
</div>
292-
</EuiPopover>
291+
</RiPopover>
293292
)}
294293
</div>
295294
</EuiForm>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ChangeEvent, useEffect, useState, useMemo } from 'react'
2-
import { EuiFieldText, EuiIcon, EuiPopover } from '@elastic/eui'
2+
import { EuiFieldText, EuiIcon } from '@elastic/eui'
33
import { useSelector } from 'react-redux'
44
import { useHistory, useParams } from 'react-router-dom'
55
import { instancesSelector as rdiInstancesSelector } from 'uiSrc/slices/rdi/instances'
@@ -15,6 +15,7 @@ import { filterAndSort } from 'uiSrc/utils'
1515
import { Spacer } from 'uiSrc/components/base/layout/spacer'
1616
import { Text } from 'uiSrc/components/base/text'
1717
import Tabs, { TabInfo } from 'uiSrc/components/base/layout/tabs'
18+
import { RiPopover } from 'uiSrc/components/base'
1819
import InstancesList from './components/instances-list'
1920
import styles from './styles.module.scss'
2021

@@ -110,7 +111,7 @@ const InstancesNavigationPopover = ({ name }: Props) => {
110111
)
111112

112113
return (
113-
<EuiPopover
114+
<RiPopover
114115
ownFocus
115116
anchorPosition="downRight"
116117
panelPaddingSize="none"
@@ -169,7 +170,7 @@ const InstancesNavigationPopover = ({ name }: Props) => {
169170
</div>
170171
</div>
171172
</div>
172-
</EuiPopover>
173+
</RiPopover>
173174
)
174175
}
175176

redisinsight/ui/src/components/instance-header/components/user-profile/UserProfileBadge.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
fireEvent,
66
render,
77
screen,
8-
waitForEuiPopoverVisible,
8+
waitForRiPopoverVisible,
99
within,
1010
} from 'uiSrc/utils/test-utils'
1111
import * as appFeaturesSlice from 'uiSrc/slices/app/features'
@@ -104,7 +104,7 @@ describe('UserProfileBadge', () => {
104104
await act(async () => {
105105
fireEvent.click(screen.getByTestId('user-profile-btn'))
106106
})
107-
await waitForEuiPopoverVisible()
107+
await waitForRiPopoverVisible()
108108

109109
return resp
110110
}

0 commit comments

Comments
 (0)