feat: revert chnages done in EntityPresentationApi

Signed-off-by: NIKUNJ LALITKUMAR HUDKA <nikunjhudka123@gmail.com>
This commit is contained in:
NIKUNJ LALITKUMAR HUDKA
2024-05-02 16:08:36 -03:00
parent 90db1ce441
commit 45446a0bfa
4 changed files with 2 additions and 77 deletions
+1 -1
View File
@@ -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.
@@ -109,11 +109,6 @@ export interface EntityRefPresentation {
* elsewhere.
*/
update$?: Observable<EntityRefPresentationSnapshot>;
/* 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<EntityRefPresentationSnapshot[]>;
}
/**
@@ -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<CatalogApi> 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(
@@ -298,35 +298,10 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi {
};
});
const entityRefPresentation: EntityRefPresentation = {
return {
snapshot: initialSnapshot,
update$: observable,
get promise() {
return new Promise<EntityRefPresentationSnapshot[]>(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): {