From b536d2206c8cc661dd246af8f93c6a71a06202a3 Mon Sep 17 00:00:00 2001
From: Alexandr Ilenko <AIlenko@IBS.RU>
Date: Thu, 28 Jul 2022 15:07:15 +0300
Subject: SILABMC-172: Fix: marker deleted static IP address

---
 src/views/_sila/Overview/Network/TableIpv4.vue | 37 +++++++++++++++++++-------
 1 file changed, 27 insertions(+), 10 deletions(-)

(limited to 'src/views/_sila/Overview/Network/TableIpv4.vue')

diff --git a/src/views/_sila/Overview/Network/TableIpv4.vue b/src/views/_sila/Overview/Network/TableIpv4.vue
index 4f9f9df1..2fa3d1f3 100644
--- a/src/views/_sila/Overview/Network/TableIpv4.vue
+++ b/src/views/_sila/Overview/Network/TableIpv4.vue
@@ -137,7 +137,9 @@ export default {
               value: 'delete',
               title: this.$t('pageNetwork.table.deleteIpv4'),
             },
-          ],
+          ].filter((action) => {
+            return action.value === 'delete' && ipv4.AddressOrigin === 'Static';
+          }),
         };
       });
     },
@@ -147,17 +149,32 @@ export default {
       }
     },
     deleteIpv4TableRow(index) {
+      const deleteMarker = null;
+      const newIpv4StaticArray = this.form.ipv4TableItems
+        .map((ipv4, idx) => {
+          // address cannot be matched, except by their index
+          if (idx === index) {
+            return deleteMarker;
+          }
+          return ipv4;
+        })
+        .filter((ipv4) => {
+          return ipv4 === deleteMarker || ipv4.AddressOrigin === 'Static';
+        })
+        .map((ipv4) => {
+          if (ipv4 === deleteMarker) {
+            return deleteMarker;
+          }
+          const { Address, SubnetMask, Gateway } = ipv4;
+          return {
+            Address,
+            SubnetMask,
+            Gateway,
+          };
+        });
       this.form.ipv4TableItems.splice(index, 1);
-      const newIpv4Array = this.form.ipv4TableItems.map((ipv4) => {
-        const { Address, SubnetMask, Gateway } = ipv4;
-        return {
-          Address,
-          SubnetMask,
-          Gateway,
-        };
-      });
       this.$store
-        .dispatch('network/editIpv4Address', newIpv4Array)
+        .dispatch('network/editIpv4Address', newIpv4StaticArray)
         .then((message) => this.successToast(message))
         .catch(({ message }) => this.errorToast(message));
     },
-- 
cgit v1.2.3

