From ba0eac4c5c4c25e43da533234501bd73efa2eb7f Mon Sep 17 00:00:00 2001 From: corpulent Date: Wed, 3 Aug 2022 15:01:56 +0300 Subject: [PATCH] feat: basic service forms --- .../src/components/Modal/service/General.tsx | 27 ++++++++++++++ .../components/Modal/service/form-utils.ts | 35 +++++++++++++++---- services/frontend/src/types/index.ts | 5 +++ 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/services/frontend/src/components/Modal/service/General.tsx b/services/frontend/src/components/Modal/service/General.tsx index 64c8c5e..0a144db 100644 --- a/services/frontend/src/components/Modal/service/General.tsx +++ b/services/frontend/src/components/Modal/service/General.tsx @@ -1,5 +1,6 @@ import { styled } from "@mui/joy"; import TextField from "../../global/FormElements/TextField"; +import Toggle from "../../global/FormElements/Toggle"; import Records from "../../Records"; const Root = styled("div")` @@ -29,6 +30,32 @@ const General = () => { + + + + + (yup.string, "port", function (message) { @@ -289,8 +293,10 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { const { node_name = "" } = canvasConfig; const { build, + command, deploy, depends_on, + entrypoint, image, container_name = "", environment, @@ -298,7 +304,9 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { networks, ports, profiles, - labels + restart, + labels, + working_dir } = serviceConfig; const volumes0: string[] = checkArray(volumes ?? [], "volumes"); @@ -330,6 +338,7 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { target: build.target?.toString() ?? initialValues.build.target } : initialValues.build, + command: (command as string) ?? (initialValues.command as string), deploy: deploy ? { mode: deploy.mode ?? initialValues.deploy.mode, @@ -447,6 +456,9 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { initialValues.deploy.labels } : initialValues.deploy, + dependsOn: + (depends_on as string[]) ?? (initialValues.dependsOn as string[]), + entrypoint: (entrypoint as string) ?? (initialValues.entrypoint as string), imageName, imageTag, serviceName: node_name, @@ -479,9 +491,10 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { return { hostPort, containerPort, protocol } as any; }), profiles: profiles ?? initialValues.profiles, + restart: (restart as string) ?? (initialValues.restart as string), labels: extractObjectOrArray("=", "key", "value", labels) ?? initialValues.labels, - dependsOn: (depends_on as string[]) ?? (initialValues.dependsOn as string[]) + workingDir: (working_dir as string) ?? (initialValues.workingDir as string) }; }; @@ -491,14 +504,18 @@ export const getFinalValues = ( ): IServiceNodeItem => { const { build, + command, deploy, dependsOn, + entrypoint, environmentVariables, + volumes, + networks, ports, profiles, - networks, - volumes, - labels + restart, + labels, + workingDir } = values; return { @@ -530,6 +547,7 @@ export const getFinalValues = ( shm_size: pruneString(build.sharedMemorySize), target: pruneString(build.target) }), + command: pruneString(command), deploy: pruneObject({ mode: pruneString(deploy.mode), replicas: pruneString(deploy.replicas), @@ -585,6 +603,8 @@ export const getFinalValues = ( }), labels: packArrayAsObject(deploy.labels, "key", "value") }), + depends_on: pruneArray(dependsOn), + entrypoint: pruneString(entrypoint), image: `${values.imageName}${ values.imageTag ? `:${values.imageTag}` : "" }`, @@ -608,8 +628,9 @@ export const getFinalValues = ( ) ), profiles: pruneArray(profiles), + restart: pruneString(restart), labels: packArrayAsObject(labels, "key", "value"), - depends_on: pruneArray(dependsOn) + working_dir: pruneString(workingDir) } }; }; diff --git a/services/frontend/src/types/index.ts b/services/frontend/src/types/index.ts index ff34d93..5a8ba7e 100644 --- a/services/frontend/src/types/index.ts +++ b/services/frontend/src/types/index.ts @@ -1,6 +1,7 @@ import { AnchorId } from "@jsplumb/common"; import { Dictionary } from "lodash"; import { KeyValuePair } from "tailwindcss/types/config"; +import { string } from "yup"; import { NodeGroupType } from "./enums"; type KeyValPair = { @@ -385,6 +386,7 @@ export interface IEditServiceForm { sharedMemorySize: string; target: string; }; + command: string; deploy: { /** * The default value for `mode` is `replicated`. However, we allow @@ -450,6 +452,7 @@ export interface IEditServiceForm { value: string; }[]; }; + entrypoint: string; serviceName: string; imageName: string; imageTag: string; @@ -465,6 +468,7 @@ export interface IEditServiceForm { key: string; value: string; }[]; + restart: string; volumes: { name: string; containerPath: string; @@ -475,6 +479,7 @@ export interface IEditServiceForm { value: string; }[]; dependsOn: string[]; + workingDir: string; } export interface IEditVolumeForm {