Skip to content

Commit e3aa9e4

Browse files
#RI-2450-add tutorials in workbench, enablement-area -> guides
1 parent 1cb88e0 commit e3aa9e4

File tree

24 files changed

+455
-117
lines changed

24 files changed

+455
-117
lines changed

redisinsight/ui/src/constants/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ enum ApiEndpoints {
4545
WORKBENCH_COMMAND_EXECUTIONS = 'workbench/command-executions',
4646

4747
REDIS_COMMANDS = 'commands',
48-
ENABLEMENT_AREA = 'static/workbench/enablement-area.json',
48+
GUIDES = 'static/workbench/guides/guides.json',
49+
// TODO double check it, when tutorials will be completed
50+
TUTORIALS = 'static/workbench/tutorials/tutorials.json',
4951
PLUGINS = 'plugins',
5052
STATE = 'state',
5153
CONTENT_CREATE_DATABASE = 'static/content/create-redis.json',
54+
ENABLEMENT_AREA_PATH = 'static/workbench/guides',
5255
}
5356

5457
export const DEFAULT_SEARCH_MATCH = '*'

redisinsight/ui/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export * from './workbenchResults'
1616
export * from './monitorEvents'
1717
export * from './socketEvents'
1818
export * from './mocks/mock-redis-commands'
19-
export * from './mocks/mock-enablement-area'
19+
export * from './mocks/mock-guides'
2020
export * from './socketErrors'
2121
export * from './browser'
2222
export { ApiEndpoints, BrowserStorageItem, ApiStatusCode, apiErrors }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'
2+
3+
export const MOCK_GUIDES_ITEMS: Record<string, IEnablementAreaItem> = {
4+
'quick-guides': {
5+
type: EnablementAreaComponent.Group,
6+
id: 'quick-guides',
7+
label: 'Quick Guides',
8+
children: {
9+
'document-capabilities': {
10+
type: EnablementAreaComponent.InternalLink,
11+
id: 'document-capabilities',
12+
label: 'Document Capabilities',
13+
args: {
14+
path: '/static/workbench/quick-guides/document/learn-more.md',
15+
},
16+
},
17+
'working-with-json': {
18+
type: EnablementAreaComponent.InternalLink,
19+
id: 'working-with-json',
20+
label: 'Working with JSON',
21+
args: {
22+
path: 'quick-guides/working-with-json.html',
23+
},
24+
},
25+
'working-with-hash': {
26+
type: EnablementAreaComponent.InternalLink,
27+
id: 'working-with-hash',
28+
label: 'Working with HASH',
29+
args: {
30+
path: 'quick-guides/working-with-hash.html',
31+
},
32+
}
33+
}
34+
},
35+
'internal-page': {
36+
type: EnablementAreaComponent.InternalLink,
37+
id: 'internal-page',
38+
label: 'Internal Page',
39+
args: {
40+
path: 'quick-guides/document-capabilities.html'
41+
},
42+
},
43+
'second-internal-page': {
44+
type: EnablementAreaComponent.InternalLink,
45+
id: 'second-internal-page',
46+
label: 'Second Internal Page',
47+
args: {
48+
path: 'quick-guides/document-capabilities.html'
49+
},
50+
},
51+
manual: {
52+
type: EnablementAreaComponent.CodeButton,
53+
id: 'manual',
54+
label: 'Manual',
55+
args: {
56+
path: '_scripts/manual.txt'
57+
},
58+
}
59+
}

redisinsight/ui/src/constants/mocks/mock-enablement-area.ts renamed to redisinsight/ui/src/constants/mocks/mock-tutorials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'
22

