From ab6b4e5a5392b712d072e9880e104e6523cc2630 Mon Sep 17 00:00:00 2001 From: gokhangunduz Date: Thu, 7 Mar 2024 16:08:33 +0300 Subject: [PATCH] refactor(cf-deploy): :tada: add deploy side at form --- src/components/SidebarLists/RobotsList.tsx | 21 ++++++++++++++----- src/contexts/FormContext.tsx | 3 ++- src/handler/deploy.handler.ts | 1 + src/interfaces/deploy.interface.ts | 1 + .../environment.step1.interface.ts | 1 + src/validations/deploy.validations.ts | 20 ++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/validations/deploy.validations.ts diff --git a/src/components/SidebarLists/RobotsList.tsx b/src/components/SidebarLists/RobotsList.tsx index ac73a12e..dbf1ec0d 100644 --- a/src/components/SidebarLists/RobotsList.tsx +++ b/src/components/SidebarLists/RobotsList.tsx @@ -113,11 +113,22 @@ export default function RobotsList({ reload }: IRobotsList): ReactElement {
Virtual: { + switch (activeTab) { + case "Develop": + return robot?.step1?.clusters?.environment?.[0] + ?.status; + + case "Deploy": + const status = + robot?.step1?.launchContainers?.find( + (container) => + container.container.status === "Creating", + ); + + return status ? "Creating" : "Ready"; + } + })()} />
{robot?.step1?.clusters?.environment?.[1]?.status && ( diff --git a/src/contexts/FormContext.tsx b/src/contexts/FormContext.tsx index 01992e38..f0b48e5a 100644 --- a/src/contexts/FormContext.tsx +++ b/src/contexts/FormContext.tsx @@ -13,6 +13,7 @@ import { CFRobotStep1Validations, CFRobotStep2Validations, } from "../validations/RobotsValidations"; +import { CFDeployStep1Validations } from "../validations/deploy.validations"; export const FormContext: any = createContext(null); @@ -41,7 +42,7 @@ export default ({ children }: any) => { const step1Formik = useFormik({ validationSchema: !robotData?.step1?.details?.isDeployMode ? CFRobotStep1Validations - : null, + : CFDeployStep1Validations, initialValues: robotData?.step1, onSubmit: async () => { step1Formik.setSubmitting(true); diff --git a/src/handler/deploy.handler.ts b/src/handler/deploy.handler.ts index 0284b640..f3638d72 100644 --- a/src/handler/deploy.handler.ts +++ b/src/handler/deploy.handler.ts @@ -114,6 +114,7 @@ function handleMapper(data: IDeployBE[]): { name: cont.container.name, image: cont.container.image, command: cont.container.command, + status: cont.container.containerStatus ? "Ready" : "Creating", privileged: false, mountedVolumes: cont.container.volumeMounts?.map((vol) => { diff --git a/src/interfaces/deploy.interface.ts b/src/interfaces/deploy.interface.ts index 436b3b63..23ced14f 100644 --- a/src/interfaces/deploy.interface.ts +++ b/src/interfaces/deploy.interface.ts @@ -11,6 +11,7 @@ export interface IDeployBE { name: string; command: string; image: string; + containerStatus: boolean; envs: { name: string; value: string; diff --git a/src/interfaces/environment/environment.step1.interface.ts b/src/interfaces/environment/environment.step1.interface.ts index 154c19d4..6459e7b5 100644 --- a/src/interfaces/environment/environment.step1.interface.ts +++ b/src/interfaces/environment/environment.step1.interface.ts @@ -118,6 +118,7 @@ export interface IEnvironmentStep1 { name: string; image: string; command: string; + status: string; privileged: boolean; mountedVolumes: { name: string; // volume name diff --git a/src/validations/deploy.validations.ts b/src/validations/deploy.validations.ts new file mode 100644 index 00000000..9a367522 --- /dev/null +++ b/src/validations/deploy.validations.ts @@ -0,0 +1,20 @@ +import * as Yup from "yup"; + +export const CFDeployStep1Validations = Yup.object().shape({ + details: Yup.object().shape({ + name: Yup.string() + .required("Robot name is required.") + .min(3, "Minimum 3 characters.") + .max(16, "Maximum 16 characters.") + .lowercase("Must be lowercase.") + .matches( + /^[a-z0-9]+(-[a-z0-9]+)*$/, + "Must be lowercase with hyphen (-) only in the middle.", + ), + physicalInstanceName: Yup.string().when("isVirtualRobot", { + is: false, + then: Yup.string().required("Physical Instance is required"), + otherwise: Yup.string().notRequired(), + }), + }), +});