feat: updated depends on field to adhere the specification

pull/117/head
Samuel Rowe 3 years ago
parent ef0fffd959
commit 32cf207dc3

@ -222,14 +222,38 @@ const General = () => {
title: "Depends on", title: "Depends on",
fields: (index: number): TFinalFormField[] => [ fields: (index: number): TFinalFormField[] => [
{ {
id: `dependsOn[${index}]`, id: `dependsOn[${index}].serviceName`,
type: "text", type: "text",
name: `dependsOn[${index}]`, name: `dependsOn[${index}].serviceName`,
placeholder: "Service name", placeholder: "Service name",
required: false required: true
},
{
id: `dependsOn[${index}].condition`,
type: "toggle",
name: `dependsOn[${index}].condition`,
label: "Condition",
required: true,
options: [
{
value: "service_started",
text: "Service started"
},
{
value: "service_healthy",
text: "Service healthy"
},
{
value: "service_completed_successfully",
text: "Service completed successfully"
}
]
} }
], ],
newValue: "" newValue: {
serviceName: "",
condition: "service_started"
}
}, },
{ {
id: "networks", id: "networks",

@ -278,9 +278,43 @@ export const validationSchema = yup.object({
key: yup.string().required("Key is required"), key: yup.string().required("Key is required"),
value: yup.string() value: yup.string()
}) })
),
dependsOn: yup.array(
yup.object({
serviceName: yup.string().required("Service name is required"),
condition: yup
.string()
.oneOf(
[
"service_started",
"service_healthy",
"service_completed_successfully"
],
"Condition should be one of: service_started, service_healthy, or service_completed_successfully."
) )
})
),
workingDir: yup.string()
}); });
const extractDependsOn = (object: string[] | any) => {
if (!object) {
return object;
}
if (Array.isArray(object)) {
return object.map((item) => ({
serviceName: item,
condition: "service_started"
}));
}
return Object.keys(object).map((key) => ({
serviceName: key,
condition: object[key].condition
}));
};
export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => { export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
if (!node) { if (!node) {
return { return {
@ -456,8 +490,7 @@ export const getInitialValues = (node?: IServiceNodeItem): IEditServiceForm => {
initialValues.deploy.labels initialValues.deploy.labels
} }
: initialValues.deploy, : initialValues.deploy,
dependsOn: dependsOn: extractDependsOn(depends_on) ?? initialValues.dependsOn,
(depends_on as string[]) ?? (initialValues.dependsOn as string[]),
entrypoint: (entrypoint as string) ?? (initialValues.entrypoint as string), entrypoint: (entrypoint as string) ?? (initialValues.entrypoint as string),
envFile: (env_file as string) ?? (initialValues.envFile as string), envFile: (env_file as string) ?? (initialValues.envFile as string),
imageName, imageName,
@ -606,7 +639,16 @@ export const getFinalValues = (
}), }),
labels: packArrayAsObject(deploy.labels, "key", "value") labels: packArrayAsObject(deploy.labels, "key", "value")
}), }),
depends_on: pruneArray(dependsOn), depends_on: pruneObject(
Object.fromEntries(
dependsOn.map((item) => [
item.serviceName,
{
condition: item.condition
}
])
)
),
entrypoint: pruneString(entrypoint), entrypoint: pruneString(entrypoint),
env_file: pruneString(envFile), env_file: pruneString(envFile),
image: pruneString( image: pruneString(

@ -149,11 +149,15 @@ export interface IService {
credential_spec: KeyValPair; credential_spec: KeyValPair;
depends_on: depends_on:
| string[] | string[]
| { | Record<
[key: string]: { string,
condition: string; {
}; condition:
}; | "service_started"
| "service_healthy"
| "service_completed_successfully";
}
>;
deploy?: { deploy?: {
endpoint_mode?: "vip" | "dnsrr"; endpoint_mode?: "vip" | "dnsrr";
labels?: string[] | Record<string, string>; labels?: string[] | Record<string, string>;
@ -480,7 +484,13 @@ export interface IEditServiceForm {
key: string; key: string;
value: string; value: string;
}[]; }[];
dependsOn: string[]; dependsOn: {
serviceName: string;
condition:
| "service_started"
| "service_healthy"
| "service_completed_successfully";
}[];
workingDir: string; workingDir: string;
} }

Loading…
Cancel
Save