Removed CatalogApi.geLocationByEntity and CatalogApi.getOriginLocationByEntity, and replaced them with CatalogApi.getLocationByRef.

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-02-15 19:15:38 +01:00
parent 816a08fa30
commit deaf6065db
30 changed files with 67 additions and 100 deletions
+15
View File
@@ -0,0 +1,15 @@
---
'@backstage/plugin-api-docs': patch
'@backstage/plugin-auth-backend': patch
'@backstage/plugin-badges-backend': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-graph': patch
'@backstage/plugin-catalog-import': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-explore': patch
'@backstage/plugin-fossa': patch
'@backstage/plugin-scaffolder': patch
'@backstage/plugin-todo-backend': patch
---
Adapt to the new `CatalogApi.getLocationByRef`
+14
View File
@@ -0,0 +1,14 @@
---
'@backstage/catalog-client': minor
---
Removed `CatalogApi.geLocationByEntity` and `CatalogApi.getOriginLocationByEntity`, and replaced them with `CatalogApi.getLocationByRef`.
If you were using one of the two old methods, you can update your code as follows:
```diff
-const originLocation = catalogApi.getOriginLocationByEntity(entity);
+const originLocation = catalogApi.getLocationByRef(entity.metadata.annotations[ANNOTATION_ORIGIN_LOCATION]!);
-const location = catalogApi.getLocationByEntity(entity);
+const location = catalogApi.getLocationByRef(entity.metadata.annotations[ANNOTATION_LOCATION]!);
```
+4 -12
View File
@@ -43,16 +43,12 @@ export interface CatalogApi {
name: EntityName,
options?: CatalogRequestOptions,
): Promise<Entity | undefined>;
getLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
getLocationById(
id: string,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
getOriginLocationByEntity(
entity: Entity,
getLocationByRef(
locationRef: string,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
refreshEntity(
@@ -95,16 +91,12 @@ export class CatalogClient implements CatalogApi {
compoundName: EntityName,
options?: CatalogRequestOptions,
): Promise<Entity | undefined>;
getLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
getLocationById(
id: string,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
getOriginLocationByEntity(
entity: Entity,
getLocationByRef(
locationRef: string,
options?: CatalogRequestOptions,
): Promise<Location_2 | undefined>;
refreshEntity(
+4 -32
View File
@@ -15,8 +15,6 @@
*/
import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
EntityName,
parseEntityRef,
@@ -246,17 +244,12 @@ export class CatalogClient implements CatalogApi {
}
/**
* {@inheritdoc CatalogApi.getOriginLocationByEntity}
* {@inheritdoc CatalogApi.getLocationByRef}
*/
async getOriginLocationByEntity(
entity: Entity,
async getLocationByRef(
locationRef: string,
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound =
entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION];
if (!locationCompound) {
return undefined;
}
const all: { data: Location }[] = await this.requestRequired(
'GET',
'/locations',
@@ -264,28 +257,7 @@ export class CatalogClient implements CatalogApi {
);
return all
.map(r => r.data)
.find(l => locationCompound === stringifyLocationRef(l));
}
/**
* {@inheritdoc CatalogApi.getLocationByEntity}
*/
async getLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound = entity.metadata.annotations?.[ANNOTATION_LOCATION];
if (!locationCompound) {
return undefined;
}
const all: { data: Location }[] = await this.requestRequired(
'GET',
'/locations',
options,
);
return all
.map(r => r.data)
.find(l => locationCompound === stringifyLocationRef(l));
.find(l => locationRef === stringifyLocationRef(l));
}
/**
+4 -15
View File
@@ -262,24 +262,13 @@ export interface CatalogApi {
): Promise<Location | undefined>;
/**
* Gets origin location by Entity.
* Gets a registered location by its ref.
*
* @param entity - An {@link catalog-model#Entity}.
* @param locationRef - A location ref, e.g. "url:https://github.com/..."
* @param options - Additional options
*/
getOriginLocationByEntity(
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined>;
/**
* Gets Location by Entity.
*
* @param entity - An {@link catalog-model#Entity}.
* @param options - Additional options
*/
getLocationByEntity(
entity: Entity,
getLocationByRef(
locationRef: string,
options?: CatalogRequestOptions,
): Promise<Location | undefined>;
@@ -56,7 +56,7 @@ describe('DefaultApiExplorerPage', () => {
},
] as Entity[],
}),
getLocationByEntity: () =>
getLocationByRef: () =>
Promise.resolve({ id: 'id', type: 'github', target: 'url' }),
getEntityByName: async entityName => {
return {
@@ -36,7 +36,7 @@ describe('<ConsumedApisCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -36,7 +36,7 @@ describe('<HasApisCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -36,7 +36,7 @@ describe('<ProvidedApisCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -32,7 +32,7 @@ describe('<ConsumingComponentsCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -32,7 +32,7 @@ describe('<ProvidingComponentsCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -30,8 +30,7 @@ describe('CatalogIdentityClient', () => {
getEntities: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
refreshEntity: jest.fn(),
getEntityAncestors: jest.fn(),
@@ -61,8 +61,7 @@ describe('createRouter', () => {
addLocation: jest.fn(),
getEntities: jest.fn(),
getEntityByName: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -60,8 +60,7 @@ describe('<CatalogGraphCard/>', () => {
getEntityByName: jest.fn(async _ => ({ ...entity, relations: [] })),
removeEntityByUid: jest.fn(),
getLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
refreshEntity: jest.fn(),
@@ -89,8 +89,7 @@ describe('<CatalogGraphPage/>', () => {
getEntityByName: jest.fn(async n => (n.name === 'e' ? entityE : entityC)),
removeEntityByUid: jest.fn(),
getLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
refreshEntity: jest.fn(),
@@ -150,8 +150,7 @@ describe('<EntityRelationsGraph/>', () => {
getEntityByName: jest.fn(async n => entities[stringifyEntityRef(n)]),
removeEntityByUid: jest.fn(),
getLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
refreshEntity: jest.fn(),
@@ -32,8 +32,7 @@ describe('useEntityStore', () => {
getEntityByName: jest.fn(),
removeEntityByUid: jest.fn(),
getLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
refreshEntity: jest.fn(),
@@ -94,8 +94,7 @@ describe('CatalogImportClient', () => {
addLocation: jest.fn(),
removeLocationById: jest.fn(),
getEntityByName: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
refreshEntity: jest.fn(),
@@ -39,8 +39,7 @@ describe('<StepPrepareCreatePullRequest />', () => {
getEntities: jest.fn(),
addLocation: jest.fn(),
getEntityByName: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -39,7 +39,7 @@ function defer<T>(): { promise: Promise<T>; resolve: (value: T) => void } {
describe('useUnregisterEntityDialogState', () => {
const catalogApiMock = {
getOriginLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getEntities: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -65,9 +65,7 @@ describe('useUnregisterEntityDialogState', () => {
resolveLocation = deferredLocation.resolve;
resolveColocatedEntities = deferredColocatedEntities.resolve;
catalogApiMock.getOriginLocationByEntity.mockReturnValue(
deferredLocation.promise,
);
catalogApiMock.getLocationByRef.mockReturnValue(deferredLocation.promise);
catalogApiMock.getEntities.mockReturnValue(
deferredColocatedEntities.promise.then(items => ({ items })),
);
@@ -67,7 +67,7 @@ export function useUnregisterEntityDialogState(
// Load the prerequisite data: what entities that are colocated with us, and
// what location that spawned us
const prerequisites = useAsync(async () => {
const locationPromise = catalogApi.getOriginLocationByEntity(entity);
const locationPromise = catalogApi.getLocationByRef(locationRef!);
let colocatedEntitiesPromise: Promise<Entity[]>;
if (!locationRef) {
@@ -38,7 +38,7 @@ describe('<AboutCard />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
refreshEntity: jest.fn(),
} as any;
@@ -100,7 +100,7 @@ describe('DefaultCatalogPage', () => {
},
] as Entity[],
}),
getLocationByEntity: () =>
getLocationByRef: () =>
Promise.resolve({ id: 'id', type: 'github', target: 'url' }),
getEntityByName: async entityName => {
return {
@@ -24,8 +24,7 @@ describe('<DefaultExplorePage />', () => {
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
addLocation: jest.fn(_a => new Promise(() => {})),
getEntities: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -25,8 +25,7 @@ describe('<DomainExplorerContent />', () => {
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
addLocation: jest.fn(_a => new Promise(() => {})),
getEntities: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -25,8 +25,7 @@ describe('<GroupsExplorerContent />', () => {
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
addLocation: jest.fn(_a => new Promise(() => {})),
getEntities: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),
@@ -30,9 +30,8 @@ describe('<FossaPage />', () => {
addLocation: jest.fn(),
getEntities: jest.fn(),
getEntityByName: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
getOriginLocationByEntity: jest.fn(),
removeEntityByUid: jest.fn(),
removeLocationById: jest.fn(),
refreshEntity: jest.fn(),
@@ -46,7 +46,7 @@ describe('<EntityPicker />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(async () => ({ items: entities })),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -43,7 +43,7 @@ describe('<OwnerPicker />', () => {
getEntityByName: jest.fn(),
getEntities: jest.fn(async () => ({ items: entities })),
addLocation: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
removeEntityByUid: jest.fn(),
} as any;
let Wrapper: React.ComponentType;
@@ -45,8 +45,7 @@ function mockCatalogClient(entity?: Entity): jest.Mocked<CatalogApi> {
addLocation: jest.fn(),
getEntities: jest.fn(),
getEntityByName: jest.fn(),
getOriginLocationByEntity: jest.fn(),
getLocationByEntity: jest.fn(),
getLocationByRef: jest.fn(),
getLocationById: jest.fn(),
removeLocationById: jest.fn(),
removeEntityByUid: jest.fn(),