1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-22 06:49:40 +02:00

refactor(app): migrate remaining form sections [EE-6231] (#10938)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run

This commit is contained in:
Ali 2024-01-11 15:13:28 +13:00 committed by GitHub
parent 0b9cebc685
commit 4e7d1c7088
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 456 additions and 284 deletions

View file

@ -0,0 +1,43 @@
import { SchemaOf, string as yupString } from 'yup';
type ValidationData = {
existingNames: string[];
isEdit: boolean;
originalName?: string;
};
export function appNameValidation(
validationData?: ValidationData
): SchemaOf<string> {
return yupString()
.required('This field is required.')
.test(
'is-unique',
'An application with the same name already exists inside the selected namespace.',
(appName) => {
if (!validationData || !appName) {
return true;
}
// if creating, check if the name is unique
if (!validationData.isEdit) {
return !validationData.existingNames.includes(appName);
}
// if editing, the original name will be in the list of existing names
// remove it before checking if the name is unique
const updatedExistingNames = validationData.existingNames.filter(
(name) => name !== validationData.originalName
);
return !updatedExistingNames.includes(appName);
}
)
.test(
'is-valid',
"This field must consist of lower case alphanumeric characters or '-', contain at most 63 characters, start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123').",
(appName) => {
if (!appName) {
return true;
}
return /^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/g.test(appName);
}
);
}