@@ -70,6 +70,7 @@ const defaultViewFormat = KeyValueFormat.Unicode
70
70
71
71
export const initialState : KeysStore = {
72
72
loading : false ,
73
+ deleting : false ,
73
74
error : '' ,
74
75
filter : null ,
75
76
search : '' ,
@@ -202,28 +203,38 @@ const keysSlice = createSlice({
202
203
updateSelectedKeyRefreshTime : ( state , { payload } ) => {
203
204
state . selectedKey . lastRefreshTime = payload
204
205
} ,
205
- // delete Key
206
- deleteKey : ( state ) => {
206
+ // delete selected Key
207
+ deleteSelectedKey : ( state ) => {
207
208
state . selectedKey = {
208
209
...state . selectedKey ,
209
210
loading : true ,
210
211
error : '' ,
211
212
}
212
213
} ,
213
- deleteKeySuccess : ( state ) => {
214
+ deleteSelectedKeySuccess : ( state ) => {
214
215
state . selectedKey = {
215
216
...state . selectedKey ,
216
217
loading : false ,
217
218
data : null ,
218
219
}
219
220
} ,
220
- deleteKeyFailure : ( state , { payload } ) => {
221
+ deleteSelectedKeyFailure : ( state , { payload } ) => {
221
222
state . selectedKey = {
222
223
...state . selectedKey ,
223
224
loading : false ,
224
225
error : payload ,
225
226
}
226
227
} ,
228
+ // delete Key
229
+ deleteKey : ( state ) => {
230
+ state . deleting = true
231
+ } ,
232
+ deleteKeySuccess : ( state ) => {
233
+ state . deleting = false
234
+ } ,
235
+ deleteKeyFailure : ( state ) => {
236
+ state . deleting = false
237
+ } ,
227
238
deletePatternKeyFromList : ( state , { payload } ) => {
228
239
remove ( state . data ?. keys , ( key ) => isEqualBuffers ( key . name , payload ) )
229
240
@@ -427,10 +438,13 @@ export const {
427
438
addKeyFailure,
428
439
addKeySuccess,
429
440
resetAddKey,
441
+ deleteSelectedKey,
442
+ deleteSelectedKeySuccess,
443
+ deleteSelectedKeyFailure,
444
+ deletePatternKeyFromList,
430
445
deleteKey,
431
446
deleteKeySuccess,
432
447
deleteKeyFailure,
433
- deletePatternKeyFromList,
434
448
editPatternKeyFromList,
435
449
editPatternKeyTTLFromList,
436
450
setPatternSearchMatch,
@@ -841,15 +855,61 @@ export function addStreamKey(
841
855
return addTypedKey ( data , KeyTypes . Stream , onSuccessAction , onFailAction )
842
856
}
843
857
858
+ // Asynchronous thunk action
859
+ export function deleteSelectedKeyAction (
860
+ key : RedisResponseBuffer ,
861
+ onSuccessAction ?: ( ) => void
862
+ ) {
863
+ return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
864
+ dispatch ( deleteSelectedKey ( ) )
865
+
866
+ try {
867
+ const state = stateInit ( )
868
+ const { encoding } = state . app . info
869
+ const { status } = await apiService . delete (
870
+ getUrl (
871
+ state . connections . instances ?. connectedInstance ?. id ?? '' ,
872
+ ApiEndpoints . KEYS
873
+ ) ,
874
+ {
875
+ data : { keyNames : [ key ] } ,
876
+ params : { encoding } ,
877
+ }
878
+ )
879
+
880
+ if ( isStatusSuccessful ( status ) ) {
881
+ sendEventTelemetry ( {
882
+ event : getBasedOnViewTypeEvent (
883
+ state . browser . keys ?. viewType ,
884
+ TelemetryEvent . BROWSER_KEYS_DELETED ,
885
+ TelemetryEvent . TREE_VIEW_KEYS_DELETED
886
+ ) ,
887
+ eventData : {
888
+ databaseId : state . connections . instances ?. connectedInstance ?. id ,
889
+ numberOfDeletedKeys : 1 ,
890
+ source : 'keyValue' ,
891
+ }
892
+ } )
893
+ dispatch ( deleteSelectedKeySuccess ( ) )
894
+ dispatch < any > ( deleteKeyFromList ( key ) )
895
+ onSuccessAction ?.( )
896
+ dispatch ( addMessageNotification ( successMessages . DELETED_KEY ( key ) ) )
897
+ }
898
+ } catch ( error ) {
899
+ const errorMessage = getApiErrorMessage ( error as AxiosError )
900
+ dispatch ( addErrorNotification ( error as AxiosError ) )
901
+ dispatch ( deleteSelectedKeyFailure ( errorMessage ) )
902
+ }
903
+ }
904
+ }
905
+
844
906
// Asynchronous thunk action
845
907
export function deleteKeyAction (
846
908
key : RedisResponseBuffer ,
847
- telemetryData : Record < string , any > = { } ,
848
909
onSuccessAction ?: ( ) => void
849
910
) {
850
911
return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
851
912
dispatch ( deleteKey ( ) )
852
-
853
913
try {
854
914
const state = stateInit ( )
855
915
const { encoding } = state . app . info
@@ -874,19 +934,17 @@ export function deleteKeyAction(
874
934
eventData : {
875
935
databaseId : state . connections . instances ?. connectedInstance ?. id ,
876
936
numberOfDeletedKeys : 1 ,
877
- ... telemetryData
937
+ source : 'keyList' ,
878
938
}
879
939
} )
880
- console . log ( sendEventTelemetry )
881
940
dispatch ( deleteKeySuccess ( ) )
882
941
dispatch < any > ( deleteKeyFromList ( key ) )
883
942
onSuccessAction ?.( )
884
943
dispatch ( addMessageNotification ( successMessages . DELETED_KEY ( key ) ) )
885
944
}
886
945
} catch ( error ) {
887
- const errorMessage = getApiErrorMessage ( error )
888
- dispatch ( addErrorNotification ( error ) )
889
- dispatch ( deleteKeyFailure ( errorMessage ) )
946
+ dispatch ( addErrorNotification ( error as AxiosError ) )
947
+ dispatch ( deleteKeyFailure ( ) )
890
948
}
891
949
}
892
950
}
@@ -959,7 +1017,7 @@ export function editKeyTTL(key: RedisResponseBuffer, ttl: number) {
959
1017
dispatch < any > ( editKeyTTLFromList ( [ key , ttl ] ) )
960
1018
dispatch < any > ( fetchKeyInfo ( key ) )
961
1019
} else {
962
- dispatch ( deleteKeySuccess ( ) )
1020
+ dispatch ( deleteSelectedKeySuccess ( ) )
963
1021
dispatch < any > ( deleteKeyFromList ( key ) )
964
1022
}
965
1023
dispatch ( defaultSelectedKeyActionSuccess ( ) )
0 commit comments