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`, name: `environmentVariables[${index}].key`,
placeholder: "Key", placeholder: "Key",
required: true required: true,
type: "text"
}, },
{ {
name: `environmentVariables[${index}].value`, name: `environmentVariables[${index}].value`,
placeholder: "Value", placeholder: "Value",
required: true required: true,
type: "text"
} }
]} ]}
onRemove={handleRemoveEnvironmentVariable} onRemove={handleRemoveEnvironmentVariable}

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

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

@ -65,15 +65,18 @@ const Volumes = () => {
{ {
name: `volumes[${index}].name`, name: `volumes[${index}].name`,
placeholder: "Name", placeholder: "Name",
required: true required: true,
type: "text"
}, },
{ {
name: `volumes[${index}].containerPath`, name: `volumes[${index}].containerPath`,
placeholder: "Container path" placeholder: "Container path",
type: "text"
}, },
{ {
name: `volumes[${index}].accessMode`, name: `volumes[${index}].accessMode`,
placeholder: "Access mode" placeholder: "Access mode",
type: "text"
} }
]} ]}
onRemove={handleRemoveVolume} 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 { styled } from "@mui/joy";
import IconButton from "@mui/joy/IconButton"; import IconButton from "@mui/joy/IconButton";
import { MinusSmIcon } from "@heroicons/react/solid"; import { MinusSmIcon } from "@heroicons/react/solid";
import TextField from "./global/FormElements/TextField"; import TextField from "./global/FormElements/TextField";
import Toggle from "./global/FormElements/Toggle";
export interface IFieldType { export interface IFieldType {
name: string; name: string;
placeholder: string; placeholder: string;
required?: boolean; required?: boolean;
type: "text" | "toggle";
options?: {
text: string;
value: string;
}[];
} }
export interface IRecordProps { export interface IRecordProps {
@ -37,14 +43,20 @@ const Record: FunctionComponent<IRecordProps> = (
return ( return (
<Root> <Root>
{fields.map(({ name, placeholder, required }) => ( {fields.map(({ type, name, placeholder, required, options }) => (
<Fragment key={name}>
{type === "text" && (
<TextField <TextField
key={name}
id={name} id={name}
name={name} name={name}
placeholder={placeholder + (required ? "*" : "")} placeholder={placeholder + (required ? "*" : "")}
required={required} required={required}
/> />
)}
{type === "toggle" && (
<Toggle name={name} label={placeholder} options={options || []} />
)}
</Fragment>
))} ))}
<RemoveButton <RemoveButton
variant="soft" variant="soft"

Loading…
Cancel
Save