From 609566cf6f87fbaf9f24fc1d274426cbb470372b Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 1 Dec 2020 13:18:12 +0100
Subject: [PATCH] bugfix: show only latest version of region...

... in "show in other tmpls"
---
 src/ui/parcellationRegion/region.base.ts | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts
index 51ea82413..473a830af 100644
--- a/src/ui/parcellationRegion/region.base.ts
+++ b/src/ui/parcellationRegion/region.base.ts
@@ -90,19 +90,31 @@ export class RegionBase {
           const filteredRsInOtherTmpls = []
           for (const bundledObj of regionsInOtherTemplates) {
             const { template, parcellation, region } = bundledObj
-            const idx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => {
+
+            /**
+             * trying to find duplicate region
+             * with same templateId, and same hemisphere
+             */
+            const sameEntityIdx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => {
               return _template['@id'] === template['@id']
-                && getRegionHemisphere(_region) !== getRegionHemisphere(region)
+                && getRegionHemisphere(_region) === getRegionHemisphere(region)
             })
-            if ( idx < 0 ) {
+            /**
+             * if doesn't exist, just push to output
+             */
+            if ( sameEntityIdx < 0 ) {
               filteredRsInOtherTmpls.push(bundledObj)
             } else {
-              const { parcellation: currentParc } = filteredRsInOtherTmpls[idx]
+
+              /**
+               * if exists, only append the latest version
+               */
+              const { parcellation: currentParc } = filteredRsInOtherTmpls[sameEntityIdx]
               /**
                * if the new element is newer than existing item
                */
               if (isNewerThan(parcellations, parcellation, currentParc)) {
-                filteredRsInOtherTmpls.splice(idx, 1)
+                filteredRsInOtherTmpls.splice(sameEntityIdx, 1)
                 filteredRsInOtherTmpls.push(bundledObj)
               }
             }
-- 
GitLab