Merge branch 'master' of github.com:nuxxapp/nuxx into feat/forms

pull/71/head
Artem Golub 3 years ago
commit af6d90b54d

@ -48,7 +48,8 @@
"typescript": "^4.5.5",
"uuid": "^8.3.2",
"web-vitals": "^2.1.4",
"yaml": "^1.10.2"
"yaml": "^1.10.2",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",

@ -1,4 +1,6 @@
import { useEffect, useState } from "react";
import { ServerIcon } from "@heroicons/react/outline";
import { truncateStr } from "../../utils";
import { IServiceNodeItem, CallbackFunction } from "../../types";
import eventBus from "../../events/eventBus";
import { Popover } from "./Popover";
@ -52,14 +54,21 @@ export default function ServiceNode(props: INodeProps) {
}}
></Popover>
)}
<div className="node-label w-full py-2 px-4">
<div className="relative node-label w-full py-2 px-4">
<>
<div className="text-sm font-semibold overflow-x-hidden">
{node.canvasConfig.service_name}
</div>
<div className="text-xs text-gray-500 overflow-x-hidden">
{node.serviceConfig.container_name}
</div>
{node.canvasConfig.service_name && (
<div className="text-sm font-semibold overflow-x-hidden">
{truncateStr(node.canvasConfig.service_name, 12)}
</div>
)}
{node.serviceConfig.container_name && (
<div className="text-xs text-gray-500 overflow-x-hidden">
{truncateStr(node.serviceConfig.container_name, 20)}
</div>
)}
<ServerIcon className="w-3 h-3 text-gray-600 absolute top-2 right-2" />
</>
</div>
</div>

@ -1,4 +1,6 @@
import { useEffect, useState } from "react";
import { DatabaseIcon } from "@heroicons/react/outline";
import { truncateStr } from "../../utils";
import { IVolumeNodeItem, CallbackFunction } from "../../types";
import eventBus from "../../events/eventBus";
import { Popover } from "./Popover";
@ -52,11 +54,15 @@ export default function VolumeNode(props: INodeProps) {
}}
></Popover>
)}
<div className="node-label w-full py-2 px-4">
<div className="relative node-label w-full py-2 px-4">
<>
<div className="text-xs text-gray-500 overflow-x-hidden">
{node.volumeConfig.name}
</div>
{node.volumeConfig.name && (
<div className="text-sm font-semibold overflow-x-hidden">
{truncateStr(node.volumeConfig.name, 20)}
</div>
)}
<DatabaseIcon className="w-3 h-3 text-gray-600 absolute top-2 right-2" />
</>
</div>
</div>

