diff client/src/store/bottlenecks.js @ 5586:215e6ba9651b surveysperbottleneckid

Added property "displayName" to bottlenecks. Before displayed, bottlenecks ordered by country are now checked for doubles per country. In case a double is found the displayName is enriched with the bottleneck_id. Otherwise the displayName is equal to "name" or "objnam". Example: const testList = [ { properties: { responsible_country: "AT", name: "Bananas", bottleneck_id: "BN1" } }, { properties: { responsible_country: "DE", name: "Bananas", bottleneck_id: "BN2" } }, { properties: { responsible_country: "DE", name: "Bananas", bottleneck_id: "BN3" } } ]; is rendered to: AT Bananas DE Bananas / BN2 Bananas / BN3
author Thomas Junk <thomas.junk@intevation.de>
date Mon, 04 Apr 2022 15:12:43 +0200
parents 1d847bc21bb7
children 2576a399c2cf
line wrap: on
line diff
--- a/client/src/store/bottlenecks.js	Fri Apr 01 18:51:23 2022 +0200
+++ b/client/src/store/bottlenecks.js	Mon Apr 04 15:12:43 2022 +0200
@@ -43,9 +43,8 @@
       }, {});
     },
     orderedBottlenecks: state => {
-      let groupedBottlenecks = {},
-        orderedGroups = {};
-
+      const groupedBottlenecks = {};
+      const orderedGroups = {};
       // group bottlenecks by cc
       state.bottlenecksList.forEach(bn => {
         let cc = bn.properties.responsible_country;
@@ -59,7 +58,27 @@
       // order groups by cc
       Object.keys(groupedBottlenecks)
         .sort()
-        .forEach(cc => (orderedGroups[cc] = groupedBottlenecks[cc]));
+        .forEach(cc => {
+          const names = {};
+          const doubleNames = {};
+          groupedBottlenecks[cc].forEach(bn => {
+            const name = bn.properties.name || bn.properties.objnam;
+            if (!names[name]) {
+              names[name] = name;
+            } else {
+              doubleNames[name] = name;
+            }
+          });
+          groupedBottlenecks[cc].forEach(bn => {
+            const name = bn.properties.name || bn.properties.objnam;
+            if (doubleNames[name]) {
+              bn.properties.displayName = `${name} / ${bn.properties.bottleneck_id}`;
+            } else {
+              bn.properties.displayName = name;
+            }
+          });
+          orderedGroups[cc] = groupedBottlenecks[cc];
+        });
 
       return orderedGroups;
     }