Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions redisinsight/ui/src/packages/redisgraph/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function responseParser(data: any): IResponseParser {
if (Array.isArray(item)) {
if (item[0][0] === 'id' && item[1][0] === 'labels') {
const node: INode = {
id: item[0][1].toString(),
id: item[0][1],
labels: item[1][1],
properties: {}
}
Expand All @@ -81,15 +81,15 @@ function responseParser(data: any): IResponseParser {
const v = resolveProps(x)
node['properties'][v.key] = v.value
})
if (nodes.findIndex((e: INode) => e.id === item[0][1].toString()) === -1) {
if (nodes.findIndex((e: INode) => e.id === item[0][1]) === -1) {
nodes.push(node)
}
} else if (item[0][0] === 'id' && item[1][0] === 'type') {
const edge: IEdge = {
id: item[0][1].toString(),
id: item[0][1],
type: item[1][1],
source: item[2][1].toString(),
target: item[3][1].toString(),
source: item[2][1],
target: item[3][1],
properties: {}
}
types[item[1][1]] = (types[item[1][1]] + 1) || 1
Expand Down Expand Up @@ -155,7 +155,7 @@ function ResultsParser(data: any[][]) : {headers: any[], results: any[] }{
if (Array.isArray(entity)) {
if (entity[0][0] === 'id') {
const item: any = {
id: entity[0][1].toString(),
id: entity[0][1],
properties: {}
}
let propValues = []
Expand All @@ -164,8 +164,8 @@ function ResultsParser(data: any[][]) : {headers: any[], results: any[] }{
propValues = entity[2][1]
} else if (entity[1][0] === 'type') {
item.type = entity[1][1]
item.source = entity[2][1].toString()
item.target = entity[3][1].toString()
item.source = entity[2][1]
item.target = entity[3][1]
propValues = entity[4][1]
}
propValues.map((x: any) => {
Expand Down
10 changes: 5 additions & 5 deletions redisinsight/ui/src/packages/redisgraph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,23 @@ export function commandIsSuccess(resp: [{ response: any, status: string }]) {
}


export function getFetchNodesByIdQuery(graphKey: string, nodeIds: string[]): string {
export function getFetchNodesByIdQuery(graphKey: string, nodeIds: number[]): string {
return `graph.ro_query ${graphKey} "MATCH (n) WHERE id(n) IN [${nodeIds}] RETURN DISTINCT n"`
}

export function getFetchNodesByEdgeIdQuery(graphKey: string, edgeIds: string[], existingNodeIds: string[]): string {
export function getFetchNodesByEdgeIdQuery(graphKey: string, edgeIds: number[], existingNodeIds: number[]): string {
return `graph.ro_query ${graphKey} "MATCH (n)-[t]->(m) WHERE id(t) IN [${edgeIds}] AND NOT id(n) IN [${existingNodeIds}] AND NOT id(m) IN [${existingNodeIds}] RETURN n, m"`
}

export function getFetchEdgesByIdQuery(graphKey: string, edgeIds: string[]): string {
export function getFetchEdgesByIdQuery(graphKey: string, edgeIds: number[]): string {
return `graph.ro_query ${graphKey} "MATCH ()-[t]->() WHERE id(t) IN [${edgeIds}] RETURN DISTINCT t"`
}

export function getFetchDirectNeighboursOfNodeQuery(graphKey: string, nodeId: string): string {
export function getFetchDirectNeighboursOfNodeQuery(graphKey: string, nodeId: number): string {
return `graph.ro_query "${graphKey}" "MATCH (n)-[t]-(m) WHERE id(n)=${nodeId} RETURN t, m"`
}


export function getFetchNodeRelationshipsQuery(graphKey: string, sourceNodeIds: string[], destNodeIds: string[], existingEdgeIds: string[]): string {
export function getFetchNodeRelationshipsQuery(graphKey: string, sourceNodeIds: number[], destNodeIds: number[], existingEdgeIds: number[]): string {
return `graph.ro_query ${graphKey} "MATCH (n)-[t]->(m) WHERE (ID(n) IN [${sourceNodeIds}] OR ID(m) IN [${destNodeIds}]) AND NOT ID(t) IN [${existingEdgeIds}] RETURN DISTINCT t"`
}
15 changes: 0 additions & 15 deletions redisinsight/ui/src/pages/browser/components/key-list/KeyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
formatLongName,
bufferToString,
bufferFormatRangeItems,
isEqualBuffers,
Nullable,
} from 'uiSrc/utils'
import {
Expand All @@ -33,9 +32,7 @@ import {
fetchKeysMetadata,
keysDataSelector,
keysSelector,
resetKeysData,
selectedKeySelector,
setLastBatchKeys,
sourceKeysFetch,
} from 'uiSrc/slices/browser/keys'
import {
Expand Down Expand Up @@ -126,18 +123,6 @@ const KeyList = forwardRef((props: Props, ref) => {
rerender({})
}, [keysState.keys])

useEffect(() => {
if (!selectedKey || !selectedKey?.data) return

const indexKeyForUpdate = itemsRef.current.findIndex(({ name }) =>
isEqualBuffers(name, selectedKey?.data?.name))

if (indexKeyForUpdate === -1) return

itemsRef.current[indexKeyForUpdate] = selectedKey.data
rerender({})
}, [selectedKey])

const cancelAllMetadataRequests = () => {
controller.current?.abort()
}
Expand Down
45 changes: 36 additions & 9 deletions redisinsight/ui/src/slices/browser/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { fetchStreamEntries, setStreamInitialState } from './stream'
import {
deleteRedisearchKeyFromList,
editRedisearchKeyFromList,
editRedisearchKeyTTLFromList,
fetchMoreRedisearchKeysAction,
fetchRedisearchKeysAction,
resetRedisearchKeysData,
Expand Down Expand Up @@ -253,6 +254,20 @@ const keysSlice = createSlice({
}
},

editPatternKeyTTLFromList: (state, { payload: [key, ttl] }: PayloadAction<[RedisResponseBuffer, number]>) => {
const keys = state.data.keys.map((keyData) => {
if (isEqualBuffers(keyData.name, key)) {
keyData.ttl = ttl
}
return keyData
})

state.data = {
...state.data,
keys,
}
},

// update length for Selected Key
updateSelectedKeyLength: (state, { payload }) => {
state.selectedKey = {
Expand Down Expand Up @@ -367,6 +382,7 @@ export const {
deleteKeyFailure,
deletePatternKeyFromList,
editPatternKeyFromList,
editPatternKeyTTLFromList,
updateSelectedKeyLength,
setPatternSearchMatch,
setFilter,
Expand Down Expand Up @@ -797,7 +813,7 @@ export function deleteKeyAction(key: RedisResponseBuffer, onSuccessAction?: () =
}
})
dispatch(deleteKeySuccess())
dispatch(deleteKeyFromList(key))
dispatch<any>(deleteKeyFromList(key))
onSuccessAction?.()
dispatch(addMessageNotification(successMessages.DELETED_KEY(key)))
}
Expand Down Expand Up @@ -832,7 +848,7 @@ export function editKey(
)

if (isStatusSuccessful(status)) {
dispatch(editKeyFromList({ key, newKey }))
dispatch<any>(editKeyFromList({ key, newKey }))
onSuccess?.()
}
} catch (error) {
Expand All @@ -845,7 +861,7 @@ export function editKey(
}

// Asynchronous thunk action
export function editKeyTTL(key: string, ttl: number) {
export function editKeyTTL(key: RedisResponseBuffer, ttl: number) {
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
dispatch(defaultSelectedKeyAction())

Expand Down Expand Up @@ -874,10 +890,11 @@ export function editKeyTTL(key: string, ttl: number) {
}
})
if (ttl !== 0) {
dispatch<any>(editKeyTTLFromList([key, ttl]))
dispatch<any>(fetchKeyInfo(key))
} else {
dispatch(deleteKeySuccess())
dispatch(deleteKeyFromList(key))
dispatch<any>(deleteKeyFromList(key))
}
dispatch(defaultSelectedKeyActionSuccess())
}
Expand Down Expand Up @@ -932,8 +949,8 @@ export function fetchKeys(
const isRedisearchExists = isRedisearchAvailable(state.connections.instances.connectedInstance.modules)

return searchMode === SearchMode.Pattern || !isRedisearchExists
? dispatch(fetchPatternKeysAction(cursor, count, onSuccess, onFailed))
: dispatch(fetchRedisearchKeysAction(cursor, count, onSuccess, onFailed))
? dispatch<any>(fetchPatternKeysAction(cursor, count, onSuccess, onFailed))
: dispatch<any>(fetchRedisearchKeysAction(cursor, count, onSuccess, onFailed))
}
}

Expand Down Expand Up @@ -977,12 +994,22 @@ export function deleteKeyFromList(key: RedisResponseBuffer) {
}
}

export function editKeyFromList(key: RedisResponseBuffer) {
export function editKeyFromList(data: { key: RedisResponseBuffer, newKey: RedisResponseBuffer }) {
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
const state = stateInit()

return state.browser.keys?.searchMode === SearchMode.Pattern
? dispatch(editPatternKeyFromList(data))
: dispatch(editRedisearchKeyFromList(data))
}
}

export function editKeyTTLFromList(data: [RedisResponseBuffer, number]) {
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
const state = stateInit()

return state.browser.keys?.searchMode === SearchMode.Pattern
? dispatch(editPatternKeyFromList(key))
: dispatch(editRedisearchKeyFromList(key))
? dispatch(editPatternKeyTTLFromList(data))
: dispatch(editRedisearchKeyTTLFromList(data))
}
}
15 changes: 15 additions & 0 deletions redisinsight/ui/src/slices/browser/redisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ const redisearchSlice = createSlice({
keys,
}
},

editRedisearchKeyTTLFromList: (state, { payload: [key, ttl] }: PayloadAction<[RedisResponseBuffer, number]>) => {
const keys = state.data.keys.map((keyData) => {
if (isEqualBuffers(keyData.name, key)) {
keyData.ttl = ttl
}
return keyData
})

state.data = {
...state.data,
keys,
}
},
},
})

Expand All @@ -207,6 +221,7 @@ export const {
resetRedisearchKeysData,
deleteRedisearchKeyFromList,
editRedisearchKeyFromList,
editRedisearchKeyTTLFromList,
} = redisearchSlice.actions

// Selectors
Expand Down
35 changes: 34 additions & 1 deletion redisinsight/ui/src/slices/tests/browser/keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
import { AxiosError } from 'axios'
import { KeyTypes, KeyValueFormat } from 'uiSrc/constants'
import { apiService } from 'uiSrc/services'
import { parseKeysListResponse, stringToBuffer } from 'uiSrc/utils'
import { parseKeysListResponse, stringToBuffer, UTF8ToBuffer } from 'uiSrc/utils'
import { cleanup, initialStateDefault, mockedStore } from 'uiSrc/utils/test-utils'
import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'
import successMessages from 'uiSrc/components/notifications/success-messages'
Expand Down Expand Up @@ -59,6 +59,7 @@ import reducer, {
resetKeyInfo,
resetKeys,
fetchKeysMetadata,
editPatternKeyTTLFromList,
} from '../../browser/keys'
import { getString } from '../../browser/string'

Expand Down Expand Up @@ -750,6 +751,37 @@ describe('keys slice', () => {
})
})

describe('editPatternKeyTTLFromList', () => {
it('should properly set the state before the edit key ttl', () => {
// Arrange

const key = UTF8ToBuffer('key')
const ttl = 12000

const initialStateMock = {
...initialState,
data: {
keys: [{ name: key }],
},
}
const state = {
...initialState,
data: {
keys: [{ name: key, ttl }],
},
}

// Act
const nextState = reducer(initialStateMock, editPatternKeyTTLFromList([key, ttl]))

// Assert
const rootState = Object.assign(initialStateDefault, {
browser: { keys: nextState },
})
expect(keysSelector(rootState)).toEqual(state)
})
})

describe('resetKeyInfo', () => {
it('should properly save viewFormat', () => {
// Arrange
Expand Down Expand Up @@ -1256,6 +1288,7 @@ describe('keys slice', () => {
const expectedActions = [
defaultSelectedKeyAction(),
// fetch keyInfo
editPatternKeyTTLFromList([key, ttl]),
defaultSelectedKeyAction(),
defaultSelectedKeyActionSuccess(),
]
Expand Down
36 changes: 35 additions & 1 deletion redisinsight/ui/src/slices/tests/browser/redisearch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import successMessages from 'uiSrc/components/notifications/success-messages'
import { apiService } from 'uiSrc/services'
import { cleanup, initialStateDefault, mockedStore, mockStore } from 'uiSrc/utils/test-utils'
import { addErrorNotification, addMessageNotification } from 'uiSrc/slices/app/notifications'
import { stringToBuffer } from 'uiSrc/utils'
import { stringToBuffer, UTF8ToBuffer } from 'uiSrc/utils'
import { REDISEARCH_LIST_DATA_MOCK } from 'uiSrc/mocks/handlers/browser/redisearchHandlers'
import { SearchMode } from 'uiSrc/slices/interfaces/keys'
import { fetchKeys, fetchMoreKeys } from 'uiSrc/slices/browser/keys'
Expand Down Expand Up @@ -35,6 +35,7 @@ import reducer, {
resetRedisearchKeysData,
deleteRedisearchKeyFromList,
editRedisearchKeyFromList,
editRedisearchKeyTTLFromList,
} from '../../browser/redisearch'

let store: typeof mockedStore
Expand Down Expand Up @@ -713,6 +714,39 @@ describe('redisearch slice', () => {
})
})

describe('editRedisearchKeyTTLFromList', () => {
it('should properly set the state before the edit key ttl', () => {
// Arrange

const key = UTF8ToBuffer('key')
const ttl = 12000

const prevState = {
...initialState,
data: {
...initialState.data,
keys: [{ name: key }],
},
}
const state = {
...initialState,
data: {
...initialState.data,
keys: [{ name: key, ttl }],
},
}

// Act
const nextState = reducer(prevState, editRedisearchKeyTTLFromList([key, ttl]))

// Assert
const rootState = Object.assign(initialStateDefault, {
browser: { redisearch: nextState },
})
expect(redisearchSelector(rootState)).toEqual(state)
})
})

describe('thunks', () => {
describe('fetchRedisearchListAction', () => {
it('call both fetchRedisearchListAction, loadListSuccess when fetch is successed', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/critical-path/browser/bulk-delete.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('Verify that user can access the bulk actions screen in the Browser', async
});
test('Verify that user can see summary of scanned level', async t => {
const expectedAmount = new RegExp('Expected amount: ~(9|10) \\d{3} keys');
const scannedKeys = new RegExp('Scanned (5|10)% \\(\\d{3,5}/10 \\d{3}\\) and found \\d{3,5} keys');
const scannedKeys = new RegExp('Scanned (5|10)% \\((500|1000)/10 \\d{3}\\) and found \\d{3,5} keys');
const messageTitle = 'No pattern or key type set';
const messageText = 'To perform a bulk action, set the pattern or select the key type';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test
await browserPage.searchByKeyName('*');
const keysNumberOfResults = await browserPage.keysNumberOfResults.textContent;
// Verify that number of results is 500
await t.expect(keysNumberOfResults).contains('500', 'Number of results is not 500');
await t.expect(keysNumberOfResults).match(/50[0-9]/, 'Number of results is not 500');
});
test
.meta({ rte: rte.standalone })('Verify that user can search iteratively via Scan more for search pattern and selected data type', async t => {
Expand Down