Skip to content

Commit 6531c99

Browse files
authored
Merge pull request #1713 from RedisInsight/feature/RI-3995_add_keys
#RI-3995 - add key into list
2 parents 8bf0f9e + 7d4095b commit 6531c99

File tree

6 files changed

+309
-165
lines changed

6 files changed

+309
-165
lines changed

redisinsight/ui/src/constants/keys.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { StreamViewType } from 'uiSrc/slices/interfaces/stream'
2+
import { ApiEndpoints } from 'uiSrc/constants'
23
import { CommandGroup } from './commands'
34

45
export enum KeyTypes {
@@ -180,6 +181,17 @@ export enum KeyValueFormat {
180181
Pickle = 'Pickle',
181182
}
182183

184+
export const ENDPOINT_BASED_ON_KEY_TYPE = Object.freeze({
185+
[KeyTypes.ZSet]: ApiEndpoints.ZSET,
186+
[KeyTypes.Set]: ApiEndpoints.SET,
187+
[KeyTypes.String]: ApiEndpoints.STRING,
188+
[KeyTypes.Hash]: ApiEndpoints.HASH,
189+
[KeyTypes.List]: ApiEndpoints.LIST,
190+
[KeyTypes.ReJSON]: ApiEndpoints.REJSON,
191+
[KeyTypes.Stream]: ApiEndpoints.STREAMS,
192+
})
193+
194+
export type EndpointBasedOnKeyType = keyof (typeof ENDPOINT_BASED_ON_KEY_TYPE)
183195
export enum SearchHistoryMode {
184196
Pattern = 'pattern',
185197
Redisearch = 'redisearch'

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

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
BrowserStorageItem,
88
KeyTypes,
99
KeyValueFormat,
10+
EndpointBasedOnKeyType,
11+
ENDPOINT_BASED_ON_KEY_TYPE,
1012
SearchHistoryMode,
1113
SortOrder
1214
} from 'uiSrc/constants'
@@ -26,6 +28,7 @@ import { DEFAULT_SEARCH_MATCH, SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
2628
import { getBasedOnViewTypeEvent, sendEventTelemetry, TelemetryEvent, getAdditionalAddedEventData, getMatchType } from 'uiSrc/telemetry'
2729
import successMessages from 'uiSrc/components/notifications/success-messages'
2830
import { IKeyPropTypes } from 'uiSrc/constants/prop-types/keys'
31+
import { resetBrowserTree } from 'uiSrc/slices/app/context'
2932

3033
import {
3134
CreateListWithExpireDto,
@@ -304,6 +307,16 @@ const keysSlice = createSlice({
304307
state.addKey = {
305308
...state.addKey,
306309
loading: false,
310+
error: '',
311+
}
312+
},
313+
updateKeyList: (state, { payload }) => {
314+
state.data?.keys.unshift({ name: payload.keyName })
315+
316+
state.data = {
317+
...state.data,
318+
total: state.data.total + 1,
319+
scanned: state.data.scanned + 1,
307320
}
308321
},
309322
addKeyFailure: (state, { payload }) => {
@@ -409,8 +422,9 @@ export const {
409422
defaultSelectedKeyActionFailure,
410423
setLastBatchPatternKeys,
411424
addKey,
412-
addKeySuccess,
425+
updateKeyList,
413426
addKeyFailure,
427+
addKeySuccess,
414428
resetAddKey,
415429
deleteKey,
416430
deleteKeySuccess,
@@ -715,12 +729,14 @@ export function refreshKeyInfoAction(key: RedisResponseBuffer) {
715729

716730
function addTypedKey(
717731
data: any,
718-
endpoint: ApiEndpoints,
732+
keyType: KeyTypes,
719733
onSuccessAction?: () => void,
720734
onFailAction?: () => void
721735
) {
722736
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
723737
dispatch(addKey())
738+
const endpoint = ENDPOINT_BASED_ON_KEY_TYPE[keyType as EndpointBasedOnKeyType]
739+
724740
try {
725741
const state = stateInit()
726742
const { encoding } = state.app.info
@@ -735,6 +751,7 @@ function addTypedKey(
735751
onSuccessAction()
736752
}
737753
dispatch(addKeySuccess())
754+
dispatch<any>(addKeyIntoList({ key: data.keyName, keyType }))
738755
dispatch(
739756
addMessageNotification(successMessages.ADDED_NEW_KEY(data.keyName))
740757
)
@@ -767,8 +784,7 @@ export function addHashKey(
767784
onSuccessAction?: () => void,
768785
onFailAction?: () => void
769786
) {
770-
const endpoint = ApiEndpoints.HASH
771-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
787+
return addTypedKey(data, KeyTypes.Hash, onSuccessAction, onFailAction)
772788
}
773789

774790
// Asynchronous thunk action
@@ -777,8 +793,7 @@ export function addZsetKey(
777793
onSuccessAction?: () => void,
778794
onFailAction?: () => void
779795
) {
780-
const endpoint = ApiEndpoints.ZSET
781-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
796+
return addTypedKey(data, KeyTypes.ZSet, onSuccessAction, onFailAction)
782797
}
783798

784799
// Asynchronous thunk action
@@ -787,8 +802,7 @@ export function addSetKey(
787802
onSuccessAction?: () => void,
788803
onFailAction?: () => void
789804
) {
790-
const endpoint = ApiEndpoints.SET
791-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
805+
return addTypedKey(data, KeyTypes.Set, onSuccessAction, onFailAction)
792806
}
793807

794808
// Asynchronous thunk action
@@ -797,8 +811,7 @@ export function addStringKey(
797811
onSuccessAction?: () => void,
798812
onFailAction?: () => void
799813
) {
800-
const endpoint = ApiEndpoints.STRING
801-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
814+
return addTypedKey(data, KeyTypes.String, onSuccessAction, onFailAction)
802815
}
803816

804817
// Asynchronous thunk action
@@ -807,8 +820,7 @@ export function addListKey(
807820
onSuccessAction?: () => void,
808821
onFailAction?: () => void
809822
) {
810-
const endpoint = ApiEndpoints.LIST
811-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
823+
return addTypedKey(data, KeyTypes.List, onSuccessAction, onFailAction)
812824
}
813825

814826
// Asynchronous thunk action
@@ -817,8 +829,7 @@ export function addReJSONKey(
817829
onSuccessAction?: () => void,
818830
onFailAction?: () => void
819831
) {
820-
const endpoint = ApiEndpoints.REJSON
821-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
832+
return addTypedKey(data, KeyTypes.ReJSON, onSuccessAction, onFailAction)
822833
}
823834

824835
// Asynchronous thunk action
@@ -827,8 +838,7 @@ export function addStreamKey(
827838
onSuccessAction?: () => void,
828839
onFailAction?: () => void
829840
) {
830-
const endpoint = ApiEndpoints.STREAMS
831-
return addTypedKey(data, endpoint, onSuccessAction, onFailAction)
841+
return addTypedKey(data, KeyTypes.Stream, onSuccessAction, onFailAction)
832842
}
833843

834844
// Asynchronous thunk action
@@ -1147,6 +1157,25 @@ export function editKeyFromList(data: { key: RedisResponseBuffer, newKey: RedisR
11471157
}
11481158
}
11491159

1160+
export function addKeyIntoList({ key, keyType }: { key: RedisString, keyType: KeyTypes }) {
1161+
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
1162+
const state = stateInit()
1163+
const { viewType, filter, search } = state.browser.keys
1164+
1165+
if (search && search !== '*') {
1166+
return null
1167+
}
1168+
1169+
if (!filter || filter === keyType) {
1170+
if (viewType !== KeyViewType.Tree) {
1171+
dispatch(resetBrowserTree())
1172+
}
1173+
return dispatch(updateKeyList({ keyName: key, keyType }))
1174+
}
1175+
return null
1176+
}
1177+
}
1178+
11501179
export function editKeyTTLFromList(data: [RedisResponseBuffer, number]) {
11511180
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
11521181
const state = stateInit()

0 commit comments

Comments
 (0)