From 45446a0bfa7e1d8b902dccc9f0ed19e0e5ffdc6d Mon Sep 17 00:00:00 2001 From: NIKUNJ LALITKUMAR HUDKA Date: Thu, 2 May 2024 16:08:36 -0300 Subject: [PATCH] feat: revert chnages done in EntityPresentationApi Signed-off-by: NIKUNJ LALITKUMAR HUDKA --- .changeset/olive-rockets-drum.md | 2 +- .../EntityPresentationApi.ts | 5 --- .../DefaultEntityPresentationApi.test.ts | 45 ------------------- .../DefaultEntityPresentationApi.ts | 27 +---------- 4 files changed, 2 insertions(+), 77 deletions(-) diff --git a/.changeset/olive-rockets-drum.md b/.changeset/olive-rockets-drum.md index 12f80dab5c..b5e6c2cefe 100644 --- a/.changeset/olive-rockets-drum.md +++ b/.changeset/olive-rockets-drum.md @@ -4,4 +4,4 @@ '@backstage/plugin-catalog': minor --- -`MultiEntityPicker` uses `entityPresentationApi` instead of `humanizeEntityRef` to display entity. Also, `EntityPresentationApi` now allows `promise` getter for under asynchronous process of presentation api +`MultiEntityPicker` uses `EntityDisplayName` instead of `humanizeEntityRef` to display entity. diff --git a/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts b/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts index f4f1193718..945bce1d27 100644 --- a/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts +++ b/plugins/catalog-react/src/apis/EntityPresentationApi/EntityPresentationApi.ts @@ -109,11 +109,6 @@ 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.test.ts b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts index c37efb204f..42ff777cbd 100644 --- a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts +++ b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.test.ts @@ -35,7 +35,6 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, - promise: new Promise(resolve => resolve({})), }); expect( @@ -49,7 +48,6 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, - promise: new Promise(resolve => resolve({})), }); expect( @@ -65,7 +63,6 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, - promise: new Promise(resolve => resolve({})), }); const entity: Entity = { @@ -88,7 +85,6 @@ describe('DefaultEntityPresentationApi', () => { Icon: expect.anything(), }, update$: undefined, - promise: new Promise(resolve => resolve({})), }); }); @@ -154,47 +150,6 @@ describe('DefaultEntityPresentationApi', () => { }), ); }); - - it('returns the correct snapshots via promise', async () => { - const catalogApi = { - getEntitiesByRefs: jest.fn(), - }; - const api = DefaultEntityPresentationApi.create({ - catalogApi: catalogApi as Partial as any, - }); - - catalogApi.getEntitiesByRefs.mockResolvedValueOnce({ - items: [ - { - apiVersion: 'backstage.io/v1alpha1', - kind: 'Component', - metadata: { - name: 'test', - namespace: 'default', - etag: 'something', - }, - spec: { - type: 'service', - }, - }, - ], - }); - - const entityRef = 'component:default/test'; - const entitySnapshot = { - entityRef: entityRef, - primaryTitle: 'test', - secondaryTitle: 'component:default/test | service', - Icon: expect.anything(), - }; - - const promise = api.forEntity(entityRef).promise; - - const snapshots = await promise; - - expect(snapshots?.length).toEqual(1); // Only one snapshot expected - expect(snapshots?.[0]).toEqual(entitySnapshot); // Snapshot should match the simulated one - }); }); async function consumePresentation( diff --git a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts index c7572cca3b..82862be435 100644 --- a/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts +++ b/plugins/catalog/src/apis/EntityPresentationApi/DefaultEntityPresentationApi.ts @@ -298,35 +298,10 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi { }; }); - const entityRefPresentation: EntityRefPresentation = { + return { snapshot: initialSnapshot, update$: observable, - get promise() { - return new Promise(resolve => { - if (!observable) { - resolve([initialSnapshot]); - } else { - const res: EntityRefPresentationSnapshot[] = []; - const subscription = observable.subscribe({ - next: snapshot => { - res.push(snapshot); - }, - error: () => { - initialSnapshot = { - primaryTitle: entityRef, - entityRef: entityRef, - }; - }, - complete() { - subscription.unsubscribe(); - resolve(res); - }, - }); - } - }); - }, }; - return entityRefPresentation; } #getEntityForInitialRender(entityOrRef: Entity | string): {