1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

feat(edge/templates): introduce edge app templates [EE-6209] (#10480)

This commit is contained in:
Chaim Lev-Ari 2023-11-14 14:54:44 +02:00 committed by GitHub
parent 95d96e1164
commit e1e90c9c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1142 additions and 365 deletions

View file

@ -0,0 +1,50 @@
import { FormikErrors } from 'formik';
import { SchemaOf, string } from 'yup';
import { STACK_NAME_VALIDATION_REGEX } from '@/react/constants';
import { FormControl } from '@@/form-components/FormControl';
import { Input } from '@@/form-components/Input';
import { EdgeStack } from '../types';
export function NameField({
onChange,
value,
errors,
}: {
onChange(value: string): void;
value: string;
errors?: FormikErrors<string>;
}) {
return (
<FormControl inputId="name-input" label="Name" errors={errors} required>
<Input
id="name-input"
onChange={(e) => onChange(e.target.value)}
value={value}
required
/>
</FormControl>
);
}
export function nameValidation(
stacks: Array<EdgeStack>,
isComposeStack: boolean | undefined
): SchemaOf<string> {
let schema = string()
.required('Name is required')
.test('unique', 'Name should be unique', (value) =>
stacks.every((s) => s.Name !== value)
);
if (isComposeStack) {
schema = schema.matches(
new RegExp(STACK_NAME_VALIDATION_REGEX),
"This field must consist of lower case alphanumeric characters, '_' or '-' (e.g. 'my-name', or 'abc-123')."
);
}
return schema;
}