refactor(frontend): moved `checkArray` function to utils module

pull/76/head
Samuel Rowe 3 years ago
parent c06f688cf3
commit 61344ff300

@ -3,7 +3,7 @@ import { PlusIcon } from "@heroicons/react/outline";
import { Button, styled } from "@mui/joy";
import { useFormikContext } from "formik";
import Record from "../../Record";
import { IEditServiceForm, IService } from "../../../types";
import { IEditServiceForm } from "../../../types";
const Root = styled("div")`
display: flex;

@ -1,6 +1,7 @@
import type { IEditServiceForm, IServiceNodeItem } from "../../../types";
import * as yup from "yup";
import lodash from "lodash";
import { checkArray } from "../../../utils/forms";
const initialValues: IEditServiceForm = {
imageName: "",
@ -96,15 +97,6 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
labels
} = serviceConfig;
const checkArray = <T>(array: any, name: string): T => {
if (!Array.isArray(array)) {
throw new Error(
`Looks like we encountered a bug. The current implementation expects "${name}" to be an array.`
);
}
return array as unknown as T;
};
const environment0: string[] = checkArray(environment, "environment");
const volumes0: string[] = checkArray(volumes, "volumes");
const ports0: string[] = checkArray(ports, "ports");

@ -0,0 +1,8 @@
export const checkArray = <T>(array: any, name: string): T => {
if (!Array.isArray(array)) {
throw new Error(
`Looks like we encountered a bug. The current implementation expects "${name}" to be an array.`
);
}
return array as unknown as T;
};
Loading…
Cancel
Save