|
|
|
@ -1,7 +1,6 @@
|
|
|
|
import lodash from "lodash";
|
|
|
|
import lodash from "lodash";
|
|
|
|
import * as yup from "yup";
|
|
|
|
import * as yup from "yup";
|
|
|
|
import { IEditNetworkForm, INetworkNodeItem } from "../../../types";
|
|
|
|
import { IEditNetworkForm, INetworkNodeItem } from "../../../types";
|
|
|
|
import { checkArray } from "../../../utils/forms";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const validationSchema = yup.object({
|
|
|
|
export const validationSchema = yup.object({
|
|
|
|
entryName: yup
|
|
|
|
entryName: yup
|
|
|
|
@ -88,12 +87,24 @@ export const getInitialValues = (node?: INetworkNodeItem): IEditNetworkForm => {
|
|
|
|
const { canvasConfig, networkConfig } = node;
|
|
|
|
const { canvasConfig, networkConfig } = node;
|
|
|
|
const { node_name = "" } = canvasConfig;
|
|
|
|
const { node_name = "" } = canvasConfig;
|
|
|
|
const { name = "", ipam, labels } = networkConfig;
|
|
|
|
const { name = "", ipam, labels } = networkConfig;
|
|
|
|
const labels0: string[] = checkArray(labels, "labels");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...initialValues,
|
|
|
|
...initialValues,
|
|
|
|
entryName: node_name,
|
|
|
|
entryName: node_name,
|
|
|
|
networkName: name,
|
|
|
|
networkName: name,
|
|
|
|
|
|
|
|
driver: ipam?.driver ?? "",
|
|
|
|
|
|
|
|
configurations:
|
|
|
|
|
|
|
|
ipam?.config.map((item) => ({
|
|
|
|
|
|
|
|
subnet: item.subnet,
|
|
|
|
|
|
|
|
ipRange: item.ip_range,
|
|
|
|
|
|
|
|
gateway: item.gateway,
|
|
|
|
|
|
|
|
auxAddresses: Object.entries(item.aux_addresses).map(
|
|
|
|
|
|
|
|
([hostName, ipAddress]) => ({
|
|
|
|
|
|
|
|
hostName,
|
|
|
|
|
|
|
|
ipAddress
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})) ?? [],
|
|
|
|
options: Object.keys(ipam?.options || {}).map((key) => {
|
|
|
|
options: Object.keys(ipam?.options || {}).map((key) => {
|
|
|
|
if (!ipam) {
|
|
|
|
if (!ipam) {
|
|
|
|
throw new Error("Control should not reach here.");
|
|
|
|
throw new Error("Control should not reach here.");
|
|
|
|
@ -103,13 +114,10 @@ export const getInitialValues = (node?: INetworkNodeItem): IEditNetworkForm => {
|
|
|
|
value: ipam.options[key].toString()
|
|
|
|
value: ipam.options[key].toString()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
labels: labels0.map((label) => {
|
|
|
|
labels: Object.entries(labels as any).map(([key, value]: any) => ({
|
|
|
|
const [key, value] = label.split(":");
|
|
|
|
key,
|
|
|
|
return {
|
|
|
|
value
|
|
|
|
key,
|
|
|
|
}))
|
|
|
|
value
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -117,7 +125,7 @@ export const getFinalValues = (
|
|
|
|
values: IEditNetworkForm,
|
|
|
|
values: IEditNetworkForm,
|
|
|
|
previous?: INetworkNodeItem
|
|
|
|
previous?: INetworkNodeItem
|
|
|
|
): INetworkNodeItem => {
|
|
|
|
): INetworkNodeItem => {
|
|
|
|
const { labels } = values;
|
|
|
|
const { labels, driver, configurations, options } = values;
|
|
|
|
|
|
|
|
|
|
|
|
return lodash.merge(
|
|
|
|
return lodash.merge(
|
|
|
|
lodash.cloneDeep(previous) || {
|
|
|
|
lodash.cloneDeep(previous) || {
|
|
|
|
@ -133,7 +141,26 @@ export const getFinalValues = (
|
|
|
|
},
|
|
|
|
},
|
|
|
|
networkConfig: {
|
|
|
|
networkConfig: {
|
|
|
|
name: values.networkName,
|
|
|
|
name: values.networkName,
|
|
|
|
labels: labels.map((label) => `${label.key}:${label.value}`)
|
|
|
|
ipam: {
|
|
|
|
|
|
|
|
driver,
|
|
|
|
|
|
|
|
config: configurations.map((configuration) => ({
|
|
|
|
|
|
|
|
subnet: configuration.subnet,
|
|
|
|
|
|
|
|
ip_range: configuration.ipRange,
|
|
|
|
|
|
|
|
gateway: configuration.gateway,
|
|
|
|
|
|
|
|
aux_addresses: Object.fromEntries(
|
|
|
|
|
|
|
|
configuration.auxAddresses.map((auxAddress) => [
|
|
|
|
|
|
|
|
auxAddress.hostName,
|
|
|
|
|
|
|
|
auxAddress.ipAddress
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})),
|
|
|
|
|
|
|
|
options: Object.fromEntries(
|
|
|
|
|
|
|
|
options.map((option) => [option.key, option.value])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
labels: Object.fromEntries(
|
|
|
|
|
|
|
|
labels.map((label) => [label.key, label.value])
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) as any;
|
|
|
|
) as any;
|
|
|
|
|