1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-09 15:55:23 +02:00

fix(custom-templates): add stack validation, remove custom template validation [EE-7102] (#11938)
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled

Co-authored-by: testa113 <testa113>
This commit is contained in:
Ali 2024-06-17 09:24:54 +12:00 committed by GitHub
parent 0f5988af49
commit be9d3285e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 68 additions and 44 deletions

View file

@ -95,14 +95,10 @@ export function CommonFields({
export function validation({
currentTemplateId,
templates = [],
viewType = 'docker',
}: {
currentTemplateId?: CustomTemplate['Id'];
templates?: Array<CustomTemplate>;
viewType?: 'kube' | 'docker' | 'edge';
} = {}): SchemaOf<Values> {
const titlePattern = titlePatternValidation(viewType);
return object({
Title: string()
.required('Title is required.')
@ -116,31 +112,12 @@ export function validation({
template.Title === value && template.Id !== currentTemplateId
)
)
.matches(titlePattern.pattern, titlePattern.error),
.max(
200,
'Custom template title must be less than or equal to 200 characters'
),
Description: string().required('Description is required.'),
Note: string().default(''),
Logo: string().default(''),
});
}
export const TEMPLATE_NAME_VALIDATION_REGEX = '^[-_a-z0-9]+$';
const KUBE_TEMPLATE_NAME_VALIDATION_REGEX =
'^(([a-z0-9](?:(?:[-a-z0-9_.]){0,61}[a-z0-9])?))$'; // alphanumeric, lowercase, can contain dashes, dots and underscores, max 63 characters
function titlePatternValidation(type: 'kube' | 'docker' | 'edge') {
switch (type) {
case 'kube':
return {
pattern: new RegExp(KUBE_TEMPLATE_NAME_VALIDATION_REGEX),
error:
"This field must consist of lower-case alphanumeric characters, '.', '_' or '-', must start and end with an alphanumeric character and must be 63 characters or less (e.g. 'my-name', or 'abc-123').",
};
default:
return {
pattern: new RegExp(TEMPLATE_NAME_VALIDATION_REGEX),
error:
"This field must consist of lower-case alphanumeric characters, '_' or '-' (e.g. 'my-name', or 'abc-123').",
};
}
}

View file

@ -6,7 +6,7 @@ import { MetadataFieldset } from './MetadataFieldset';
export function MoreSettingsSection({ children }: PropsWithChildren<unknown>) {
return (
<FormSection title="More settings" isFoldable>
<FormSection title="More settings" className="ml-0" isFoldable>
<div className="ml-8">
{children}

View file

@ -72,7 +72,6 @@ export function useValidation({
}).concat(
commonFieldsValidation({
templates: customTemplatesQuery.data,
viewType,
})
),
[

View file

@ -62,7 +62,6 @@ export function useValidation({
commonFieldsValidation({
templates: customTemplatesQuery.data,
currentTemplateId: templateId,
viewType,
})
),
[

View file

@ -63,7 +63,7 @@ export function DeployForm({
const isGit = !!template.GitConfig;
const initialValues: FormValues = {
name: template.Title || '',
name: '',
variables: getVariablesFieldDefaultValues(template.Variables),
accessControl: parseAccessControlFormData(
isEdgeAdminQuery.isAdmin,
@ -86,6 +86,7 @@ export function DeployForm({
value={values.name}
onChange={(v) => setFieldValue('name', v)}
errors={errors.name}
placeholder="e.g. mystack"
/>
</FormSection>