From a8cb6bd28fb53ab00bafc4b26c1c83b19e0058d7 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Fri, 26 Feb 2021 09:48:54 +0100
Subject: [PATCH] bugfix: explore in other tmpl bug

---
 docs/releases/v2.3.9.md                       |  5 ++
 mkdocs.yml                                    |  1 +
 package.json                                  |  2 +-
 src/res/ext/bigbrain.json                     | 15 ----
 src/ui/parcellationRegion/region.base.spec.ts | 90 ++++++++++++++++++-
 src/ui/parcellationRegion/region.base.ts      |  7 +-
 6 files changed, 97 insertions(+), 23 deletions(-)
 create mode 100644 docs/releases/v2.3.9.md

diff --git a/docs/releases/v2.3.9.md b/docs/releases/v2.3.9.md
new file mode 100644
index 000000000..510ef7cf0
--- /dev/null
+++ b/docs/releases/v2.3.9.md
@@ -0,0 +1,5 @@
+# v2.3.9
+
+## Bugfixes
+
+- Explore in other templates sometimes bugs out.
\ No newline at end of file
diff --git a/mkdocs.yml b/mkdocs.yml
index 089276c5f..27dd11a40 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -40,6 +40,7 @@ pages:
     - Fetching datasets: 'advanced/datasets.md'
     - Display non-atlas volumes: 'advanced/otherVolumes.md'
   - Release notes:
+    - v2.3.9: 'releases/v2.3.9.md'
     - v2.3.8: 'releases/v2.3.8.md'
     - v2.3.7: 'releases/v2.3.7.md'
     - v2.3.6: 'releases/v2.3.6.md'
