Skip to content

Commit e1b8aac

Browse files
Merge pull request #3505 from RedisInsight/fe/bugfix/RI-5840_change_JMESPath_format
#RI-5840 - change format for JMESPath functions
2 parents 191116c + 695547f commit e1b8aac

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

redisinsight/ui/src/slices/interfaces/rdi.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { monaco as monacoEditor } from 'react-monaco-editor'
12
import { Nullable } from 'uiSrc/utils'
3+
import { ICommand } from 'uiSrc/constants'
24
import { Rdi as RdiInstanceResponse } from 'apiSrc/modules/rdi/models/rdi'
35

46
// tabs for dry run job panel
@@ -151,7 +153,7 @@ export interface IStateRdiPipeline {
151153
schema: Nullable<object>
152154
strategies: IRdiPipelineStrategies
153155
changes: Record<string, FileChangeType>
154-
jobFunctions: IStateJobFunction[]
156+
jobFunctions: monacoEditor.languages.CompletionItem[]
155157
status: {
156158
loading: boolean
157159
error: string
@@ -188,19 +190,6 @@ export interface InitialStateRdiInstances {
188190
isPipelineLoaded: boolean
189191
}
190192

191-
export interface IJobFunctionResponse {
192-
function: string
193-
description: string
194-
example: string
195-
comments: string
196-
}
197-
198-
export interface IStateJobFunction {
199-
label: string
200-
detail: string
201-
documentation: string
202-
}
203-
204193
// Rdi test target connections
205194
export enum TestConnectionStatus {
206195
Fail = 'fail',
@@ -240,3 +229,7 @@ export interface IStateRdiTestConnections {
240229
error: string
241230
results: Nullable<TransformResult>
242231
}
232+
233+
export type TJMESPathFunctions = {
234+
[key: string]: Pick<ICommand, 'summary'> & Required<Pick<ICommand, 'arguments'>>
235+
}

redisinsight/ui/src/slices/rdi/pipeline.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ import {
88
FileChangeType,
99
IPipelineJSON,
1010
IRdiPipelineStrategy,
11-
IJobFunctionResponse,
11+
TJMESPathFunctions,
1212
IPipelineStatus,
1313
} from 'uiSrc/slices/interfaces/rdi'
14-
import { getApiErrorMessage, getAxiosError, getRdiUrl, isStatusSuccessful, Nullable, pipelineToYaml } from 'uiSrc/utils'
14+
import {
15+
getApiErrorMessage,
16+
getAxiosError,
17+
getRdiUrl,
18+
isStatusSuccessful,
19+
Nullable,
20+
parseJMESPathFunctions,
21+
pipelineToYaml,
22+
} from 'uiSrc/utils'
1523
import { EnhancedAxiosError } from 'uiSrc/slices/interfaces'
1624
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
1725
import { ApiEndpoints } from 'uiSrc/constants'
@@ -110,11 +118,8 @@ const rdiPipelineSlice = createSlice({
110118
data: null
111119
}
112120
},
113-
setJobFunctions: (state, { payload }: PayloadAction<IJobFunctionResponse[]>) => {
114-
state.jobFunctions = payload.map(
115-
({ function: label, description: documentation, example: detail }) =>
116-
({ label, documentation, detail })
117-
)
121+
setJobFunctions: (state, { payload }: PayloadAction<TJMESPathFunctions>) => {
122+
state.jobFunctions = parseJMESPathFunctions(payload)
118123
},
119124
},
120125
})
@@ -289,7 +294,7 @@ export function fetchRdiPipelineJobFunctions(
289294
) {
290295
return async (dispatch: AppDispatch) => {
291296
try {
292-
const { data, status } = await apiService.get<IJobFunctionResponse[]>(
297+
const { data, status } = await apiService.get<TJMESPathFunctions>(
293298
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_PIPELINE_JOB_FUNCTIONS),
294299
)
295300

redisinsight/ui/src/slices/tests/rdi/pipeline.spec.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { apiService } from 'uiSrc/services'
3737
import { addErrorNotification, addInfiniteNotification } from 'uiSrc/slices/app/notifications'
3838
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
3939
import { FileChangeType } from 'uiSrc/slices/interfaces'
40+
import { parseJMESPathFunctions } from 'uiSrc/utils'
4041

4142
let store: typeof mockedStore
4243

@@ -357,21 +358,24 @@ describe('rdi pipe slice', () => {
357358

358359
describe('setJobFunctions', () => {
359360
it('should set job functions as monaco compilation items', () => {
360-
const functionValue = 'function'
361-
const descriptionValue = 'description'
362-
const exampleValue = 'example'
363-
const commentsValue = 'comments'
364-
const mockData = [{
365-
function: functionValue,
366-
description: descriptionValue,
367-
example: exampleValue,
368-
comments: commentsValue,
361+
const summaryValue = 'summary'
362+
const argumentsValue = [{
363+
name: 'encoded',
364+
type: 'string',
365+
display_text: 'base64 encoded string',
366+
optional: false
369367
}]
368+
const mockData = {
369+
function: {
370+
summary: summaryValue,
371+
arguments: argumentsValue,
372+
}
373+
}
370374

371375
// Arrange
372376
const state = {
373377
...initialState,
374-
jobFunctions: [{ label: functionValue, detail: exampleValue, documentation: descriptionValue }]
378+
jobFunctions: parseJMESPathFunctions(mockData)
375379
}
376380

377381
// Act
@@ -603,7 +607,7 @@ describe('rdi pipe slice', () => {
603607

604608
describe('fetchRdiPipelineJobFunctions', () => {
605609
it('succeed to fetch data', async () => {
606-
const data = [{ function: 'func', comments: '123', description: 'desc', example: 'ex' }]
610+
const data = { function: { summary: 'summary', arguments: [] } }
607611
const responsePayload = { data, status: 200 }
608612

609613
apiService.get = jest.fn().mockResolvedValue(responsePayload)

redisinsight/ui/src/utils/monaco/monacoUtils.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { monaco as monacoEditor } from 'react-monaco-editor'
22
import { first, isEmpty, isUndefined, reject, without } from 'lodash'
33
import { decode } from 'html-entities'
4-
import { ICommands } from 'uiSrc/constants'
5-
import { IMonacoCommand, IMonacoQuery } from 'uiSrc/utils'
4+
import { ICommands, ICommand } from 'uiSrc/constants'
5+
import {
6+
generateArgsForInsertText,
7+
generateArgsNames,
8+
getCommandMarkdown,
9+
IMonacoCommand,
10+
IMonacoQuery
11+
} from 'uiSrc/utils'
12+
import { TJMESPathFunctions } from 'uiSrc/slices/interfaces'
613
import { Nullable } from '../types'
714
import { getCommandRepeat, isRepeatCountCorrect } from '../commands'
815

@@ -234,3 +241,25 @@ export const getCommandsFromQuery = (query: string, commandsArray: string[] = []
234241
const listOfCommands = [commandLine, multiCommands].filter(Boolean)
235242
return listOfCommands.length ? listOfCommands.join(';') : null
236243
}
244+
245+
export const parseJMESPathFunctions = (functions: TJMESPathFunctions) => Object.entries(functions)
246+
.map(([labelInit, func]) => {
247+
const { arguments: args } = func
248+
const label = labelInit.toUpperCase()
249+
const range = { startLineNumber: 0, endLineNumber: 0, startColumn: 0, endColumn: 0 }
250+
const detail = `${label}(${generateArgsNames('', args).join(', ')})`
251+
const argsNames = generateArgsNames('', args, false, true)
252+
const insertText = `${label}(${generateArgsForInsertText(argsNames, ', ')})`
253+
254+
return {
255+
label,
256+
detail,
257+
range,
258+
documentation: {
259+
value: getCommandMarkdown(func as ICommand)
260+
},
261+
insertText,
262+
kind: monacoEditor.languages.CompletionItemKind.Function,
263+
insertTextRules: monacoEditor.languages.CompletionItemInsertTextRule.InsertAsSnippet,
264+
}
265+
})

0 commit comments

Comments
 (0)