From 54ba850b893c62d77c6ffe753da9ac01db544def Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Mon, 19 Aug 2019 16:52:31 +0200
Subject: [PATCH] bugfix: general get kgId

---
 src/ui/databrowserModule/databrowser.service.ts     | 6 ++++++
 src/ui/databrowserModule/databrowser.useEffect.ts   | 8 ++++----
 src/ui/nehubaContainer/nehubaContainer.component.ts | 4 +++-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/ui/databrowserModule/databrowser.service.ts b/src/ui/databrowserModule/databrowser.service.ts
index af5c2b53a..91bebdc58 100644
--- a/src/ui/databrowserModule/databrowser.service.ts
+++ b/src/ui/databrowserModule/databrowser.service.ts
@@ -369,6 +369,12 @@ export function getModalityFromDE(dataentries:DataEntry[]):CountedDataModality[]
   return dataentries.reduce((acc, de) => reduceDataentry(acc, de), [])
 }
 
+export function getIdFromDataEntry(dataentry: DataEntry){
+  const { id, fullId } = dataentry
+  const regex = /\/([a-zA-Z0-9\-]*?)$/.exec(fullId)
+  return (regex && regex[1]) || id
+}
+
 
 export interface CountedDataModality{
   name: string
diff --git a/src/ui/databrowserModule/databrowser.useEffect.ts b/src/ui/databrowserModule/databrowser.useEffect.ts
index aeda75e0f..f9a57b519 100644
--- a/src/ui/databrowserModule/databrowser.useEffect.ts
+++ b/src/ui/databrowserModule/databrowser.useEffect.ts
@@ -5,6 +5,7 @@ import { DATASETS_ACTIONS_TYPES, DataEntry } from "src/services/state/dataStore.
 import { Observable, of, from, merge, Subscription } from "rxjs";
 import { withLatestFrom, map, catchError, filter, switchMap, scan, share, switchMapTo, shareReplay } from "rxjs/operators";
 import { KgSingleDatasetService } from "./kgSingleDatasetService.service";
+import { getIdFromDataEntry } from "./databrowser.service";
 
 @Injectable({
   providedIn: 'root'
@@ -73,10 +74,9 @@ export class DataBrowserUseEffect implements OnDestroy{
          * 
          * do not save anything else on localstorage. This could potentially be leaking sensitive information
          */
-        const serialisedFavDataentries = favDataEntries.map(({ id, fullId }) => {
-          const regex = /\/([a-zA-Z0-9\-]*?)$/.exec(fullId)
-          const tempId = (regex && regex[1]) || id
-          return { id: tempId }
+        const serialisedFavDataentries = favDataEntries.map(dataentry => {
+          const id = getIdFromDataEntry(dataentry)
+          return { id }
         })
         window.localStorage.setItem(LOCAL_STORAGE_CONST.FAV_DATASET, JSON.stringify(serialisedFavDataentries))
       })
diff --git a/src/ui/nehubaContainer/nehubaContainer.component.ts b/src/ui/nehubaContainer/nehubaContainer.component.ts
index 8682d7400..d1e7f5fa7 100644
--- a/src/ui/nehubaContainer/nehubaContainer.component.ts
+++ b/src/ui/nehubaContainer/nehubaContainer.component.ts
@@ -15,6 +15,7 @@ import { SELECT_REGIONS_WITH_ID, NEHUBA_LAYER_CHANGED } from "src/services/state
 import { MatBottomSheet, MatButton } from "@angular/material";
 import { DATASETS_ACTIONS_TYPES } from "src/services/state/dataStore.store";
 import { KgSingleDatasetService } from "../databrowserModule/kgSingleDatasetService.service";
+import { getIdFromDataEntry } from "../databrowserModule/databrowser.service";
 
 const getProxyUrl = (ngUrl) => `nifti://${BACKEND_URL}preview/file?fileUrl=${encodeURIComponent(ngUrl.replace(/^nifti:\/\//,''))}`
 const getProxyOther = ({source}) => /AUTH_227176556f3c4bb38df9feea4b91200c/.test(source)
@@ -1175,7 +1176,8 @@ export class NehubaContainer implements OnInit, OnDestroy{
 
   downloadDs(event: MouseEvent, ds: DataEntry, downloadBtn: MatButton){
     downloadBtn.disabled = true
-    this.kgSingleDataset.downloadZipFromKg({kgId: ds.id})
+    const id = getIdFromDataEntry(ds)
+    this.kgSingleDataset.downloadZipFromKg({kgId: id})
       .finally(() => downloadBtn.disabled = false)
   }
 }
-- 
GitLab