Skip to content

Commit 5d4255f

Browse files
author
Kristiyan Ivanov
authored
RI-6299 - Total count keys can be -1 (#4142)
* RI-6299 - Total count keys can be -1 Also fixed TS errors and linting across the file. The actual fix is on line 245 * cleanup
1 parent 4fcb17a commit 5d4255f

File tree

1 file changed

+31
-19
lines changed
  • redisinsight/ui/src/slices/browser

1 file changed

+31
-19
lines changed

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ const keysSlice = createSlice({
238238
state.deleting = false
239239
},
240240
deletePatternKeyFromList: (state, { payload }) => {
241-
remove(state.data?.keys, (key) => isEqualBuffers(key.name, payload))
241+
remove(state.data?.keys, (key) => isEqualBuffers(key.name as RedisResponseBuffer, payload))
242242

243243
state.data = {
244244
...state.data,
245-
total: state.data.total - 1,
245+
total: Math.max(state.data.total - 1, 0),
246246
scanned: state.data.scanned - 1,
247247
}
248248
},
@@ -271,9 +271,12 @@ const keysSlice = createSlice({
271271
},
272272
editPatternKeyFromList: (state, { payload }) => {
273273
const keys = state.data.keys.map((key) => {
274-
if (isEqualBuffers(key.name, payload?.key)) {
275-
key.name = payload?.newKey
276-
key.nameString = bufferToString(payload?.newKey)
274+
if (isEqualBuffers(key.name as RedisResponseBuffer, payload?.key)) {
275+
return {
276+
...key,
277+
name: payload?.newKey,
278+
nameString: bufferToString(payload?.newKey)
279+
}
277280
}
278281
return key
279282
})
@@ -286,7 +289,7 @@ const keysSlice = createSlice({
286289

287290
editPatternKeyTTLFromList: (state, { payload: [key, ttl] }: PayloadAction<[RedisResponseBuffer, number]>) => {
288291
const keys = state.data.keys.map((keyData) => {
289-
if (isEqualBuffers(keyData.name, key)) {
292+
if (isEqualBuffers(keyData.name as RedisResponseBuffer, key)) {
290293
keyData.ttl = ttl
291294
}
292295
return keyData
@@ -348,12 +351,12 @@ const keysSlice = createSlice({
348351
state.filter = payload
349352
},
350353

351-
changeKeyViewType: (state, { payload }:{ payload: KeyViewType }) => {
354+
changeKeyViewType: (state, { payload }: { payload: KeyViewType }) => {
352355
state.viewType = payload
353356
localStorageService?.set(BrowserStorageItem.browserViewType, payload)
354357
},
355358

356-
changeSearchMode: (state, { payload }:{ payload: SearchMode }) => {
359+
changeSearchMode: (state, { payload }: { payload: SearchMode }) => {
357360
state.searchMode = payload
358361
},
359362

@@ -541,7 +544,7 @@ export function fetchPatternKeysAction(
541544
if (isStatusSuccessful(status)) {
542545
dispatch(
543546
loadKeysSuccess({
544-
data: parseKeysListResponse({}, data),
547+
data: parseKeysListResponse({}, data as never[]),
545548
isSearched: !!match,
546549
isFiltered: !!type,
547550
})
@@ -571,7 +574,8 @@ export function fetchPatternKeysAction(
571574
}
572575
onSuccess?.(data)
573576
}
574-
} catch (error) {
577+
} catch (_err) {
578+
const error = _err as AxiosError
575579
if (!axios.isCancel(error)) {
576580
const errorMessage = getApiErrorMessage(error)
577581
dispatch(addErrorNotification(error))
@@ -632,7 +636,8 @@ export function fetchMorePatternKeysAction(oldKeys: IKeyPropTypes[] = [], cursor
632636
}
633637
})
634638
}
635-
} catch (error) {
639+
} catch (_err) {
640+
const error = _err as AxiosError
636641
if (!axios.isCancel(error)) {
637642
const errorMessage = getApiErrorMessage(error)
638643
dispatch(addErrorNotification(error))
@@ -732,10 +737,12 @@ export function refreshKeyInfoAction(key: RedisResponseBuffer) {
732737
dispatch(refreshKeyInfoSuccess(data))
733738
dispatch(updateSelectedKeyRefreshTime(Date.now()))
734739
}
735-
} catch (error) {
740+
} catch (_err) {
741+
const error = _err as AxiosError
736742
dispatch(refreshKeyInfoFail())
737743
dispatch(addErrorNotification(error))
738-
if (isStatusNotFoundError(get(error, ['response', 'status']))) {
744+
const status = get(error, ['response', 'status'])
745+
if (status && isStatusNotFoundError(status)) {
739746
dispatch(resetKeyInfo())
740747
dispatch(deleteKeyFromList(key))
741748
}
@@ -783,7 +790,8 @@ function addTypedKey(
783790
}
784791
})
785792
}
786-
} catch (error) {
793+
} catch (_err) {
794+
const error = _err as AxiosError
787795
if (onFailAction) {
788796
onFailAction()
789797
}
@@ -885,7 +893,8 @@ export function deleteSelectedKeyAction(
885893
onSuccessAction?.()
886894
dispatch(addMessageNotification(successMessages.DELETED_KEY(key)))
887895
}
888-
} catch (error) {
896+
} catch (_err) {
897+
const error = _err as AxiosError
889898
const errorMessage = getApiErrorMessage(error as AxiosError)
890899
dispatch(addErrorNotification(error as AxiosError))
891900
dispatch(deleteSelectedKeyFailure(errorMessage))
@@ -920,7 +929,8 @@ export function deleteKeyAction(
920929
onSuccessAction?.()
921930
dispatch(addMessageNotification(successMessages.DELETED_KEY(key)))
922931
}
923-
} catch (error) {
932+
} catch (_err) {
933+
const error = _err as AxiosError
924934
dispatch(addErrorNotification(error as AxiosError))
925935
dispatch(deleteKeyFailure())
926936
}
@@ -953,7 +963,8 @@ export function editKey(
953963
dispatch<any>(editKeyFromList({ key, newKey }))
954964
onSuccess?.()
955965
}
956-
} catch (error) {
966+
} catch (_err) {
967+
const error = _err as AxiosError
957968
const errorMessage = getApiErrorMessage(error)
958969
dispatch(addErrorNotification(error))
959970
dispatch(defaultSelectedKeyActionFailure(errorMessage))
@@ -1000,7 +1011,8 @@ export function editKeyTTL(key: RedisResponseBuffer, ttl: number) {
10001011
}
10011012
dispatch(defaultSelectedKeyActionSuccess())
10021013
}
1003-
} catch (error) {
1014+
} catch (_err) {
1015+
const error = _err as AxiosError
10041016
const errorMessage = getApiErrorMessage(error)
10051017
dispatch(addErrorNotification(error))
10061018
dispatch(defaultSelectedKeyActionFailure(errorMessage))
@@ -1055,7 +1067,7 @@ export function fetchKeysMetadataTree(
10551067
state.connections.instances?.connectedInstance?.id,
10561068
ApiEndpoints.KEYS_METADATA
10571069
),
1058-
{ keys: keys.map(([,nameBuffer]) => nameBuffer), type: filter || undefined },
1070+
{ keys: keys.map(([, nameBuffer]) => nameBuffer), type: filter || undefined },
10591071
{ params: { encoding: state.app.info.encoding }, signal }
10601072
)
10611073

0 commit comments

Comments
 (0)