Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7126 from vikram-raj/odc-5092
i18n support in devconsole hpa components
- Loading branch information
Showing
7 changed files
with
127 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 62 additions & 59 deletions
121
frontend/packages/dev-console/src/components/hpa/validation-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,69 @@ | ||
import * as yup from 'yup'; | ||
import { TFunction } from 'i18next'; | ||
import { EditorType } from '@console/shared/src/components/synced-editor/editor-toggle'; | ||
|
||
export const hpaValidationSchema = yup.object({ | ||
editorType: yup.string(), | ||
formData: yup.object().when('editorType', { | ||
is: EditorType.Form, | ||
then: yup.object({ | ||
metadata: yup.object({ | ||
name: yup | ||
.string() | ||
.matches(/^([a-z]([-a-z0-9]*[a-z0-9])?)*$/, { | ||
message: | ||
'Name must consist of lower-case letters, numbers and hyphens. It must start with a letter and end with a letter or number.', | ||
excludeEmptyString: true, | ||
}) | ||
.max(253, 'Cannot be longer than 253 characters.') | ||
.required('Required'), | ||
}), | ||
spec: yup.object({ | ||
minReplicas: yup | ||
.number() | ||
.integer('Minimum Pods must be an integer.') | ||
.min(1, 'Minimum Pods must greater than or equal to 1.') | ||
.test( | ||
'test-less-than-max', | ||
'Minimum Pods should be less than or equal to Maximum Pods.', | ||
function(minReplicas) { | ||
const { maxReplicas } = this.parent; | ||
return minReplicas <= maxReplicas; | ||
}, | ||
), | ||
maxReplicas: yup | ||
.number() | ||
.integer('Maximum Pods must be an integer.') | ||
.test( | ||
'test-greater-than-min', | ||
'Maximum Pods should be greater than or equal to Minimum Pods.', | ||
function(maxReplicas) { | ||
const { minReplicas } = this.parent; | ||
return minReplicas <= maxReplicas; | ||
}, | ||
) | ||
.required('Max Pods must be defined.'), | ||
metrics: yup.array( | ||
yup.object({ | ||
resource: yup.object({ | ||
target: yup.object({ | ||
averageUtilization: yup | ||
.mixed() | ||
.test( | ||
'test-for-valid-utilization', | ||
'Average Utilization must be a positive number.', | ||
function(avgUtilization) { | ||
if (!avgUtilization) return true; | ||
return /^\d+$/.test(String(avgUtilization)); | ||
}, | ||
), | ||
export const hpaValidationSchema = (t: TFunction) => | ||
yup.object({ | ||
editorType: yup.string(), | ||
formData: yup.object().when('editorType', { | ||
is: EditorType.Form, | ||
then: yup.object({ | ||
metadata: yup.object({ | ||
name: yup | ||
.string() | ||
.matches(/^([a-z]([-a-z0-9]*[a-z0-9])?)*$/, { | ||
message: t( | ||
'devconsole~Name must consist of lower-case letters, numbers and hyphens. It must start with a letter and end with a letter or number.', | ||
), | ||
excludeEmptyString: true, | ||
}) | ||
.max(253, t('devconsole~Cannot be longer than 253 characters.')) | ||
.required(t('devconsole~Required')), | ||
}), | ||
spec: yup.object({ | ||
minReplicas: yup | ||
.number() | ||
.integer(t('devconsole~Minimum Pods must be an integer.')) | ||
.min(1, t('devconsole~Minimum Pods must greater than or equal to 1.')) | ||
.test( | ||
'test-less-than-max', | ||
t('devconsole~Minimum Pods should be less than or equal to Maximum Pods.'), | ||
function(minReplicas) { | ||
const { maxReplicas } = this.parent; | ||
return minReplicas <= maxReplicas; | ||
}, | ||
), | ||
maxReplicas: yup | ||
.number() | ||
.integer(t('devconsole~Maximum Pods must be an integer.')) | ||
.test( | ||
'test-greater-than-min', | ||
t('devconsole~Maximum Pods should be greater than or equal to Minimum Pods.'), | ||
function(maxReplicas) { | ||
const { minReplicas } = this.parent; | ||
return minReplicas <= maxReplicas; | ||
}, | ||
) | ||
.required(t('devconsole~Max Pods must be defined.')), | ||
metrics: yup.array( | ||
yup.object({ | ||
resource: yup.object({ | ||
target: yup.object({ | ||
averageUtilization: yup | ||
.mixed() | ||
.test( | ||
'test-for-valid-utilization', | ||
t('devconsole~Average Utilization must be a positive number.'), | ||
function(avgUtilization) { | ||
if (!avgUtilization) return true; | ||
return /^\d+$/.test(String(avgUtilization)); | ||
}, | ||
), | ||
}), | ||
}), | ||
}), | ||
}), | ||
), | ||
), | ||
}), | ||
}), | ||
}), | ||
}), | ||
}); | ||
}); |