mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
feat(namespace): migrate create ns to react [EE-2226] (#10377)
This commit is contained in:
parent
31bcba96c6
commit
7218eb0892
83 changed files with 1869 additions and 358 deletions
68
app/react/kubernetes/annotations/validation.ts
Normal file
68
app/react/kubernetes/annotations/validation.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
import { SchemaOf, array, object, string } from 'yup';
|
||||
|
||||
import { buildUniquenessTest } from '@@/form-components/validate-unique';
|
||||
|
||||
import { Annotation } from './types';
|
||||
|
||||
const re = /^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$/;
|
||||
|
||||
export const annotationsSchema: SchemaOf<Annotation[]> = array(
|
||||
getAnnotationValidation()
|
||||
).test(
|
||||
'unique',
|
||||
'Duplicate keys are not allowed.',
|
||||
buildUniquenessTest(() => 'Duplicate keys are not allowed.', 'Key')
|
||||
);
|
||||
|
||||
function getAnnotationValidation(): SchemaOf<Annotation> {
|
||||
return object({
|
||||
Key: string()
|
||||
.required('Key is required.')
|
||||
.test('is-valid', (value, { createError }) => {
|
||||
if (!value) {
|
||||
return true;
|
||||
}
|
||||
const keySegments = value.split('/');
|
||||
if (keySegments.length > 2) {
|
||||
return createError({
|
||||
message:
|
||||
'Two segments are allowed, separated by a slash (/): a prefix (optional) and a name.',
|
||||
});
|
||||
}
|
||||
if (keySegments.length === 2) {
|
||||
if (keySegments[0].length > 253) {
|
||||
return createError({
|
||||
message: "Prefix (before the slash) can't exceed 253 characters.",
|
||||
});
|
||||
}
|
||||
if (keySegments[1].length > 63) {
|
||||
return createError({
|
||||
message: "Name (after the slash) can't exceed 63 characters.",
|
||||
});
|
||||
}
|
||||
if (!re.test(keySegments[1])) {
|
||||
return createError({
|
||||
message:
|
||||
'Start and end with alphanumeric characters only, limiting characters in between to dashes, underscores, and alphanumerics.',
|
||||
});
|
||||
}
|
||||
} else if (keySegments.length === 1) {
|
||||
if (keySegments[0].length > 63) {
|
||||
return createError({
|
||||
message:
|
||||
"Name (the segment after a slash (/), or only segment if no slash) can't exceed 63 characters.",
|
||||
});
|
||||
}
|
||||
if (!re.test(keySegments[0])) {
|
||||
return createError({
|
||||
message:
|
||||
'Start and end with alphanumeric characters only, limiting characters in between to dashes, underscores, and alphanumerics.',
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
Value: string().required('Value is required.'),
|
||||
ID: string().required('ID is required.'),
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue