From 0ce415cb0a4dd782376b08ab7b8c7dc3ac3d66f4 Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Sat, 23 Jul 2022 12:00:25 +0530 Subject: [PATCH] feat(frontend): created utilities for create/edit service forms --- .../components/Modal/Service/form-utils.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 services/frontend/src/components/Modal/Service/form-utils.ts diff --git a/services/frontend/src/components/Modal/Service/form-utils.ts b/services/frontend/src/components/Modal/Service/form-utils.ts new file mode 100644 index 0000000..8c9bfa2 --- /dev/null +++ b/services/frontend/src/components/Modal/Service/form-utils.ts @@ -0,0 +1,58 @@ +import { IEditServiceForm, IServiceNodeItem } from "../../../types"; +import * as yup from "yup"; + +const initialValues: IEditServiceForm = { + serviceName: "", + containerName: "", + ports: [], + environmentVariables: [], + volumes: [], + labels: [] +}; + +export const getInitialValues = ( + node?: IServiceNodeItem +): IEditServiceForm => ({ + ...initialValues, + serviceName: node?.canvasConfig.node_name || "", + containerName: node?.serviceConfig.container_name || "" +}); + +export const validationSchema = yup.object({ + serviceName: yup + .string() + .max(256, "Service name should be 256 characters or less") + .required("Service name is required"), + containerName: yup + .string() + .max(256, "Container name should be 256 characters or less") + .required("Container name is required"), + ports: yup.array( + yup.object({ + hostPort: yup.string().required("Host port is required"), + containerPort: yup.string(), + protocol: yup + .string() + .oneOf(["tcp", "udp"], "Protocol should be tcp or udp") + }) + ), + environmentVariables: yup.array( + yup.object({ + key: yup.string().required("Key is required"), + value: yup.string().required("Value is required") + }) + ), + volumes: yup.array( + yup.object({ + name: yup.string().required("Name is required"), + containerPath: yup.string(), + accessMode: yup.string() + }) + ), + labels: yup.array( + yup.object({ + key: yup.string().required("Key is required"), + value: yup.string().required("Value is required") + }) + ) +});