Skip to content

Commit face974

Browse files
authored
RI-7179: replace eui tour step
* replace eui tour step
1 parent debba5d commit face974

File tree

9 files changed

+202
-63
lines changed

9 files changed

+202
-63
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import React, { useEffect, useState } from 'react'
2+
import { Popover } from '@redis-ui/components'
3+
import {
4+
PopoverPlacementMapType,
5+
TourStepProps,
6+
} from 'uiSrc/components/base/display/tour/types'
7+
import { useGenerateId } from 'uiSrc/components/base/utils/hooks/generate-id'
8+
9+
const popoverPlacementMap: PopoverPlacementMapType = {
10+
upCenter: {
11+
placement: 'top',
12+
align: 'center',
13+
},
14+
upLeft: {
15+
placement: 'top',
16+
align: 'start',
17+
},
18+
upRight: {
19+
placement: 'top',
20+
align: 'end',
21+
},
22+
downCenter: {
23+
placement: 'bottom',
24+
align: 'center',
25+
},
26+
downLeft: {
27+
placement: 'bottom',
28+
align: 'start',
29+
},
30+
downRight: {
31+
placement: 'bottom',
32+
align: 'end',
33+
},
34+
leftCenter: {
35+
placement: 'left',
36+
align: 'center',
37+
},
38+
leftUp: {
39+
placement: 'left',
40+
align: 'start',
41+
},
42+
leftDown: {
43+
placement: 'left',
44+
align: 'end',
45+
},
46+
rightCenter: {
47+
placement: 'right',
48+
align: 'center',
49+
},
50+
rightUp: {
51+
placement: 'right',
52+
align: 'start',
53+
},
54+
rightDown: {
55+
placement: 'right',
56+
align: 'end',
57+
},
58+
}
59+
60+
export const TourStep = ({
61+
open,
62+
content,
63+
title,
64+
onClose,
65+
placement = 'rightUp',
66+
className = '',
67+
children,
68+
minWidth = 300,
69+
maxWidth,
70+
offset = 5,
71+
...rest
72+
}: TourStepProps) => {
73+
const [isVisible, setIsVisible] = useState(open)
74+
const id = useGenerateId()
75+
const titleId = `${id}-title`
76+
77+
useEffect(() => {
78+
setIsVisible(open)
79+
}, [open])
80+
81+
if (!isVisible) {
82+
return null
83+
}
84+
const place = popoverPlacementMap[placement]
85+
const popoverContent = (
86+
<Popover.Card.Compose style={{ minWidth, maxWidth }}>
87+
<Popover.Card.Header.Compose id={titleId}>
88+
{title}
89+
</Popover.Card.Header.Compose>
90+
<Popover.Card.Body.Compose>{content}</Popover.Card.Body.Compose>
91+
</Popover.Card.Compose>
92+
)
93+
return (
94+
<Popover
95+
className={className}
96+
open={isVisible}
97+
placement={place.placement}
98+
align={place.align}
99+
sideOffset={offset}
100+
alignOffset={-10}
101+
content={popoverContent}
102+
id={id}
103+
aria-labelledby={titleId}
104+
{...rest}
105+
withButton
106+
persistent
107+
>
108+
{children}
109+
</Popover>
110+
)
111+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { ReactNode } from 'react'
2+
import { Popover } from '@redis-ui/components'
3+
4+
export type TourStepProps = {
5+
/**
6+
* Contents of the tour step popover
7+
*/
8+
content: ReactNode
9+
/**
10+
* Step will display if set to `true`
11+
*/
12+
open?: boolean
13+
/**
14+
* The title text that appears atop each step in the tour.
15+
*/
16+
title?: ReactNode
17+
placement?:
18+
| 'upCenter'
19+
| 'upLeft'
20+
| 'upRight'
21+
| 'downCenter'
22+
| 'downLeft'
23+
| 'downRight'
24+
| 'leftCenter'
25+
| 'leftUp'
26+
| 'leftDown'
27+
| 'rightCenter'
28+
| 'rightUp'
29+
| 'rightDown'
30+
className?: string
31+
children?: ReactNode
32+
minWidth?: number | string
33+
maxWidth?: number | string
34+
offset?: number
35+
}
36+
type PopoverTypes = React.ComponentProps<typeof Popover>
37+
38+
export type PopoverPlacementMapType = Record<
39+
NonNullable<TourStepProps['placement']>,
40+
{
41+
placement: PopoverTypes['placement']
42+
align: PopoverTypes['align']
43+
}
44+
>

redisinsight/ui/src/components/cli/components/cli-header/CliHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const CliHeader = () => {
6464
return (
6565
<div className={styles.container} id="cli-header">
6666
<Row justify="between" align="center" style={{ height: '100%' }}>
67-
<FlexItem className={styles.title}>
67+
<FlexItem className={styles.title} direction="row">
6868
<EuiIcon type="console" size="m" />
6969
<OnboardingTour
7070
options={ONBOARDING_FEATURES.BROWSER_CLI}

redisinsight/ui/src/components/cli/components/cli-header/styles.module.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
}
3434

3535
.title {
36-
display: flex;
37-
flex-direction: row !important;
3836
align-items: center;
3937
:global {
4038
.euiIcon {

redisinsight/ui/src/components/onboarding-features/OnboardingFeatures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ const ONBOARDING_FEATURES = {
697697

698698
useEffect(() => {
699699
const closeLastStep = async () => {
700-
await dispatch(
700+
dispatch(
701701
incrementOnboardStepAction(OnboardingSteps.Finish, 0, async () => {
702702
await sendEventTelemetry({
703703
event: TelemetryEvent.ONBOARDING_TOUR_FINISHED,

redisinsight/ui/src/components/onboarding-tour/OnboardingTour.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('OnboardingTour', () => {
106106

107107
fireEvent.click(screen.getByTestId('back-btn'))
108108
expect(store.getActions()).toEqual([setOnboardPrevStep()])
109-
expect(onBack).toBeCalled()
109+
expect(onBack).toHaveBeenCalled()
110110
})
111111

112112
it('should call proper actions on next button', () => {
@@ -131,7 +131,7 @@ describe('OnboardingTour', () => {
131131

132132
fireEvent.click(screen.getByTestId('next-btn'))
133133
expect(store.getActions()).toEqual([setOnboardNextStep()])
134-
expect(onNext).toBeCalled()
134+
expect(onNext).toHaveBeenCalled()
135135
})
136136

137137
it('should call proper actions on skip button', () => {
@@ -156,7 +156,7 @@ describe('OnboardingTour', () => {
156156

157157
fireEvent.click(screen.getByTestId('skip-tour-btn'))
158158
expect(store.getActions()).toEqual([skipOnboarding()])
159-
expect(onSkip).toBeCalled()
159+
expect(onSkip).toHaveBeenCalled()
160160
})
161161

162162
it('should not show onboarding if step !== currentStep', () => {

redisinsight/ui/src/components/onboarding-tour/OnboardingTour.tsx

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import React, { useEffect, useState } from 'react'
2-
3-
import { EuiTourStep } from '@elastic/eui'
42
import { useDispatch } from 'react-redux'
53
import cx from 'classnames'
64

@@ -16,7 +14,10 @@ import {
1614
PrimaryButton,
1715
SecondaryButton,
1816
} from 'uiSrc/components/base/forms/buttons'
19-
import { Text } from 'uiSrc/components/base/text'
17+
import { ColorText } from 'uiSrc/components/base/text'
18+
import { TourStep } from 'uiSrc/components/base/display/tour/TourStep'
19+
import { Col, Row } from 'uiSrc/components/base/layout/flex'
20+
import { Title } from 'uiSrc/components/base/text/Title'
2021
import { Props as OnboardingWrapperProps } from './OnboardingTourWrapper'
2122

2223
import styles from './styles.module.scss'
@@ -79,7 +80,7 @@ const OnboardingTour = (props: Props) => {
7980
}
8081

8182
const Header = (
82-
<div className={styles.header}>
83+
<Col className={styles.header}>
8384
{!isLastStep ? (
8485
<EmptyButton
8586
onClick={handleSkip}
@@ -99,24 +100,22 @@ const OnboardingTour = (props: Props) => {
99100
data-testid="close-tour-btn"
100101
/>
101102
)}
102-
<div className={styles.title} data-testid="step-title">
103+
<Title size="XS" data-testid="step-title">
103104
{title}
104-
</div>
105-
</div>
105+
</Title>
106+
</Col>
106107
)
107108

108109
const StepContent = (
109-
<>
110-
<div className={styles.content}>
111-
<Text>
112-
<div data-testid="step-content">{content}</div>
113-
</Text>
110+
<Col>
111+
<div className={styles.content} data-testid="step-content">
112+
{content}
114113
</div>
115-
<div className={styles.footer}>
116-
<Text color="subdued" className={styles.stepCount}>
114+
<Row className={styles.footer} align="center" justify="between">
115+
<ColorText color="subdued" className={styles.stepCount}>
117116
{currentStep} of {totalSteps}
118-
</Text>
119-
<div className={styles.backNext}>
117+
</ColorText>
118+
<Row grow={false} gap="m">
120119
{currentStep > 1 && (
121120
<SecondaryButton
122121
onClick={handleClickBack}
@@ -130,13 +129,12 @@ const OnboardingTour = (props: Props) => {
130129
onClick={handleClickNext}
131130
size="s"
132131
data-testid="next-btn"
133-
style={{ marginLeft: 8 }}
134132
>
135133
{!isLastStep ? 'Next' : 'Take me back'}
136134
</PrimaryButton>
137-
</div>
138-
</div>
139-
</>
135+
</Row>
136+
</Row>
137+
</Col>
140138
)
141139

142140
return (
@@ -147,28 +145,21 @@ const OnboardingTour = (props: Props) => {
147145
})}
148146
role="presentation"
149147
>
150-
<EuiTourStep
148+
<TourStep
151149
content={StepContent}
152-
decoration="none"
153-
isStepOpen={isOpen}
150+
open={isOpen}
154151
minWidth={300}
155-
onFinish={() => setIsOpen(false)}
156-
step={step}
157-
stepsTotal={totalSteps}
158-
title=""
159-
subtitle={Header}
160-
anchorPosition={anchorPosition}
161-
className={styles.popover}
162-
anchorClassName={styles.popoverAnchor}
163-
panelClassName={cx(styles.popoverPanel, panelClassName, {
152+
maxWidth={360}
153+
title={Header}
154+
placement={anchorPosition}
155+
className={cx(styles.popoverPanel, panelClassName, {
164156
[styles.lastStep]: isLastStep,
165157
})}
166-
zIndex={9999}
167158
offset={5}
168159
data-testid="onboarding-tour"
169160
>
170161
{children}
171-
</EuiTourStep>
162+
</TourStep>
172163
</div>
173164
)
174165
}

redisinsight/ui/src/components/onboarding-tour/styles.module.scss

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
.wrapper {
2-
&.fullSize {
3-
width: 100%;
4-
height: 100%;
5-
6-
:global {
7-
.euiPopover, .euiPopover__anchor {
8-
width: 100%;
9-
height: 100%;
10-
}
11-
}
12-
}
2+
&.fullSize {
3+
width: 100%;
4+
height: 100%;
5+
6+
:global {
7+
.euiPopover, .euiPopover__anchor {
8+
width: 100%;
9+
height: 100%;
10+
}
11+
}
12+
}
1313
}
1414

1515
.popoverPanel {
16-
position: fixed !important;
1716
background-color: var(--euiTooltipBackgroundColor) !important;
18-
border: 0 !important;
1917
max-width: 360px !important;
2018

21-
&.lastStep {
22-
:global(.euiPopover__panelArrow) {
23-
display: none;
24-
}
19+
&.lastStep > span {
20+
display: none;
2521
}
2622

2723
.header {
28-
display: flex;
29-
flex-direction: column;
30-
3124
.skipTourBtn {
3225
display: flex;
3326
align-self: flex-end;
@@ -73,16 +66,19 @@
7366
border-right-color: var(--euiTooltipBackgroundColor) !important;
7467
}
7568
}
69+
7670
&--left {
7771
&:before, &:after {
7872
border-left-color: var(--euiTooltipBackgroundColor) !important;
7973
}
8074
}
75+
8176
&--bottom {
8277
&:before, &:after {
8378
border-bottom-color: var(--euiTooltipBackgroundColor) !important;
8479
}
8580
}
81+
8682
&--top {
8783
&:before, &:after {
8884
border-top-color: var(--euiTooltipBackgroundColor) !important;

0 commit comments

Comments
 (0)