3-
export const MOCK_ENABLEMENT_AREA_ITEMS: Record<string, IEnablementAreaItem> = {
3+
export const MOCK_TUTORIALS_ITEMS: Record<string, IEnablementAreaItem> = {
44
'quick-guides': {
55
type: EnablementAreaComponent.Group,
66
id: 'quick-guides',

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import { cloneDeep } from 'lodash'
33
import { instance, mock } from 'ts-mockito'
44
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
5-
import { MOCK_ENABLEMENT_AREA_ITEMS } from 'uiSrc/constants'
5+
import { MOCK_GUIDES_ITEMS } from 'uiSrc/constants'
66
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'
77

88
import EnablementArea, { Props } from './EnablementArea'
@@ -17,19 +17,19 @@ beforeEach(() => {
1717
store.clearActions()
1818
})
1919

20-
jest.mock('uiSrc/slices/workbench/wb-enablement-area', () => {
21-
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-enablement-area').initialState
20+
jest.mock('uiSrc/slices/workbench/wb-guides', () => {
21+
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-guides').initialState
2222
return {
23-
...jest.requireActual('uiSrc/slices/workbench/wb-enablement-area'),
24-
workbenchEnablementAreaSelector: jest.fn().mockReturnValue({
23+
...jest.requireActual('uiSrc/slices/workbench/wb-guides'),
24+
workbenchGuidesSelector: jest.fn().mockReturnValue({
2525
...defaultState,
2626
}),
2727
}
2828
})
2929

3030
describe('EnablementArea', () => {
3131
it('should render', () => {
32-
expect(render(<EnablementArea {...instance(mockedProps)} items={MOCK_ENABLEMENT_AREA_ITEMS} />))
32+
expect(render(<EnablementArea {...instance(mockedProps)} items={MOCK_GUIDES_ITEMS} />))
3333
.toBeTruthy()
3434
})
3535

@@ -46,15 +46,15 @@ describe('EnablementArea', () => {
4646
const { queryByTestId } = render(
4747
<EnablementArea
4848
{...instance(mockedProps)}
49-
items={MOCK_ENABLEMENT_AREA_ITEMS}
49+
items={MOCK_GUIDES_ITEMS}
5050
/>
5151
)
5252
const loaderEl = queryByTestId('enablementArea-loader')
5353
const treeViewEl = queryByTestId('enablementArea-treeView')
5454

5555
expect(loaderEl).not.toBeInTheDocument()
5656
expect(treeViewEl).toBeInTheDocument()
57-
expect(treeViewEl?.childNodes.length).toEqual(Object.values(MOCK_ENABLEMENT_AREA_ITEMS).length)
57+
expect(treeViewEl?.childNodes.length).toEqual(Object.values(MOCK_GUIDES_ITEMS).length)
5858
})
5959
it('should render Group component', () => {
6060
const item: IEnablementAreaItem = {

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EuiListGroup, EuiLoadingContent } from '@elastic/eui'
66
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'
77
import { EnablementAreaProvider, IInternalPage } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
88
import { appContextWorkbenchEA, resetWorkbenchEAGuide } from 'uiSrc/slices/app/context'
9+
import { ApiEndpoints } from 'uiSrc/constants'
910
import {
1011
CodeButton,
1112
Group,
@@ -36,22 +37,23 @@ const EnablementArea = ({ items, openScript, loading, onOpenInternalPage, isCode
3637
const [internalPage, setInternalPage] = useState<IInternalPage>({ path: '' })
3738

3839
useEffect(() => {
39-
const pagePath = new URLSearchParams(search).get('guide')
40+
const pagePath = new URLSearchParams(search).get('item')
4041
if (pagePath) {
4142
setIsInternalPageVisible(true)
42-
setInternalPage({ path: pagePath })
43+
setInternalPage({ path: `${ApiEndpoints.ENABLEMENT_AREA_PATH}/${pagePath}` })
44+
4345
return
4446
}
4547
if (guideFromContext) {
46-
handleOpenInternalPage({ path: guideFromContext })
48+
handleOpenInternalPage({ path: `${ApiEndpoints.ENABLEMENT_AREA_PATH}/${guideFromContext}` })
4749
return
4850
}
4951
setIsInternalPageVisible(false)
5052
}, [search])
5153

5254
const handleOpenInternalPage = (page: IInternalPage) => {
5355
history.push({
54-
search: `?guide=${page.path}`
56+
search: `?item=${page.path}`
5557
})
5658
onOpenInternalPage(page)
5759
}
@@ -76,11 +78,15 @@ const EnablementArea = ({ items, openScript, loading, onOpenInternalPage, isCode
7678
)
7779
case EnablementAreaComponent.CodeButton:
7880
return (
79-
<div style={{ marginTop: '12px', ...paddingsStyle }}>
80-
{args?.path
81-
? <LazyCodeButton label={label} {...args} />
82-
: <CodeButton onClick={() => openScript(args?.content || '')} label={label} {...args} />}
83-
</div>
81+
<>
82+
<div style={paddingsStyle} className="divider"><hr /></div>
83+
<div style={{ marginTop: '24px', ...paddingsStyle }}>
84+
{args?.path
85+
? <LazyCodeButton label={label} {...args} />
86+
: <CodeButton onClick={() => openScript(args?.content || '')} label={label} {...args} />}
87+
</div>
88+
</>
89+
8490
)
8591
case EnablementAreaComponent.InternalLink:
8692
return (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Code = ({ children, ...rest }: Props) => {
1717
const { setScript, isCodeBtnDisabled } = useContext(EnablementAreaContext)
1818

1919
const loadContent = () => {
20-
const pagePath = new URLSearchParams(search).get('guide')
20+
const pagePath = new URLSearchParams(search).get('item')
2121
if (pagePath) {
2222
const pageInfo = getFileInfo(pagePath)
2323
setScript(children, `${pageInfo.location}/${pageInfo.name}`, startCase(rest.label))

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ const Group = (props: Props) => {
4949
style={{ whiteSpace: 'nowrap', width: 'auto' }}
5050
className={[withBorder ? 'withBorder' : ''].join(' ')}
5151
>
52-
<>
53-
{children}
54-
{withBorder && <div style={triggerStyle} className="divider"><hr /></div> }
55-
</>
52+
{children}
5653
</EuiAccordion>
5754
)
5855
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getApiErrorMessage, isStatusSuccessful } from 'uiSrc/utils'
55
import { resourcesService } from 'uiSrc/services'
66
import EnablementAreaContext from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
77
import { getFileInfo } from 'uiSrc/pages/workbench/components/enablement-area/EnablementArea/utils/getFileInfo'
8+
import { ApiEndpoints } from 'uiSrc/constants'
89

910
import CodeButton from '../CodeButton'
1011

@@ -22,7 +23,7 @@ const LazyCodeButton = ({ path = '', ...rest }: Props) => {
2223
setLoading(true)
2324
setError('')
2425
try {
25-
const { data, status } = await resourcesService.get<string>(path)
26+
const { data, status } = await resourcesService.get<string>(`${ApiEndpoints.ENABLEMENT_AREA_PATH}/${path}`)
2627
if (isStatusSuccessful(status)) {
2728
setLoading(false)
2829
const pageInfo = getFileInfo(path)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
setWorkbenchEAGuideScrollTop
1515
} from 'uiSrc/slices/app/context'
1616
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
17-
import { workbenchEnablementAreaSelector } from 'uiSrc/slices/workbench/wb-enablement-area'
17+
import { workbenchGuidesSelector } from 'uiSrc/slices/workbench/wb-guides'
1818

1919
import InternalPage from '../InternalPage'
2020
import { getFileInfo, getPagesInsideGroup, IFileInfo } from '../../utils/getFileInfo'
@@ -35,7 +35,7 @@ export interface Props {
3535
const LazyInternalPage = ({ onClose, title, path }: Props) => {
3636
const history = useHistory()
3737
const { guideScrollTop } = useSelector(appContextWorkbenchEA)
38-
const enablementArea = useSelector(workbenchEnablementAreaSelector)
38+
const guides = useSelector(workbenchGuidesSelector)
3939
const [isLoading, setLoading] = useState<boolean>(false)
4040
const [error, setError] = useState<string>('')
4141
const [pageData, setPageData] = useState<IPageData>(DEFAULT_PAGE_DATA)
@@ -46,7 +46,7 @@ const LazyInternalPage = ({ onClose, title, path }: Props) => {
4646
setLoading(true)
4747
setError('')
4848
const pageInfo = getFileInfo(path)
49-
const relatedPages = getPagesInsideGroup(enablementArea.items, pageInfo.location)
49+
const relatedPages = getPagesInsideGroup(guides.items, pageInfo.location)
5050
setPageData({ ...DEFAULT_PAGE_DATA, ...pageInfo, relatedPages })
5151
try {
5252
const formatter = FormatSelector.selectFor(pageInfo.extension)
@@ -67,11 +67,11 @@ const LazyInternalPage = ({ onClose, title, path }: Props) => {
6767

6868
useEffect(() => {
6969
(async function () {
70-
if (!enablementArea.loading) {
70+
if (!guides.loading) {
7171
await loadContent()
7272
}
7373
}())
74-
}, [path, enablementArea.loading])
74+
}, [path, guides.loading])
7575

7676
const handlePageScroll = (top: number) => {
7777
dispatch(setWorkbenchEAGuideScrollTop(top))
@@ -84,7 +84,7 @@ const LazyInternalPage = ({ onClose, title, path }: Props) => {
8484
onClose={onClose}
8585
title={startCase(title || pageData.name)}
8686
backTitle={startCase(pageData?.parent)}
87-
isLoading={isLoading || enablementArea.loading}
87+
isLoading={isLoading || guides.loading}
8888
content={pageData.content}
8989
error={error}
9090
onScroll={handlePageScroll}

0 commit comments

Comments
 (0)