From c4b24016a781673f120d4dce8d4f9eb67ffe0fee Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Wed, 15 Feb 2023 14:06:00 +0100
Subject: [PATCH] tmp: remove storybook chore: remove used sapi.service methods

---
 Dockerfile                                    |  6 +--
 src/atlasComponents/sapi/core/base.ts         |  2 +-
 src/atlasComponents/sapi/sapi.service.ts      | 44 ---------------
 src/atlasComponents/sapi/translate_v3.ts      |  3 +-
 .../region/region.features.directive.ts       | 34 +-----------
 src/state/atlasSelection/effects.ts           | 49 +++++------------
 .../layerCtrl.service/layerCtrl.effects.ts    | 53 +++++++++----------
 7 files changed, 46 insertions(+), 145 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 40c8e43dd..afce1bc8f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -40,7 +40,7 @@ RUN node ./src/environments/parseEnv.js
 
 RUN npm run build
 RUN node third_party/matomo/processMatomo.js
-RUN npm run build-storybook
+# RUN npm run build-storybook
 
 # gzipping container
 FROM ubuntu:22.04 as compressor
@@ -48,10 +48,10 @@ RUN apt upgrade -y && apt update && apt install brotli
 
 RUN mkdir /iv
 COPY --from=builder /iv/dist/aot /iv
-COPY --from=builder /iv/storybook-static /iv/storybook-static
+# COPY --from=builder /iv/storybook-static /iv/storybook-static
 
 # Remove duplicated assets. Use symlink instead.
-WORKDIR /iv/storybook-static
+# WORKDIR /iv/storybook-static
 RUN rm -rf ./assets
 RUN ln -s ../assets ./assets
 
diff --git a/src/atlasComponents/sapi/core/base.ts b/src/atlasComponents/sapi/core/base.ts
index 2fa7e1897..5649c6ba1 100644
--- a/src/atlasComponents/sapi/core/base.ts
+++ b/src/atlasComponents/sapi/core/base.ts
@@ -28,7 +28,7 @@ export abstract class SAPIBase<T extends AF> {
   }
   
   getFeatureInstance(featureType: T, param: RouteParam<`/feature/${T}/{feature_id}`> & Partial<SapiQueryPriorityArg>) {
-    let route = `/feature/${featureType}/{feature_id}` as `/feature/${T}/{feature_id}`
+    const route = `/feature/${featureType}/{feature_id}` as `/feature/${T}/{feature_id}`
     return this._sapi.v3Get(route, param)
   }
 }
