Skip to content

Commit 7f226b9

Browse files
Merge pull request #3518 from RedisInsight/fe/feature/RI-5750_update_rdi
#RI-5750 - update get template endpoint
2 parents b539a1e + bfda9b7 commit 7f226b9

File tree

8 files changed

+97
-40
lines changed

8 files changed

+97
-40
lines changed

redisinsight/ui/src/constants/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ enum ApiEndpoints {
148148
RDI_DEPLOY_PIPELINE = 'pipeline/deploy',
149149
RDI_TEST_CONNECTIONS = 'pipeline/test-connections',
150150
RDI_PIPELINE_STRATEGIES = 'pipeline/strategies',
151-
RDI_PIPELINE_TEMPLATE = 'pipeline/template',
151+
RDI_JOB_TEMPLATE = 'pipeline/job/template',
152+
RDI_CONFIG_TEMPLATE = 'pipeline/config/template',
152153
RDI_PIPELINE_JOB_FUNCTIONS = 'pipeline/job-functions',
153154
RDI_STATISTICS = 'statistics',
154155
RDI_PIPELINE_STATUS = 'pipeline/status',

redisinsight/ui/src/pages/rdi/pipeline-management/components/template-form/TemplateForm.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import { useDispatch, useSelector } from 'react-redux'
1313
import { useParams } from 'react-router-dom'
1414
import cx from 'classnames'
1515

16-
import { fetchPipelineStrategies, fetchPipelineTemplate, rdiPipelineStrategiesSelector } from 'uiSrc/slices/rdi/pipeline'
16+
import {
17+
fetchPipelineStrategies,
18+
fetchJobTemplate,
19+
fetchConfigTemplate,
20+
rdiPipelineStrategiesSelector,
21+
} from 'uiSrc/slices/rdi/pipeline'
1722
import { RdiPipelineTabs } from 'uiSrc/slices/interfaces/rdi'
1823
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1924
import { NO_TEMPLATE_VALUE, NO_OPTIONS, INGEST_OPTION } from './constants'
@@ -69,11 +74,12 @@ const TemplateForm = (props: Props) => {
6974
}
7075

7176
const handleApply = () => {
72-
const values = source === RdiPipelineTabs.Config
73-
? { dbType: selectedDbType, pipelineType: selectedPipelineType }
74-
: { pipelineType: selectedPipelineType }
75-
76-
dispatch(fetchPipelineTemplate(rdiInstanceId, values, onSuccess))
77+
if (source === RdiPipelineTabs.Config) {
78+
dispatch(fetchConfigTemplate(rdiInstanceId, selectedPipelineType, selectedDbType, onSuccess))
79+
}
80+
if (source === RdiPipelineTabs.Jobs) {
81+
dispatch(fetchJobTemplate(rdiInstanceId, selectedPipelineType, onSuccess))
82+
}
7783
sendEventTelemetry({
7884
event: TelemetryEvent.RDI_TEMPLATE_CLICKED,
7985
eventData: {

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ export interface IRdiPipelineStrategies {
5252

5353
export interface IConnections {
5454
[key: string]: {
55-
host: string;
56-
port: number;
57-
status: string;
58-
type: string;
59-
database: string;
60-
user: string;
55+
host: string
56+
port: number
57+
status: string
58+
type: string
59+
database: string
60+
user: string
6161
}
6262
}
6363

@@ -209,31 +209,31 @@ export enum TestConnectionStatus {
209209
}
210210

211211
interface IErrorDetail {
212-
code: string;
213-
message: string;
212+
code: string
213+
message: string
214214
}
215215

216-
interface ISourceDetail {
217-
status: TestConnectionStatus;
218-
error?: IErrorDetail;
216+
interface ITargetDetail {
217+
status: TestConnectionStatus
218+
error?: IErrorDetail
219219
}
220220

221-
export interface ISources {
222-
[key: string]: ISourceDetail;
221+
export interface ITargets {
222+
[key: string]: ITargetDetail
223223
}
224224

225225
export interface TestConnectionsResponse {
226-
sources: ISources
226+
targets: ITargets
227227
}
228228

229229
export interface IRdiConnectionResult {
230-
target: string;
231-
error?: string;
230+
target: string
231+
error?: string
232232
}
233233

234234
export interface TransformResult {
235-
success: IRdiConnectionResult[];
236-
fail: IRdiConnectionResult[];
235+
success: IRdiConnectionResult[]
236+
fail: IRdiConnectionResult[]
237237
}
238238

239239
export interface IStateRdiTestConnections {

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,42 @@ export function fetchPipelineStrategies(
232232
}
233233
}
234234

235-
export function fetchPipelineTemplate(
235+
export function fetchJobTemplate(
236236
rdiInstanceId: string,
237-
// TODO add interface
238-
options: any,
237+
pipelineType: string,
239238
onSuccessAction?: (template: string) => void,
240239
onFailAction?: () => void,
241240
) {
242241
return async (dispatch: AppDispatch) => {
243242
try {
244243
const { status, data } = await apiService.get(
245-
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_PIPELINE_TEMPLATE),
246-
{ params: options },
244+
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_JOB_TEMPLATE, pipelineType),
245+
)
246+
247+
if (isStatusSuccessful(status)) {
248+
onSuccessAction?.(data.template)
249+
}
250+
} catch (_err) {
251+
const error = _err as AxiosError
252+
const parsedError = getAxiosError(error as EnhancedAxiosError)
253+
254+
dispatch(addErrorNotification(parsedError))
255+
onFailAction?.()
256+
}
257+
}
258+
}
259+
260+
export function fetchConfigTemplate(
261+
rdiInstanceId: string,
262+
pipelineType: string,
263+
dbType: string,
264+
onSuccessAction?: (template: string) => void,
265+
onFailAction?: () => void,
266+
) {
267+
return async (dispatch: AppDispatch) => {
268+
try {
269+
const { status, data } = await apiService.get(
270+
getRdiUrl(rdiInstanceId, ApiEndpoints.RDI_CONFIG_TEMPLATE, pipelineType, dbType),
247271
)
248272

249273
if (isStatusSuccessful(status)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function testConnectionsAction(
8888
testConnectionsController = null
8989

9090
if (isStatusSuccessful(status)) {
91-
dispatch(testConnectionsSuccess(transformConnectionResults(data?.sources)))
91+
dispatch(testConnectionsSuccess(transformConnectionResults(data?.targets)))
9292
onSuccessAction?.()
9393
}
9494
} catch (_err) {

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import reducer, {
2626
deployPipelineAction,
2727
fetchRdiPipelineSchema,
2828
fetchPipelineStrategies,
29-
fetchPipelineTemplate,
29+
fetchConfigTemplate,
30+
fetchJobTemplate,
3031
setJobFunctions,
3132
fetchRdiPipelineJobFunctions,
3233
getPipelineStatusAction,
@@ -387,7 +388,6 @@ describe('rdi pipe slice', () => {
387388
})
388389
})
389390

390-
391391
describe('getPipelineStatus', () => {
392392
it('should set loading = true', () => {
393393
// Arrange
@@ -689,9 +689,34 @@ describe('rdi pipe slice', () => {
689689
})
690690
})
691691

692-
describe('fetchPipelineTemplate', () => {
692+
describe('fetchJobTemplate', () => {
693+
it('failed to fetch data', async () => {
694+
const errorMessage = 'Something was wrong!'
695+
const responsePayload = {
696+
response: {
697+
status: 500,
698+
data: { message: errorMessage },
699+
},
700+
}
701+
702+
apiService.get = jest.fn().mockRejectedValue(responsePayload)
703+
704+
// Act
705+
await store.dispatch<any>(
706+
fetchJobTemplate('123', 'db_type')
707+
)
708+
709+
// Assert
710+
const expectedActions = [
711+
addErrorNotification(responsePayload as AxiosError),
712+
]
713+
714+
expect(store.getActions()).toEqual(expectedActions)
715+
})
716+
})
717+
718+
describe('fetchConfigTemplate', () => {
693719
it('failed to fetch data', async () => {
694-
const mockOptions = { dbType: 'db type' }
695720
const errorMessage = 'Something was wrong!'
696721
const responsePayload = {
697722
response: {
@@ -704,7 +729,7 @@ describe('rdi pipe slice', () => {
704729

705730
// Act
706731
await store.dispatch<any>(
707-
fetchPipelineTemplate('123', mockOptions)
732+
fetchConfigTemplate('123', 'ingest', 'db_type')
708733
)
709734

710735
// Assert

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { apiService } from 'uiSrc/services'
1313
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
1414

1515
const mockData = {
16-
sources: {
16+
targets: {
1717
target: {
1818
status: 'success',
1919
}
@@ -54,14 +54,15 @@ describe('rdi test connections slice', () => {
5454
describe('testConnectionsSuccess', () => {
5555
it('should properly set state', () => {
5656
// Arrange
57+
const data = { success: [{ target: 'target' }], fail: [] }
5758
const state = {
5859
...initialState,
59-
results: mockData,
60+
results: data,
6061
loading: false,
6162
}
6263

6364
// Act
64-
const nextState = reducer(initialState, testConnectionsSuccess(mockData))
65+
const nextState = reducer(initialState, testConnectionsSuccess(data))
6566

6667
// Assert
6768
const rootState = Object.assign(initialStateDefault, {

redisinsight/ui/src/utils/transformers/transformRdiPipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const pipelineToJson = ({ config, jobs }: IPipeline): IPipelineJSON => <I
1919

2020
export const transformConnectionResults = (sources: ISources): TransformResult => {
2121
const result: TransformResult = { success: [], fail: [] }
22-
22+
console.log(sources)
2323
if (!sources) {
2424
return result
2525
}

0 commit comments

Comments
 (0)