Skip to content

Commit 89f6cc2

Browse files
authored
RI-7315: fix rdi pipeline upload from file (#5114)
1 parent d690928 commit 89f6cc2

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

redisinsight/ui/src/components/yaml-validator/validatePipeline.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { get } from 'lodash'
22
import { Nullable } from 'uiSrc/utils'
3-
import { validateSchema, validateYamlSchema } from './validateYamlSchema'
3+
import {
4+
validateSchema,
5+
validateYamlSchema,
6+
VALID_RESULT,
7+
} from './validateYamlSchema'
48

59
interface PipelineValidationProps {
610
config: string
@@ -28,10 +32,12 @@ export const validatePipeline = ({
2832
}>(
2933
(acc, j) => {
3034
const validation = validateYamlSchema(j.value, monacoJobsSchema)
31-
const jobNameValidation = validateSchema(j.name, jobNameSchema, {
32-
errorMessagePrefix: 'Job name',
33-
includePathIntoErrorMessage: false,
34-
})
35+
const jobNameValidation = !jobNameSchema
36+
? VALID_RESULT
37+
: validateSchema(j.name, jobNameSchema, {
38+
errorMessagePrefix: 'Job name',
39+
includePathIntoErrorMessage: false,
40+
})
3541

3642
if (!acc.jobsErrors[j.name]) {
3743
acc.jobsErrors[j.name] = new Set()
@@ -41,7 +47,7 @@ export const validatePipeline = ({
4147
validation.errors.forEach((error) => acc.jobsErrors[j.name].add(error))
4248
}
4349

44-
if (jobNameSchema && !jobNameValidation.valid) {
50+
if (!jobNameValidation.valid) {
4551
jobNameValidation.errors.forEach((error) =>
4652
acc.jobsErrors[j.name].add(error),
4753
)

redisinsight/ui/src/components/yaml-validator/validateYamlSchema.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ type ValidationConfig = {
66
includePathIntoErrorMessage?: boolean
77
}
88

9+
type ValidationResult = {
10+
valid: boolean
11+
errors: string[]
12+
}
13+
14+
export const VALID_RESULT: ValidationResult = { valid: true, errors: [] }
15+
916
export const validateSchema = (
1017
parsed: any,
1118
schema: any,
1219
config: ValidationConfig = {},
13-
): { valid: boolean; errors: string[] } => {
20+
): ValidationResult => {
1421
const errorMessagePrefix = config.errorMessagePrefix ?? 'Error:'
1522
const includePathIntoErrorMessage = config.includePathIntoErrorMessage ?? true
1623

@@ -25,12 +32,12 @@ export const validateSchema = (
2532
const valid = validate(parsed)
2633

2734
if (!valid) {
28-
const errors = validate.errors?.map(
29-
(err) => {
30-
const pathMessage = includePathIntoErrorMessage ? ` (at ${err.instancePath || 'root'})` : ''
31-
return `${[errorMessagePrefix]} ${err.message}${pathMessage}`
32-
}
33-
)
35+
const errors = validate.errors?.map((err) => {
36+
const pathMessage = includePathIntoErrorMessage
37+
? ` (at ${err.instancePath || 'root'})`
38+
: ''
39+
return `${[errorMessagePrefix]} ${err.message}${pathMessage}`
40+
})
3441
return { valid: false, errors: errors || [] }
3542
}
3643

@@ -43,7 +50,7 @@ export const validateSchema = (
4350
export const validateYamlSchema = (
4451
content: string,
4552
schema: any,
46-
): { valid: boolean; errors: string[] } => {
53+
): ValidationResult => {
4754
try {
4855
const parsed = yaml.load(content) as object
4956

redisinsight/ui/src/pages/rdi/pipeline-management/components/upload-modal/UploadModal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const UploadModal = (props: Props) => {
3737
config: pipelineConfig,
3838
jobs: pipelineJobs,
3939
schema,
40+
monacoJobsSchema,
41+
jobNameSchema,
4042
} = useSelector(rdiPipelineSelector)
4143

4244
const { rdiInstanceId } = useParams<{ rdiInstanceId: string }>()
@@ -111,7 +113,13 @@ const UploadModal = (props: Props) => {
111113

112114
if (config && schema && jobs?.length) {
113115
const { result, configValidationErrors, jobsValidationErrors } =
114-
validatePipeline({ config, schema, jobs })
116+
validatePipeline({
117+
config,
118+
schema,
119+
jobs,
120+
monacoJobsSchema,
121+
jobNameSchema,
122+
})
115123

116124
dispatch(setConfigValidationErrors(configValidationErrors))
117125
dispatch(setJobsValidationErrors(jobsValidationErrors))

0 commit comments

Comments
 (0)