Skip to content

Commit 07dbaee

Browse files
committed
#RI-3844 - loading after canceling redisearch request
1 parent a9d52ba commit 07dbaee

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

redisinsight/ui/src/slices/browser/redisearch.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { remove } from 'lodash'
55
import successMessages from 'uiSrc/components/notifications/success-messages'
66
import { ApiEndpoints } from 'uiSrc/constants'
77
import { apiService } from 'uiSrc/services'
8-
import { bufferToString, getApiErrorMessage, getUrl, isEqualBuffers, isStatusSuccessful, Nullable } from 'uiSrc/utils'
8+
import { bufferToString, getApiErrorMessage, getUrl, isEqualBuffers, isStatusSuccessful, Maybe, Nullable } from 'uiSrc/utils'
99
import { DEFAULT_SEARCH_MATCH } from 'uiSrc/constants/api'
1010
import { IKeyPropTypes } from 'uiSrc/constants/prop-types/keys'
1111
import ApiErrors from 'uiSrc/constants/apiErrors'
@@ -67,8 +67,10 @@ const redisearchSlice = createSlice({
6767
state.isSearched = isSearched
6868
state.data.lastRefreshTime = Date.now()
6969
},
70-
loadKeysFailure: (state, { payload }) => {
71-
state.error = payload
70+
loadKeysFailure: (state, { payload }: PayloadAction<Maybe<string>>) => {
71+
if (payload) {
72+
state.error = payload
73+
}
7274
state.loading = false
7375
},
7476

@@ -86,9 +88,11 @@ const redisearchSlice = createSlice({
8688

8789
state.loading = false
8890
},
89-
loadMoreKeysFailure: (state, { payload }) => {
91+
loadMoreKeysFailure: (state, { payload }: PayloadAction<Maybe<string>>) => {
92+
if (payload) {
93+
state.error = payload
94+
}
9095
state.loading = false
91-
state.error = payload
9296
},
9397

9498
// load list of indexes
@@ -278,6 +282,8 @@ export function fetchRedisearchKeysAction(
278282
dispatch(fetchRedisearchListAction())
279283
}
280284
onFailed?.()
285+
} else {
286+
dispatch(loadKeysFailure())
281287
}
282288
}
283289
}
@@ -326,6 +332,8 @@ export function fetchMoreRedisearchKeysAction(
326332
const errorMessage = getApiErrorMessage(error)
327333
dispatch(addErrorNotification(error))
328334
dispatch(loadMoreKeysFailure(errorMessage))
335+
} else {
336+
dispatch(loadMoreKeysFailure())
329337
}
330338
}
331339
}

redisinsight/ui/src/slices/tests/browser/redisearch.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,33 @@ describe('redisearch slice', () => {
171171
})
172172
expect(redisearchSelector(rootState)).toEqual(state)
173173
})
174+
175+
it('should not properly set the error if no payload', () => {
176+
// Arrange
177+
const state = {
178+
...initialState,
179+
loading: false,
180+
error: initialState.error,
181+
data: {
182+
...initialState.data,
183+
keys: [],
184+
nextCursor: '0',
185+
total: 0,
186+
scanned: 0,
187+
shardsMeta: {},
188+
previousResultCount: 0,
189+
},
190+
}
191+
192+
// Act
193+
const nextState = reducer(initialState, loadKeysFailure())
194+
195+
// Assert
196+
const rootState = Object.assign(initialStateDefault, {
197+
browser: { redisearch: nextState },
198+
})
199+
expect(redisearchSelector(rootState)).toEqual(state)
200+
})
174201
})
175202

176203
describe('loadMoreKeys', () => {
@@ -298,6 +325,33 @@ describe('redisearch slice', () => {
298325
})
299326
expect(redisearchSelector(rootState)).toEqual(state)
300327
})
328+
329+
it('should not properly set the error if no payload', () => {
330+
// Arrange
331+
const state = {
332+
...initialState,
333+
loading: false,
334+
error: initialState.error,
335+
data: {
336+
...initialState.data,
337+
keys: [],
338+
nextCursor: '0',
339+
total: 0,
340+
scanned: 0,
341+
shardsMeta: {},
342+
previousResultCount: 0,
343+
},
344+
}
345+
346+
// Act
347+
const nextState = reducer(initialState, loadMoreKeysFailure())
348+
349+
// Assert
350+
const rootState = Object.assign(initialStateDefault, {
351+
browser: { redisearch: nextState },
352+
})
353+
expect(redisearchSelector(rootState)).toEqual(state)
354+
})
301355
})
302356

303357
describe('loadList', () => {

0 commit comments

Comments
 (0)