Skip to content

Commit 4731b61

Browse files
Merge pull request #1910 from RedisInsight/feature/RI-4295_delete-keys-from-list
Feature/ri 4295 delete keys from list
2 parents 31a1c8e + 9e4f4fe commit 4731b61

File tree

23 files changed

+468
-90
lines changed

23 files changed

+468
-90
lines changed

redisinsight/ui/src/pages/browser/BrowserPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const BrowserPage = () => {
213213
>
214214
<BrowserLeftPanel
215215
selectKey={selectKey}
216+
setSelectedKey={setSelectedKey}
216217
handleAddKeyPanel={handleAddKeyPanel}
217218
handleBulkActionsPanel={handleBulkActionsPanel}
218219
handleCreateIndexPanel={handleCreateIndexPanel}

redisinsight/ui/src/pages/browser/components/browser-left-panel/BrowserLeftPanel.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { IKeyPropTypes } from 'uiSrc/constants/prop-types/keys'
1818
import { setConnectedInstanceId } from 'uiSrc/slices/instances/instances'
1919
import { SCAN_COUNT_DEFAULT, SCAN_TREE_COUNT_DEFAULT } from 'uiSrc/constants/api'
2020
import { redisearchDataSelector, redisearchListSelector, redisearchSelector } from 'uiSrc/slices/browser/redisearch'
21+
import { Nullable } from 'uiSrc/utils'
22+
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
2123

2224
import KeyList from '../key-list'
2325
import KeyTree from '../key-tree'
@@ -27,6 +29,7 @@ import styles from './styles.module.scss'
2729

2830
export interface Props {
2931
selectKey: ({ rowData }: { rowData: any }) => void
32+
setSelectedKey: (keyName: Nullable<RedisResponseBuffer>) => void
3033
handleAddKeyPanel: (value: boolean) => void
3134
handleBulkActionsPanel: (value: boolean) => void
3235
handleCreateIndexPanel: (value: boolean) => void
@@ -35,6 +38,7 @@ export interface Props {
3538
const BrowserLeftPanel = (props: Props) => {
3639
const {
3740
selectKey,
41+
setSelectedKey,
3842
handleAddKeyPanel,
3943
handleBulkActionsPanel,
4044
handleCreateIndexPanel,
@@ -99,6 +103,11 @@ const BrowserLeftPanel = (props: Props) => {
99103
keyListRef.current?.handleLoadMoreItems?.(config)
100104
}
101105

106+
const onDeleteKey = useCallback(
107+
() => setSelectedKey(null),
108+
[],
109+
)
110+
102111
return (
103112
<div className={styles.container}>
104113
<KeysHeader
@@ -121,6 +130,7 @@ const BrowserLeftPanel = (props: Props) => {
121130
scrollTopPosition={scrollTopPosition}
122131
loadMoreItems={loadMoreItems}
123132
selectKey={selectKey}
133+
onDelete={onDeleteKey}
124134
/>
125135
)}
126136
{viewType === KeyViewType.Tree && (
@@ -130,6 +140,7 @@ const BrowserLeftPanel = (props: Props) => {
130140
loading={loading}
131141
selectKey={selectKey}
132142
loadMoreItems={loadMoreItems}
143+
onDelete={onDeleteKey}
133144
/>
134145
)}
135146
</div>

redisinsight/ui/src/pages/browser/components/key-details-header/KeyDetailsHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const KeyDetailsHeader = ({
175175
),
176176
eventData: {
177177
databaseId: instanceId,
178+
source: 'keyValue',
178179
keyType: type
179180
}
180181
})

redisinsight/ui/src/pages/browser/components/key-details/KeyDetailsWrapper.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux'
44
import { useParams } from 'react-router-dom'
55

66
import {
7-
deleteKeyAction,
7+
deleteSelectedKeyAction,
88
editKey,
99
editKeyTTL,
1010
fetchKeyInfo,
@@ -81,14 +81,13 @@ const KeyDetailsWrapper = (props: Props) => {
8181
}, [keyName])
8282

8383
const handleDeleteKey = (key: RedisResponseBuffer, type: string) => {
84-
if (type === KeyTypes.String) {
85-
dispatch(deleteKeyAction(key, () => {
86-
dispatch(resetStringValue())
84+
dispatch(deleteSelectedKeyAction(key,
85+
() => {
86+
if (type === KeyTypes.String) {
87+
dispatch(resetStringValue())
88+
}
8789
onRemoveKey()
8890
}))
89-
return
90-
}
91-
dispatch(deleteKeyAction(key, onRemoveKey))
9291
}
9392

9493
const handleRefreshKey = (key: RedisResponseBuffer, type: KeyTypes | ModulesKeyTypes) => {

redisinsight/ui/src/pages/browser/components/key-list/KeyList.spec.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react'
22
import { cloneDeep } from 'lodash'
3-
import { render, waitFor } from 'uiSrc/utils/test-utils'
3+
import { fireEvent } from '@testing-library/react'
4+
import { cleanup, mockedStore, render, waitFor, screen, clearStoreActions } from 'uiSrc/utils/test-utils'
45
import { KeysStoreData, KeyViewType, SearchMode } from 'uiSrc/slices/interfaces/keys'
5-
import { keysSelector, setLastBatchKeys } from 'uiSrc/slices/browser/keys'
6+
import { deleteSelectedKey, keysSelector, setLastBatchKeys } from 'uiSrc/slices/browser/keys'
67
import { apiService } from 'uiSrc/services'
78
import KeyList from './KeyList'
89

@@ -15,6 +16,7 @@ const propsMock = {
1516
ttl: -1,
1617
size: 100,
1718
length: 100,
19+
nameString: 'key1'
1820
},
1921
{
2022
name: 'key2',
@@ -56,6 +58,13 @@ jest.mock('uiSrc/slices/browser/keys', () => ({
5658
}),
5759
}))
5860

61+
let store: typeof mockedStore
62+
beforeEach(() => {
63+
cleanup()
64+
store = cloneDeep(mockedStore)
65+
store.clearActions()
66+
})
67+
5968
// afterEach(() => {
6069
// setLastBatchKeys.mockRestore()
6170
// })
@@ -175,4 +184,20 @@ describe('KeyList', () => {
175184
expect(queryAllByTestId(/type-loading/).length).toEqual(propsMock.keysState.keys.length)
176185
expect(queryAllByTestId(/size-loading/).length).toEqual(propsMock.keysState.keys.length)
177186
})
187+
188+
it('should call proper action after click on delete', async () => {
189+
const { container } = render(<KeyList {...propsMock} />)
190+
191+
fireEvent.mouseOver(container.querySelectorAll(
192+
'.ReactVirtualized__Table__row[role="row"]'
193+
)[0])
194+
195+
fireEvent.click(screen.getByTestId('delete-key-btn-key1'))
196+
fireEvent.click(screen.getByTestId('submit-delete-key'))
197+
198+
const expectedActions = [
199+
deleteSelectedKey()
200+
]
201+
expect(clearStoreActions(store.getActions().slice(-1))).toEqual(clearStoreActions(expectedActions))
202+
})
178203
})

0 commit comments

Comments
 (0)