From ff03fd55dee6b85b63ee79bdd8a1930433b46f8a Mon Sep 17 00:00:00 2001 From: NIKUNJ LALITKUMAR HUDKA Date: Sat, 20 Apr 2024 12:03:21 -0300 Subject: [PATCH] feat: allow promise in EntityPresentationApi for all the asynchronous processes working under the hood Signed-off-by: NIKUNJ LALITKUMAR HUDKA --- .../EntityPresentationApi.ts | 5 ++++ .../DefaultEntityPresentationApi.ts | 29 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts b/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts index 945bce1d27..de5449917a 100644 --- a/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts +++ b/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts @@ -109,6 +109,11 @@ export interface EntityRefPresentation { * elsewhere. */ update$?: Observable; + + /* The `promise` property in the `EntityRefPresentation` interface is defining a property named + `promise` that holds a promise. This promise resolves to an array of + `EntityRefPresentationSnapshot` objects. */ + promise: Promise; } /** diff --git a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts index 82862be435..bbd5540d15 100644 --- a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts +++ b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts @@ -298,10 +298,37 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi { }; }); - return { + const entityRefPresentation: EntityRefPresentation = { snapshot: initialSnapshot, update$: observable, + get promise() { + return new Promise( + (resolve, reject) => { + if (!observable) { + resolve([initialSnapshot]); + } else { + const res: EntityRefPresentationSnapshot[] = []; + const subscription = observable.subscribe({ + next: snapshot => { + res.push(snapshot); + }, + error: error => { + initialSnapshot = { + primaryTitle: entityRef, + entityRef: entityRef, + }; + }, + complete() { + subscription.unsubscribe(); + resolve(res); + }, + }); + } + }, + ); + }, }; + return entityRefPresentation; } #getEntityForInitialRender(entityOrRef: Entity | string): {