From 46d03d809ad38aba57884600c66186c8294115c3 Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Fri, 29 Jul 2022 11:30:05 +0530 Subject: [PATCH] fix(frontend): fixed logic for generating final values for network forms * Previously, final values were generated by merging with previous state. This caused unexpected overwriting of values. Therefore, we do not merge states anymore. --- .../components/Modal/network/form-utils.ts | 62 +++++++++---------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/services/frontend/src/components/Modal/network/form-utils.ts b/services/frontend/src/components/Modal/network/form-utils.ts index 54762f0..66c9e4e 100644 --- a/services/frontend/src/components/Modal/network/form-utils.ts +++ b/services/frontend/src/components/Modal/network/form-utils.ts @@ -127,41 +127,37 @@ export const getFinalValues = ( ): INetworkNodeItem => { const { labels, driver, configurations, options } = values; - return lodash.merge( - lodash.cloneDeep(previous) || { - key: "network", - type: "NETWORK", - inputs: [], - outputs: [], - config: {} + return { + key: "network", + type: "NETWORK", + inputs: previous?.inputs ?? [], + outputs: previous?.outputs ?? [], + config: (previous as any)?.config ?? {}, + canvasConfig: { + node_name: values.entryName }, - { - canvasConfig: { - node_name: values.entryName - }, - networkConfig: { - name: values.networkName, - 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]) + networkConfig: { + name: values.networkName, + 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 + ]) ) - }, - labels: Object.fromEntries( - labels.map((label) => [label.key, label.value]) + })), + options: Object.fromEntries( + options.map((option) => [option.key, option.value]) ) - } + }, + labels: Object.fromEntries( + labels.map((label) => [label.key, label.value]) + ) } - ) as any; + } as any; };