Skip to content

Commit e2ef64b

Browse files
author
Artyom Podymov
committed
#RI-2055 - save context for enablement area
1 parent 6739dc0 commit e2ef64b

File tree

19 files changed

+311
-45
lines changed

19 files changed

+311
-45
lines changed

redisinsight/ui/src/packages/enablement-area/enablement-area.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"id": "introduction",
2222
"label": "Introduction",
2323
"args": {
24-
"backTitle": "Document Capabilities",
2524
"path": "/static/workbench/guides/document-capabilities/introduction.html"
2625
}
2726
},
@@ -30,7 +29,6 @@
3029
"id": "working-with-hashes",
3130
"label": "Working with Hashes",
3231
"args": {
33-
"backTitle": "Document Capabilities",
3432
"path": "/static/workbench/guides/document-capabilities/working-with-hashes.html"
3533
}
3634
},
@@ -39,7 +37,6 @@
3937
"id": "working-with-json",
4038
"label": "Working with JSON",
4139
"args": {
42-
"backTitle": "Document Capabilities",
4340
"path": "/static/workbench/guides/document-capabilities/working-with-json.html"
4441
}
4542
},
@@ -48,7 +45,6 @@
4845
"id": "learn-more",
4946
"label": "Learn More",
5047
"args": {
51-
"backTitle": "Document Capabilities",
5248
"path": "/static/workbench/guides/document-capabilities/learn-more.html"
5349
}
5450
}

redisinsight/ui/src/packages/enablement-area/guides/document-capabilities/introduction.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ <h3>PRE-REQUISITES</h3>
6868
</p>
6969
</div>
7070
<div style="width: 100%" class="sticky-footer">
71-
<div style="width: 100%; margin-bottom: 12px">
71+
<div style="width: 100%">
7272
<InternalLink
7373
size="xs"
74-
backTitle="Document Capabilities"
7574
path="/static/workbench/guides/document-capabilities/working-with-hashes.html"
7675
label="Working with Hashes"
7776
iconType="arrowRight"

redisinsight/ui/src/packages/enablement-area/guides/document-capabilities/learn-more.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ <h3>Tutorials</h3>
3838
</div>
3939
</div>
4040
<div style="width: 100%" class="sticky-footer">
41-
<div style="width: 100%; margin-bottom: 12px">
41+
<div style="width: 100%;">
4242
<InternalLink
4343
size="xs"
44-
backTitle="Document Capabilities"
4544
path="/static/workbench/guides/document-capabilities/working-with-json.html"
4645
label="Working with JSON"
4746
iconType="arrowLeft"

redisinsight/ui/src/packages/enablement-area/guides/document-capabilities/working-with-hashes.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,10 @@
134134
</ol>
135135
</div>
136136
<div style="width: 100%" class="sticky-footer">
137-
<div style="width: 100%; display: flex; margin-bottom: 12px">
137+
<div style="width: 100%; display: flex;">
138138
<div style="width: 50%; border-right: 1px solid var(--separatorColor)">
139139
<InternalLink
140140
size="xs"
141-
backTitle="Document Capabilities"
142141
path="/static/workbench/guides/document-capabilities/introduction.html"
143142
label="Introduction"
144143
iconType="arrowLeft"
@@ -155,7 +154,6 @@
155154
<div style="width: 50%">
156155
<InternalLink
157156
size="xs"
158-
backTitle="Document Capabilities"
159157
path="/static/workbench/guides/document-capabilities/working-with-json.html"
160158
label="Working with JSON"
161159
iconType="arrowRight"

