From 9d0ad2201c28ffd14c3795925bb6831c7e692589 Mon Sep 17 00:00:00 2001
From: fsdavid <daviti1@mail.com>
Date: Wed, 11 May 2022 16:35:26 +0200
Subject: [PATCH] Show message when region connectivity does not exist

---
 .../connectivityBrowser.component.ts           | 18 +++++++++++++++---
 .../connectivityBrowser.template.html          |  7 ++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.component.ts b/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.component.ts
index c18233e61..a3cf0cb8c 100644
--- a/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.component.ts
+++ b/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.component.ts
@@ -92,7 +92,7 @@ export class ConnectivityBrowserComponent implements AfterViewInit, OnDestroy {
     public logConnectionsString: string
     public pureConnections: any
     public connectedAreas: BehaviorSubject<any[]> = new BehaviorSubject([])
-
+    public noConnectivityForRegion: boolean
     private subscriptions: Subscription[] = []
     public allRegions = []
     private regionIndexInMatrix = -1
@@ -217,14 +217,18 @@ export class ConnectivityBrowserComponent implements AfterViewInit, OnDestroy {
 
     // ToDo this is caused by the bug existing on siibra python
     private fixDatasetFormat = (ds) => ds.name.includes('{')? ({
+      ...JSON.parse(ds.name.substring(ds.name.indexOf('{')).replace(/'/g, '"')),
       ...ds,
-      ...JSON.parse(ds.name.substring(ds.name.indexOf('{')).replace(/'/g, '"'))
     }) : ds
 
     fetchConnectivity() {
       this.sapi.getParcellation(this.atlas["@id"], this.parcellation["@id"]).getFeatureInstance(this.selectedDataset['@id'])
+        .pipe(catchError(() => {
+          this.fetching = false
+          return of(null)
+        }))
         .subscribe(ds=> {
-          this.setMatrixData(ds)  
+          this.setMatrixData(ds)
           this.fetching = false
         })
     }
@@ -232,6 +236,14 @@ export class ConnectivityBrowserComponent implements AfterViewInit, OnDestroy {
     setMatrixData(data) {
       const matrixData = data as SapiParcellationFeatureMatrixModel
       this.regionIndexInMatrix = (matrixData.columns as Array<string>).findIndex(md => md === this.regionName)
+      if (this.regionIndexInMatrix < 0) {
+        this.fetching = false
+        this.noConnectivityForRegion = true
+        this.changeDetectionRef.detectChanges()
+        return
+      } else if (this.noConnectivityForRegion) {
+        this.noConnectivityForRegion = false
+      }
       this.sapi.processNpArrayData<PARSE_TYPEDARRAY.RAW_ARRAY>(matrixData.matrix, PARSE_TYPEDARRAY.RAW_ARRAY)
         .then(matrix => {
           const regionProfile = matrix.rawArray[this.regionIndexInMatrix]
diff --git a/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.template.html b/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.template.html
index 705a6fd9b..581154905 100644
--- a/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.template.html
+++ b/src/atlasComponents/sapiViews/features/connectivity/connectivityBrowser/connectivityBrowser.template.html
@@ -55,7 +55,7 @@
         <mat-checkbox class="mr-2"
                       [checked]="logChecked"
                       (change)="changeLog($event.checked)"
-                      [disabled]="logDisabled">Log 10</mat-checkbox>
+                      [disabled]="logDisabled || noConnectivityForRegion">Log 10</mat-checkbox>
         <button mat-button [matMenuTriggerFor]="exportMenu"
                 [disabled]="!connectedAreas.value">
             <i class="fas fa-download mb-2 mr-2"></i>
@@ -65,12 +65,13 @@
 
     <hbp-connectivity-matrix-row
         #connectivityComponent
-        *ngIf="regionName && !fetching"
+        *ngIf="regionName && !fetching && !noConnectivityForRegion"
         [region]="regionName + (regionHemisphere? ' - ' + regionHemisphere : '')"
         [connections]="connectionsString"
         show-export="true" hide-export-view="true"
         theme="dark">
     </hbp-connectivity-matrix-row>
+    <div *ngIf="noConnectivityForRegion">No connectivity for the region.</div>
     <full-connectivity-grid #fullConnectivityGrid
                             [matrix]="matrixString"
                             [datasetName]="selectedDataset?.name"
@@ -79,7 +80,7 @@
     </full-connectivity-grid>
 
     <mat-menu #exportMenu="matMenu">
-        <button mat-menu-item (click)="exportConnectivityProfile()">Regional</button>
+        <button mat-menu-item [disabled]="noConnectivityForRegion" (click)="exportConnectivityProfile()">Regional</button>
         <button mat-menu-item (click)="exportFullConnectivity()">Dataset</button>
     </mat-menu>
 </div>
-- 
GitLab