From 27eccab2160a18e24d37abad021e584acf1a1114 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 15 Feb 2022 09:30:41 +0100 Subject: [PATCH] catalog-model: Prefix annotations with ANNOTATION_ Signed-off-by: Johan Haals --- .changeset/tasty-taxis-dance.md | 14 +++++++++ .changeset/twenty-dodos-rule.md | 6 ++++ packages/catalog-client/src/CatalogClient.ts | 8 ++--- packages/catalog-model/api-report.md | 26 ++++++++++++---- .../catalog-model/src/entity/constants.ts | 16 ++++++++++ packages/catalog-model/src/entity/index.ts | 2 ++ .../catalog-model/src/location/annotation.ts | 30 +++++++++++++++++-- .../catalog-model/src/location/helpers.ts | 7 +++-- packages/catalog-model/src/location/index.ts | 3 ++ .../src/processors/LdapOrgEntityProvider.ts | 8 ++--- .../MicrosoftGraphOrgEntityProvider.test.ts | 8 ++--- .../MicrosoftGraphOrgEntityProvider.ts | 8 ++--- .../AnnotateLocationEntityProcessor.ts | 20 ++++++------- .../providers/GitHubOrgEntityProvider.ts | 8 ++--- ...faultCatalogProcessingOrchestrator.test.ts | 16 +++++----- .../processing/ProcessorOutputCollector.ts | 8 ++--- .../catalog-backend/src/processing/util.ts | 8 ++--- .../src/service/DefaultLocationService.ts | 8 ++--- .../catalog-backend/src/util/conversion.ts | 12 ++++---- .../components/ColocatedPage.tsx | 16 +++++----- .../UnregisterEntityDialog.test.tsx | 4 +-- .../useUnregisterEntityDialogState.test.tsx | 8 ++--- .../useUnregisterEntityDialogState.ts | 6 ++-- .../src/utils/getEntityMetadataUrl.ts | 8 ++--- .../src/utils/getEntitySourceLocation.ts | 4 +-- .../src/components/AboutCard/AboutCard.tsx | 4 +-- .../CatalogTable/CatalogTable.test.tsx | 8 ++--- .../DeleteEntityDialog.test.tsx | 4 +-- .../src/components/GithubDeploymentsCard.tsx | 8 ++--- .../actions/builtin/catalog/write.test.ts | 6 ++-- .../scaffolder-backend/src/service/helpers.ts | 8 ++--- .../src/service/TodoReaderService.ts | 8 ++--- plugins/todo/dev/index.tsx | 4 +-- 33 files changed, 197 insertions(+), 115 deletions(-) create mode 100644 .changeset/tasty-taxis-dance.md create mode 100644 .changeset/twenty-dodos-rule.md diff --git a/.changeset/tasty-taxis-dance.md b/.changeset/tasty-taxis-dance.md new file mode 100644 index 0000000000000..34ed30f686573 --- /dev/null +++ b/.changeset/tasty-taxis-dance.md @@ -0,0 +1,14 @@ +--- +'@backstage/catalog-client': patch +'@backstage/plugin-catalog': patch +'@backstage/plugin-catalog-backend': patch +'@backstage/plugin-catalog-backend-module-ldap': patch +'@backstage/plugin-catalog-backend-module-msgraph': patch +'@backstage/plugin-catalog-react': patch +'@backstage/plugin-github-deployments': patch +'@backstage/plugin-scaffolder-backend': patch +'@backstage/plugin-todo': patch +'@backstage/plugin-todo-backend': patch +--- + +Replaces use of deprecated catalog-model constants. diff --git a/.changeset/twenty-dodos-rule.md b/.changeset/twenty-dodos-rule.md new file mode 100644 index 0000000000000..6b892ce68f7e2 --- /dev/null +++ b/.changeset/twenty-dodos-rule.md @@ -0,0 +1,6 @@ +--- +'@backstage/catalog-model': patch +--- + +Deprecates `EDIT_URL_ANNOTATION`, `LOCATION_ANNOTATION`, `ORIGIN_LOCATION_ANNOTATION`, `SOURCE_LOCATION_ANNOTATION`, `VIEW_URL_ANNOTATION` +and replaces these constants all prefixed with ANNOTATION_ `ANNOTATION_EDIT_URL`, `ANNOTATION_LOCATION`, `ANNOTATION_ORIGIN_LOCATION`, `ANNOTATION_SOURCE_LOCATION`, `ANNOTATION_VIEW_URL` diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index eea77d3f985fe..bcf8750658c22 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -15,10 +15,10 @@ */ import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, Entity, EntityName, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, parseEntityRef, stringifyEntityRef, stringifyLocationRef, @@ -253,7 +253,7 @@ export class CatalogClient implements CatalogApi { options?: CatalogRequestOptions, ): Promise { const locationCompound = - entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION]; + entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION]; if (!locationCompound) { return undefined; } @@ -274,7 +274,7 @@ export class CatalogClient implements CatalogApi { entity: Entity, options?: CatalogRequestOptions, ): Promise { - const locationCompound = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + const locationCompound = entity.metadata.annotations?.[ANNOTATION_LOCATION]; if (!locationCompound) { return undefined; } diff --git a/packages/catalog-model/api-report.md b/packages/catalog-model/api-report.md index 51249459332ae..655d01fef131b 100644 --- a/packages/catalog-model/api-report.md +++ b/packages/catalog-model/api-report.md @@ -13,6 +13,22 @@ export interface AlphaEntity extends Entity { status?: EntityStatus; } +// @public +export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url'; + +// @public +export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location'; + +// @public +export const ANNOTATION_ORIGIN_LOCATION = + 'backstage.io/managed-by-origin-location'; + +// @public +export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location'; + +// @public +export const ANNOTATION_VIEW_URL = 'backstage.io/view-url'; + // @public interface ApiEntityV1alpha1 extends Entity { // (undocumented) @@ -105,7 +121,7 @@ export { DomainEntityV1alpha1 }; // @public export const domainEntityV1alpha1Validator: KindValidator; -// @public +// @public @deprecated export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url'; // @public @@ -325,7 +341,7 @@ type Location_2 = { } & LocationSpec; export { Location_2 as Location }; -// @public +// @public @deprecated export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location'; // @public @@ -365,7 +381,7 @@ export class NoForeignRootFieldsEntityPolicy implements EntityPolicy { enforce(entity: Entity): Promise; } -// @public +// @public @deprecated export const ORIGIN_LOCATION_ANNOTATION = 'backstage.io/managed-by-origin-location'; @@ -489,7 +505,7 @@ export class SchemaValidEntityPolicy implements EntityPolicy { enforce(entity: Entity): Promise; } -// @public +// @public @deprecated export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location'; // @public @@ -595,6 +611,6 @@ export type Validators = { isValidTag(value: unknown): boolean; }; -// @public +// @public @deprecated export const VIEW_URL_ANNOTATION = 'backstage.io/view-url'; ``` diff --git a/packages/catalog-model/src/entity/constants.ts b/packages/catalog-model/src/entity/constants.ts index 96d29d06e1658..4d0e6799beb9c 100644 --- a/packages/catalog-model/src/entity/constants.ts +++ b/packages/catalog-model/src/entity/constants.ts @@ -37,6 +37,7 @@ export const ENTITY_META_GENERATED_FIELDS = [ * Annotation for linking to entity page from catalog pages. * * @public + * @deprecated use {@link ANNOTATION_VIEW_URL} instead. */ export const VIEW_URL_ANNOTATION = 'backstage.io/view-url'; @@ -44,5 +45,20 @@ export const VIEW_URL_ANNOTATION = 'backstage.io/view-url'; * Annotation for linking to entity edit page from catalog pages. * * @public + * @deprecated use {@link ANNOTATION_EDIT_URL} instead. */ export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url'; + +/** + * Annotation for linking to entity page from catalog pages. + * + * @public + */ +export const ANNOTATION_VIEW_URL = 'backstage.io/view-url'; + +/** + * Annotation for linking to entity edit page from catalog pages. + * + * @public + */ +export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url'; diff --git a/packages/catalog-model/src/entity/index.ts b/packages/catalog-model/src/entity/index.ts index ea2145ab1a83a..49a6da5e0a336 100644 --- a/packages/catalog-model/src/entity/index.ts +++ b/packages/catalog-model/src/entity/index.ts @@ -19,6 +19,8 @@ export { ENTITY_DEFAULT_NAMESPACE, ENTITY_META_GENERATED_FIELDS, VIEW_URL_ANNOTATION, + ANNOTATION_EDIT_URL, + ANNOTATION_VIEW_URL, } from './constants'; export type { AlphaEntity, diff --git a/packages/catalog-model/src/location/annotation.ts b/packages/catalog-model/src/location/annotation.ts index 8eb393f555916..3ff624360ef71 100644 --- a/packages/catalog-model/src/location/annotation.ts +++ b/packages/catalog-model/src/location/annotation.ts @@ -17,17 +17,41 @@ /** * Constant storing location annotation. * - * @public */ + * @public + * @deprecated use {@link ANNOTATION_LOCATION} instead. + * */ export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location'; /** * Constant storing origin location annotation * - * @public */ + * @public + * @deprecated use {@link ANNOTATION_ORIGIN_LOCATION} instead. + */ export const ORIGIN_LOCATION_ANNOTATION = 'backstage.io/managed-by-origin-location'; /** * Contant storing source location annotation * - * @public */ + * @public + * @deprecated use {@link ANNOTATION_SOURCE_LOCATION} instead. + * */ export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location'; + +/** + * Constant storing location annotation. + * + * @public */ +export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location'; +/** + * Constant storing origin location annotation + * + * @public */ +export const ANNOTATION_ORIGIN_LOCATION = + 'backstage.io/managed-by-origin-location'; + +/** + * Contant storing source location annotation + * + * @public */ +export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location'; diff --git a/packages/catalog-model/src/location/helpers.ts b/packages/catalog-model/src/location/helpers.ts index 76241ef208c36..d308c004492ae 100644 --- a/packages/catalog-model/src/location/helpers.ts +++ b/packages/catalog-model/src/location/helpers.ts @@ -14,8 +14,9 @@ * limitations under the License. */ +import { ANNOTATION_SOURCE_LOCATION } from '.'; import { Entity, stringifyEntityRef } from '../entity'; -import { LOCATION_ANNOTATION, SOURCE_LOCATION_ANNOTATION } from './annotation'; +import { ANNOTATION_LOCATION } from './annotation'; /** * Parses a string form location reference. @@ -142,8 +143,8 @@ export function getEntitySourceLocation(entity: Entity): { target: string; } { const locationRef = - entity.metadata?.annotations?.[SOURCE_LOCATION_ANNOTATION] ?? - entity.metadata?.annotations?.[LOCATION_ANNOTATION]; + entity.metadata?.annotations?.[ANNOTATION_SOURCE_LOCATION] ?? + entity.metadata?.annotations?.[ANNOTATION_LOCATION]; if (!locationRef) { throw new Error( diff --git a/packages/catalog-model/src/location/index.ts b/packages/catalog-model/src/location/index.ts index c0e2b40c7f6a5..8302ec202f6e7 100644 --- a/packages/catalog-model/src/location/index.ts +++ b/packages/catalog-model/src/location/index.ts @@ -15,6 +15,9 @@ */ export { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, + ANNOTATION_SOURCE_LOCATION, LOCATION_ANNOTATION, ORIGIN_LOCATION_ANNOTATION, SOURCE_LOCATION_ANNOTATION, diff --git a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts index c74e5b3aeeaa5..4c5bd2e3bd213 100644 --- a/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-ldap/src/processors/LdapOrgEntityProvider.ts @@ -15,9 +15,9 @@ */ import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, Entity, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -207,8 +207,8 @@ function withLocations(providerId: string, entity: Entity): Entity { { metadata: { annotations: { - [LOCATION_ANNOTATION]: location, - [ORIGIN_LOCATION_ANNOTATION]: location, + [ANNOTATION_LOCATION]: location, + [ANNOTATION_ORIGIN_LOCATION]: location, }, }, }, diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts index eab2d93526ea2..456afda550601 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts @@ -15,9 +15,9 @@ */ import { getVoidLogger } from '@backstage/backend-common'; import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, GroupEntity, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, UserEntity, } from '@backstage/catalog-model'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; @@ -162,8 +162,8 @@ describe('withLocations', () => { name: 'u1', annotations: { [MICROSOFT_GRAPH_USER_ID_ANNOTATION]: 'uid', - [LOCATION_ANNOTATION]: 'msgraph:test/uid', - [ORIGIN_LOCATION_ANNOTATION]: 'msgraph:test/uid', + [ANNOTATION_LOCATION]: 'msgraph:test/uid', + [ANNOTATION_ORIGIN_LOCATION]: 'msgraph:test/uid', }, }, spec: { diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts index 6d66723970088..92836893f0fb8 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts @@ -15,9 +15,9 @@ */ import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, Entity, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -180,8 +180,8 @@ export function withLocations(providerId: string, entity: Entity): Entity { { metadata: { annotations: { - [LOCATION_ANNOTATION]: location, - [ORIGIN_LOCATION_ANNOTATION]: location, + [ANNOTATION_LOCATION]: location, + [ANNOTATION_ORIGIN_LOCATION]: location, }, }, }, diff --git a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts index e7afbf720f913..8adbaec628fcf 100644 --- a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts @@ -15,14 +15,14 @@ */ import { - EDIT_URL_ANNOTATION, + ANNOTATION_EDIT_URL, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, + ANNOTATION_SOURCE_LOCATION, + ANNOTATION_VIEW_URL, Entity, LocationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, - SOURCE_LOCATION_ANNOTATION, stringifyLocationRef, - VIEW_URL_ANNOTATION, } from '@backstage/catalog-model'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { identity, merge, pickBy } from 'lodash'; @@ -70,12 +70,12 @@ export class AnnotateLocationEntityProcessor implements CatalogProcessor { metadata: { annotations: pickBy( { - [LOCATION_ANNOTATION]: stringifyLocationRef(location), - [ORIGIN_LOCATION_ANNOTATION]: + [ANNOTATION_LOCATION]: stringifyLocationRef(location), + [ANNOTATION_ORIGIN_LOCATION]: stringifyLocationRef(originLocation), - [VIEW_URL_ANNOTATION]: viewUrl, - [EDIT_URL_ANNOTATION]: editUrl, - [SOURCE_LOCATION_ANNOTATION]: sourceLocation, + [ANNOTATION_VIEW_URL]: viewUrl, + [ANNOTATION_EDIT_URL]: editUrl, + [ANNOTATION_SOURCE_LOCATION]: sourceLocation, }, identity, ), diff --git a/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts b/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts index b1d44a55b53db..20e9966bd1a81 100644 --- a/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts +++ b/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts @@ -14,9 +14,9 @@ * limitations under the License. */ import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, Entity, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -178,8 +178,8 @@ export function withLocations( { metadata: { annotations: { - [LOCATION_ANNOTATION]: location, - [ORIGIN_LOCATION_ANNOTATION]: location, + [ANNOTATION_LOCATION]: location, + [ANNOTATION_ORIGIN_LOCATION]: location, }, }, }, diff --git a/plugins/catalog-backend/src/processing/DefaultCatalogProcessingOrchestrator.test.ts b/plugins/catalog-backend/src/processing/DefaultCatalogProcessingOrchestrator.test.ts index 5ae4d58ec7071..cc77f6a17b9bd 100644 --- a/plugins/catalog-backend/src/processing/DefaultCatalogProcessingOrchestrator.test.ts +++ b/plugins/catalog-backend/src/processing/DefaultCatalogProcessingOrchestrator.test.ts @@ -16,12 +16,12 @@ import { getVoidLogger } from '@backstage/backend-common'; import { + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, Entity, EntityPolicies, LocationEntity, LocationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, } from '@backstage/catalog-model'; import { ScmIntegrations } from '@backstage/integration'; import { @@ -82,8 +82,8 @@ describe('DefaultCatalogProcessingOrchestrator', () => { metadata: { name: 'my-foo-bar', annotations: { - [LOCATION_ANNOTATION]: 'url:./here', - [ORIGIN_LOCATION_ANNOTATION]: 'url:./there', + [ANNOTATION_LOCATION]: 'url:./here', + [ANNOTATION_ORIGIN_LOCATION]: 'url:./there', }, }, }; @@ -128,8 +128,8 @@ describe('DefaultCatalogProcessingOrchestrator', () => { metadata: { name: 'my-new-foo-bar', annotations: { - [LOCATION_ANNOTATION]: 'url:./new-place', - [ORIGIN_LOCATION_ANNOTATION]: 'url:./there', + [ANNOTATION_LOCATION]: 'url:./new-place', + [ANNOTATION_ORIGIN_LOCATION]: 'url:./there', }, }, }, @@ -196,8 +196,8 @@ describe('DefaultCatalogProcessingOrchestrator', () => { metadata: { name: 'l', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml', - [LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml', + [ANNOTATION_ORIGIN_LOCATION]: 'url:https://example.com/origin.yaml', + [ANNOTATION_LOCATION]: 'url:https://example.com/origin.yaml', }, }, spec: { diff --git a/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts b/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts index 7fe43edba184e..832c5b41bfa6f 100644 --- a/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts +++ b/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts @@ -17,8 +17,8 @@ import { Entity, EntityRelationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, stringifyLocationRef, } from '@backstage/catalog-model'; import { assertError } from '@backstage/errors'; @@ -98,8 +98,8 @@ export class ProcessorOutputCollector { ...entity.metadata, annotations: { ...annotations, - [ORIGIN_LOCATION_ANNOTATION]: originLocation, - [LOCATION_ANNOTATION]: location, + [ANNOTATION_ORIGIN_LOCATION]: originLocation, + [ANNOTATION_LOCATION]: location, }, }, }; diff --git a/plugins/catalog-backend/src/processing/util.ts b/plugins/catalog-backend/src/processing/util.ts index 9f5f23ed09899..a4fa984dc15b8 100644 --- a/plugins/catalog-backend/src/processing/util.ts +++ b/plugins/catalog-backend/src/processing/util.ts @@ -20,8 +20,8 @@ import { entitySchemaValidator, LocationEntity, LocationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, stringifyEntityRef, } from '@backstage/catalog-model'; import { JsonObject, JsonValue } from '@backstage/types'; @@ -34,7 +34,7 @@ export function isLocationEntity(entity: Entity): entity is LocationEntity { } export function getEntityLocationRef(entity: Entity): string { - const ref = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + const ref = entity.metadata.annotations?.[ANNOTATION_LOCATION]; if (!ref) { const entityRef = stringifyEntityRef(entity); throw new InputError(`Entity '${entityRef}' does not have a location`); @@ -43,7 +43,7 @@ export function getEntityLocationRef(entity: Entity): string { } export function getEntityOriginLocationRef(entity: Entity): string { - const ref = entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION]; + const ref = entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION]; if (!ref) { const entityRef = stringifyEntityRef(entity); throw new InputError( diff --git a/plugins/catalog-backend/src/service/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts index abc82084e2c30..8bc02e24f664e 100644 --- a/plugins/catalog-backend/src/service/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -16,8 +16,8 @@ import { Entity, LocationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, stringifyEntityRef, } from '@backstage/catalog-model'; import { Location } from '@backstage/catalog-client'; @@ -112,8 +112,8 @@ export class DefaultLocationService implements LocationService { }), namespace: 'default', annotations: { - [LOCATION_ANNOTATION]: `${spec.type}:${spec.target}`, - [ORIGIN_LOCATION_ANNOTATION]: `${spec.type}:${spec.target}`, + [ANNOTATION_LOCATION]: `${spec.type}:${spec.target}`, + [ANNOTATION_ORIGIN_LOCATION]: `${spec.type}:${spec.target}`, }, }, spec: { diff --git a/plugins/catalog-backend/src/util/conversion.ts b/plugins/catalog-backend/src/util/conversion.ts index e75abdbab0681..9dd5ce7986a0f 100644 --- a/plugins/catalog-backend/src/util/conversion.ts +++ b/plugins/catalog-backend/src/util/conversion.ts @@ -18,8 +18,8 @@ import { Entity, LocationEntityV1alpha1, LocationSpec, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, stringifyEntityRef, stringifyLocationRef, } from '@backstage/catalog-model'; @@ -40,7 +40,7 @@ export function locationSpecToLocationEntity( let originLocation: string; if (parentEntity) { const maybeOwnLocation = - parentEntity.metadata.annotations?.[LOCATION_ANNOTATION]; + parentEntity.metadata.annotations?.[ANNOTATION_LOCATION]; if (!maybeOwnLocation) { throw new Error( `Parent entity '${stringifyEntityRef( @@ -52,7 +52,7 @@ export function locationSpecToLocationEntity( } ownLocation = maybeOwnLocation; const maybeOriginLocation = - parentEntity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION]; + parentEntity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION]; if (!maybeOriginLocation) { throw new Error( `Parent entity '${stringifyEntityRef( @@ -74,8 +74,8 @@ export function locationSpecToLocationEntity( metadata: { name: locationSpecToMetadataName(location), annotations: { - [LOCATION_ANNOTATION]: ownLocation, - [ORIGIN_LOCATION_ANNOTATION]: originLocation, + [ANNOTATION_LOCATION]: ownLocation, + [ANNOTATION_ORIGIN_LOCATION]: originLocation, }, }, spec: { diff --git a/plugins/catalog-react/src/components/InspectEntityDialog/components/ColocatedPage.tsx b/plugins/catalog-react/src/components/InspectEntityDialog/components/ColocatedPage.tsx index 96d3900a59115..d5a98f434c226 100644 --- a/plugins/catalog-react/src/components/InspectEntityDialog/components/ColocatedPage.tsx +++ b/plugins/catalog-react/src/components/InspectEntityDialog/components/ColocatedPage.tsx @@ -16,8 +16,8 @@ import { Entity, - LOCATION_ANNOTATION, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_ORIGIN_LOCATION, stringifyEntityRef, } from '@backstage/catalog-model'; import { Progress, ResponseErrorPanel } from '@backstage/core-components'; @@ -53,8 +53,8 @@ function useColocated(entity: Entity): { } { const catalogApi = useApi(catalogApiRef); const currentEntityRef = stringifyEntityRef(entity); - const location = entity.metadata.annotations?.[LOCATION_ANNOTATION]; - const origin = entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION]; + const location = entity.metadata.annotations?.[ANNOTATION_LOCATION]; + const origin = entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION]; const { loading, error, value } = useAsync(async () => { if (!location && !origin) { @@ -63,10 +63,10 @@ function useColocated(entity: Entity): { const response = await catalogApi.getEntities({ filter: [ ...(location - ? [{ [`metadata.annotations.${LOCATION_ANNOTATION}`]: location }] + ? [{ [`metadata.annotations.${ANNOTATION_LOCATION}`]: location }] : []), ...(origin - ? [{ [`metadata.annotations.${ORIGIN_LOCATION_ANNOTATION}`]: origin }] + ? [{ [`metadata.annotations.${ANNOTATION_ORIGIN_LOCATION}`]: origin }] : []), ], }); @@ -128,11 +128,11 @@ function Contents(props: { entity: Entity }) { } const atLocation = colocatedEntities.filter( - e => e.metadata.annotations?.[LOCATION_ANNOTATION] === location, + e => e.metadata.annotations?.[ANNOTATION_LOCATION] === location, ); const atOrigin = colocatedEntities.filter( e => - e.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION] === originLocation, + e.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION] === originLocation, ); return ( diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx index 2b29bba4fdb6f..68cb5f2bdf23a 100644 --- a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx +++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx @@ -19,7 +19,7 @@ jest.mock('./useUnregisterEntityDialogState'); import userEvent from '@testing-library/user-event'; import React from 'react'; import { UnregisterEntityDialog } from './UnregisterEntityDialog'; -import { ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model'; +import { ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model'; import { CatalogClient } from '@backstage/catalog-client'; import { catalogApiRef } from '../../api'; import { entityRouteRef } from '../../routes'; @@ -55,7 +55,7 @@ describe('UnregisterEntityDialog', () => { name: 'n', namespace: 'ns', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:http://example.com', + [ANNOTATION_ORIGIN_LOCATION]: 'url:http://example.com', }, }, spec: {}, diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx index d9d9fcf1dbfcc..44fc3886ea668 100644 --- a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx +++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx @@ -14,8 +14,8 @@ * limitations under the License. */ -import { Entity, ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model'; import { CatalogApi, Location } from '@backstage/catalog-client'; +import { Entity, ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model'; import { catalogApiRef } from '../../api'; import { act, @@ -79,7 +79,7 @@ describe('useUnregisterEntityDialogState', () => { name: 'n', namespace: 'ns', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com', + [ANNOTATION_ORIGIN_LOCATION]: 'url:https://example.com', }, }, spec: {}, @@ -113,7 +113,7 @@ describe('useUnregisterEntityDialogState', () => { }); it('chooses the bootstrap path when necessary', async () => { - entity.metadata.annotations![ORIGIN_LOCATION_ANNOTATION] = + entity.metadata.annotations![ANNOTATION_ORIGIN_LOCATION] = 'bootstrap:bootstrap'; let rendered: RenderHookResult; @@ -137,7 +137,7 @@ describe('useUnregisterEntityDialogState', () => { }); it('chooses only-delete when there was no location annotation', async () => { - delete entity.metadata.annotations![ORIGIN_LOCATION_ANNOTATION]; + delete entity.metadata.annotations![ANNOTATION_ORIGIN_LOCATION]; let rendered: RenderHookResult; act(() => { diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.ts b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.ts index 7f75016e162b8..c637490268509 100644 --- a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.ts +++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.ts @@ -18,7 +18,7 @@ import { Entity, EntityName, getEntityName, - ORIGIN_LOCATION_ANNOTATION, + ANNOTATION_ORIGIN_LOCATION, } from '@backstage/catalog-model'; import { catalogApiRef } from '../../api'; import { useCallback } from 'react'; @@ -60,7 +60,7 @@ export function useUnregisterEntityDialogState( entity: Entity, ): UseUnregisterEntityDialogState { const catalogApi = useApi(catalogApiRef); - const locationRef = entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION]; + const locationRef = entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION]; const uid = entity.metadata.uid; const isBootstrap = locationRef === 'bootstrap:bootstrap'; @@ -73,7 +73,7 @@ export function useUnregisterEntityDialogState( if (!locationRef) { colocatedEntitiesPromise = Promise.resolve([]); } else { - const locationAnnotationFilter = `metadata.annotations.${ORIGIN_LOCATION_ANNOTATION}`; + const locationAnnotationFilter = `metadata.annotations.${ANNOTATION_ORIGIN_LOCATION}`; colocatedEntitiesPromise = catalogApi .getEntities({ filter: { [locationAnnotationFilter]: locationRef }, diff --git a/plugins/catalog-react/src/utils/getEntityMetadataUrl.ts b/plugins/catalog-react/src/utils/getEntityMetadataUrl.ts index 996f928ecf323..3b44816ac1d1e 100644 --- a/plugins/catalog-react/src/utils/getEntityMetadataUrl.ts +++ b/plugins/catalog-react/src/utils/getEntityMetadataUrl.ts @@ -15,15 +15,15 @@ */ import { - EDIT_URL_ANNOTATION, + ANNOTATION_EDIT_URL, + ANNOTATION_VIEW_URL, Entity, - VIEW_URL_ANNOTATION, } from '@backstage/catalog-model'; export function getEntityMetadataViewUrl(entity: Entity): string | undefined { - return entity.metadata.annotations?.[VIEW_URL_ANNOTATION]; + return entity.metadata.annotations?.[ANNOTATION_VIEW_URL]; } export function getEntityMetadataEditUrl(entity: Entity): string | undefined { - return entity.metadata.annotations?.[EDIT_URL_ANNOTATION]; + return entity.metadata.annotations?.[ANNOTATION_EDIT_URL]; } diff --git a/plugins/catalog-react/src/utils/getEntitySourceLocation.ts b/plugins/catalog-react/src/utils/getEntitySourceLocation.ts index 1b8df5828c94e..dd4d5c07f6013 100644 --- a/plugins/catalog-react/src/utils/getEntitySourceLocation.ts +++ b/plugins/catalog-react/src/utils/getEntitySourceLocation.ts @@ -15,9 +15,9 @@ */ import { + ANNOTATION_SOURCE_LOCATION, Entity, parseLocationRef, - SOURCE_LOCATION_ANNOTATION, } from '@backstage/catalog-model'; import { ScmIntegrationRegistry } from '@backstage/integration'; @@ -31,7 +31,7 @@ export function getEntitySourceLocation( scmIntegrationsApi: ScmIntegrationRegistry, ): EntitySourceLocation | undefined { const sourceLocation = - entity.metadata.annotations?.[SOURCE_LOCATION_ANNOTATION]; + entity.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION]; if (!sourceLocation) { return undefined; diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index a6c9635db2524..cb6e057e613ac 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -17,7 +17,7 @@ import { Entity, ENTITY_DEFAULT_NAMESPACE, - LOCATION_ANNOTATION, + ANNOTATION_LOCATION, stringifyEntityRef, } from '@backstage/catalog-model'; import { @@ -127,7 +127,7 @@ export function AboutCard({ variant }: AboutCardProps) { cardContentClass = classes.fullHeightCardContent; } - const entityLocation = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + const entityLocation = entity.metadata.annotations?.[ANNOTATION_LOCATION]; // Limiting the ability to manually refresh to the less expensive locations const allowRefresh = entityLocation?.startsWith('url:') || entityLocation?.startsWith('file:'); diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index 4c6adcf400247..db9835e3a3d2b 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -15,9 +15,9 @@ */ import { - EDIT_URL_ANNOTATION, + ANNOTATION_EDIT_URL, + ANNOTATION_VIEW_URL, Entity, - VIEW_URL_ANNOTATION, } from '@backstage/catalog-model'; import { ApiProvider } from '@backstage/core-app-api'; import { @@ -123,7 +123,7 @@ describe('CatalogTable component', () => { kind: 'Component', metadata: { name: 'component1', - annotations: { [EDIT_URL_ANNOTATION]: 'https://other.place' }, + annotations: { [ANNOTATION_EDIT_URL]: 'https://other.place' }, }, }; @@ -155,7 +155,7 @@ describe('CatalogTable component', () => { kind: 'Component', metadata: { name: 'component1', - annotations: { [VIEW_URL_ANNOTATION]: 'https://other.place' }, + annotations: { [ANNOTATION_VIEW_URL]: 'https://other.place' }, }, }; diff --git a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx index f58e6b9b668a9..75155aa07555e 100644 --- a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx +++ b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx @@ -16,7 +16,7 @@ import userEvent from '@testing-library/user-event'; import React from 'react'; import { DeleteEntityDialog } from './DeleteEntityDialog'; -import { ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model'; +import { ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model'; import { CatalogApi } from '@backstage/catalog-client'; import { catalogApiRef } from '@backstage/plugin-catalog-react'; import { screen, waitFor } from '@testing-library/react'; @@ -42,7 +42,7 @@ describe('DeleteEntityDialog', () => { name: 'n', namespace: 'ns', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:http://example.com', + [ANNOTATION_ORIGIN_LOCATION]: 'url:http://example.com', }, }, spec: {}, diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx index 901e20a8998fc..68881617f4f89 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx @@ -23,8 +23,8 @@ import { } from '../Router'; import { GithubDeploymentsTable } from './GithubDeploymentsTable/GithubDeploymentsTable'; import { - LOCATION_ANNOTATION, - SOURCE_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_SOURCE_LOCATION, } from '@backstage/catalog-model'; import { @@ -88,8 +88,8 @@ export const GithubDeploymentsCard = (props: { const { last, lastStatuses, columns } = props; const { entity } = useEntity(); const [host] = [ - entity?.metadata.annotations?.[SOURCE_LOCATION_ANNOTATION], - entity?.metadata.annotations?.[LOCATION_ANNOTATION], + entity?.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION], + entity?.metadata.annotations?.[ANNOTATION_LOCATION], ].filter(Boolean); return !isGithubDeploymentsAvailable(entity) ? ( diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/catalog/write.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/catalog/write.test.ts index 9612780b1249d..dd6f29f99b1ac 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/catalog/write.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/catalog/write.test.ts @@ -23,7 +23,7 @@ const fsMock = fs as jest.Mocked; import { PassThrough } from 'stream'; import os from 'os'; import { getVoidLogger } from '@backstage/backend-common'; -import { ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model'; +import { ANNOTATION_ORIGIN_LOCATION } from '@backstage/catalog-model'; import { createCatalogWriteAction } from './write'; import { resolve as resolvePath } from 'path'; import * as yaml from 'yaml'; @@ -51,7 +51,7 @@ describe('catalog:write', () => { name: 'n', namespace: 'ns', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com', + [ANNOTATION_ORIGIN_LOCATION]: 'url:https://example.com', }, }, spec: {}, @@ -79,7 +79,7 @@ describe('catalog:write', () => { name: 'n', namespace: 'ns', annotations: { - [ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com', + [ANNOTATION_ORIGIN_LOCATION]: 'url:https://example.com', }, }, spec: {}, diff --git a/plugins/scaffolder-backend/src/service/helpers.ts b/plugins/scaffolder-backend/src/service/helpers.ts index f57e7eca19444..f86b1663a7b73 100644 --- a/plugins/scaffolder-backend/src/service/helpers.ts +++ b/plugins/scaffolder-backend/src/service/helpers.ts @@ -16,9 +16,9 @@ import { Entity, - LOCATION_ANNOTATION, + ANNOTATION_LOCATION, parseLocationRef, - SOURCE_LOCATION_ANNOTATION, + ANNOTATION_SOURCE_LOCATION, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { assertError } from '@backstage/errors'; @@ -59,9 +59,9 @@ export async function getWorkingDirectory( * For file locations this will return a `file://` URL. */ export function getEntityBaseUrl(entity: Entity): string | undefined { - let location = entity.metadata.annotations?.[SOURCE_LOCATION_ANNOTATION]; + let location = entity.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION]; if (!location) { - location = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + location = entity.metadata.annotations?.[ANNOTATION_LOCATION]; } if (!location) { return undefined; diff --git a/plugins/todo-backend/src/service/TodoReaderService.ts b/plugins/todo-backend/src/service/TodoReaderService.ts index c3cd1c189bebb..86f53057daba0 100644 --- a/plugins/todo-backend/src/service/TodoReaderService.ts +++ b/plugins/todo-backend/src/service/TodoReaderService.ts @@ -17,8 +17,8 @@ import { InputError, NotFoundError } from '@backstage/errors'; import { CatalogApi } from '@backstage/catalog-client'; import { - LOCATION_ANNOTATION, - SOURCE_LOCATION_ANNOTATION, + ANNOTATION_LOCATION, + ANNOTATION_SOURCE_LOCATION, Entity, parseLocationRef, stringifyEntityRef, @@ -128,7 +128,7 @@ export class TodoReaderService implements TodoService { private getEntitySourceUrl(entity: Entity) { const sourceLocation = - entity.metadata.annotations?.[SOURCE_LOCATION_ANNOTATION]; + entity.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION]; if (sourceLocation) { const parsed = parseLocationRef(sourceLocation); if (parsed.type !== 'url') { @@ -141,7 +141,7 @@ export class TodoReaderService implements TodoService { return parsed.target; } - const location = entity.metadata.annotations?.[LOCATION_ANNOTATION]; + const location = entity.metadata.annotations?.[ANNOTATION_LOCATION]; if (location) { const parsed = parseLocationRef(location); if (parsed.type !== 'url') { diff --git a/plugins/todo/dev/index.tsx b/plugins/todo/dev/index.tsx index fe547812ecc50..375c89e4a4736 100644 --- a/plugins/todo/dev/index.tsx +++ b/plugins/todo/dev/index.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Entity, LOCATION_ANNOTATION } from '@backstage/catalog-model'; +import { Entity, ANNOTATION_LOCATION } from '@backstage/catalog-model'; import { createDevApp } from '@backstage/dev-utils'; import { EntityProvider } from '@backstage/plugin-catalog-react'; import OnlineIcon from '@material-ui/icons/Cloud'; @@ -31,7 +31,7 @@ const entity: Entity = { metadata: { name: 'backstage', annotations: { - [LOCATION_ANNOTATION]: + [ANNOTATION_LOCATION]: 'https://github.com/backstage/backstage/blob/master/catalog-info.yaml', }, },