From 96dda16a25e5438fad5d299e9b476a0d2c002756 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Mon, 26 Jul 2021 16:36:39 +0200
Subject: [PATCH] chore: hide profile and AR when not available

---
 .../receptor/ar/autoradiograph.component.ts   |  6 +++
 .../receptor/entry/entry.component.ts         |  5 ++
 .../receptor/entry/entry.template.html        | 51 ++++++++++---------
 .../receptor/profile/profile.component.ts     |  6 ++-
 4 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/ar/autoradiograph.component.ts b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/ar/autoradiograph.component.ts
index 867f18fb9..efd93a3b9 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/ar/autoradiograph.component.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/ar/autoradiograph.component.ts
@@ -1,9 +1,15 @@
 import { Component, Input, OnChanges } from "@angular/core";
 import { BsFeatureReceptorBase } from "../base";
 import { CONST } from 'common/constants'
+import { TBSDetail } from "../type";
 
 const { RECEPTOR_AR_CAPTION } = CONST
 
+export function isAr(detail: TBSDetail, label: string){
+  if (label) return !!detail.__data.__autoradiographs[label]
+  return !!detail.__data.__autoradiographs
+}
+
 @Component({
   selector: 'bs-features-receptor-autoradiograph',
   templateUrl: './autoradiograph.template.html',
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.component.ts b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.component.ts
index c7ddc98b3..7856a6ad7 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.component.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.component.ts
@@ -6,6 +6,7 @@ import { REGISTERED_FEATURE_INJECT_DATA } from "../../constants";
 import { BsFeatureService, TFeatureCmpInput } from "../../service";
 import { TBSDetail } from "../type";
 import { ARIA_LABELS } from 'common/constants'
+import { isPr } from "../profile/profile.component";
 
 @Component({
   selector: 'bs-features-receptor-entry',
@@ -38,6 +39,10 @@ export class BsFeatureReceptorEntry extends BsRegionInputBase implements OnDestr
     shareReplay(1),
   )
 
+  public hasPrAr$: Observable<boolean> = this.selectedReceptor$.pipe(
+    map(detail => detail.__files.some(f => isPr(f))),
+  )
+
   ngOnDestroy(){
     while (this.sub.length > 0) this.sub.pop().unsubscribe()
   }
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.template.html b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.template.html
index 5a6294e1f..813c489a6 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.template.html
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/entry/entry.template.html
@@ -15,30 +15,33 @@
     [bsFeature]="selectedRec">
   </bs-features-receptor-fingerprint>
 
-  <mat-divider></mat-divider>
+  <ng-template [ngIf]="hasPrAr$ | async">
+    <mat-divider></mat-divider>
 
-  <mat-form-field class="mt-2 w-100">
-    <mat-label>
-      Select a receptor
-    </mat-label>
-    <mat-select [(value)]="selectedReceptor">
-      <mat-option
-        *ngFor="let receptorName of (allReceptors$ | async)"
-        [value]="receptorName">
-        {{ receptorName }}
-      </mat-option>
-    </mat-select>
-  </mat-form-field>
+    <mat-form-field class="mt-2 w-100">
+      <mat-label>
+        Select a receptor
+      </mat-label>
+      <mat-select [(value)]="selectedReceptor">
+        <mat-option
+          *ngFor="let receptorName of (allReceptors$ | async)"
+          [value]="receptorName">
+          {{ receptorName }}
+        </mat-option>
+      </mat-select>
+    </mat-form-field>
+  
+    <bs-features-receptor-profile
+      *ngIf="selectedReceptor"
+      [bsFeature]="selectedRec"
+      [bsLabel]="selectedReceptor">
+    </bs-features-receptor-profile>
+  
+    <bs-features-receptor-autoradiograph
+      *ngIf="selectedReceptor"
+      [bsFeature]="selectedRec"
+      [bsLabel]="selectedReceptor">
+    </bs-features-receptor-autoradiograph>
+  </ng-template>
 
-  <bs-features-receptor-profile
-    *ngIf="selectedReceptor"
-    [bsFeature]="selectedRec"
-    [bsLabel]="selectedReceptor">
-  </bs-features-receptor-profile>
-
-  <bs-features-receptor-autoradiograph
-    *ngIf="selectedReceptor"
-    [bsFeature]="selectedRec"
-    [bsLabel]="selectedReceptor">
-  </bs-features-receptor-autoradiograph>
 </ng-container>
diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/profile/profile.component.ts b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/profile/profile.component.ts
index 02f9ef7fe..6b33a73b4 100644
--- a/src/atlasComponents/regionalFeatures/bsFeatures/receptor/profile/profile.component.ts
+++ b/src/atlasComponents/regionalFeatures/bsFeatures/receptor/profile/profile.component.ts
@@ -4,6 +4,10 @@ import { BS_DARKTHEME } from "../../constants";
 import { BsFeatureReceptorBase } from "../base";
 import { CONST } from 'common/constants'
 
+export function isPr(filename: string, label: string = ''){
+  return filename.indexOf(`_pr_${label}`) >= 0
+}
+
 const { RECEPTOR_PR_CAPTION } = CONST
 
 @Component({
@@ -43,7 +47,7 @@ export class BsFeatureReceptorProfile extends BsFeatureReceptorBase implements O
     }
 
     this.urls = this.bsFeature.__files
-      .filter(url => url.indexOf(`_pr_${this.bsLabel}`) >= 0)
+      .filter(url => isPr(url, this.bsLabel))
       .map(url => {
         return { url }
       })
-- 
GitLab