feat(frontend): updated `Record` to render toggles

* The `Record` component now accepts `type` and `options` props.
pull/75/head
Samuel Rowe 3 years ago
parent 05fe8059f3
commit 5957758f1f

@ -68,12 +68,14 @@ const Environment = () => {
{
name: `environmentVariables[${index}].key`,
placeholder: "Key",
required: true
required: true,
type: "text"
},
{
name: `environmentVariables[${index}].value`,
placeholder: "Value",
required: true
required: true,
type: "text"
}
]}
onRemove={handleRemoveEnvironmentVariable}

@ -59,7 +59,7 @@ const General = () => {
formik.setFieldValue(`ports[${ports.length}]`, {
hostPort: "",
containerPort: "",
protocol: ""
protocol: "tcp"
});
}, [formik]);
@ -105,15 +105,28 @@ const General = () => {
{
name: `ports[${index}].hostPort`,
placeholder: "Host Port",
required: true
required: true,
type: "text"
},
{
name: `ports[${index}].containerPort`,
placeholder: "Container Port"
placeholder: "Container Port",
type: "text"
},
{
name: `ports[${index}].protocol`,
placeholder: "Protocol"
placeholder: "Protocol",
type: "toggle",
options: [
{
value: "tcp",
text: "TCP"
},
{
value: "udp",
text: "UDP"
}
]
}
]}
onRemove={handleRemovePort}

@ -64,12 +64,14 @@ const Labels = () => {
{
name: `labels[${index}].key`,
placeholder: "Key",
required: true
required: true,
type: "text"
},
{
name: `labels[${index}].value`,
placeholder: "Value",
required: true
required: true,
type: "text"
}
]}
onRemove={handleRemoveLabel}

@ -65,15 +65,18 @@ const Volumes = () => {
{
name: `volumes[${index}].name`,
placeholder: "Name",
required: true
required: true,
type: "text"
},
{
name: `volumes[${index}].containerPath`,
placeholder: "Container path"
placeholder: "Container path",
type: "text"
},
{
name: `volumes[${index}].accessMode`,
placeholder: "Access mode"
placeholder: "Access mode",
type: "text"
}
]}
onRemove={handleRemoveVolume}

@ -1,13 +1,19 @@
import { FunctionComponent, ReactElement, useCallback } from "react";
import { Fragment, FunctionComponent, ReactElement, useCallback } from "react";
import { styled } from "@mui/joy";
import IconButton from "@mui/joy/IconButton";
import { MinusSmIcon } from "@heroicons/react/solid";
import TextField from "./global/FormElements/TextField";
import Toggle from "./global/FormElements/Toggle";
export interface IFieldType {
name: string;
placeholder: string;
required?: boolean;
type: "text" | "toggle";
options?: {
text: string;
value: string;
}[];
}
export interface IRecordProps {
@ -37,14 +43,20 @@ const Record: FunctionComponent<IRecordProps> = (
return (
<Root>
{fields.map(({ name, placeholder, required }) => (
<TextField
key={name}
id={name}
name={name}
placeholder={placeholder + (required ? "*" : "")}
required={required}
/>
{fields.map(({ type, name, placeholder, required, options }) => (
<Fragment key={name}>
{type === "text" && (
<TextField
id={name}
name={name}
placeholder={placeholder + (required ? "*" : "")}
required={required}
/>
)}
{type === "toggle" && (
<Toggle name={name} label={placeholder} options={options || []} />
)}
</Fragment>
))}
<RemoveButton
variant="soft"

Loading…
Cancel
Save