From 850fb086dc5e5700413a52ec7bf8da06eeeac149 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Mon, 18 Sep 2023 13:43:24 +0200 Subject: [PATCH] fixed: feature fetching --- docs/releases/v2.13.2.md | 2 ++ src/atlasComponents/sapi/sapi.service.ts | 40 ------------------------ src/features/category-acc.directive.ts | 6 ++++ src/util/pullable.ts | 10 ++++-- 4 files changed, 16 insertions(+), 42 deletions(-) diff --git a/docs/releases/v2.13.2.md b/docs/releases/v2.13.2.md index 0c9d3d19b..0f4731c3b 100644 --- a/docs/releases/v2.13.2.md +++ b/docs/releases/v2.13.2.md @@ -7,3 +7,5 @@ ## Bugfixes - fixed displaying annotation in `saneurl` +- fixed feature fetching spinner +- fixed feature fetching logic diff --git a/src/atlasComponents/sapi/sapi.service.ts b/src/atlasComponents/sapi/sapi.service.ts index 52e4f79f8..932b6bcb4 100644 --- a/src/atlasComponents/sapi/sapi.service.ts +++ b/src/atlasComponents/sapi/sapi.service.ts @@ -192,40 +192,6 @@ export class SAPI{ if (!!resp.total || resp.total === 0) return true return false } - getV3Features<T extends FeatureType>(featureType: T, sapiParam: RouteParam<`/feature/${T}`>): Observable<Feature[]> { - const query = structuredClone(sapiParam) - return this.v3Get<`/feature/${T}`>(`/feature/${featureType}`, { - ...query - }).pipe( - switchMap(resp => { - if (!this.#isPaged(resp)) return throwError(`endpoint not returning paginated response`) - return this.iteratePages( - resp, - page => { - const query = structuredClone(sapiParam) - query.query.page = page - return this.v3Get(`/feature/${featureType}`, { - ...query, - }).pipe( - map(val => { - if (this.#isPaged(val)) return val - return { items: [], total: 0, page: 0, size: 0 } - }) - ) - } - ) - }), - switchMap(features => features.length === 0 - ? of([]) - : forkJoin( - features.map(feat => translateV3Entities.translateFeature(feat) ) - ) - ), - catchError((err) => { - console.error("Error fetching features", err) - return of([])}), - ) - } getV3FeatureDetail<T extends FeatureType>(featureType: T, sapiParam: RouteParam<`/feature/${T}/{feature_id}`>): Observable<PathReturn<`/feature/${T}/{feature_id}`>> { return this.v3Get<`/feature/${T}/{feature_id}`>(`/feature/${featureType}/{feature_id}`, { @@ -253,12 +219,6 @@ export class SAPI{ ) } - getModalities() { - return this.v3Get("/feature/_types", { query: {} }).pipe( - map(v => v.items) - ) - } - v3GetRoute<T extends SapiRoute>(route: T, sapiParam: RouteParam<T>) { const params: Record<string, string|number> = "query" in sapiParam ? sapiParam["query"] : {} const _path: Record<string, string|number> = "path" in sapiParam ? sapiParam["path"] : {} diff --git a/src/features/category-acc.directive.ts b/src/features/category-acc.directive.ts index 73156e7af..a6f34d27d 100644 --- a/src/features/category-acc.directive.ts +++ b/src/features/category-acc.directive.ts @@ -144,6 +144,12 @@ export class CategoryAccDirective implements AfterContentInit, OnDestroy { ).subscribe(async ({ total, current, ds }) => { if (total > current && current < 50) { try { + /** + * TODO Interaction between ParentDataSource and ListDatadirective, which both pulls seems + * to weirdly interact with each other. + * For now, pulling twice seems to solve the issue + */ + await ds.pull() await ds.pull() } catch (e) { // if already pulling, ignore diff --git a/src/util/pullable.ts b/src/util/pullable.ts index 6a5d87e96..02bf6dc44 100644 --- a/src/util/pullable.ts +++ b/src/util/pullable.ts @@ -70,8 +70,14 @@ export class PulledDataSource<T> extends DataSource<T> { return [] } this.isPulling = true - const newResults = await this.#pull() - this.isPulling = false + let newResults = [] + try { + newResults = await this.#pull() + } catch (e) { + console.error("Pulling failed", e) + } finally { + this.isPulling = false + } if (newResults.length === 0) { this.complete() } -- GitLab