@ -1,32 +1,11 @@
const General = (props: any) => {
const { formik } = props;
import TextField from "../../global/FormElements/InputField";
const General = () => {
return (
<>
<div className="relative pb-3 flex-auto">
<div className="grid grid-cols-6 gap-4">
<div className="col-span-3">
<label
htmlFor="name"
className="block text-xs font-medium text-gray-700"
>
Name
</label>
<div className="mt-1">
<input
id="name"
name="name"
type="text"
autoComplete="none"
className="input-util"
onChange={formik.handleChange}
value={formik.values.name}
/>
</div>
</div>
</div>
</div>
<TextField label="Name" name="name" />
</>
);
};
export default General;

@ -1,6 +1,5 @@
const IPam = (props: any) => {
const { formik } = props;
const IPam = () => {
return <></>;
};
export default IPam;

@ -1,6 +1,5 @@
const Labels = (props: any) => {
const { formik } = props;
const Labels = () => {
return <></>;
};
export default Labels;

@ -1,5 +1,6 @@
import { useState } from "react";
import { useFormik } from "formik";
import { Formik } from "formik";
import * as yup from "yup";
import { XIcon } from "@heroicons/react/outline";
import General from "./General";
import IPam from "./IPam";
@ -14,12 +15,14 @@ interface IModalNetworkProps {
const ModalNetwork = (props: IModalNetworkProps) => {
const { onHide } = props;
const [openTab, setOpenTab] = useState("General");
const formik = useFormik({
initialValues: {
...topLevelNetworkConfigInitialValues()
},
onSubmit: () => undefined
const handleCreate = (values: any, formik: any) => {
formik.resetForm();
};
const validationSchema = yup.object({
name: yup
.string()
.max(256, "name should be 256 characters or less")
.required("name is required")
});
const tabs = [
{
@ -66,54 +69,70 @@ const ModalNetwork = (props: IModalNetworkProps) => {
</button>
</div>
<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>
<Formik
initialValues={{
...topLevelNetworkConfigInitialValues(),
key: "volume",
type: "VOLUME",
inputs: [],
outputs: [],
config: {}
}}
enableReinitialize={true}
onSubmit={(values, formik) => {
handleCreate(values, formik);
}}
validationSchema={validationSchema}
>
{(formik) => (
<>
<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">
<form onSubmit={formik.handleSubmit}>
{openTab === "General" && <General formik={formik} />}
{openTab === "IPam" && <IPam formik={formik} />}
{openTab === "Labels" && <Labels formik={formik} />}
</form>
</div>
</div>
<div className="relative px-4 py-3 flex-auto">
{openTab === "General" && <General />}
{openTab === "IPam" && <IPam />}
{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.resetForm();
}}
>
Add
</button>
</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();
}}
>
Add
</button>
</div>
</>
)}
</Formik>
</div>
</div>
</div>

@ -1,5 +1,6 @@
import { useState } from "react";
import { useFormik } from "formik";
import { Formik } from "formik";
import * as yup from "yup";
import { XIcon } from "@heroicons/react/outline";
import General from "./General";
import Environment from "./Environment";
@ -16,24 +17,23 @@ interface IModalServiceProps {
const ModalServiceCreate = (props: IModalServiceProps) => {
const { onHide, onAddEndpoint } = props;
const [openTab, setOpenTab] = useState("General");
const formik = useFormik({
initialValues: {
canvasConfig: {
...serviceConfigCanvasInitialValues()
},
serviceConfig: {
container_name: "",
labels: [],
environmentVariables: []
},
key: "service",
type: "SERVICE",
inputs: ["op_source"],
outputs: [],
config: {}
},
onSubmit: () => undefined
const handleCreate = (values: any, formik: any) => {
onAddEndpoint(values);
formik.resetForm();
};
const validationSchema = yup.object({
canvasConfig: yup.object({
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 = [
{
@ -86,56 +86,77 @@ const ModalServiceCreate = (props: IModalServiceProps) => {
</button>
</div>
<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>
<Formik
initialValues={{
canvasConfig: {
...serviceConfigCanvasInitialValues()
},
serviceConfig: {
container_name: ""
},
key: "service",
type: "SERVICE",
inputs: ["op_source"],
outputs: [],
config: {}
}}
enableReinitialize={true}
onSubmit={(values, formik) => {
handleCreate(values, formik);
}}
validationSchema={validationSchema}
>
{(formik) => (
<>
<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">
<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="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={() => {
onAddEndpoint(formik.values);
formik.resetForm();
}}
>
Add
</button>
</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={() => {
onAddEndpoint(formik.values);
formik.resetForm();
}}
>
Add
</button>
</div>
</>
)}
</Formik>
</div>
</div>
</div>

@ -1,16 +1,16 @@
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 General from "./General";
import Environment from "./Environment";
import Volumes from "./Volumes";
import Labels from "./Labels";
import { serviceConfigCanvasInitialValues } from "../../../utils";
import {
CallbackFunction,
ICanvasConfig,
IServiceNodeItem,
IService
IService,
IServiceNodeItem
} from "../../../types";
interface IModalServiceProps {
@ -23,18 +23,26 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
const { node, onHide, onUpdateEndpoint } = props;
const [openTab, setOpenTab] = useState("General");
const [selectedNode, setSelectedNode] = useState<IServiceNodeItem>();
const formik = useFormik({
initialValues: {
canvasConfig: {
...serviceConfigCanvasInitialValues()
},
serviceConfig: {
container_name: "",
labels: [],
environmentVariables: []
}
},
onSubmit: () => undefined
const handleUpdate = (values: any) => {
const updated = { ...selectedNode };
updated.canvasConfig = values.canvasConfig;
updated.serviceConfig = values.serviceConfig;
onUpdateEndpoint(updated);
};
const validationSchema = yup.object({
canvasConfig: yup.object({
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 = [
{
@ -72,25 +80,6 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
}
}, [node]);
useEffect(() => {
formik.resetForm();
if (selectedNode) {
formik.initialValues.canvasConfig = {
...selectedNode.canvasConfig
} as ICanvasConfig;
formik.initialValues.serviceConfig = {
...selectedNode.serviceConfig
} as any; // as IService;
}
}, [selectedNode]);
useEffect(() => {
return () => {
formik.resetForm();
};
}, []);
return (
<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">
@ -112,58 +101,76 @@ const ModalServiceEdit = (props: IModalServiceProps) => {
</button>
</div>
<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">
<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);
{selectedNode && (
<Formik
initialValues={{
canvasConfig: {
...selectedNode.canvasConfig
} as ICanvasConfig,
serviceConfig: {
...selectedNode.serviceConfig
} as IService
}}
enableReinitialize={true}
onSubmit={(values) => {
handleUpdate(values);
}}
validationSchema={validationSchema}
>
Update
</button>
</div>
{(formik) => (
<>
<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>

@ -1,8 +1,9 @@
import { useCallback } from "react";
import { PlusIcon } from "@heroicons/react/outline";
import Record from "../../Record";
import { Button } from "@mui/joy";
import { styled } from "@mui/joy";
import { useCallback } from "react";
import { useFormikContext } from "formik";
import Record from "../../Record";
import { IService } from "../../../types";
const Root = styled("div")`
display: flex;
@ -12,87 +13,80 @@ const Root = styled("div")`
const Records = styled("div")`
display: flex;
flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(1)};
`;
const AddButton = styled(Button)`
width: 140px;
margin-top: ${({ theme }) => theme.spacing(2)};
row-gap: ${({ theme }: { theme: any }) => theme.spacing(1)};
`;
const EnvironmentVariables = (props: any) => {
const { formik } = props;
const { environmentVariables } = formik.values.serviceConfig;
const Environment = () => {
const formik = useFormikContext<{
serviceConfig: IService;
}>();
const environment = (formik.values.serviceConfig.environment as []) || [];
const handleNewEnvironmentVariable = useCallback(() => {
formik.setFieldValue(
`serviceConfig.environmentVariables[${environmentVariables.length}]`,
{
key: "",
value: ""
}
);
formik.setFieldValue(`serviceConfig.environment[${environment.length}]`, {
key: "",
value: ""
});
}, [formik]);
const handleRemoveEnvironmentVariable = useCallback(
(index: number) => {
const newEnvironmentVariables = environmentVariables.filter(
const newEnvironmentVariables = environment.filter(
(_: unknown, currentIndex: number) => currentIndex != index
);
formik.setFieldValue(
`serviceConfig.environmentVariables`,
`serviceConfig.environment`,
newEnvironmentVariables
);
},
[formik]
);
const emptyEnvironmentVariables = environmentVariables.length === 0;
const emptyEnvironmentVariables =
environment && environment.length === 0 ? true : false;
return (
<Root
sx={{ alignItems: emptyEnvironmentVariables ? "center" : "flex-start" }}
>
{!emptyEnvironmentVariables && (
<Records>
{environmentVariables.map((_: unknown, index: number) => (
<Record
key={index}
index={index}
formik={formik}
fields={[
{
name: `serviceConfig.environmentVariables[${index}].key`,
placeholder: "Key"
},
{
name: `serviceConfig.environmentVariables[${index}].value`,
placeholder: "Value"
}
]}
onRemove={handleRemoveEnvironmentVariable}
/>
))}
</Records>
)}
{emptyEnvironmentVariables && (
<p className="mt-4 text-md text-gray-500 dark:text-gray-400 text-center">
The service does not have any environment variables.
<br />
Click "+ New Variable" to add a new environment variable.
</p>
)}
<AddButton
size="sm"
variant="plain"
onClick={handleNewEnvironmentVariable}
<>
<Root
sx={{ alignItems: emptyEnvironmentVariables ? "center" : "flex-start" }}
>
<PlusIcon className="h-4 w-4 mr-2" />
New Variable
</AddButton>
</Root>
{!emptyEnvironmentVariables && (
<Records>
{environment.map((_: unknown, index: number) => (
<Record
key={index}
index={index}
formik={formik}
fields={[
{
name: `serviceConfig.environment[${index}].key`,
placeholder: "Key"
},
{
name: `serviceConfig.environment[${index}].value`,
placeholder: "Value"
}
]}
onRemove={handleRemoveEnvironmentVariable}
/>
))}
</Records>
)}
{emptyEnvironmentVariables && (
<p className="mt-4 text-md text-gray-500 dark:text-gray-400 text-center">
add environment variables
</p>
)}
</Root>
<div className="flex justify-end pt-2">
<button className="btn-util" onClick={handleNewEnvironmentVariable}>
<PlusIcon className="h-4 w-4 mr-1" />
New Variable
</button>
</div>
</>
);
};
export default EnvironmentVariables;
export default Environment;

@ -1,56 +1,12 @@
const General = (props: any) => {
const { formik } = props;
import TextField from "../../global/FormElements/InputField";
const General = () => {
return (
<>
<div className="relative pb-3 flex-auto">
<div className="grid grid-cols-6 gap-4">
<div className="col-span-3">
<label
htmlFor="service_name"
className="block text-xs font-medium text-gray-700"
>
Service name
</label>
<div className="mt-1">
<input
id="service_name"
name="canvasConfig.service_name"
type="text"
autoComplete="none"
className="input-util"
onChange={formik.handleChange}
value={formik.values.canvasConfig.service_name}
/>
</div>
</div>
</div>
</div>
<div className="relative pb-3 flex-auto">
<div className="grid grid-cols-6 gap-4">
<div className="col-span-3">
<label
htmlFor="container_name"
className="block text-xs font-medium text-gray-700"
>
Container name
</label>
<div className="mt-1">
<input
id="container_name"
name="serviceConfig.container_name"
type="text"
autoComplete="none"
className="input-util"
onChange={formik.handleChange}
value={formik.values.serviceConfig.container_name}
/>
</div>
</div>
</div>
</div>
<TextField label="Service name" name="canvasConfig.service_name" />
<TextField label="Container name" name="serviceConfig.container_name" />
</>
);
};
export default General;

@ -1,8 +1,9 @@
import { useCallback } from "react";
import { PlusIcon } from "@heroicons/react/outline";
import Record from "../../Record";
import { Button } from "@mui/joy";
import { styled } from "@mui/joy";
import { useCallback } from "react";
import { useFormikContext } from "formik";
import Record from "../../Record";
import { IService } from "../../../types";
const Root = styled("div")`
display: flex;
@ -15,15 +16,11 @@ const Records = styled("div")`
row-gap: ${({ theme }) => theme.spacing(1)};
`;
const AddButton = styled(Button)`
width: 120px;
margin-top: ${({ theme }) => theme.spacing(2)};
`;
const Labels = (props: any) => {
const { formik } = props;
const { labels } = formik.values.serviceConfig;
const Labels = () => {
const formik = useFormikContext<{
serviceConfig: IService;
}>();
const labels = (formik.values.serviceConfig.labels as []) || [];
const handleNewLabel = useCallback(() => {
formik.setFieldValue(`serviceConfig.labels[${labels.length}]`, {
@ -42,45 +39,48 @@ const Labels = (props: any) => {
[formik]
);
const emptyLabels = labels.length === 0;
const emptyLabels = labels && labels.length === 0 ? true : false;
return (
<Root sx={{ alignItems: emptyLabels ? "center" : "flex-start" }}>
{!emptyLabels && (
<Records>
{labels.map((_: unknown, index: number) => (
<Record
key={index}
index={index}
formik={formik}
fields={[
{
name: `serviceConfig.labels[${index}].key`,
placeholder: "Key"
},
{
name: `serviceConfig.labels[${index}].value`,
placeholder: "Value"
}
]}
onRemove={handleRemoveLabel}
/>
))}
</Records>
)}
{emptyLabels && (
<p className="mt-4 text-md text-gray-500 dark:text-gray-400 text-center">
The service does not have any labels.
<br />
Click "+ New Label" to add a new label.
</p>
)}
<>
<Root sx={{ alignItems: emptyLabels ? "center" : "flex-start" }}>
{!emptyLabels && (
<Records>
{labels.map((_: unknown, index: number) => (
<Record
key={index}
index={index}
formik={formik}
fields={[
{
name: `serviceConfig.labels[${index}].key`,
placeholder: "Key"
},
{
name: `serviceConfig.labels[${index}].value`,
placeholder: "Value"
}
]}
onRemove={handleRemoveLabel}
/>
))}
</Records>
)}
{emptyLabels && (
<p className="mt-4 text-md text-gray-500 dark:text-gray-400 text-center">
add labels
</p>
)}
</Root>
<AddButton size="sm" variant="plain" onClick={handleNewLabel}>
<PlusIcon className="h-4 w-4 mr-2" />
New Label
</AddButton>
</Root>
<div className="flex justify-end pt-2">
<button className="btn-util" onClick={handleNewLabel}>
<PlusIcon className="h-4 w-4 mr-1" />
New Labels
</button>
</div>
</>
);
};
export default Labels;

@ -1,6 +1,5 @@
const Volumes = (props: any) => {
const { formik } = props;
const Volumes = () => {
return <></>;
};
export default Volumes;

@ -1,5 +1,6 @@
import { useState } from "react";
import { useFormik } from "formik";
import { Formik } from "formik";
import * as yup from "yup";
import { XIcon } from "@heroicons/react/outline";
import General from "./General";
import Labels from "./Labels";
@ -14,19 +15,17 @@ interface IModalVolumeCreate {
const ModalVolumeCreate = (props: IModalVolumeCreate) => {
const { onHide, onAddEndpoint } = props;
const [openTab, setOpenTab] = useState("General");
const formik = useFormik({
initialValues: {
volumeConfig: {
...topLevelVolumeConfigInitialValues()
},
key: "volume",
type: "VOLUME",
inputs: [],
outputs: [],
config: {}
},
onSubmit: () => undefined
const handleCreate = (values: any, formik: any) => {
onAddEndpoint(values);
formik.resetForm();
};
const validationSchema = yup.object({
volumeConfig: yup.object({
name: yup
.string()
.max(256, "name should be 256 characters or less")
.required("name is required")
})
});
const tabs = [
{
@ -67,54 +66,71 @@ const ModalVolumeCreate = (props: IModalVolumeCreate) => {
</button>
</div>
<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>
<Formik
initialValues={{
volumeConfig: {
...topLevelVolumeConfigInitialValues()
},
key: "volume",
type: "VOLUME",
inputs: [],
outputs: [],
config: {}
}}
enableReinitialize={true}
onSubmit={(values, formik) => {
handleCreate(values, formik);
}}
validationSchema={validationSchema}
>
{(formik) => (
<>
<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">
<form onSubmit={formik.handleSubmit}>
{openTab === "General" && <General formik={formik} />}
{openTab === "Labels" && <Labels formik={formik} />}
</form>
</div>
</div>
<div className="relative px-4 py-3 flex-auto">
{openTab === "General" && <General />}
{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={() => {
onAddEndpoint(formik.values);
formik.resetForm();
}}
>
Add
</button>
</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();
}}
>
Add
</button>
</div>
</>
)}
</Formik>
</div>
</div>
</div>

@ -1,14 +1,10 @@
import { useEffect, useState } from "react";
import { useFormik } from "formik";
import { Formik } from "formik";
import * as yup from "yup";
import { XIcon } from "@heroicons/react/outline";
import General from "./General";
import Labels from "./Labels";
import { topLevelVolumeConfigInitialValues } from "../../../utils";
import {
CallbackFunction,
IVolumeNodeItem,
IVolumeTopLevel
} from "../../../types";
import { CallbackFunction, IVolumeNodeItem } from "../../../types";
interface IModalVolumeEdit {
node: IVolumeNodeItem;
@ -20,14 +16,18 @@ const ModalVolumeEdit = (props: IModalVolumeEdit) => {
const { node, onHide, onUpdateEndpoint } = props;
const [openTab, setOpenTab] = useState("General");
const [selectedNode, setSelectedNode] = useState<IVolumeNodeItem>();
const formik = useFormik({
initialValues: {
volumeConfig: {
...topLevelVolumeConfigInitialValues()
}
},
onSubmit: () => undefined
const handleUpdate = (values: any) => {
const updated = { ...selectedNode };
updated.volumeConfig = values.volumeConfig;
onUpdateEndpoint(updated);
};
const validationSchema = yup.object({
volumeConfig: yup.object({
name: yup
.string()
.max(256, "name should be 256 characters or less")
.required("name is required")
})
});
const tabs = [
{
@ -53,22 +53,6 @@ const ModalVolumeEdit = (props: IModalVolumeEdit) => {
}
}, [node]);
useEffect(() => {
formik.resetForm();
if (selectedNode) {
formik.initialValues.volumeConfig = {
...selectedNode.volumeConfig
} as IVolumeTopLevel;
}
}, [selectedNode]);
useEffect(() => {
return () => {
formik.resetForm();
};
}, []);
return (
<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">
@ -92,55 +76,71 @@ const ModalVolumeEdit = (props: IModalVolumeEdit) => {
</button>
</div>
<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">
<form onSubmit={formik.handleSubmit}>
{openTab === "General" && <General 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.volumeConfig = formik.values.volumeConfig;
onUpdateEndpoint(updated);
{selectedNode && (
<Formik
initialValues={{
volumeConfig: {
...selectedNode.volumeConfig
}
}}
enableReinitialize={true}
onSubmit={(values) => {
handleUpdate(values);
}}
validationSchema={validationSchema}
>
Update
</button>
</div>
{(formik) => (
<>
<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 === "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>

@ -1,32 +1,11 @@
const General = (props: any) => {
const { formik } = props;
import TextField from "../../global/FormElements/InputField";
const General = () => {
return (
<>
<div className="relative pb-3 flex-auto">
<div className="grid grid-cols-6 gap-4">
<div className="col-span-3">
<label
htmlFor="name"
className="block text-xs font-medium text-gray-700"
>
Name
</label>
<div className="mt-1">
<input
id="name"
name="volumeConfig.name"
type="text"
autoComplete="none"
className="input-util"
onChange={formik.handleChange}
value={formik.values.volumeConfig.name}
/>
</div>
</div>
</div>
</div>
<TextField label="Name" name="volumeConfig.name" />
</>
);
};
export default General;

@ -1,6 +1,4 @@
const Labels = (props: any) => {
const { formik } = props;
const Labels = () => {
return <></>;
};
export default Labels;

@ -245,9 +245,9 @@ export default function Project() {
if (existingIndex !== -1) {
_connections.splice(existingIndex, 1);
setConnections(_connections);
stateConnectionsRef.current = _connections;
}
setConnections(_connections);
};
const onConnectionAttached = (data: any) => {

@ -0,0 +1,50 @@
import _ from "lodash";
import { useFormikContext } from "formik";
interface Props {
name: string;
help?: string;
[key: string]: any;
}
const TextField = (props: Props) => {
const { label, name, help, ...otherProps } = props;
const formik = useFormikContext();
const error = _.get(formik.touched, name) && _.get(formik.errors, name);
return (
<div className="relative pb-3 flex-auto">
<div className="grid grid-cols-6 gap-4">
<div className="col-span-3">
<label
htmlFor={name}
className="block text-xs font-medium text-gray-700"
>
{label}
</label>
<div className="mt-1">
<input
id={name}
name={name}
type="text"
autoComplete="none"
className="input-util"
onBlur={formik.handleBlur}
onChange={formik.handleChange}
{...otherProps}
value={_.get(formik.values, name)}
/>
{
<div className="mt-1 text-xs text-red-600">
{error && <div className="caption">{error}</div>}
{!error && help}
</div>
}
</div>
</div>
</div>
</div>
);
};
export default TextField;
Loading…
Cancel
Save