Skip to content

Commit

Permalink
refactor(cf-deploy): 🎉 add deploy side at form
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangunduz committed Mar 7, 2024
1 parent fad0417 commit ab6b4e5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/components/SidebarLists/RobotsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,22 @@ export default function RobotsList({ reload }: IRobotsList): ReactElement {
<div className="flex gap-1.5">
<span className="font-medium">Virtual:</span>
<StateCell
state={
activeTab === "Deploy"
? "Ready"
: robot?.step1?.clusters?.environment?.[0]?.status
}
state={(() => {
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";
}
})()}
/>
</div>
{robot?.step1?.clusters?.environment?.[1]?.status && (
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/FormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CFRobotStep1Validations,
CFRobotStep2Validations,
} from "../validations/RobotsValidations";
import { CFDeployStep1Validations } from "../validations/deploy.validations";

export const FormContext: any = createContext<any>(null);

Expand Down Expand Up @@ -41,7 +42,7 @@ export default ({ children }: any) => {
const step1Formik = useFormik<IEnvironmentStep1>({
validationSchema: !robotData?.step1?.details?.isDeployMode
? CFRobotStep1Validations
: null,
: CFDeployStep1Validations,
initialValues: robotData?.step1,
onSubmit: async () => {
step1Formik.setSubmitting(true);
Expand Down
1 change: 1 addition & 0 deletions src/handler/deploy.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/deploy.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IDeployBE {
name: string;
command: string;
image: string;
containerStatus: boolean;
envs: {
name: string;
value: string;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/environment/environment.step1.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface IEnvironmentStep1 {
name: string;
image: string;
command: string;
status: string;
privileged: boolean;
mountedVolumes: {
name: string; // volume name
Expand Down
20 changes: 20 additions & 0 deletions src/validations/deploy.validations.ts
Original file line number Diff line number Diff line change
@@ -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(),
}),
}),
});

0 comments on commit ab6b4e5

Please sign in to comment.