7
7
BrowserStorageItem ,
8
8
KeyTypes ,
9
9
KeyValueFormat ,
10
+ EndpointBasedOnKeyType ,
11
+ ENDPOINT_BASED_ON_KEY_TYPE ,
10
12
SearchHistoryMode ,
11
13
SortOrder
12
14
} from 'uiSrc/constants'
@@ -26,6 +28,7 @@ import { DEFAULT_SEARCH_MATCH, SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
26
28
import { getBasedOnViewTypeEvent , sendEventTelemetry , TelemetryEvent , getAdditionalAddedEventData , getMatchType } from 'uiSrc/telemetry'
27
29
import successMessages from 'uiSrc/components/notifications/success-messages'
28
30
import { IKeyPropTypes } from 'uiSrc/constants/prop-types/keys'
31
+ import { resetBrowserTree } from 'uiSrc/slices/app/context'
29
32
30
33
import {
31
34
CreateListWithExpireDto ,
@@ -304,6 +307,16 @@ const keysSlice = createSlice({
304
307
state . addKey = {
305
308
...state . addKey ,
306
309
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 ,
307
320
}
308
321
} ,
309
322
addKeyFailure : ( state , { payload } ) => {
@@ -409,8 +422,9 @@ export const {
409
422
defaultSelectedKeyActionFailure,
410
423
setLastBatchPatternKeys,
411
424
addKey,
412
- addKeySuccess ,
425
+ updateKeyList ,
413
426
addKeyFailure,
427
+ addKeySuccess,
414
428
resetAddKey,
415
429
deleteKey,
416
430
deleteKeySuccess,
@@ -715,12 +729,14 @@ export function refreshKeyInfoAction(key: RedisResponseBuffer) {
715
729
716
730
function addTypedKey (
717
731
data : any ,
718
- endpoint : ApiEndpoints ,
732
+ keyType : KeyTypes ,
719
733
onSuccessAction ?: ( ) => void ,
720
734
onFailAction ?: ( ) => void
721
735
) {
722
736
return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
723
737
dispatch ( addKey ( ) )
738
+ const endpoint = ENDPOINT_BASED_ON_KEY_TYPE [ keyType as EndpointBasedOnKeyType ]
739
+
724
740
try {
725
741
const state = stateInit ( )
726
742
const { encoding } = state . app . info
@@ -735,6 +751,7 @@ function addTypedKey(
735
751
onSuccessAction ( )
736
752
}
737
753
dispatch ( addKeySuccess ( ) )
754
+ dispatch < any > ( addKeyIntoList ( { key : data . keyName , keyType } ) )
738
755
dispatch (
739
756
addMessageNotification ( successMessages . ADDED_NEW_KEY ( data . keyName ) )
740
757
)
@@ -767,8 +784,7 @@ export function addHashKey(
767
784
onSuccessAction ?: ( ) => void ,
768
785
onFailAction ?: ( ) => void
769
786
) {
770
- const endpoint = ApiEndpoints . HASH
771
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
787
+ return addTypedKey ( data , KeyTypes . Hash , onSuccessAction , onFailAction )
772
788
}
773
789
774
790
// Asynchronous thunk action
@@ -777,8 +793,7 @@ export function addZsetKey(
777
793
onSuccessAction ?: ( ) => void ,
778
794
onFailAction ?: ( ) => void
779
795
) {
780
- const endpoint = ApiEndpoints . ZSET
781
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
796
+ return addTypedKey ( data , KeyTypes . ZSet , onSuccessAction , onFailAction )
782
797
}
783
798
784
799
// Asynchronous thunk action
@@ -787,8 +802,7 @@ export function addSetKey(
787
802
onSuccessAction ?: ( ) => void ,
788
803
onFailAction ?: ( ) => void
789
804
) {
790
- const endpoint = ApiEndpoints . SET
791
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
805
+ return addTypedKey ( data , KeyTypes . Set , onSuccessAction , onFailAction )
792
806
}
793
807
794
808
// Asynchronous thunk action
@@ -797,8 +811,7 @@ export function addStringKey(
797
811
onSuccessAction ?: ( ) => void ,
798
812
onFailAction ?: ( ) => void
799
813
) {
800
- const endpoint = ApiEndpoints . STRING
801
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
814
+ return addTypedKey ( data , KeyTypes . String , onSuccessAction , onFailAction )
802
815
}
803
816
804
817
// Asynchronous thunk action
@@ -807,8 +820,7 @@ export function addListKey(
807
820
onSuccessAction ?: ( ) => void ,
808
821
onFailAction ?: ( ) => void
809
822
) {
810
- const endpoint = ApiEndpoints . LIST
811
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
823
+ return addTypedKey ( data , KeyTypes . List , onSuccessAction , onFailAction )
812
824
}
813
825
814
826
// Asynchronous thunk action
@@ -817,8 +829,7 @@ export function addReJSONKey(
817
829
onSuccessAction ?: ( ) => void ,
818
830
onFailAction ?: ( ) => void
819
831
) {
820
- const endpoint = ApiEndpoints . REJSON
821
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
832
+ return addTypedKey ( data , KeyTypes . ReJSON , onSuccessAction , onFailAction )
822
833
}
823
834
824
835
// Asynchronous thunk action
@@ -827,8 +838,7 @@ export function addStreamKey(
827
838
onSuccessAction ?: ( ) => void ,
828
839
onFailAction ?: ( ) => void
829
840
) {
830
- const endpoint = ApiEndpoints . STREAMS
831
- return addTypedKey ( data , endpoint , onSuccessAction , onFailAction )
841
+ return addTypedKey ( data , KeyTypes . Stream , onSuccessAction , onFailAction )
832
842
}
833
843
834
844
// Asynchronous thunk action
@@ -1147,6 +1157,25 @@ export function editKeyFromList(data: { key: RedisResponseBuffer, newKey: RedisR
1147
1157
}
1148
1158
}
1149
1159
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
+
1150
1179
export function editKeyTTLFromList ( data : [ RedisResponseBuffer , number ] ) {
1151
1180
return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
1152
1181
const state = stateInit ( )
0 commit comments