Skip to content

Commit 2a2e2de

Browse files
#RI-3432-reverse commands in workbench execution (#1107)
* #RI-3432-reverse commands in workbench execution
1 parent 82a553d commit 2a2e2de

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

redisinsight/ui/src/pages/workbench/components/wb-view/WBViewWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux'
33
import { decode } from 'html-entities'
44
import { useParams } from 'react-router-dom'
55
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'
6-
import { chunk, reverse, without } from 'lodash'
6+
import { chunk, without } from 'lodash'
77

88
import {
99
Nullable,
@@ -159,7 +159,7 @@ const WBViewWrapper = () => {
159159

160160
isNewCommand() && scrollResults('start')
161161

162-
sendCommand(reverse(commandLine), multiCommands)
162+
sendCommand(commandLine, multiCommands)
163163
}
164164

165165
const sendCommand = (

redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,33 @@ describe('workbench results slice', () => {
206206
})
207207

208208
describe('thunks', () => {
209-
describe('Standalone Cli command', () => {
209+
describe('Standalone Cli commands', () => {
210210
it('call both sendWBCommandAction and sendWBCommandSuccess when response status is successed', async () => {
211211
// Arrange
212-
const commands = ['keys *']
212+
const commands = ['keys *', 'set 1 1']
213213
const commandId = `${Date.now()}`
214-
const data = [{
215-
command: 'command',
216-
databaseId: '123',
217-
id: commandId + (commands.length - 1),
218-
createdAt: new Date(),
219-
result: [{
220-
response: 'test',
221-
status: CommandExecutionStatus.Success
222-
}]
223-
}]
214+
const data = [
215+
{
216+
command: 'keys *',
217+
databaseId: '123',
218+
id: commandId + (commands.length - 1),
219+
createdAt: new Date(),
220+
result: [{
221+
response: 'test',
222+
status: CommandExecutionStatus.Success
223+
}]
224+
},
225+
{
226+
command: 'set 1 1',
227+
databaseId: '123',
228+
id: commandId + (commands.length - 1),
229+
createdAt: new Date(),
230+
result: [{
231+
response: 'test',
232+
status: CommandExecutionStatus.Success
233+
}]
234+
}
235+
]
224236
const responsePayload = { data, status: 200 }
225237

226238
apiService.post = jest.fn().mockResolvedValue(responsePayload)
@@ -238,9 +250,9 @@ describe('workbench results slice', () => {
238250

239251
it('call both sendWBCommandAction and sendWBCommandSuccess when response status is fail', async () => {
240252
// Arrange
241-
const command = 'keys *'
253+
const commands = ['keys *']
242254
const commandId = `${Date.now()}`
243-
const data = {
255+
const data = [{
244256
command: 'command',
245257
databaseId: '123',
246258
id: commandId,
@@ -249,17 +261,17 @@ describe('workbench results slice', () => {
249261
response: 'test',
250262
status: CommandExecutionStatus.Fail
251263
}]
252-
}
264+
}]
253265
const responsePayload = { data, status: 200 }
254266

255267
apiService.post = jest.fn().mockResolvedValue(responsePayload)
256268

257269
// Act
258-
await store.dispatch<any>(sendWBCommandAction({ command, commandId }))
270+
await store.dispatch<any>(sendWBCommandAction({ commands, commandId }))
259271

260272
// Assert
261273
const expectedActions = [
262-
sendWBCommand({ command, commandId }),
274+
sendWBCommand({ commands, commandId }),
263275
sendWBCommandSuccess({ data, commandId })
264276
]
265277

@@ -268,7 +280,7 @@ describe('workbench results slice', () => {
268280

269281
it('call both sendWBCommandAction and processWBCommandFailure when fetch is fail', async () => {
270282
// Arrange
271-
const command = 'keys *'
283+
const commands = ['keys *']
272284
const commandId = `${Date.now()}`
273285
const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'
274286
const responsePayload = {
@@ -281,13 +293,13 @@ describe('workbench results slice', () => {
281293
apiService.post = jest.fn().mockRejectedValueOnce(responsePayload)
282294

283295
// Act
284-
await store.dispatch<any>(sendWBCommandAction({ command, commandId }))
296+
await store.dispatch<any>(sendWBCommandAction({ commands, commandId }))
285297

286298
// Assert
287299
const expectedActions = [
288-
sendWBCommand({ command, commandId }),
300+
sendWBCommand({ commands, commandId }),
289301
addErrorNotification(responsePayload as AxiosError),
290-
processWBCommandFailure({ command, error: responsePayload.response.data.message }),
302+
processWBCommandFailure({ id: commandId, error: responsePayload.response.data.message }),
291303
]
292304
expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions))
293305
})
@@ -335,8 +347,8 @@ describe('workbench results slice', () => {
335347

336348
it('call both sendWBCommandClusterAction and sendWBCommandSuccess when response status is fail', async () => {
337349
// Arrange
338-
const command = 'keys *'
339-
const data = {
350+
const commands = ['keys *']
351+
const data = [{
340352
command: 'command',
341353
databaseId: '123',
342354
id: commandId,
@@ -345,25 +357,25 @@ describe('workbench results slice', () => {
345357
response: 'test',
346358
status: CommandExecutionStatus.Fail
347359
}]
348-
}
360+
}]
349361
const responsePayload = { data, status: 200 }
350362

351363
apiService.post = jest.fn().mockResolvedValue(responsePayload)
352364

353365
// Act
354-
await store.dispatch<any>(sendWBCommandClusterAction({ command, options, commandId }))
366+
await store.dispatch<any>(sendWBCommandClusterAction({ commands, options, commandId }))
355367

356368
// Assert
357369
const expectedActions = [
358-
sendWBCommand({ command, commandId }),
370+
sendWBCommand({ commands, commandId }),
359371
sendWBCommandSuccess({ data, commandId })
360372
]
361373
expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions))
362374
})
363375

364376
it('call both sendWBCommandClusterAction and processWBCommandFailure when fetch is fail', async () => {
365377
// Arrange
366-
const command = 'keys *'
378+
const commands = ['keys *']
367379
const errorMessage = 'Could not connect to aoeu:123, please check the connection details.'
368380
const responsePayload = {
369381
response: {
@@ -375,13 +387,13 @@ describe('workbench results slice', () => {
375387
apiService.post = jest.fn().mockRejectedValueOnce(responsePayload)
376388

377389
// Act
378-
await store.dispatch<any>(sendWBCommandAction({ command, options, commandId }))
390+
await store.dispatch<any>(sendWBCommandAction({ commands, options, commandId }))
379391

380392
// Assert
381393
const expectedActions = [
382-
sendWBCommand({ command, commandId }),
394+
sendWBCommand({ commands, commandId }),
383395
addErrorNotification(responsePayload as AxiosError),
384-
processWBCommandFailure({ command, error: responsePayload.response.data.message }),
396+
processWBCommandFailure({ id: commandId, error: responsePayload.response.data.message }),
385397
]
386398
expect(clearStoreActions(store.getActions())).toEqual(clearStoreActions(expectedActions))
387399
})

redisinsight/ui/src/slices/workbench/wb-results.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createSlice } from '@reduxjs/toolkit'
22
import { AxiosError } from 'axios'
3+
import { reverse } from 'lodash'
34
import { apiService } from 'uiSrc/services'
45
import { ApiEndpoints } from 'uiSrc/constants'
56
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
@@ -204,7 +205,7 @@ export function sendWBCommandAction({
204205
commands: string[]
205206
multiCommands?: string[]
206207
commandId?: string
207-
mode: RunQueryMode
208+
mode?: RunQueryMode
208209
onSuccessAction?: (multiCommands: string[]) => void
209210
onFailAction?: () => void
210211
}) {
@@ -227,7 +228,7 @@ export function sendWBCommandAction({
227228
)
228229

229230
if (isStatusSuccessful(status)) {
230-
dispatch(sendWBCommandSuccess({ commandId, data, processing: !!multiCommands?.length }))
231+
dispatch(sendWBCommandSuccess({ commandId, data: reverse(data), processing: !!multiCommands?.length }))
231232

232233
onSuccessAction?.(multiCommands)
233234
}
@@ -255,7 +256,7 @@ export function sendWBCommandClusterAction({
255256
options: CreateCommandExecutionDto
256257
commandId?: string
257258
multiCommands?: string[]
258-
mode: RunQueryMode,
259+
mode?: RunQueryMode,
259260
onSuccessAction?: (multiCommands: string[]) => void
260261
onFailAction?: () => void
261262
}) {
@@ -280,7 +281,7 @@ export function sendWBCommandClusterAction({
280281
)
281282

282283
if (isStatusSuccessful(status)) {
283-
dispatch(sendWBCommandSuccess({ commandId, data }))
284+
dispatch(sendWBCommandSuccess({ commandId, data: reverse(data) }))
284285

285286
onSuccessAction?.(multiCommands)
286287
}

0 commit comments

Comments
 (0)