From a0e400fb4b54a96d5911b86185ad062572b65927 Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Sun, 31 Jul 2022 23:54:00 +0530 Subject: [PATCH] feat(frontend): updated `getFinalValues` to prune `deploy` object --- .../components/Modal/service/form-utils.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/services/frontend/src/components/Modal/service/form-utils.ts b/services/frontend/src/components/Modal/service/form-utils.ts index c642be0..57d5d75 100644 --- a/services/frontend/src/components/Modal/service/form-utils.ts +++ b/services/frontend/src/components/Modal/service/form-utils.ts @@ -6,7 +6,8 @@ import { pruneObject, extractObjectOrArray, extractArray, - pruneString + pruneString, + pruneNumber } from "../../../utils/forms"; export const tabs = [ @@ -57,8 +58,8 @@ const initialValues: IEditServiceForm = { target: "" }, deploy: { - mode: "replicated", - replicas: "1", + mode: "", + replicas: "", endpointMode: "", placement: { constraints: [], @@ -425,7 +426,7 @@ export const getFinalValues = ( }, serviceConfig: { build: pruneObject({ - context: build.context, + context: pruneString(build.context), dockerfile: pruneString(build.dockerfile), args: pruneObject(build.arguments), ssh: pruneArray( @@ -447,31 +448,31 @@ export const getFinalValues = ( target: pruneString(build.target) }), deploy: pruneObject({ - mode: deploy.mode, - replicas: deploy.replicas, - endpoint_mode: deploy.endpointMode, + mode: pruneString(deploy.mode), + replicas: pruneString(deploy.replicas), + endpoint_mode: pruneString(deploy.endpointMode), placement: pruneObject({ constraints: pruneArray(deploy.placement.constraints), preferences: pruneArray(deploy.placement.preferences) }), resources: pruneObject({ limits: pruneObject({ - cpus: deploy.resources.limits.cpus, - memory: deploy.resources.limits.memory, + cpus: pruneString(deploy.resources.limits.cpus), + memory: pruneString(deploy.resources.limits.memory), // NOTE: Could be a potential bug. - pids: parseInt(deploy.resources.limits.pids) ?? undefined + pids: pruneNumber(parseInt(deploy.resources.limits.pids)) }), reservations: pruneObject({ - cpus: deploy.resources.reservations.cpus, - memory: deploy.resources.reservations.memory + cpus: pruneString(deploy.resources.reservations.cpus), + memory: pruneString(deploy.resources.reservations.memory) }) }), restart_policy: pruneObject({ - condition: deploy.restartPolicy.condition, - delay: deploy.restartPolicy.delay, + condition: pruneString(deploy.restartPolicy.condition), + delay: pruneString(deploy.restartPolicy.delay), // NOTE: Could be a potential bug. - maxAttempts: parseInt(deploy.restartPolicy.maxAttempts) ?? undefined, - window: deploy.restartPolicy.window + maxAttempts: pruneNumber(parseInt(deploy.restartPolicy.maxAttempts)), + window: pruneString(deploy.restartPolicy.window) }), labels: pruneObject( Object.fromEntries(labels.map((label) => [label.key, label.value]))