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
21 changes: 7 additions & 14 deletions redisinsight/ui/src/slices/interfaces/rdi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { monaco as monacoEditor } from 'react-monaco-editor'
import { Nullable } from 'uiSrc/utils'
import { ICommand } from 'uiSrc/constants'
import { Rdi as RdiInstanceResponse } from 'apiSrc/modules/rdi/models/rdi'

// tabs for dry run job panel
Expand Down Expand Up @@ -151,7 +153,7 @@ export interface IStateRdiPipeline {
schema: Nullable<object>
strategies: IRdiPipelineStrategies
changes: Record<string, FileChangeType>
jobFunctions: IStateJobFunction[]
jobFunctions: monacoEditor.languages.CompletionItem[]
status: {
loading: boolean
error: string
Expand Down Expand Up @@ -188,19 +190,6 @@ export interface InitialStateRdiInstances {
isPipelineLoaded: boolean
}

export interface IJobFunctionResponse {
function: string
description: string
example: string
comments: string
}

export interface IStateJobFunction {
label: string
detail: string
documentation: string
}

// Rdi test target connections
export enum TestConnectionStatus {
Fail = 'fail',
Expand Down Expand Up @@ -240,3 +229,7 @@ export interface IStateRdiTestConnections {
error: string
results: Nullable<TransformResult>
}

export type TJMESPathFunctions = {
[key: string]: Pick<ICommand, 'summary'> & Required<Pick<ICommand, 'arguments'>>
}
21 changes: 13 additions & 8 deletions redisinsight/ui/src/slices/rdi/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import {
FileChangeType,
IPipelineJSON,
IRdiPipelineStrategy,
IJobFunctionResponse,
TJMESPathFunctions,
IPipelineStatus,
} from 'uiSrc/slices/interfaces/rdi'
import { getApiErrorMessage, getAxiosError, getRdiUrl, isStatusSuccessful, Nullable, pipelineToYaml } from 'uiSrc/utils'
import {
getApiErrorMessage,
getAxiosError,
getRdiUrl,
isStatusSuccessful,
Nullable,
parseJMESPathFunctions,
pipelineToYaml,
} from 'uiSrc/utils'
import { EnhancedAxiosError } from 'uiSrc/slices/interfaces'
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
import { ApiEndpoints } from 'uiSrc/constants'
Expand Down Expand Up @@ -110,11 +118,8 @@ const rdiPipelineSlice = createSlice({
data: null
}
},
setJobFunctions: (state, { payload }: PayloadAction<IJobFunctionResponse[]>) => {
state.jobFunctions = payload.map(
({ function: label, description: documentation, example: detail }) =>
({ label, documentation, detail })
)
setJobFunctions: (state, { payload }: PayloadAction<TJMESPathFunctions>) => {
state.jobFunctions = parseJMESPathFunctions(payload)
},
},
})
Expand Down Expand Up @@ -289,7 +294,7 @@ export function fetchRdiPipelineJobFunctions(
) {
return async (dispatch: AppDispatch) => {
try {
const { data, status } = await apiService.get<IJobFunctionResponse[]>(
const { data, status } = await apiService.get<TJMESPathFunctions>(
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_PIPELINE_JOB_FUNCTIONS),
)

Expand Down
26 changes: 15 additions & 11 deletions redisinsight/ui/src/slices/tests/rdi/pipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { apiService } from 'uiSrc/services'
import { addErrorNotification, addInfiniteNotification } from 'uiSrc/slices/app/notifications'
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
import { FileChangeType } from 'uiSrc/slices/interfaces'
import { parseJMESPathFunctions } from 'uiSrc/utils'

let store: typeof mockedStore

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

describe('setJobFunctions', () => {
it('should set job functions as monaco compilation items', () => {
const functionValue = 'function'
const descriptionValue = 'description'
const exampleValue = 'example'
const commentsValue = 'comments'
const mockData = [{
function: functionValue,
description: descriptionValue,
example: exampleValue,
comments: commentsValue,
const summaryValue = 'summary'
const argumentsValue = [{
name: 'encoded',
type: 'string',
display_text: 'base64 encoded string',
optional: false
}]
const mockData = {
function: {
summary: summaryValue,
arguments: argumentsValue,
}
}

// Arrange
const state = {
...initialState,
jobFunctions: [{ label: functionValue, detail: exampleValue, documentation: descriptionValue }]
jobFunctions: parseJMESPathFunctions(mockData)
}

// Act
Expand Down Expand Up @@ -603,7 +607,7 @@ describe('rdi pipe slice', () => {

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

apiService.get = jest.fn().mockResolvedValue(responsePayload)
Expand Down
33 changes: 31 additions & 2 deletions redisinsight/ui/src/utils/monaco/monacoUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { monaco as monacoEditor } from 'react-monaco-editor'
import { first, isEmpty, isUndefined, reject, without } from 'lodash'
import { decode } from 'html-entities'
import { ICommands } from 'uiSrc/constants'
import { IMonacoCommand, IMonacoQuery } from 'uiSrc/utils'
import { ICommands, ICommand } from 'uiSrc/constants'
import {
generateArgsForInsertText,
generateArgsNames,
getCommandMarkdown,
IMonacoCommand,
IMonacoQuery
} from 'uiSrc/utils'
import { TJMESPathFunctions } from 'uiSrc/slices/interfaces'
import { Nullable } from '../types'
import { getCommandRepeat, isRepeatCountCorrect } from '../commands'

Expand Down Expand Up @@ -234,3 +241,25 @@ export const getCommandsFromQuery = (query: string, commandsArray: string[] = []
const listOfCommands = [commandLine, multiCommands].filter(Boolean)
return listOfCommands.length ? listOfCommands.join(';') : null
}

export const parseJMESPathFunctions = (functions: TJMESPathFunctions) => Object.entries(functions)
.map(([labelInit, func]) => {
const { arguments: args } = func
const label = labelInit.toUpperCase()
const range = { startLineNumber: 0, endLineNumber: 0, startColumn: 0, endColumn: 0 }
const detail = `${label}(${generateArgsNames('', args).join(', ')})`
const argsNames = generateArgsNames('', args, false, true)
const insertText = `${label}(${generateArgsForInsertText(argsNames, ', ')})`

return {
label,
detail,
range,
documentation: {
value: getCommandMarkdown(func as ICommand)
},
insertText,
kind: monacoEditor.languages.CompletionItemKind.Function,
insertTextRules: monacoEditor.languages.CompletionItemInsertTextRule.InsertAsSnippet,
}
})