diff --git a/src/atlasComponents/sapi/sapi.service.ts b/src/atlasComponents/sapi/sapi.service.ts
index 34977f4b8..8b0e84ee3 100644
--- a/src/atlasComponents/sapi/sapi.service.ts
+++ b/src/atlasComponents/sapi/sapi.service.ts
@@ -25,8 +25,6 @@ import { BoundingBox, SxplrAtlas, SxplrParcellation, SxplrRegion, SxplrTemplate,
 export const SIIBRA_API_VERSION_HEADER_KEY='x-siibra-api-version'
 export const EXPECTED_SIIBRA_API_VERSION = '0.3.0'
 
-type RegistryType = SAPIAtlas | SAPISpace | SAPIParcellation
-
 let BS_ENDPOINT_CACHED_VALUE: Observable<string> = null
 
 type PaginatedResponse<T> = {
@@ -146,35 +144,6 @@ export class SAPI{
   }
 
   static ErrorMessage = null
-  
-  registry = {
-    _map: {} as Record<string, {
-      func: (...arg: any[]) => RegistryType
-      args: string[]
-    }>,
-    get<T>(id: string): T {
-      if (!this._map[id]) return null
-      const { func, args } = this._map[id]
-      return func(...args)
-    },
-    set(id: string, func: (...args: any[]) => RegistryType, args: string[]) {
-      if (this._map[id]) {
-        console.warn(`id ${id} already mapped as ${this._map[id]}`)
-      }
-      this._map[id] = { func, args }
-    }
-  }
-  getSpace(atlasId: string, spaceId: string): SAPISpace {
-    return new SAPISpace(this, atlasId, spaceId)
-  }
-
-  getParcellation(atlasId: string, parcId: string): SAPIParcellation {
-    return new SAPIParcellation(this, atlasId, parcId)
-  }
-
-  getRegion(atlasId: string, parcId: string, regionId: string): SAPIRegion{
-    return new SAPIRegion(this, atlasId, parcId, regionId)
-  }
 
   getSpaceDetail(_atlasId: string, spaceId: string, param?: SapiQueryPriorityArg): Observable<SxplrTemplate> {
     return this.v3Get("/spaces/{space_id}", {
@@ -486,19 +455,6 @@ export class SAPI{
     if (SAPI.ErrorMessage) {
       this.snackbar.open(SAPI.ErrorMessage, 'Dismiss', { duration: 5000 })
     }
-    this.atlases$.subscribe(atlases => {
-      for (const atlas of atlases) {
-        const sapiAtlas = translateV3Entities.retrieveAtlas(atlas)
-        for (const space of sapiAtlas.spaces) {
-          this.registry.set(space["@id"], this.getSpace.bind(this), [atlas["@id"], space["@id"]])
-          this.getSpaceDetail(atlas["@id"], space["@id"])
-        }
-        for (const parc of sapiAtlas.parcellations) {
-          this.registry.set(parc["@id"], this.getParcellation.bind(this), [atlas["@id"], parc["@id"]])
-          this.getParcDetail(atlas["@id"], parc["@id"])
-        }
-      }
-    })
   }
   
   /**
diff --git a/src/atlasComponents/sapi/translate_v3.ts b/src/atlasComponents/sapi/translate_v3.ts
index b8eeff87e..7851f3f71 100644
--- a/src/atlasComponents/sapi/translate_v3.ts
+++ b/src/atlasComponents/sapi/translate_v3.ts
@@ -34,7 +34,6 @@ class TranslateV3 {
 
   #templateMap: Map<string, PathReturn<"/spaces/{space_id}">> = new Map()
   retrieveTemplate(template:SxplrTemplate): PathReturn<"/spaces/{space_id}"> {
-    if (!template) debugger
     return this.#templateMap.get(template.id)
   }
   async translateTemplate(template:PathReturn<"/spaces/{space_id}">): Promise<SxplrTemplate> {
@@ -234,7 +233,7 @@ class TranslateV3 {
         if (!label) {
           console.error(`Attempmting to add labelledmap with label '${label}'`)
         }
-        let error = `Attempting to access map volume with idx '${volumeIdx}'`
+        const error = `Attempting to access map volume with idx '${volumeIdx}'`
         if (!map.volumes[volumeIdx]) {
           console.error(`${error}, IndexError, Skipping`)
           continue
diff --git a/src/atlasComponents/sapiViews/core/region/region/region.features.directive.ts b/src/atlasComponents/sapiViews/core/region/region/region.features.directive.ts
index de2084a76..4dadb9e09 100644
--- a/src/atlasComponents/sapiViews/core/region/region/region.features.directive.ts
+++ b/src/atlasComponents/sapiViews/core/region/region/region.features.directive.ts
@@ -1,5 +1,5 @@
 import { Directive, OnChanges, SimpleChanges } from "@angular/core";
-import { BehaviorSubject, merge } from "rxjs";
+import { BehaviorSubject, merge, NEVER } from "rxjs";
 import { switchMap,  filter, startWith, shareReplay, scan } from "rxjs/operators";
 import { SAPI, SAPIRegion } from "src/atlasComponents/sapi";
 import { SxplrAtlas, SxplrParcellation, SxplrTemplate, SxplrRegion } from "src/atlasComponents/sapi/type_sxplr"
@@ -28,37 +28,7 @@ export class SapiViewsCoreRegionRegionalFeatureDirective extends SapiViewsCoreRe
     super(sapi)
   }
 
-  private features$ = this.ATPR$.pipe(
-    filter(arg => {
-      if (!arg) return false
-      const { atlas, parcellation, region, template } = arg
-      return !!atlas && !!parcellation && !!region && !!template 
-    }),
-    switchMap(({ atlas, parcellation, region, template }) => {
-      this.busy$.next(true)
-      const parcId = parcellation["@id"]
-      const regionId = region.name
-      const atlasId = atlas["@id"]
-      const reg = this.sapi.getRegion(atlasId, parcId, regionId)
-      return SAPIRegion.Features$.pipe(
-        switchMap(features => merge(
-          ...features.map(
-            feature => reg.getFeatures(
-              feature,
-              {
-                query: {
-                  parcellation_id: parcId,
-                  region_id: regionId,
-                },
-                priority: 1
-              }
-            )
-          )
-        )),
-        scan((acc, curr) => [...acc, ...curr.items], [])
-      )
-    }),
-  )
+  private features$ = NEVER
 
   public listOfFeatures$ = this.features$.pipe(
     startWith([]),
diff --git a/src/state/atlasSelection/effects.ts b/src/state/atlasSelection/effects.ts
index b61069617..778aac2ba 100644
--- a/src/state/atlasSelection/effects.ts
+++ b/src/state/atlasSelection/effects.ts
@@ -1,6 +1,6 @@
 import { Injectable } from "@angular/core";
 import { Actions, createEffect, ofType } from "@ngrx/effects";
-import { forkJoin, merge, Observable, of } from "rxjs";
+import { forkJoin, merge, NEVER, Observable, of } from "rxjs";
 import { catchError, filter, map, mapTo, switchMap, switchMapTo, take, withLatestFrom } from "rxjs/operators";
 import { SAPI, SAPIRegion } from "src/atlasComponents/sapi";
 import * as mainActions from "../actions"
@@ -316,48 +316,27 @@ export class Effect {
         select(selectors.selectedParcellation)
       )
     ),
-    switchMap(([{ region: _region }, selectedTemplate, selectedAtlas, selectedParcellation]) => {
+    map(([{ region: _region }, selectedTemplate, selectedAtlas, selectedParcellation]) => {
       if (!selectedAtlas || !selectedTemplate || !selectedParcellation || !_region)  {
-        return of(
-          mainActions.generalActionError({
-            message: `atlas, template, parcellation or region not set`
-          })
-        )
+        return mainActions.generalActionError({
+          message: `atlas, template, parcellation or region not set`
+        })
       }
 
       const region = translateV3Entities.retrieveRegion(_region)
 
       if (region.hasAnnotation?.bestViewPoint && region.hasAnnotation.bestViewPoint.coordinateSpace['@id'] === selectedTemplate["@id"]) {
-        return of(
-          actions.navigateTo({
-            animation: true,
-            navigation: {
-              position: region.hasAnnotation.bestViewPoint.coordinates.map(v => v.value * 1e6)
-            }
-          })
-        )
+        return actions.navigateTo({
+          animation: true,
+          navigation: {
+            position: region.hasAnnotation.bestViewPoint.coordinates.map(v => v.value * 1e6)
+          }
+        })
       }
       
-      return this.sapiSvc.getRegion(selectedAtlas['@id'], selectedParcellation['@id'], region["@id"]).getDetail(selectedTemplate["@id"]).pipe(
-        map(detailedRegion => {
-          if (!detailedRegion?.hasAnnotation?.bestViewPoint?.coordinates) {
-            return mainActions.generalActionError({
-              message: `getting region detail error! cannot get coordinates`
-            })
-          }
-          return actions.navigateTo({
-            animation: true,
-            navigation: {
-              position: detailedRegion.hasAnnotation.bestViewPoint.coordinates.map(v => v.value * 1e6)
-            }
-          })
-        }),
-        catchError((_err, _obs) => of(
-          mainActions.generalActionError({
-            message: `Error getting region centroid`
-          })
-        ))
-      )
+      return mainActions.generalActionError({
+        message: `getting region detail error! cannot get coordinates`
+      })
     })
   ))
 
diff --git a/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts b/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts
index 973b7d4d3..1e154fe57 100644
--- a/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts
+++ b/src/viewerModule/nehuba/layerCtrl.service/layerCtrl.effects.ts
@@ -1,7 +1,7 @@
 import { Injectable } from "@angular/core";
 import { createEffect } from "@ngrx/effects";
 import { select, Store } from "@ngrx/store";
-import { forkJoin, from, of } from "rxjs";
+import { forkJoin, from, of, throwError } from "rxjs";
 import { mapTo, switchMap, withLatestFrom, filter, catchError, map, debounceTime, shareReplay, distinctUntilChanged, startWith, pairwise, tap } from "rxjs/operators";
 import { NgSegLayerSpec, SxplrAtlas, SxplrParcellation, SxplrTemplate } from "src/atlasComponents/sapi/type_sxplr";
 import { SAPI } from "src/atlasComponents/sapi"
@@ -54,34 +54,31 @@ export class LayerCtrlEffects {
       )
     ),
     switchMap(([ regions, { atlas, parcellation, template } ]) => {
-      const sapiRegion = this.sapi.getRegion(atlas["@id"], parcellation["@id"], regions[0].name)
-      return forkJoin([
-        sapiRegion.getMapInfo(template["@id"]),
-        sapiRegion.getMapUrl(template["@id"])
-      ]).pipe(
-        map(([mapInfo, mapUrl]) => 
-          atlasAppearance.actions.addCustomLayer({
-            customLayer: {
-              clType: "customlayer/nglayer",
-              id: PMAP_LAYER_NAME,
-              source: `nifti://${mapUrl}`,
-              shader: getShader({
-                colormap: EnumColorMapName.VIRIDIS,
-                highThreshold: mapInfo.max,
-                lowThreshold: mapInfo.min,
-                removeBg: true,
-              })
-            }
-          })
-        ),
-        catchError(() => of(
-          atlasAppearance.actions.removeCustomLayer({
-            id: PMAP_LAYER_NAME
-          })
-        ))
-      )
+      return throwError(`IMPLEMENT PMAP LAYER YO`)
+      const actions = [
+        atlasAppearance.actions.addCustomLayer({
+          customLayer: {
+            clType: "customlayer/nglayer",
+            id: PMAP_LAYER_NAME,
+            source: `nifti://${regions['url']}`,
+            shader: getShader({
+              colormap: EnumColorMapName.VIRIDIS,
+              // highThreshold: [regions['']].max,
+              // lowThreshold: [regions['']].min,
+              removeBg: true,
+            })
+          }
+        }),
+        
+        /**
+         * on error, remove layer
+         */
+        atlasAppearance.actions.removeCustomLayer({
+          id: PMAP_LAYER_NAME
+        })
+      ]
     }),
-  ))
+  ), { dispatch: false })
 
   onATP$ = this.store.pipe(
     atlasSelection.fromRootStore.distinctATP(),
-- 
GitLab