From a92c6aa9ce8859bb89bdc859d3a75953591dfcab Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 28 Sep 2022 16:59:12 +0800 Subject: [PATCH] fix associate floating IP in the port list if allowed Show Associate Floating IP in port list if allowed Closes-Bug: #1991078 Change-Id: I100b2bc184bb8e3e861cfd6437745ab799ca02da --- src/stores/neutron/port-extension.js | 51 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/stores/neutron/port-extension.js b/src/stores/neutron/port-extension.js index f92c211f..c2db8795 100644 --- a/src/stores/neutron/port-extension.js +++ b/src/stores/neutron/port-extension.js @@ -174,28 +174,37 @@ export class PortStore extends Base { return items; } const { subnetId } = filters; - if (!subnetId) { - return items; + if (subnetId) { + const newItems = []; + items.forEach((it) => { + const { fixed_ips = [] } = it; + const newFixedIps = fixed_ips.filter((ip) => ip.subnet_id === subnetId); + if (newFixedIps.length) { + const ipv4 = it.ipv4.filter((ip) => + newFixedIps.some((newIp) => newIp.ip_address === ip) + ); + const ipv6 = it.ipv6.filter((ip) => + newFixedIps.some((newIp) => newIp.ip_address === ip) + ); + newItems.push({ + ...it, + fixed_ips: newFixedIps, + ipv4, + ipv6, + subnet_id: subnetId, + }); + } + }); + return newItems; } - const newItems = []; - items.forEach((it) => { - const { fixed_ips = [] } = it; - const newFixedIps = fixed_ips.filter((ip) => ip.subnet_id === subnetId); - if (newFixedIps.length) { - const ipv4 = it.ipv4.filter((ip) => - newFixedIps.some((newIp) => newIp.ip_address === ip) - ); - const ipv6 = it.ipv6.filter((ip) => - newFixedIps.some((newIp) => newIp.ip_address === ip) - ); - newItems.push({ - ...it, - fixed_ips: newFixedIps, - ipv4, - ipv6, - subnet_id: subnetId, - }); - } + const fips = (await globalFloatingIpsStore.pureFetchList()) || []; + const newItems = items.map((it) => { + it.associatedDetail = fips.filter( + (f) => + f.port_id === it.id && + it.fixed_ips.find((ff) => ff.ip_address === f.fixed_ip_address) + ); + return it; }); return newItems; }