Skip to content

Commit 6d9f45f

Browse files
authored
RI-7040: replace eui accordion
Replace EuiAccordion with RiAccordion
1 parent 59650e0 commit 6d9f45f

File tree

13 files changed

+276
-184
lines changed

13 files changed

+276
-184
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React, { ComponentProps, isValidElement, ReactNode } from 'react'
2+
import { Section, SectionProps } from '@redis-ui/components'
3+
4+
export type RiAccordionProps = Omit<ComponentProps<typeof Section>, 'label'> & {
5+
label: ReactNode
6+
actions?: ReactNode
7+
collapsible?: SectionProps['collapsible']
8+
actionButtonText?: SectionProps['actionButtonText']
9+
collapsedInfo?: SectionProps['collapsedInfo']
10+
content?: SectionProps['content']
11+
children?: SectionProps['content']
12+
onAction?: SectionProps['onAction']
13+
}
14+
15+
const RiAccordionLabel = ({ label }: Pick<RiAccordionProps, 'label'>) => {
16+
if (!label) {
17+
return null
18+
}
19+
if (typeof label === 'string') {
20+
return <Section.Header.Label label={label} />
21+
}
22+
// Ensure we always return a valid JSX element by wrapping non-JSX values
23+
return isValidElement(label) ? label : <>{label}</>
24+
}
25+
26+
type RiAccordionActionsProps = Pick<
27+
RiAccordionProps,
28+
'actionButtonText' | 'actions' | 'onAction'
29+
>
30+
31+
const RiAccordionActions = ({
32+
actionButtonText,
33+
actions,
34+
onAction,
35+
}: RiAccordionActionsProps) => (
36+
<Section.Header.Group>
37+
<Section.Header.ActionButton onClick={onAction}>
38+
{actionButtonText}
39+
</Section.Header.ActionButton>
40+
{actions}
41+
<Section.Header.CollapseIndicator />
42+
</Section.Header.Group>
43+
)
44+
45+
export const RiAccordion = ({
46+
id,
47+
content,
48+
label,
49+
onAction,
50+
actionButtonText,
51+
collapsedInfo,
52+
children,
53+
actions,
54+
collapsible = true,
55+
...rest
56+
}: RiAccordionProps) => (
57+
<Section.Compose
58+
id={`ri-accordion-${id}`}
59+
data-testid={`ri-accordion-${id}`}
60+
{...rest}
61+
collapsible={collapsible}
62+
>
63+
<Section.Header.Compose
64+
collapsedInfo={collapsedInfo}
65+
id={`ri-accordion-${id}`}
66+
data-testid={`ri-accordion-header-${id}`}
67+
>
68+
<RiAccordionLabel
69+
label={label}
70+
data-testid={`ri-accordion-label-${id}`}
71+
/>
72+
<RiAccordionActions
73+
actions={actions}
74+
onAction={onAction}
75+
actionButtonText={actionButtonText}
76+
data-testid={`ri-accordion-actions-${id}`}
77+
/>
78+
</Section.Header.Compose>
79+
<Section.Body
80+
content={children ?? content}
81+
data-testid={`ri-accordion-body-${id}`}
82+
/>
83+
</Section.Compose>
84+
)

