1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

feat(app): rearrange app form services [EE-5566] (#9056)

This commit is contained in:
Ali 2023-06-12 11:50:13 +12:00 committed by GitHub
parent d7fc2046d7
commit 2d69e93efa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1104 additions and 739 deletions

View file

@ -1,5 +1,7 @@
import { FormikErrors } from 'formik';
import { ServiceFormValues } from './types';
export function isServicePortError<T>(
error: string | FormikErrors<T> | undefined
): error is FormikErrors<T> {
@ -16,3 +18,42 @@ export function newPort(serviceName?: string) {
serviceName,
};
}
function generateIndexedName(appName: string, index: number) {
return index === 0 ? appName : `${appName}-${index}`;
}
function isNameUnique(name: string, services: ServiceFormValues[]) {
return services.findIndex((service) => service.Name === name) === -1;
}
export function generateUniqueName(
appName: string,
index: number,
services: ServiceFormValues[]
) {
let initialIndex = index;
let uniqueName = appName;
while (!isNameUnique(uniqueName, services)) {
uniqueName = generateIndexedName(appName, initialIndex);
initialIndex++;
}
return uniqueName;
}
export const serviceFormDefaultValues: ServiceFormValues = {
Headless: false,
Namespace: '',
Name: '',
StackName: '',
Ports: [],
Type: 1, // clusterip type as default
ClusterIP: '',
ApplicationName: '',
ApplicationOwner: '',
Note: '',
Ingress: false,
Selector: {},
};