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:
parent
95d96e1164
commit
e1e90c9c1d
58 changed files with 1142 additions and 365 deletions
50
app/react/edge/edge-stacks/CreateView/NameField.tsx
Normal file
50
app/react/edge/edge-stacks/CreateView/NameField.tsx
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue