|
|
|
@ -1,17 +1,12 @@
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
import { useFormik } from "formik";
|
|
|
|
import { Formik } from "formik";
|
|
|
|
|
|
|
|
import * as yup from "yup";
|
|
|
|
import { XIcon } from "@heroicons/react/outline";
|
|
|
|
import { XIcon } from "@heroicons/react/outline";
|
|
|
|
import General from "./General";
|
|
|
|
import General from "./General";
|
|
|
|
import Environment from "./Environment";
|
|
|
|
import Environment from "./Environment";
|
|
|
|
import Volumes from "./Volumes";
|
|
|
|
import Volumes from "./Volumes";
|
|
|
|
import Labels from "./Labels";
|
|
|
|
import Labels from "./Labels";
|
|
|
|
import { serviceConfigCanvasInitialValues } from "../../../utils";
|
|
|
|
import { CallbackFunction, IServiceNodeItem } from "../../../types";
|
|
|
|
import {
|
|
|
|
|
|
|
|
CallbackFunction,
|
|
|
|
|
|
|
|
ICanvasConfig,
|
|
|
|
|
|
|
|
IServiceNodeItem,
|
|
|
|
|
|
|
|
IService
|
|
|
|
|
|
|
|
} from "../../../types";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IModalServiceProps {
|
|
|
|
interface IModalServiceProps {
|
|
|
|
node: IServiceNodeItem;
|
|
|
|
node: IServiceNodeItem;
|
|
|
|
@ -23,16 +18,26 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
|
|
|
|
const { node, onHide, onUpdateEndpoint } = props;
|
|
|
|
const { node, onHide, onUpdateEndpoint } = props;
|
|
|
|
const [openTab, setOpenTab] = useState("General");
|
|
|
|
const [openTab, setOpenTab] = useState("General");
|
|
|
|
const [selectedNode, setSelectedNode] = useState<IServiceNodeItem>();
|
|
|
|
const [selectedNode, setSelectedNode] = useState<IServiceNodeItem>();
|
|
|
|
const formik = useFormik({
|
|
|
|
|
|
|
|
initialValues: {
|
|
|
|
const handleUpdate = (values: any) => {
|
|
|
|
canvasConfig: {
|
|
|
|
const updated = { ...selectedNode };
|
|
|
|
...serviceConfigCanvasInitialValues()
|
|
|
|
updated.canvasConfig = values.canvasConfig;
|
|
|
|
},
|
|
|
|
updated.serviceConfig = values.serviceConfig;
|
|
|
|
serviceConfig: {
|
|
|
|
onUpdateEndpoint(updated);
|
|
|
|
container_name: ""
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const validationSchema = yup.object({
|
|
|
|
},
|
|
|
|
canvasConfig: yup.object({
|
|
|
|
onSubmit: () => undefined
|
|
|
|
service_name: yup
|
|
|
|
|
|
|
|
.string()
|
|
|
|
|
|
|
|
.max(256, "service name should be 256 characters or less")
|
|
|
|
|
|
|
|
.required("service name is required")
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
serviceConfig: yup.object({
|
|
|
|
|
|
|
|
container_name: yup
|
|
|
|
|
|
|
|
.string()
|
|
|
|
|
|
|
|
.max(256, "container name should be 256 characters or less")
|
|
|
|
|
|
|
|
.required("container name is required")
|
|
|
|
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const tabs = [
|
|
|
|
const tabs = [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -70,25 +75,6 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [node]);
|
|
|
|
}, [node]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
formik.resetForm();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedNode) {
|
|
|
|
|
|
|
|
formik.initialValues.canvasConfig = {
|
|
|
|
|
|
|
|
...selectedNode.canvasConfig
|
|
|
|
|
|
|
|
} as ICanvasConfig;
|
|
|
|
|
|
|
|
formik.initialValues.serviceConfig = {
|
|
|
|
|
|
|
|
...selectedNode.serviceConfig
|
|
|
|
|
|
|
|
} as IService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [selectedNode]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
formik.resetForm();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="fixed z-50 inset-0 overflow-y-auto">
|
|
|
|
<div className="fixed z-50 inset-0 overflow-y-auto">
|
|
|
|
<div className="justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 outline-none focus:outline-none">
|
|
|
|
<div className="justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 outline-none focus:outline-none">
|
|
|
|
@ -110,58 +96,76 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
{selectedNode && (
|
|
|
|
<div className="hidden sm:block">
|
|
|
|
<Formik
|
|
|
|
<div className="border-b border-gray-200 px-8">
|
|
|
|
initialValues={{
|
|
|
|
<nav className="-mb-px flex space-x-8" aria-label="Tabs">
|
|
|
|
canvasConfig: {
|
|
|
|
{tabs.map((tab) => (
|
|
|
|
...selectedNode.canvasConfig
|
|
|
|
<a
|
|
|
|
},
|
|
|
|
key={tab.name}
|
|
|
|
serviceConfig: {
|
|
|
|
href={tab.href}
|
|
|
|
...selectedNode.serviceConfig
|
|
|
|
className={classNames(
|
|
|
|
}
|
|
|
|
tab.name === openTab
|
|
|
|
}}
|
|
|
|
? "border-indigo-500 text-indigo-600"
|
|
|
|
enableReinitialize={true}
|
|
|
|
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300",
|
|
|
|
onSubmit={(values) => {
|
|
|
|
"whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm",
|
|
|
|
handleUpdate(values);
|
|
|
|
tab.hidden ? "hidden" : ""
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
aria-current={tab.current ? "page" : undefined}
|
|
|
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
setOpenTab(tab.name);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{tab.name}
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="relative px-4 py-3 flex-auto">
|
|
|
|
|
|
|
|
<form onSubmit={formik.handleSubmit}>
|
|
|
|
|
|
|
|
{openTab === "General" && <General formik={formik} />}
|
|
|
|
|
|
|
|
{openTab === "Environment" && <Environment formik={formik} />}
|
|
|
|
|
|
|
|
{openTab === "Volumes" && <Volumes formik={formik} />}
|
|
|
|
|
|
|
|
{openTab === "Labels" && <Labels formik={formik} />}
|
|
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-end px-4 py-3 border-t border-solid border-blueGray-200 rounded-b">
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
className="btn-util"
|
|
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
const updated = { ...selectedNode };
|
|
|
|
|
|
|
|
updated.canvasConfig = formik.values.canvasConfig;
|
|
|
|
|
|
|
|
updated.serviceConfig = formik.values.serviceConfig;
|
|
|
|
|
|
|
|
onUpdateEndpoint(updated);
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
|
|
|
|
validationSchema={validationSchema}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
Update
|
|
|
|
{(formik) => (
|
|
|
|
</button>
|
|
|
|
<>
|
|
|
|
</div>
|
|
|
|
<div className="hidden sm:block">
|
|
|
|
|
|
|
|
<div className="border-b border-gray-200 px-8">
|
|
|
|
|
|
|
|
<nav
|
|
|
|
|
|
|
|
className="-mb-px flex space-x-8"
|
|
|
|
|
|
|
|
aria-label="Tabs"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{tabs.map((tab) => (
|
|
|
|
|
|
|
|
<a
|
|
|
|
|
|
|
|
key={tab.name}
|
|
|
|
|
|
|
|
href={tab.href}
|
|
|
|
|
|
|
|
className={classNames(
|
|
|
|
|
|
|
|
tab.name === openTab
|
|
|
|
|
|
|
|
? "border-indigo-500 text-indigo-600"
|
|
|
|
|
|
|
|
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300",
|
|
|
|
|
|
|
|
"whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm",
|
|
|
|
|
|
|
|
tab.hidden ? "hidden" : ""
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
aria-current={tab.current ? "page" : undefined}
|
|
|
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
setOpenTab(tab.name);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{tab.name}
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="relative px-4 py-3 flex-auto">
|
|
|
|
|
|
|
|
{openTab === "General" && <General />}
|
|
|
|
|
|
|
|
{openTab === "Environment" && <Environment />}
|
|
|
|
|
|
|
|
{openTab === "Volumes" && <Volumes />}
|
|
|
|
|
|
|
|
{openTab === "Labels" && <Labels />}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-end px-4 py-3 border-t border-solid border-blueGray-200 rounded-b">
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
|
|
className="btn-util"
|
|
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
|
|
formik.submitForm();
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
Update
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
</Formik>
|
|
|
|
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|