Skip to content

Commit

Permalink
feat(delete launch-manager modal): 🎉 add delete launch manager modal …
Browse files Browse the repository at this point in the history
…and update workspace component
  • Loading branch information
gokhangunduz committed Aug 8, 2023
1 parent d6d2ddb commit fb5f023
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 113 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.9.6",
"version": "0.9.7",
"private": true,
"dependencies": {
"@emotion/css": "^11.10.6",
Expand Down
35 changes: 7 additions & 28 deletions src/components/CreateForms/CreateRobotFormStep4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import InputText from "../InputText/InputText";
import InputError from "../InputError/InputError";
import { useAppDispatch } from "../../hooks/redux";
import useMain from "../../hooks/useMain";
import {
createLaunchManager,
deleteLaunchManager,
} from "../../toolkit/RobotSlice";
import { createLaunchManager } from "../../toolkit/RobotSlice";
import Button from "../Button/Button";
import { toast } from "sonner";
import useFunctions from "../../hooks/useFunctions";
Expand All @@ -23,10 +20,10 @@ import CreateRobotFormCodeScope from "../CreateRobotFormCodeScope/CreateRobotFor
import CreateRobotFormEnvItem from "../CreateRobotFormEnvItem/CreateRobotFormEnvItem";
import CreateRobotFormAddButton from "../CreateRobotFormAddButton/CreateRobotFormAddButton";
import { organizationNameViewer } from "../../functions/GeneralFunctions";
import CreateRobotFormDeleteButton from "../CreateRobotFormDeleteButton/CreateRobotFormDeleteButton";
import { useParams } from "react-router-dom";
import InfoTip from "../InfoTip/InfoTip";
import * as Yup from "yup";
import RobotDeleteLaunchManagerButton from "../RobotDeleteLaunchManagerButton/RobotDeleteLaunchManagerButton";

interface ICreateRobotFormStep4 {
isImportRobot?: boolean;
Expand Down Expand Up @@ -351,35 +348,17 @@ export default function CreateRobotFormStep4({
/>
</div>

{isImportRobot ? (
<CreateRobotFormDeleteButton
onClick={async () => {
await dispatch(
deleteLaunchManager({
organizationId: selectedState?.organization?.organizationId,
roboticsCloudName: selectedState?.roboticsCloud?.name,
instanceId: selectedState?.instance?.instanceId,
region: selectedState?.instance?.region,
robotName: robotData?.step1?.robotName,
fleetName: selectedState?.fleet?.name,
physicalInstanceName: robotData?.step1?.physicalInstanceName,
launchManagerName: formik.values?.name,
})
);

setTimeout(() => {
window.location.reload();
}, 1000);
}}
text="Delete Launch Step"
/>
) : (
{!isImportRobot ? (
<Button
type="submit"
disabled={!formik?.isValid || formik.isSubmitting}
className="w-full !h-11 text-xs"
text={url?.robotName ? `Add Launch Step` : `Create Robot`}
/>
) : (
<RobotDeleteLaunchManagerButton
launchManagerName={formik.values?.name}
/>
)}
</form>
</CreateRobotFormLoader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function CreateRobotFormWorkspaceItem({
title={`Launch State of Cloud Instance`}
className="font-medium"
>
CI:
V:
</span>
<StateCell state={workspaceState?.[0]} />
</div>
Expand All @@ -74,7 +74,7 @@ export default function CreateRobotFormWorkspaceItem({
title={`Launch State of Physical Instance`}
className="font-medium"
>
PI:
P:
</span>
<StateCell state={workspaceState?.[1]} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export default function DeployApplicationSelector({
});
}

const { setSidebarState } = useMain();

return (
<form
onSubmit={formik.handleSubmit}
Expand All @@ -245,7 +247,20 @@ export default function DeployApplicationSelector({
/>
<span className="capitalize text-xs">Organization</span>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
{!formik?.values?.organization && (
<span
onClick={() => {
handleCloseModal();
setSidebarState((prev: any) => {
return { ...prev, isOpen: true, page: "organization" };
});
}}
className="text-xs text-layer-light-700 cursor-pointer hover:underline "
>
Create
</span>
)}
<InputSelect
className="min-w-[12rem]"
{...formik.getFieldProps(`organization`)}
Expand Down Expand Up @@ -286,7 +301,20 @@ export default function DeployApplicationSelector({
/>
<span className="capitalize text-xs">Robotics Cloud</span>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
{!formik?.values?.roboticscloud && (
<span
onClick={() => {
handleCloseModal();
setSidebarState((prev: any) => {
return { ...prev, isOpen: true, page: "roboticscloud" };
});
}}
className="text-xs text-layer-light-700 cursor-pointer hover:underline "
>
Create
</span>
)}
<InputSelect
className="min-w-[12rem]"
{...formik.getFieldProps(`roboticscloud`)}
Expand Down Expand Up @@ -327,7 +355,20 @@ export default function DeployApplicationSelector({
/>
<span className="capitalize text-xs">Cloud Instance</span>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
{!formik?.values?.instance && (
<span
onClick={() => {
handleCloseModal();
setSidebarState((prev: any) => {
return { ...prev, isOpen: true, page: "instance" };
});
}}
className="text-xs text-layer-light-700 cursor-pointer hover:underline "
>
Create
</span>
)}
<InputSelect
className="min-w-[12rem]"
{...formik.getFieldProps(`instance`)}
Expand Down Expand Up @@ -373,7 +414,20 @@ export default function DeployApplicationSelector({
/>
<span className="capitalize text-xs">Fleet</span>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
{!formik?.values?.fleet && (
<span
onClick={() => {
handleCloseModal();
setSidebarState((prev: any) => {
return { ...prev, isOpen: true, page: "fleet" };
});
}}
className="text-xs text-layer-light-700 cursor-pointer hover:underline "
>
Create
</span>
)}
<InputSelect
className="min-w-[12rem]"
{...formik.getFieldProps(`fleet`)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { Fragment, ReactElement, useState } from "react";
import Button from "../Button/Button";
import DeleteLaunchManagerModal from "../../modals/DeleteLaunchManagerModal";

interface IRobotDeleteLaunchManagerButton {
launchManagerName: string;
}

export default function RobotDeleteLaunchManagerButton({
launchManagerName,
}: IRobotDeleteLaunchManagerButton): ReactElement {
const [isShowDeleteModal, setIsShowDeleteModal] = useState<boolean>(false);

return (
<Fragment>
<Button
className="text-xs w-full !h-11 !bg-transparent hover:!bg-red-100 !text-red-500 !border !border-red-500 focus:!ring-red-300"
onClick={() => setIsShowDeleteModal(true)}
text="Delete Launch Step"
/>
{isShowDeleteModal && (
<DeleteLaunchManagerModal
handleCloseModal={() => setIsShowDeleteModal(false)}
launchManagerName={launchManagerName}
/>
)}
</Fragment>
);
}
54 changes: 5 additions & 49 deletions src/components/UpdateRobotLaunchsForm/UpdateRobotLaunchsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function UpdateRobotLaunchsForm(): ReactElement {
useState<any>(undefined);
const { getLaunchManagers } = useFunctions();
const url = useParams();
const { robotData, setRobotData } = useRobot();
const { robotData, handleAddLaunchManager } = useRobot();
const { selectedState } = useMain();

useEffect(() => {
Expand Down Expand Up @@ -74,29 +74,7 @@ export default function UpdateRobotLaunchsForm(): ReactElement {
) : (
<CreateRobotFormAddButton
onClick={() => {
setRobotData((prev: any) => {
return {
...prev,
step4: {
...prev.step4,
robotLaunchSteps: [
...prev.step4.robotLaunchSteps,
{
workspace: "",
entryPointType: "custom",
entryPointCmd: "",
instancesName: [],
robotLmEnvs: [
// {
// name: "",
// value: "",
// },
],
},
],
},
};
});
handleAddLaunchManager();
setIsAddedForm(true);
}}
/>
Expand Down Expand Up @@ -127,7 +105,7 @@ export default function UpdateRobotLaunchsForm(): ReactElement {
title={`Launch State of Cloud Instance`}
className="font-medium"
>
CI:
Virtual:
</span>
<StateCell
state={
Expand All @@ -142,7 +120,7 @@ export default function UpdateRobotLaunchsForm(): ReactElement {
title={`Launch State of Physical Instance`}
className="font-medium"
>
PI:
Physical:
</span>
<StateCell
state={
Expand Down Expand Up @@ -187,29 +165,7 @@ export default function UpdateRobotLaunchsForm(): ReactElement {
) : (
<CreateRobotFormAddButton
onClick={() => {
setRobotData((prev: any) => {
return {
...prev,
step4: {
...prev.step4,
robotLaunchSteps: [
...prev.step4.robotLaunchSteps,
{
workspace: "",
entryPointType: "custom",
entryPointCmd: "",
instancesName: [],
robotLmEnvs: [
{
name: "",
value: "",
},
],
},
],
},
};
});
handleAddLaunchManager();
setIsAddedForm(true);
}}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/contexts/FunctionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,9 @@ export default ({ children }: any) => {
...prevState,
step3: {
buildManagerName:
responseRobotBuildManager?.payload?.data[0]?.roboticsClouds[0]
?.cloudInstances[0]?.robolaunchFederatedRobots[0]
?.buildManagerName,
responseRobotBuildManager?.payload?.data[0]?.roboticsClouds[0]?.cloudInstances[0]?.robolaunchFederatedRobots[0]?.buildManagerName?.split(
"-"
)[0],
robotBuildSteps:
responseRobotBuildManager?.payload?.data[0]?.roboticsClouds[0]
?.cloudInstances[0]?.robolaunchFederatedRobots[0]
Expand Down
Loading

0 comments on commit fb5f023

Please sign in to comment.