Skip to content

Commit 2e03e37

Browse files
authored
Merge pull request #2966 from RedisInsight/fe/bugfix/RI-5343
#RI-5343 - handle loading pages when restoring from context
2 parents 6efb016 + 5b33b4c commit 2e03e37

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

redisinsight/ui/src/components/database-side-panels/panels/enablement-area/EnablementArea/EnablementArea.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ describe('EnablementArea', () => {
165165

166166
it('should call proper actions after upload form submit', async () => {
167167
render(<EnablementArea {...instance(mockedProps)} customTutorials={MOCK_CUSTOM_TUTORIALS_ITEMS} />)
168+
169+
const afterRenderActions = [...store.getActions()]
170+
168171
fireEvent.click(screen.getByTestId('open-upload-tutorial-btn'))
169172

170173
await act(() => {
@@ -178,16 +181,18 @@ describe('EnablementArea', () => {
178181
fireEvent.click(screen.getByTestId('submit-upload-tutorial-btn'))
179182
})
180183

181-
const expectedActions = [uploadWbCustomTutorial()]
184+
const expectedActions = [...afterRenderActions, uploadWbCustomTutorial()]
182185
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
183186
})
184187

185188
it('should render delete button and call proper actions after click on delete', () => {
186189
render(<EnablementArea {...instance(mockedProps)} customTutorials={MOCK_CUSTOM_TUTORIALS_ITEMS} />)
190+
const afterRenderActions = [...store.getActions()]
191+
187192
fireEvent.click(screen.getByTestId('delete-tutorial-icon-12mfp-rem'))
188193
fireEvent.click(screen.getByTestId('delete-tutorial-12mfp-rem'))
189194

190-
const expectedActions = [deleteWbCustomTutorial()]
195+
const expectedActions = [...afterRenderActions, deleteWbCustomTutorial()]
191196
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
192197
})
193198

redisinsight/ui/src/components/database-side-panels/panels/enablement-area/EnablementArea/EnablementArea.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useHistory, useLocation } from 'react-router-dom'
33
import { useSelector, useDispatch } from 'react-redux'
44
import cx from 'classnames'
55
import { EuiLoadingContent } from '@elastic/eui'
6-
import { isEmpty } from 'lodash'
76
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
87
import { EnablementAreaProvider, IInternalPage } from 'uiSrc/pages/workbench/contexts/enablementAreaContext'
98
import { ApiEndpoints, EAManifestFirstKey, CodeButtonParams } from 'uiSrc/constants'
@@ -87,31 +86,38 @@ const EnablementArea = (props: Props) => {
8786

8887
if (manifestPath) {
8988
handleOpenInternalPage({ path: '', manifestPath }, false)
89+
return
9090
}
91+
92+
dispatch(setExplorePanelIsPageOpen(false))
9193
}
9294
}, [search, tutorials])
9395

9496
useEffect(() => {
9597
const searchParams = new URLSearchParams(search)
96-
const searchContextParams = new URLSearchParams(searchEAContext)
9798

98-
const manifestPath = searchParams.get('path')
9999
const guidePath = searchParams.get('guidePath')
100100
const tutorialId = searchParams.get('tutorialId')
101-
const contextManifestPath = searchContextParams.get('path')
102-
const { manifest, prefixFolder } = getManifestByPath(manifestPath)
101+
const itemPath = searchParams.get('item')
103102

104-
if (guidePath || tutorialId || (isEmpty(manifest) && !contextManifestPath)) {
103+
// if we have guidePath or tutorialId another useUffect handle it
104+
if (guidePath || tutorialId || itemPath) {
105105
return
106106
}
107107

108-
dispatch(setExplorePanelManifest(manifest))
109-
108+
// otherwise we handle path from url or from the context
109+
const manifestPath = searchParams.get('path')
110110
if (manifestPath) {
111+
const { manifest, prefixFolder } = getManifestByPath(manifestPath)
111112
const path = getMarkdownPathByManifest(manifest, manifestPath, prefixFolder)
112-
dispatch(setExplorePanelIsPageOpen(true))
113-
setInternalPage({ path, manifestPath })
114-
return
113+
114+
if (path) {
115+
dispatch(setExplorePanelIsPageOpen(true))
116+
dispatch(setExplorePanelManifest(manifest))
117+
118+
setInternalPage({ path, manifestPath })
119+
return
120+
}
115121
}
116122

117123
if (contextManifestPath) {

0 commit comments

Comments
 (0)