stop returning the entity

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-10-23 16:53:13 +02:00
parent 430f2931b3
commit 3988751087
7 changed files with 2 additions and 74 deletions
-1
View File
@@ -416,7 +416,6 @@ export interface EntityRefPresentation {
// @public
export interface EntityRefPresentationSnapshot {
entity?: Entity | undefined;
entityRef: string;
Icon?: IconComponent | undefined;
primaryTitle: string;
@@ -49,17 +49,6 @@ export interface EntityRefPresentationSnapshot {
* usable for example for forming a clickable link to the entity.
*/
entityRef: string;
/**
* The entity that this snapshot represents.
*
* @remarks
*
* Note that this may be a partial entity, i.e. it may not contain all of the
* fields that the kind at hand normally contains, since the input to the
* representation renderer might have been a partial entity. So be careful
* when accessing fields on this.
*/
entity?: Entity | undefined;
/**
* A string that can be used as a plain representation of the entity, for
* example in a header or a link.
@@ -34,7 +34,6 @@ describe('defaultEntityPresentation', () => {
},
}),
).toEqual({
entity: expect.anything(),
entityRef: 'component:default/test',
primaryTitle: 'test',
secondaryTitle: 'component:default/test | type | desc',
@@ -56,7 +55,6 @@ describe('defaultEntityPresentation', () => {
},
}),
).toEqual({
entity: expect.anything(),
entityRef: 'component:default/test',
primaryTitle: 'title',
secondaryTitle: 'component:default/test | type | desc',
@@ -81,7 +79,6 @@ describe('defaultEntityPresentation', () => {
},
}),
).toEqual({
entity: expect.anything(),
entityRef: 'component:default/test',
primaryTitle: 'displayName',
secondaryTitle: 'component:default/test | type | desc',
@@ -96,7 +93,6 @@ describe('defaultEntityPresentation', () => {
metadata: { name: 'test' },
} as Entity),
).toEqual({
entity: expect.anything(),
entityRef: 'component:default/test',
primaryTitle: 'test',
secondaryTitle: 'component:default/test',
@@ -108,7 +104,6 @@ describe('defaultEntityPresentation', () => {
expect(
defaultEntityPresentation({ metadata: 7 } as unknown as Entity),
).toEqual({
entity: expect.anything(),
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -120,7 +115,6 @@ describe('defaultEntityPresentation', () => {
describe('string ref given', () => {
it('happy path', () => {
expect(defaultEntityPresentation('component:default/test')).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'test',
secondaryTitle: 'component:default/test',
@@ -132,7 +126,6 @@ describe('defaultEntityPresentation', () => {
defaultKind: 'X',
}),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'component:test',
secondaryTitle: 'component:default/test',
@@ -144,7 +137,6 @@ describe('defaultEntityPresentation', () => {
defaultNamespace: 'X',
}),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'default/test',
secondaryTitle: 'component:default/test',
@@ -154,7 +146,6 @@ describe('defaultEntityPresentation', () => {
it('works without throwing on malformed and shortened refs', () => {
expect(defaultEntityPresentation('')).toEqual({
entity: undefined,
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -162,7 +153,6 @@ describe('defaultEntityPresentation', () => {
});
expect(defaultEntityPresentation('name')).toEqual({
entity: undefined,
entityRef: 'unknown:default/name',
primaryTitle: 'name',
secondaryTitle: 'unknown:default/name',
@@ -180,7 +170,6 @@ describe('defaultEntityPresentation', () => {
name: 'test',
}),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'test',
secondaryTitle: 'component:default/test',
@@ -195,7 +184,6 @@ describe('defaultEntityPresentation', () => {
},
),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'component:test',
secondaryTitle: 'component:default/test',
@@ -210,7 +198,6 @@ describe('defaultEntityPresentation', () => {
},
),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'default/test',
secondaryTitle: 'component:default/test',
@@ -227,7 +214,6 @@ describe('defaultEntityPresentation', () => {
},
),
).toEqual({
entity: undefined,
entityRef: 'component:default/test',
primaryTitle: 'default/test',
secondaryTitle: 'component:default/test',
@@ -235,7 +221,6 @@ describe('defaultEntityPresentation', () => {
});
expect(defaultEntityPresentation('')).toEqual({
entity: undefined,
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -247,7 +232,6 @@ describe('defaultEntityPresentation', () => {
describe('entirely invalid input type given', () => {
it('sad path', () => {
expect(defaultEntityPresentation(null as unknown as Entity)).toEqual({
entity: undefined,
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -256,7 +240,6 @@ describe('defaultEntityPresentation', () => {
expect(defaultEntityPresentation(undefined as unknown as Entity)).toEqual(
{
entity: undefined,
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -267,7 +250,6 @@ describe('defaultEntityPresentation', () => {
expect(
defaultEntityPresentation(Symbol.for('Prince') as unknown as Entity),
).toEqual({
entity: undefined,
entityRef: 'unknown:default/unknown',
primaryTitle: 'unknown',
secondaryTitle: 'unknown:default/unknown',
@@ -70,13 +70,6 @@ export function defaultEntityPresentation(
(kind && DEFAULT_ICONS[kind.toLocaleLowerCase('en-US')]) ||
UNKNOWN_KIND_ICON;
const entity: Entity | undefined =
typeof entityOrRef === 'object' &&
entityOrRef !== null &&
'metadata' in entityOrRef
? entityOrRef
: undefined;
const entityRef: string = stringifyEntityRef({
kind: kind || 'unknown',
namespace: namespace || DEFAULT_NAMESPACE,
@@ -98,7 +91,6 @@ export function defaultEntityPresentation(
.join(' | ');
return {
entity,
entityRef,
primaryTitle: primary,
secondaryTitle: secondary || undefined,
@@ -80,7 +80,6 @@ describe('DefaultEntityPresentationApi', () => {
expect(api.forEntity(entity)).toEqual({
snapshot: {
entityRef: 'component:default/test',
entity: entity,
primaryTitle: 'test',
secondaryTitle: 'component:default/test | service',
Icon: expect.anything(),
@@ -120,25 +119,12 @@ describe('DefaultEntityPresentationApi', () => {
).resolves.toEqual([
{
entityRef: 'component:default/test',
entity: undefined,
primaryTitle: 'test',
secondaryTitle: 'component:default/test',
Icon: expect.anything(),
},
{
entityRef: 'component:default/test',
entity: {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
etag: 'something',
name: 'test',
namespace: 'default',
},
spec: {
type: 'service',
},
},
primaryTitle: 'test',
secondaryTitle: 'component:default/test | service',
Icon: expect.anything(),
@@ -151,18 +137,6 @@ describe('DefaultEntityPresentationApi', () => {
).resolves.toEqual([
{
entityRef: 'component:default/test',
entity: {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
etag: 'something',
name: 'test',
namespace: 'default',
},
spec: {
type: 'service',
},
},
primaryTitle: 'test',
secondaryTitle: 'component:default/test | service',
Icon: expect.anything(),
@@ -240,7 +240,6 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi {
subscriber.next({
...output.snapshot,
entityRef: entityRef,
entity: newEntity,
});
}
})
@@ -265,7 +264,6 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi {
snapshot: {
...rendered,
entityRef: entityRef,
entity: entity,
},
update$: observable,
};
@@ -33,19 +33,13 @@ const Contents = () => {
<Grid item xs={12}>
<Typography variant="subtitle1" gutterBottom>
User Entity:{' '}
<EntityRefLinks
entityRefs={[backstageIdentity.userEntityRef]}
getTitle={ref => ref}
/>
<EntityRefLinks entityRefs={[backstageIdentity.userEntityRef]} />
</Typography>
</Grid>
<Grid item xs={12}>
<Typography variant="subtitle1">
Ownership Entities:{' '}
<EntityRefLinks
entityRefs={backstageIdentity.ownershipEntityRefs}
getTitle={ref => ref}
/>
<EntityRefLinks entityRefs={backstageIdentity.ownershipEntityRefs} />
</Typography>
</Grid>
</Grid>