diff --git a/package.json b/package.json
index 4675362b8..ddaadebbe 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "interactive-viewer",
-  "version": "2.3.8",
+  "version": "2.3.9",
   "description": "HBP interactive atlas viewer. Integrating KG query, dataset previews & more. Based on humanbrainproject/nehuba & google/neuroglancer. Built with angular.io",
   "scripts": {
     "dev-server-export": "webpack-dev-server --config webpack.export.js",
diff --git a/src/res/ext/bigbrain.json b/src/res/ext/bigbrain.json
index 17f945dfa..225568836 100644
--- a/src/res/ext/bigbrain.json
+++ b/src/res/ext/bigbrain.json
@@ -852,7 +852,6 @@
                           "ngId": "v3v",
                           "status": "fully mapped",
                           "labelIndex": 1,
-                          "position": [],
                           "rgb": [
                             83,
                             179,
@@ -908,7 +907,6 @@
                               "ngId": "v5",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 255,
                                 0,
@@ -962,7 +960,6 @@
                               "ngId": "LGB-lam1",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 255,
                                 255,
@@ -991,7 +988,6 @@
                               "ngId": "LGB-lam2",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 222,
                                 74,
@@ -1020,7 +1016,6 @@
                               "ngId": "LGB-lam3",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 132,
                                 90,
@@ -1049,7 +1044,6 @@
                               "ngId": "LGB-lam4",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 41,
                                 123,
@@ -1078,7 +1072,6 @@
                               "ngId": "LGB-lam5",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 82,
                                 214,
@@ -1107,7 +1100,6 @@
                               "ngId": "LGB-lam6",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 99,
                                 231,
@@ -1141,7 +1133,6 @@
                               "ngId": "v5",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 255,
                                 0,
@@ -1186,7 +1177,6 @@
                               "ngId": "LGB-lam1",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 255,
                                 255,
@@ -1206,7 +1196,6 @@
                               "ngId": "LGB-lam2",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 222,
                                 74,
@@ -1226,7 +1215,6 @@
                               "ngId": "LGB-lam3",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 132,
                                 90,
@@ -1246,7 +1234,6 @@
                               "ngId": "LGB-lam4",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 41,
                                 123,
@@ -1266,7 +1253,6 @@
                               "ngId": "LGB-lam5",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 82,
                                 214,
@@ -1286,7 +1272,6 @@
                               "ngId": "LGB-lam6",
                               "status": "fully mapped",
                               "labelIndex": 1,
-                              "position": [],
                               "rgb": [
                                 99,
                                 231,
diff --git a/src/ui/parcellationRegion/region.base.spec.ts b/src/ui/parcellationRegion/region.base.spec.ts
index 44695ff6b..c2fba7c31 100644
--- a/src/ui/parcellationRegion/region.base.spec.ts
+++ b/src/ui/parcellationRegion/region.base.spec.ts
@@ -1,5 +1,6 @@
 import { TestBed } from '@angular/core/testing'
 import { MockStore, provideMockStore } from '@ngrx/store/testing'
+import { viewerStateNewViewer } from 'src/services/state/viewerState/actions'
 import { RegionBase, regionInOtherTemplateSelector, getRegionParentParcRefSpace } from './region.base'
 
 /**
@@ -449,19 +450,20 @@ describe('> region.base.ts', () => {
   })
   
   describe('> RegionBase', () => {
+    let regionBase: RegionBase
+    let mockStore: MockStore
     beforeEach(() => {
       TestBed.configureTestingModule({
         providers: [
           provideMockStore()
         ]
       })
+      mockStore = TestBed.inject(MockStore)
+      mockStore.overrideSelector(regionInOtherTemplateSelector, [])
+      mockStore.overrideSelector(getRegionParentParcRefSpace, { template: null, parcellation: null })
     })
     describe('> position', () => {
-      let regionBase: RegionBase
       beforeEach(() => {
-        const mockStore = TestBed.inject(MockStore)
-        mockStore.overrideSelector(regionInOtherTemplateSelector, [])
-        mockStore.overrideSelector(getRegionParentParcRefSpace, { template: null, parcellation: null })
         regionBase = new RegionBase(mockStore)
       })
       it('> does not populate if position property is absent', () => {
@@ -526,5 +528,85 @@ describe('> region.base.ts', () => {
         expect(regionBase.position).toBeTruthy()
       })
     })
+  
+    describe('> changeView', () => {
+      const fakeTmpl = {
+        name: 'fakeTmpl'
+      }
+      const fakeParc = {
+        name: 'fakeParc'
+      }
+      beforeEach(() => {
+        regionBase = new RegionBase(mockStore)
+      })
+
+      describe('> if sameRegion has position attribute', () => {
+        let dispatchSpy: jasmine.Spy
+
+        beforeEach(() => {
+          dispatchSpy = spyOn(mockStore, 'dispatch')
+        })
+        afterEach(() => {
+          dispatchSpy.calls.reset()
+        })
+        it('> malformed position is not an array > do not pass position', () => {
+
+          regionBase.changeView({
+            template: fakeTmpl,
+            parcellation: fakeParc,
+            region: {
+              position: 'hello wolrd'
+            }
+          })
+
+          expect(dispatchSpy).toHaveBeenCalledWith(
+            viewerStateNewViewer({
+              selectTemplate: fakeTmpl,
+              selectParcellation: fakeParc,
+              navigation: {}
+            })
+          )
+        })
+
+        it('> malformed position is an array of incorrect size > do not pass position', () => {
+
+          regionBase.changeView({
+            template: fakeTmpl,
+            parcellation: fakeParc,
+            region: {
+              position: []
+            }
+          })
+
+          expect(dispatchSpy).toHaveBeenCalledWith(
+            viewerStateNewViewer({
+              selectTemplate: fakeTmpl,
+              selectParcellation: fakeParc,
+              navigation: {}
+            })
+          )
+        })
+
+        it('> correct position > pass position', () => {
+          regionBase.changeView({
+            template: fakeTmpl,
+            parcellation: fakeParc,
+            region: {
+              position: [1,2,3]
+            }
+          })
+
+          expect(dispatchSpy).toHaveBeenCalledWith(
+            viewerStateNewViewer({
+              selectTemplate: fakeTmpl,
+              selectParcellation: fakeParc,
+              navigation: {
+                position: [1,2,3]
+              }
+            })
+          )
+        })
+      })
+    })
   })
 })
diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts
index 35c33e9c6..27a83cdf5 100644
--- a/src/ui/parcellationRegion/region.base.ts
+++ b/src/ui/parcellationRegion/region.base.ts
@@ -169,6 +169,9 @@ export class RegionBase {
       region
     } = sameRegion
     const { position } = region
+    const navigation = Array.isArray(position) && position.length === 3
+      ? { position }
+      : {  }
     this.closeRegionMenu.emit()
 
     /**
@@ -178,9 +181,7 @@ export class RegionBase {
     this.store$.dispatch(viewerStateNewViewer ({
       selectTemplate: template,
       selectParcellation: parcellation,
-      navigation: {
-        position
-      },
+      navigation,
     }))
   }
 
-- 
GitLab