Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions redisinsight/ui/src/components/config/Config.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { appServerInfoSelector, getServerInfo } from 'uiSrc/slices/app/info'
import { processCliClient } from 'uiSrc/slices/cli/cli-settings'
import { getRedisCommands } from 'uiSrc/slices/app/redis-commands'
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
import { getWBGuides } from 'uiSrc/slices/workbench/wb-guides'
import { getWBTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
import { getContentRecommendations } from 'uiSrc/slices/recommendations/recommendations'
import { getGuideLinks } from 'uiSrc/slices/content/guide-links'
Expand Down Expand Up @@ -68,7 +67,6 @@ describe('Config', () => {
getNotifications(),
getContentRecommendations(),
getGuideLinks(),
getWBGuides(),
getWBTutorials(),
getWBCustomTutorials(),
getFeatureFlags(),
Expand Down Expand Up @@ -106,7 +104,6 @@ describe('Config', () => {
getNotifications(),
getContentRecommendations(),
getGuideLinks(),
getWBGuides(),
getWBTutorials(),
getWBCustomTutorials(),
getFeatureFlags(),
Expand Down
4 changes: 1 addition & 3 deletions redisinsight/ui/src/components/config/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { setFavicon, isDifferentConsentsExists } from 'uiSrc/utils'
import { fetchUnsupportedCliCommandsAction } from 'uiSrc/slices/cli/cli-settings'
import { fetchRedisCommandsInfo } from 'uiSrc/slices/app/redis-commands'
import { fetchGuides } from 'uiSrc/slices/workbench/wb-guides'
import { fetchTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
import { fetchCustomTutorials } from 'uiSrc/slices/workbench/wb-custom-tutorials'
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
Expand Down Expand Up @@ -52,8 +51,7 @@ const Config = () => {
dispatch(fetchContentRecommendations())
dispatch(fetchGuideLinksAction())

// get guides & tutorials
dispatch(fetchGuides())
// get tutorials
dispatch(fetchTutorials())
dispatch(fetchCustomTutorials())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jest.mock('uiSrc/telemetry', () => ({

jest.mock('uiSrc/utils', () => ({
...jest.requireActual('uiSrc/utils'),
getTutorialCapability: jest.fn().mockReturnValue({ tutorialPage: { id: 'id' }, telemetryName: 'searchAndQuery' }),
getTutorialCapability: jest.fn().mockReturnValue({ path: 'path', telemetryName: 'searchAndQuery' }),
}))

jest.mock('uiSrc/services', () => ({
Expand Down Expand Up @@ -243,6 +243,8 @@ describe('DatabaseSidePanels', () => {
render(<DatabaseSidePanels />)

const expectedActions = [
resetExplorePanelSearch(),
setExplorePanelIsPageOpen(false),
changeSelectedTab(InsightsPanelTabs.Explore),
toggleInsightsPanel(true),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FullScreen, OnboardingTour } from 'uiSrc/components'
import { appContextCapability } from 'uiSrc/slices/app/context'
import { getTutorialCapability } from 'uiSrc/utils'
import { isShowCapabilityTutorialPopover } from 'uiSrc/services'
import { EAManifestFirstKey } from 'uiSrc/constants'
import LiveTimeRecommendations from './panels/live-time-recommendations'
import EnablementAreaWrapper from './panels/enablement-area'

Expand Down Expand Up @@ -63,12 +64,12 @@ const DatabaseSidePanels = (props: Props) => {
return
}

const tutorialCapabilityPath = getTutorialCapability(capabilitySource)?.tutorialPage?.args?.path || ''
const tutorialCapabilityPath = getTutorialCapability(capabilitySource)?.path || ''

// set 'guidPath' with the path to capability tutorial
// set 'path' with the path to capability tutorial
if (tutorialCapabilityPath) {
const search = new URLSearchParams(window.location.search)
search.set('guidePath', tutorialCapabilityPath)
search.set('path', `${EAManifestFirstKey.TUTORIALS}/${tutorialCapabilityPath}`)
history.push({ search: search.toString() })
} else {
// reset explore if tutorial is not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
import { instance, mock } from 'ts-mockito'
import reactRouterDom from 'react-router-dom'
import { cleanup, mockedStore, render, screen, fireEvent, act, waitFor } from 'uiSrc/utils/test-utils'
import { MOCK_GUIDES_ITEMS, MOCK_TUTORIALS_ITEMS, MOCK_CUSTOM_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { MOCK_TUTORIALS_ITEMS, MOCK_CUSTOM_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'

import {
Expand Down Expand Up @@ -36,11 +36,11 @@ jest.mock('uiSrc/slices/workbench/wb-custom-tutorials', () => ({
)
}))

jest.mock('uiSrc/slices/workbench/wb-guides', () => {
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-guides').initialState
jest.mock('uiSrc/slices/workbench/wb-tutorials', () => {
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-tutorials').initialState
return {
...jest.requireActual('uiSrc/slices/workbench/wb-guides'),
workbenchGuidesSelector: jest.fn().mockReturnValue({
...jest.requireActual('uiSrc/slices/workbench/wb-tutorials'),
workbenchTutorialsSelector: jest.fn().mockReturnValue({
...defaultState,
}),
}
Expand All @@ -59,7 +59,6 @@ describe('EnablementArea', () => {
it('should render', () => {
expect(render(<EnablementArea
{...instance(mockedProps)}
guides={MOCK_GUIDES_ITEMS}
tutorials={MOCK_TUTORIALS_ITEMS}
/>))
.toBeTruthy()
Expand Down Expand Up @@ -94,7 +93,7 @@ describe('EnablementArea', () => {
const { queryByTestId } = render(
<EnablementArea
{...instance(mockedProps)}
guides={[item]}
tutorials={[item]}
/>
)

Expand All @@ -114,26 +113,30 @@ describe('EnablementArea', () => {
const { queryByTestId } = render(
<EnablementArea
{...instance(mockedProps)}
guides={[item]}
tutorials={[item]}
/>
)

expect(queryByTestId('internal-link-internal-page')).toBeInTheDocument()
})

it('should find guide and push proper search path', async () => {
const search = '?guidePath=/quick-guides/working-with-json.html'
const search = '?guidePath=quick-guides/working-with-json.html'

const pushMock = jest.fn()
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock })
reactRouterDom.useLocation = jest.fn().mockImplementationOnce(() => ({ search }))

await act(() => {
render(<EnablementArea {...instance(mockedProps)} guides={MOCK_GUIDES_ITEMS} onOpenInternalPage={jest.fn} />)
render(<EnablementArea
{...instance(mockedProps)}
tutorials={MOCK_TUTORIALS_ITEMS}
onOpenInternalPage={jest.fn}
/>)
})

await waitFor(() => {
expect(pushMock).toBeCalledWith({ search: '?path=quick-guides/0/1' })
expect(pushMock).toBeCalledWith({ search: '?path=tutorials/0/1' })
}, { timeout: 1000 })
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isEmpty } from 'lodash'
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
import { EnablementAreaProvider, IInternalPage } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
import { ApiEndpoints, EAManifestFirstKey, CodeButtonParams } from 'uiSrc/constants'
import { findMarkdownPathByPath, Nullable } from 'uiSrc/utils'
import { findMarkdownPath, Nullable } from 'uiSrc/utils'
import {
explorePanelSelector,
resetExplorePanelSearch,
Expand All @@ -27,7 +27,6 @@ import {
import styles from './styles.module.scss'

export interface Props {
guides: IEnablementAreaItem[]
tutorials: IEnablementAreaItem[]
customTutorials: IEnablementAreaItem[]
loading: boolean
Expand All @@ -42,7 +41,6 @@ export interface Props {

const EnablementArea = (props: Props) => {
const {
guides = [],
tutorials = [],
customTutorials = [],
openScript,
Expand Down Expand Up @@ -75,37 +73,35 @@ const EnablementArea = (props: Props) => {
}, [search])

useEffect(() => {
// handle guidePath search param
const guidePathParam = new URLSearchParams(search).get('guidePath')
if (guidePathParam) {
const guidesPath = findMarkdownPathByPath(guides, guidePathParam)
// handle guidePath or tutorialId search params
const tutorialPathParam = new URLSearchParams(search).get('guidePath') ?? ''
const tutorialIdParam = new URLSearchParams(search).get('tutorialId') ?? ''
if (tutorialPathParam || tutorialIdParam) {
let manifestPath = ''
const options = tutorialIdParam ? { id: tutorialIdParam } : { mdPath: tutorialPathParam }
const tutorialPath = findMarkdownPath(tutorials, options)

if (guidesPath) {
manifestPath = `${EAManifestFirstKey.GUIDES}/${guidesPath}`
}

const tutorialsPath = findMarkdownPathByPath(tutorials, guidePathParam)
if (tutorialsPath) {
manifestPath = `${EAManifestFirstKey.TUTORIALS}/${tutorialsPath}`
if (tutorialPath) {
manifestPath = `${EAManifestFirstKey.TUTORIALS}/${tutorialPath}`
}

if (manifestPath) {
handleOpenInternalPage({ path: '', manifestPath }, false)
}
}
}, [search, tutorials, guides])
}, [search, tutorials])

useEffect(() => {
const searchParams = new URLSearchParams(search)
const searchContextParams = new URLSearchParams(searchEAContext)

const manifestPath = searchParams.get('path')
const guidePath = searchParams.get('guidePath')
const tutorialId = searchParams.get('tutorialId')
const contextManifestPath = searchContextParams.get('path')
const { manifest, prefixFolder } = getManifestByPath(manifestPath)

if (guidePath || (isEmpty(manifest) && !contextManifestPath)) {
if (guidePath || tutorialId || (isEmpty(manifest) && !contextManifestPath)) {
return
}

Expand All @@ -124,7 +120,7 @@ const EnablementArea = (props: Props) => {
}

dispatch(setExplorePanelIsPageOpen(false))
}, [search, customTutorials, guides, tutorials])
}, [search, customTutorials, tutorials])

const getManifestByPath = (path: Nullable<string> = '') => {
const manifestPath = path?.replace(/^\//, '') || ''
Expand All @@ -134,9 +130,6 @@ const EnablementArea = (props: Props) => {
if (manifestPath.startsWith(EAManifestFirstKey.TUTORIALS)) {
return ({ manifest: tutorials, prefixFolder: ApiEndpoints.TUTORIALS_PATH })
}
if (manifestPath.startsWith(EAManifestFirstKey.GUIDES)) {
return ({ manifest: guides, prefixFolder: ApiEndpoints.GUIDES_PATH })
}

return { manifest: null }
}
Expand Down Expand Up @@ -175,7 +168,6 @@ const EnablementArea = (props: Props) => {
: (
<Navigation
tutorials={tutorials}
guides={guides}
customTutorials={customTutorials}
isInternalPageVisible={isInternalPageVisible}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jest.mock('uiSrc/services', () => ({

jest.mock('uiSrc/utils', () => ({
...jest.requireActual('uiSrc/utils'),
getTutorialCapability: jest.fn().mockReturnValue({ tutorialPage: { id: 'id' }, telemetryName: 'searchAndQuery' }),
getTutorialCapability: jest.fn().mockReturnValue({ path: 'path', telemetryName: 'searchAndQuery' }),
}))

jest.mock('uiSrc/slices/instances/instances', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const InternalPage = (props: Props) => {
}

useEffect(() => {
if (isShowCapabilityTutorialPopover(free) && !!tutorialCapability?.tutorialPage?.id) {
if (isShowCapabilityTutorialPopover(free) && !!tutorialCapability?.path) {
setShowCapabilityPopover(true)
setCapabilityPopoverShown()
sendEventTelemetry({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getApiErrorMessage, isStatusSuccessful, Nullable } from 'uiSrc/utils'
import { resourcesService } from 'uiSrc/services'
import { IS_ABSOLUTE_PATH } from 'uiSrc/constants/regex'
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
import { workbenchGuidesSelector } from 'uiSrc/slices/workbench/wb-guides'
import { workbenchTutorialsSelector } from 'uiSrc/slices/workbench/wb-tutorials'
import { workbenchCustomTutorialsSelector } from 'uiSrc/slices/workbench/wb-custom-tutorials'

Expand Down Expand Up @@ -53,7 +52,6 @@ const LazyInternalPage = ({
}: Props) => {
const history = useHistory()
const { itemScrollTop, data: contentContext, url } = useSelector(explorePanelSelector)
const { loading: guidesLoading } = useSelector(workbenchGuidesSelector)
const { loading: tutorialsLoading } = useSelector(workbenchTutorialsSelector)
const { loading: customTutorialsLoading } = useSelector(workbenchCustomTutorialsSelector)
const [isLoading, setLoading] = useState<boolean>(false)
Expand All @@ -75,7 +73,7 @@ const LazyInternalPage = ({
startLoadContent()
}, [path, sourcePath])

const isMarkdownLoading = isLoading || guidesLoading || tutorialsLoading || customTutorialsLoading
const isMarkdownLoading = isLoading || tutorialsLoading || customTutorialsLoading
const getRelatedPages = () => (manifest ? getPagesInsideGroup(manifest, manifestPath) : [])
const loadContent = async () => {
setLoading(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react'
import { render, screen } from 'uiSrc/utils/test-utils'

import { MOCK_CUSTOM_TUTORIALS_ITEMS, MOCK_GUIDES_ITEMS, MOCK_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { MOCK_CUSTOM_TUTORIALS_ITEMS, MOCK_TUTORIALS_ITEMS } from 'uiSrc/constants'
import Navigation from './Navigation'

const guides = {
guides: MOCK_GUIDES_ITEMS,
tutorials: MOCK_TUTORIALS_ITEMS,
customTutorials: MOCK_CUSTOM_TUTORIALS_ITEMS
}
Expand All @@ -18,7 +17,6 @@ describe('Navigation', () => {
it('should render navigation groups', () => {
render(<Navigation {...guides} isInternalPageVisible />)

expect(screen.queryByTestId('accordion-quick-guides')).toBeInTheDocument()
expect(screen.queryByTestId('accordion-tutorials')).toBeInTheDocument()
expect(screen.queryByTestId('accordion-custom-tutorials')).toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import styles from './styles.module.scss'
const padding = parseInt(styles.paddingHorizontal)

export interface Props {
guides: IEnablementAreaItem[]
tutorials: IEnablementAreaItem[]
customTutorials: IEnablementAreaItem[]
isInternalPageVisible: boolean
Expand All @@ -40,7 +39,7 @@ const PATHS = {
}

const Navigation = (props: Props) => {
const { guides, tutorials, customTutorials, isInternalPageVisible } = props
const { tutorials, customTutorials, isInternalPageVisible } = props

const [isCreateOpen, setIsCreateOpen] = useState(false)

Expand Down Expand Up @@ -171,7 +170,6 @@ const Navigation = (props: Props) => {
flush
className={cx(styles.innerContainer)}
>
{guides && renderTreeView(getManifestItems(guides), PATHS.guides)}
{tutorials && renderTreeView(getManifestItems(tutorials), PATHS.tutorials)}
{customTutorials && renderTreeView(getManifestItems(customTutorials), PATHS.customTutorials)}
</EuiListGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { act } from '@testing-library/react'
import React from 'react'
import { fireEvent, render, screen } from 'uiSrc/utils/test-utils'
import { ApiEndpoints, MOCK_GUIDES_ITEMS } from 'uiSrc/constants'
import { ApiEndpoints, MOCK_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { defaultValue, EnablementAreaProvider } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
import { EnablementAreaComponent } from 'uiSrc/slices/interfaces'

import Pagination from './Pagination'

const paginationItems = MOCK_GUIDES_ITEMS[0]?.children
const paginationItems = MOCK_TUTORIALS_ITEMS[0]?.children
?.map((item, index) => ({ ...item, _key: `${index}` }))
?.filter((item) => item.type === EnablementAreaComponent.InternalLink)
|| []
Expand Down
Loading