Skip to content

Commit be75ad3

Browse files
author
Artyom Podymov
committed
#RI-2162 refactror enablement area tree view
1 parent c9de90c commit be75ad3

File tree

6 files changed

+69
-28
lines changed

6 files changed

+69
-28
lines changed

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/EnablementArea.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717

1818
import styles from './styles.module.scss'
1919

20+
const padding = parseInt(styles.paddingHorizontal)
21+
2022
export interface Props {
2123
items: Record<string, IEnablementAreaItem>;
2224
loading: boolean;
@@ -61,38 +63,39 @@ const EnablementArea = ({ items, openScript, loading, onOpenInternalPage }: Prop
6163
})
6264
}
6365

64-
const renderSwitch = (item: IEnablementAreaItem) => {
66+
const renderSwitch = (item: IEnablementAreaItem, level: number) => {
6567
const { label, type, children, id, args } = item
68+
const paddingsStyle = { paddingLeft: `${padding + level * 8}px`, paddingRight: `${padding}px` }
6669
switch (type) {
6770
case EnablementAreaComponent.Group:
6871
return (
69-
<Group
70-
testId={id}
71-
label={label}
72-
{...args}
73-
>
74-
{renderTreeView(Object.values(children || {}) || [])}
72+
<Group triggerStyle={paddingsStyle} testId={id} label={label}{...args}>
73+
{renderTreeView(Object.values(children || {}) || [], level + 1)}
7574
</Group>
7675
)
7776
case EnablementAreaComponent.CodeButton:
78-
return args?.path
79-
? <div style={{ marginTop: '16px' }}><LazyCodeButton label={label} {...args} /></div>
80-
: <div style={{ marginTop: '16px' }}><CodeButton onClick={() => openScript(args?.content || '')} label={label} {...args} /></div>
77+
return (
78+
<div style={{ marginTop: '12px', ...paddingsStyle }}>
79+
{args?.path
80+
? <LazyCodeButton label={label} {...args} />
81+
: <CodeButton onClick={() => openScript(args?.content || '')} label={label} {...args} />}
82+
</div>
83+
)
8184
case EnablementAreaComponent.InternalLink:
8285
return (
83-
<InternalLink testId={id || label} label={label} {...args}>
86+
<InternalLink style={paddingsStyle} testId={id || label} label={label}{...args}>
8487
{args?.content || label}
8588
</InternalLink>
8689
)
8790
default:
88-
return <PlainText>{label}</PlainText>
91+
return <PlainText style={paddingsStyle}>{label}</PlainText>
8992
}
9093
}
9194

92-
const renderTreeView = (elements: IEnablementAreaItem[]) => (
95+
const renderTreeView = (elements: IEnablementAreaItem[], level: number = 0) => (
9396
elements?.map((item) => (
9497
<div className="fluid" key={item.id}>
95-
{renderSwitch(item)}
98+
{renderSwitch(item, level)}
9699
</div>
97100
)))
98101

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/Group/Group.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,30 @@ export interface Props {
1111
forceState?: 'open' | 'closed';
1212
arrowDisplay?: 'left' | 'right' | 'none';
1313
onToggle?: (isOpen: boolean) => void;
14+
triggerStyle?: any,
1415
}
1516

1617
const Group = (props: Props) => {
17-
const { label, children, testId, forceState, withBorder = false, arrowDisplay = 'right', initialIsOpen = false, onToggle } = props
18+
const {
19+
label,
20+
children,
21+
testId,
22+
forceState,
23+
withBorder = false,
24+
arrowDisplay = 'right',
25+
initialIsOpen = false,
26+
onToggle,
27+
triggerStyle,
28+
} = props
1829
const buttonContent = (
1930
<EuiText className="group-header" size="m">
2031
{label}
2132
</EuiText>
2233
)
23-
const buttonProps: any = { 'data-testid': `accordion-button-${testId}` }
34+
const buttonProps: any = {
35+
'data-testid': `accordion-button-${testId}`,
36+
style: triggerStyle,
37+
}
2438

2539
return (
2640
<EuiAccordion
@@ -35,7 +49,10 @@ const Group = (props: Props) => {
3549
style={{ whiteSpace: 'nowrap', width: 'auto' }}
3650
className={[withBorder ? 'withBorder' : ''].join(' ')}
3751
>
38-
{children}
52+
<>
53+
{children}
54+
{withBorder && <div style={triggerStyle} className="divider"><hr /></div> }
55+
</>
3956
</EuiAccordion>
4057
)
4158
}

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/Group/styles.scss

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,42 @@
1010
white-space: nowrap;
1111
text-overflow: ellipsis;
1212
}
13+
.divider {
14+
visibility: hidden;
15+
width: 100%;
16+
height: 1px;
17+
position: absolute;
18+
bottom: 0;
19+
hr {
20+
border: none;
21+
height: 1px;
22+
width: 100%;
23+
background-color: var(--separatorColor);
24+
}
25+
}
1326
}
1427
.euiAccordion__button {
1528
padding: 3px 0;
1629
& > span {
1730
overflow: hidden;
1831
}
32+
&:hover {
33+
background-color: var(--hoverInListColorDarken);
34+
}
1935
}
2036
.euiAccordion-isOpen {
2137
min-width: 100%;
22-
&.withBorder {
23-
border-color: var(--separatorColor);
38+
.divider {
39+
visibility: visible;
2440
}
2541
}
2642
.euiAccordion__triggerWrapper, .euiAccordion__childWrapper {
2743
border: none !important;
2844
background-color: transparent !important;
2945
}
3046
.euiAccordion__childWrapper {
31-
padding-left: 8px;
32-
margin-bottom: 4px;
47+
padding-left: 0;
48+
margin-bottom: 8px;
3349
.euiListGroupItem {
3450
button {
3551
padding: 3px 8px;

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/InternalLink/InternalLink.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export interface Props {
1515
iconType?: string;
1616
iconPosition?: 'left' | 'right';
1717
toolTip?: string;
18+
style?: any;
1819
}
1920
const InternalLink = (props: Props) => {
20-
const { label, testId, children, path = '', size = 's', iconType, iconPosition = 'left', toolTip } = props
21+
const { label, testId, children, path = '', size = 's', iconType, iconPosition = 'left', toolTip, ...rest } = props
2122
const { openPage } = useContext(EnablementAreaContext)
2223
const handleOpenPage = () => {
2324
if (path) {
@@ -43,6 +44,7 @@ const InternalLink = (props: Props) => {
4344
color="subdued"
4445
onClick={handleOpenPage}
4546
label={content}
47+
{...rest}
4648
/>
4749
)
4850
}

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/components/PlainText/PlainText.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { EuiText } from '@elastic/eui'
33

44
export interface Props {
55
children: React.ReactElement | string;
6+
style?: any;
67
}
7-
const PlainText = ({ children }: Props) => (
8+
const PlainText = ({ children, ...rest }: Props) => (
89
<EuiText
9-
style={{ whiteSpace: 'nowrap', width: 'auto' }}
10+
style={{ whiteSpace: 'nowrap', width: 'auto', ...rest.style }}
1011
color="subdued"
1112
size="m"
1213
>

redisinsight/ui/src/pages/workbench/components/enablament-area/EnablementArea/styles.module.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
@import '@elastic/eui/src/components/table/mixins';
33
@import '@elastic/eui/src/global_styling/index';
44

5-
$paddingHorizontal: 18px;
65
.container {
76
overflow: hidden;
87
height: 100%;
9-
padding: 0 $paddingHorizontal;
108
flex-grow: 1;
119
}
1210

@@ -26,12 +24,16 @@ $paddingHorizontal: 18px;
2624
position: absolute;
2725
top: 0;
2826
height: 100%;
29-
transform: translateX(calc(100% + 8px));
27+
transform: translateX(calc(100% + 18px));
3028
backface-visibility: hidden;
3129
transition: transform 0.4s ease-in-out;
3230
box-shadow: -5px 1px 10px rgba(0, 0, 0, 0.2);
3331
}
3432

3533
.internalPageVisible {
36-
transform: translateX(-$paddingHorizontal);
34+
transform: translateX(0);
35+
}
36+
37+
:export {
38+
paddingHorizontal: 18
3739
}

0 commit comments

Comments
 (0)