Skip to content

Commit 592377b

Browse files
committed
#RI-6345 - fix tutorials state after uploading, hide upload button when collapsed
1 parent c150983 commit 592377b

File tree

4 files changed

+112
-8
lines changed

4 files changed

+112
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const Group = (props: Props) => {
7979

8080
const actionsContent = (
8181
<>
82-
{actions?.includes(EAItemActions.Create) && (
82+
{actions?.includes(EAItemActions.Create) && isGroupOpen && (
8383
<OnboardingTour
8484
options={ONBOARDING_FEATURES.EXPLORE_CUSTOM_TUTORIALS}
8585
anchorPosition="downLeft"

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import cx from 'classnames'
33
import { EuiListGroup } from '@elastic/eui'
44
import { isArray } from 'lodash'
@@ -8,7 +8,11 @@ import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/inter
88

99
import { ApiEndpoints, EAItemActions, EAManifestFirstKey } from 'uiSrc/constants'
1010
import { sendEventTelemetry, TELEMETRY_EMPTY_VALUE, TelemetryEvent } from 'uiSrc/telemetry'
11-
import { deleteCustomTutorial, uploadCustomTutorial } from 'uiSrc/slices/workbench/wb-custom-tutorials'
11+
import {
12+
deleteCustomTutorial,
13+
setWbCustomTutorialsState,
14+
uploadCustomTutorial
15+
} from 'uiSrc/slices/workbench/wb-custom-tutorials'
1216

1317
import UploadWarning from 'uiSrc/components/upload-warning'
1418
import {
@@ -47,6 +51,10 @@ const Navigation = (props: Props) => {
4751
const dispatch = useDispatch()
4852
const { instanceId = '' } = useParams<{ instanceId: string }>()
4953

54+
useEffect(() => () => {
55+
dispatch(setWbCustomTutorialsState())
56+
}, [])
57+
5058
const submitCreate = ({ file, link }: FormValues) => {
5159
const formData = new FormData()
5260

@@ -66,7 +74,10 @@ const Navigation = (props: Props) => {
6674

6775
dispatch(uploadCustomTutorial(
6876
formData,
69-
() => setIsCreateOpen(false),
77+
() => {
78+
setIsCreateOpen(false)
79+
dispatch(setWbCustomTutorialsState(true))
80+
},
7081
))
7182
}
7283

redisinsight/ui/src/slices/tests/workbench/wb-custom-tutorials.spec.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import reducer, {
2828
uploadDataBulkFailed,
2929
uploadDataBulkAction,
3030
defaultItems,
31+
setWbCustomTutorialsState,
3132
} from '../../workbench/wb-custom-tutorials'
3233

3334
let store: typeof mockedStore
@@ -371,6 +372,85 @@ describe('slices', () => {
371372

372373
expect(workbenchCustomTutorialsSelector(rootState)).toEqual(state)
373374
})
375+
376+
describe('setWbCustomTutorialsState', () => {
377+
it('should properly set open state', () => {
378+
// Arrange
379+
const currentState = {
380+
...initialState,
381+
items: [{
382+
...defaultItems[0],
383+
args: {
384+
initialIsOpen: false
385+
},
386+
children: MOCK_TUTORIALS_ITEMS
387+
}]
388+
}
389+
390+
const state = {
391+
...initialState,
392+
items: [{
393+
...defaultItems[0],
394+
args: {
395+
defaultInitialIsOpen: false,
396+
initialIsOpen: true
397+
},
398+
children: MOCK_TUTORIALS_ITEMS
399+
}]
400+
}
401+
402+
// Act
403+
const nextState = reducer(currentState, setWbCustomTutorialsState(true))
404+
405+
// Assert
406+
const rootState = Object.assign(initialStateDefault, {
407+
workbench: {
408+
customTutorials: nextState,
409+
},
410+
})
411+
412+
expect(workbenchCustomTutorialsSelector(rootState)).toEqual(state)
413+
})
414+
415+
it('should properly return open state', () => {
416+
// Arrange
417+
const currentState = {
418+
...initialState,
419+
items: [{
420+
...defaultItems[0],
421+
args: {
422+
defaultInitialIsOpen: false,
423+
initialIsOpen: true
424+
},
425+
children: MOCK_TUTORIALS_ITEMS
426+
}]
427+
}
428+
429+
const state = {
430+
...initialState,
431+
items: [{
432+
...defaultItems[0],
433+
args: {
434+
defaultInitialIsOpen: false,
435+
initialIsOpen: false
436+
},
437+
children: MOCK_TUTORIALS_ITEMS
438+
}]
439+
}
440+
441+
// Act
442+
const nextState = reducer(currentState, setWbCustomTutorialsState())
443+
444+
// Assert
445+
const rootState = Object.assign(initialStateDefault, {
446+
workbench: {
447+
customTutorials: nextState,
448+
},
449+
})
450+
451+
expect(workbenchCustomTutorialsSelector(rootState)).toEqual(state)
452+
})
453+
})
374454
})
375455

376456
// thunks

redisinsight/ui/src/slices/workbench/wb-custom-tutorials.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createSlice } from '@reduxjs/toolkit'
2-
import { remove } from 'lodash'
1+
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
2+
import { isUndefined, remove } from 'lodash'
33
import { AxiosError } from 'axios'
44
import { ApiEndpoints } from 'uiSrc/constants'
5-
import { getApiErrorMessage, getUrl, isStatusSuccessful, } from 'uiSrc/utils'
5+
import { getApiErrorMessage, getUrl, isStatusSuccessful, Maybe, } from 'uiSrc/utils'
66
import { apiService } from 'uiSrc/services'
77
import {
88
EnablementAreaComponent,
@@ -86,7 +86,19 @@ const workbenchCustomTutorialsSlice = createSlice({
8686
},
8787
uploadDataBulkFailed: (state, { payload }) => {
8888
remove(state.bulkUpload.pathsInProgress, (p) => p === payload)
89-
}
89+
},
90+
setWbCustomTutorialsState: (state, { payload }: PayloadAction<Maybe<boolean>>) => {
91+
if (state.items[0].args) {
92+
const { defaultInitialIsOpen, initialIsOpen } = state.items[0].args
93+
if (isUndefined(payload)) {
94+
state.items[0].args.initialIsOpen = defaultInitialIsOpen ?? initialIsOpen
95+
return
96+
}
97+
98+
state.items[0].args.defaultInitialIsOpen = initialIsOpen
99+
state.items[0].args.initialIsOpen = payload
100+
}
101+
},
90102
}
91103
})
92104

@@ -108,6 +120,7 @@ export const {
108120
uploadDataBulk,
109121
uploadDataBulkSuccess,
110122
uploadDataBulkFailed,
123+
setWbCustomTutorialsState,
111124
} = workbenchCustomTutorialsSlice.actions
112125

113126
// The reducer

0 commit comments

Comments
 (0)