redisinsight/ui/src/packages/enablement-area/guides/document-capabilities/working-with-json.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@
128128
</ol>
129129
</div>
130130
<div style="width: 100%" class="sticky-footer">
131-
<div style="width: 100%; display: flex; margin-bottom: 12px">
131+
<div style="width: 100%; display: flex;">
132132
<div style="width: 50%; border-right: 1px solid var(--separatorColor)">
133133
<InternalLink
134134
size="xs"
135-
backTitle="Document Capabilities"
136135
path="/static/workbench/guides/document-capabilities/working-with-hashes.html"
137136
label="Working with Hashes"
138137
iconType="arrowLeft"
@@ -149,7 +148,6 @@
149148
<div style="width: 50%">
150149
<InternalLink
151150
size="xs"
152-
backTitle="Document Capabilities"
153151
path="/static/workbench/guides/document-capabilities/learn-more.html"
154152
label="Learn More"
155153
iconType="arrowRight"

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

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import React, { useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
2+
import { useHistory, useLocation } from 'react-router-dom'
3+
import { useSelector, useDispatch } from 'react-redux'
24
import cx from 'classnames'
35
import { EuiListGroup, EuiLoadingContent } from '@elastic/eui'
46
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'
57
import { EnablementAreaProvider, IInternalPage } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
8+
import { appContextWorkbenchEA, resetWorkbenchEAGuide } from 'uiSrc/slices/app/context'
69
import {
710
CodeButton,
811
Group,
@@ -22,27 +25,53 @@ export interface Props {
2225
openInternalPage: (page: IInternalPage) => void;
2326
}
2427

25-
const EnablementArea = ({ items, openScript, openInternalPage, loading }: Props) => {
28+
const EnablementArea = ({ items, openScript, loading }: Props) => {
29+
const { search } = useLocation()
30+
const history = useHistory()
31+
const dispatch = useDispatch()
32+
const { guidePath: guideFromContext } = useSelector(appContextWorkbenchEA)
2633
const [isInternalPageVisible, setIsInternalPageVisible] = useState(false)
27-
const [internalPage, setInternalPage] = useState<IInternalPage>(
28-
{ backTitle: '', path: '', label: '' }
29-
)
34+
const [internalPage, setInternalPage] = useState<IInternalPage>({ path: '' })
35+
36+
useEffect(() => {
37+
const pagePath = new URLSearchParams(search).get('guide')
38+
if (pagePath) {
39+
setIsInternalPageVisible(true)
40+
setInternalPage({ path: pagePath })
41+
} else if (guideFromContext) {
42+
handleOpenInternalPage({ path: guideFromContext })
43+
} else {
44+
setIsInternalPageVisible(false)
45+
}
46+
}, [search])
3047

3148
const handleOpenInternalPage = (page: IInternalPage) => {
32-
setIsInternalPageVisible(true)
33-
setInternalPage(page)
34-
openInternalPage(page)
49+
history.push({
50+
search: `?guide=${page.path}`
51+
})
3552
}
3653

3754
const handleCloseInternalPage = () => {
38-
setIsInternalPageVisible(false)
55+
dispatch(resetWorkbenchEAGuide())
56+
history.push({
57+
// TODO: better to use query-string parser and update only one parameter (instead of replacing all)
58+
search: ''
59+
})
3960
}
4061

4162
const renderSwitch = (item: IEnablementAreaItem) => {
4263
const { label, type, children, id, args } = item
4364
switch (type) {
4465
case EnablementAreaComponent.Group:
45-
return <Group testId={id || label} label={label} {...args}>{renderTreeView(children || [])}</Group>
66+
return (
67+
<Group
68+
testId={id}
69+
label={label}
70+
{...args}
71+
>
72+
{renderTreeView(children || [])}
73+
</Group>
74+
)
4675
case EnablementAreaComponent.CodeButton:
4776
return args?.path
4877
? <LazyCodeButton label={label} {...args} />
@@ -91,7 +120,6 @@ const EnablementArea = ({ items, openScript, openInternalPage, loading }: Props)
91120
{internalPage?.path && (
92121
<LazyInternalPage
93122
onClose={handleCloseInternalPage}
94-
backTitle={internalPage.backTitle}
95123
title={internalPage?.label}
96124
path={internalPage?.path}
97125
/>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export interface Props {
77
onClick: () => void;
88
label: string;
99
isLoading?: boolean;
10+
className?: string;
1011
}
11-
const CodeButton = ({ onClick, label, isLoading }: Props) => (
12+
const CodeButton = ({ onClick, label, isLoading, ...rest }: Props) => (
1213
<EuiButton
1314
iconSide="right"
1415
isLoading={isLoading}
@@ -19,6 +20,7 @@ const CodeButton = ({ onClick, label, isLoading }: Props) => (
1920
contentProps={{ className: styles.button }}
2021
textProps={{ className: styles.buttonText }}
2122
data-testid={`preselect-${label}`}
23+
{...rest}
2224
>
2325
{label}
2426
</EuiButton>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
3-
import { render } from 'uiSrc/utils/test-utils'
3+
import { fireEvent, render, screen } from 'uiSrc/utils/test-utils'
44
import Group, { Props } from './Group'
55

66
const mockedProps = mock<Props>()
@@ -20,6 +20,16 @@ describe('Group', () => {
2020
<Group {...instance(mockedProps)} testId={testId} label={label}>{children}</Group>
2121
)
2222
const accordionButton = queryByTestId(`accordion-button-${testId}`)
23+
2324
expect(accordionButton).toHaveTextContent(label)
2425
})
26+
it('should emit onToggle', () => {
27+
const callback = jest.fn()
28+
const label = 'Quick Guides'
29+
30+
render(<Group {...instance(mockedProps)} testId={testId} label={label} onToggle={callback} />)
31+
fireEvent.click(screen.getByTestId(`accordion-button-${testId}`))
32+
33+
expect(callback).toHaveBeenCalled()
34+
})
2535
})

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export interface Props {
1010
initialIsOpen?: boolean;
1111
forceState?: 'open' | 'closed';
1212
arrowDisplay?: 'left' | 'right' | 'none';
13+
onToggle?: (isOpen: boolean) => void;
1314
}
1415

1516
const Group = (props: Props) => {
16-
const { label, children, testId, forceState, withBorder = false, arrowDisplay = 'right', initialIsOpen = false } = props
17+
const { label, children, testId, forceState, withBorder = false, arrowDisplay = 'right', initialIsOpen = false, onToggle } = props
1718
const buttonContent = (
1819
<EuiText className="group-header" size="m">
1920
{label}
@@ -29,6 +30,7 @@ const Group = (props: Props) => {
2930
buttonProps={buttonProps}
3031
forceState={forceState}
3132
arrowDisplay={arrowDisplay}
33+
onToggle={onToggle}
3234
initialIsOpen={initialIsOpen}
3335
style={{ whiteSpace: 'nowrap', width: 'auto' }}
3436
className={[withBorder ? 'withBorder' : ''].join(' ')}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ export interface Props {
1111
label: string;
1212
children: React.ReactElement[] | string;
1313
path?: string,
14-
backTitle?: string;
1514
size?: 's' | 'xs' | 'm' | 'l';
1615
iconType?: string;
1716
iconPosition?: 'left' | 'right';
1817
toolTip?: string;
1918
}
2019
const InternalLink = (props: Props) => {
21-
const { label, testId, children, backTitle = '', path = '', size = 's', iconType, iconPosition = 'left', toolTip } = props
20+
const { label, testId, children, path = '', size = 's', iconType, iconPosition = 'left', toolTip } = props
2221
const { openPage } = useContext(EnablementAreaContext)
2322
const handleOpenPage = () => {
2423
if (path) {
25-
openPage({ path, label, backTitle: backTitle || label })
24+
openPage({ path, label })
2625
}
2726
}
2827

0 commit comments

Comments
 (0)