From 0ac83d064fb5933fa9dcc4cb04c786614a472f18 Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Fri, 29 Jul 2022 20:35:21 +0530 Subject: [PATCH] fix(frontend): fixed logic for generating final values for service forms --- .../components/Modal/service/form-utils.ts | 81 ++++++++----------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/services/frontend/src/components/Modal/service/form-utils.ts b/services/frontend/src/components/Modal/service/form-utils.ts index 286b6a5..190cb14 100644 --- a/services/frontend/src/components/Modal/service/form-utils.ts +++ b/services/frontend/src/components/Modal/service/form-utils.ts @@ -1,6 +1,5 @@ import type { IEditServiceForm, IServiceNodeItem } from "../../../types"; import * as yup from "yup"; -import lodash from "lodash"; import { checkArray } from "../../../utils/forms"; const initialValues: IEditServiceForm = { @@ -153,51 +152,41 @@ export const getFinalValues = ( ): IServiceNodeItem => { const { environmentVariables, ports, volumes, labels } = values; - return lodash.mergeWith( - lodash.cloneDeep(previous) || { - key: "service", - type: "SERVICE", - inputs: ["op_source"], - outputs: [], - config: {} - }, - { - canvasConfig: { - node_name: values.serviceName - }, - serviceConfig: { - image: `${values.imageName}${ - values.imageTag ? `:${values.imageTag}` : "" - }`, - container_name: values.containerName, - environment: environmentVariables.map( - (variable) => - `${variable.key}${variable.value ? `=${variable.value}` : ""}` - ), - volumes: volumes.length - ? volumes.map( - (volume) => - volume.name + - (volume.containerPath ? `:${volume.containerPath}` : "") + - (volume.accessMode ? `:${volume.accessMode}` : "") - ) - : [], - ports: ports.map( - (port) => - port.hostPort + - (port.containerPort ? `:${port.containerPort}` : "") + - (port.protocol ? `/${port.protocol}` : "") - ), - labels: labels.map( - (label) => `${label.key}${label.value ? `=${label.value}` : ""}` - ) - } + return { + key: previous?.key ?? "service", + type: "SERVICE", + inputs: previous?.inputs ?? ["op_source"], + outputs: previous?.outputs ?? [], + config: (previous as any)?.config ?? {}, + canvasConfig: { + node_name: values.serviceName }, - (obj, src) => { - if (!lodash.isNil(src)) { - return src; - } - return obj; + serviceConfig: { + image: `${values.imageName}${ + values.imageTag ? `:${values.imageTag}` : "" + }`, + container_name: values.containerName, + environment: environmentVariables.map( + (variable) => + `${variable.key}${variable.value ? `=${variable.value}` : ""}` + ), + volumes: volumes.length + ? volumes.map( + (volume) => + volume.name + + (volume.containerPath ? `:${volume.containerPath}` : "") + + (volume.accessMode ? `:${volume.accessMode}` : "") + ) + : [], + ports: ports.map( + (port) => + port.hostPort + + (port.containerPort ? `:${port.containerPort}` : "") + + (port.protocol ? `/${port.protocol}` : "") + ), + labels: labels.map( + (label) => `${label.key}${label.value ? `=${label.value}` : ""}` + ) } - ) as any; + } as any; };