redisinsight/ui/src/components/base/layout/flex/flex.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const gapStyles = {
88
xs: '0.2rem',
99
s: '0.4rem',
1010
m: '0.8rem',
11-
l: '2rem',
12-
xl: '2.4rem',
11+
l: '1.2rem',
12+
xl: '2rem',
13+
xxl: '2.4rem',
1314
}
1415
describe('Flex Components', () => {
1516
it('should render', () => {

redisinsight/ui/src/components/base/layout/flex/flex.styles.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled, { css } from 'styled-components'
44
import { useTheme } from '@redis-ui/styles'
55
import { CommonProps } from 'uiSrc/components/base/theme/types'
66

7-
export const gapSizes = ['none', 'xs', 's', 'm', 'l', 'xl'] as const
7+
export const gapSizes = ['none', 'xs', 's', 'm', 'l', 'xl', 'xxl'] as const
88
export type GapSizeType = (typeof gapSizes)[number]
99
export const columnCount = [1, 2, 3, 4] as const
1010
export type ColumnCountType = (typeof columnCount)[number]
@@ -103,9 +103,12 @@ const flexGroupStyles = {
103103
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space100};
104104
`,
105105
l: css`
106-
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space250};
106+
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space150};
107107
`,
108108
xl: css`
109+
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space250};
110+
`,
111+
xxl: css`
109112
gap: ${({ theme }: { theme: ThemeType }) => theme.core.space.space300};
110113
`,
111114
},

redisinsight/ui/src/components/recommendation/badge-icon/BadgeIcon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
23
import { RiTooltip } from 'uiSrc/components'
34
import { FlexItem } from 'uiSrc/components/base/layout/flex'
45
import styles from '../styles.module.scss'

redisinsight/ui/src/components/recommendation/recommendation-badges/RecommendationBadges.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import React from 'react'
33
import { Row } from 'uiSrc/components/base/layout/flex'
44
import BadgeIcon from '../badge-icon'
55
import { badgesContent } from '../constants'
6-
import styles from '../styles.module.scss'
76

87
export interface Props {
98
badges?: string[]
109
}
1110

1211
const RecommendationBadges = ({ badges = [] }: Props) => (
13-
<Row className={styles.badgesContainer} align="center" justify="between">
12+
<Row align="center" justify="end" gap="m">
1413
{badgesContent.map(
1514
({ id, name, icon }) =>
1615
badges.includes(id) && (

redisinsight/ui/src/components/side-panels/panels/enablement-area/EnablementArea/components/Group/Group.spec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Group', () => {
2323
{children}
2424
</Group>,
2525
)
26-
const accordionButton = queryByTestId(`accordion-button-${testId}`)
26+
const accordionButton = queryByTestId(`accordion-${testId}`)
2727

2828
expect(accordionButton).toHaveTextContent(label)
2929
})
@@ -39,7 +39,9 @@ describe('Group', () => {
3939
onToggle={callback}
4040
/>,
4141
)
42-
fireEvent.click(screen.getByTestId(`accordion-button-${testId}`))
42+
const accordion = screen.getByTestId(`accordion-${testId}`)
43+
const btn = accordion.querySelector('button')
44+
fireEvent.click(btn!)
4345

4446
expect(callback).toHaveBeenCalled()
4547
})

redisinsight/ui/src/components/side-panels/panels/enablement-area/EnablementArea/components/Group/Group.tsx

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react'
2-
import { EuiAccordion, EuiIcon } from '@elastic/eui'
2+
3+
import { EuiIcon } from '@elastic/eui'
34
import { useSelector } from 'react-redux'
45
import { useParams } from 'react-router-dom'
56
import cx from 'classnames'
@@ -12,8 +13,12 @@ import {
1213
import { workbenchCustomTutorialsSelector } from 'uiSrc/slices/workbench/wb-custom-tutorials'
1314
import { EAItemActions } from 'uiSrc/constants'
1415
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
16+
17+
import { RiAccordion } from 'uiSrc/components/base/display/accordion/RiAccordion'
18+
import { Col } from 'uiSrc/components/base/layout/flex'
1519
import { RiTooltip, OnboardingTour } from 'uiSrc/components'
1620
import { Text } from 'uiSrc/components/base/text'
21+
1722
import DeleteTutorialButton from '../DeleteTutorialButton'
1823

1924
import './styles.scss'
@@ -22,19 +27,16 @@ export interface Props {
2227
id: string
2328
label: string
2429
actions?: string[]
25-
isShowActions?: boolean
26-
isShowFolder?: boolean
2730
onCreate?: () => void
2831
onDelete?: (id: string) => void
2932
children: React.ReactNode
3033
withBorder?: boolean
3134
initialIsOpen?: boolean
3235
forceState?: 'open' | 'closed'
33-
arrowDisplay?: 'left' | 'right' | 'none'
3436
onToggle?: (isOpen: boolean) => void
35-
triggerStyle?: any
36-
buttonClassName?: string
3737
isPageOpened?: boolean
38+
isShowActions?: boolean
39+
isShowFolder?: boolean
3840
}
3941

4042
const Group = (props: Props) => {
@@ -46,15 +48,12 @@ const Group = (props: Props) => {
4648
id,
4749
forceState,
4850
withBorder = false,
49-
arrowDisplay = 'right',
50-
isShowFolder = true,
5151
initialIsOpen = false,
5252
onToggle,
5353
onCreate,
5454
onDelete,
55-
triggerStyle,
56-
buttonClassName,
5755
isPageOpened,
56+
isShowFolder,
5857
} = props
5958
const { deleting: deletingCustomTutorials } = useSelector(
6059
workbenchCustomTutorialsSelector,
@@ -120,39 +119,33 @@ const Group = (props: Props) => {
120119
</>
121120
)
122121

123-
const buttonContent = (
124-
<div className="group-header-wrapper">
125-
<Text className="group-header" size="m">
126-
{isShowFolder && (
127-
<EuiIcon type={isGroupOpen ? 'folderOpen' : 'folderClosed'} />
128-
)}
129-
{label}
130-
</Text>
131-
{isShowActions && actionsContent}
132-
</div>
133-
)
134-
135-
const buttonProps: any = {
136-
'data-testid': `accordion-button-${id}`,
137-
style: triggerStyle,
138-
className: buttonClassName,
139-
}
140-
141122
return (
142-
<EuiAccordion
123+
<RiAccordion
143124
id={id}
144125
data-testid={`accordion-${id}`}
145-
buttonContent={buttonContent}
146-
buttonProps={buttonProps}
147-
forceState={forceState}
148-
arrowDisplay={arrowDisplay}
149-
onToggle={handleOpen}
150-
initialIsOpen={initialIsOpen}
151-
style={{ whiteSpace: 'nowrap', width: 'auto' }}
152-
className={[withBorder ? 'withBorder' : ''].join(' ')}
126+
defaultOpen={initialIsOpen}
127+
open={forceState === 'open' || isGroupOpen}
128+
label={
129+
<Text className="group-header" size="m">
130+
{isShowFolder && (
131+
<EuiIcon
132+
type={isGroupOpen ? 'folderOpen' : 'folderClosed'}
133+
style={{ marginRight: '10px' }}
134+
/>
135+
)}
136+
{label}
137+
</Text>
138+
}
139+
onOpenChange={handleOpen}
140+
style={{
141+
whiteSpace: 'nowrap',
142+
width: 'auto',
143+
}}
144+
className={cx({ withBorder })}
145+
actions={isShowActions ? actionsContent : null}
153146
>
154-
{children}
155-
</EuiAccordion>
147+
<Col gap="l">{children}</Col>
148+
</RiAccordion>
156149
)
157150
}
158151

redisinsight/ui/src/components/side-panels/panels/enablement-area/EnablementArea/components/Navigation/Navigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ const Navigation = (props: Props) => {
161161
case EnablementAreaComponent.Group:
162162
return (
163163
<Group
164-
buttonClassName={level === 0 ? styles.baseGroup : ''}
165-
triggerStyle={paddingsStyle}
166164
id={id}
167165
label={label}
168166
actions={actions}
@@ -242,6 +240,8 @@ const Navigation = (props: Props) => {
242240

243241
return (
244242
<ListGroup
243+
style={{ padding: 5 }}
244+
gap="m"
245245
maxWidth="false"
246246
data-testid="enablementArea-treeView"
247247
flush

0 commit comments

Comments
 (0)