From dcdb9f06518e481a09a4e396ed9c0320b5224199 Mon Sep 17 00:00:00 2001 From: James Turley Date: Sat, 20 Feb 2021 11:26:37 +0000 Subject: [PATCH] Extract view/edit annotations to constants --- packages/catalog-model/src/entity/constants.ts | 6 ++++++ packages/catalog-model/src/entity/index.ts | 2 ++ .../src/components/AboutCard/AboutCard.test.tsx | 7 +++++-- .../src/components/CatalogTable/CatalogTable.test.tsx | 10 +++++++--- plugins/catalog/src/components/actions.ts | 11 ++++++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/catalog-model/src/entity/constants.ts b/packages/catalog-model/src/entity/constants.ts index 42ea2ae8ba..c8f88e3b0c 100644 --- a/packages/catalog-model/src/entity/constants.ts +++ b/packages/catalog-model/src/entity/constants.ts @@ -27,3 +27,9 @@ export const ENTITY_META_GENERATED_FIELDS = [ 'etag', 'generation', ] as const; + +/** + * Annotations for linking to entity from catalog pages. + */ +export const VIEW_URL_ANNOTATION = 'backstage.io/view-url'; +export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url'; diff --git a/packages/catalog-model/src/entity/index.ts b/packages/catalog-model/src/entity/index.ts index e80e14f7a4..e267c607e1 100644 --- a/packages/catalog-model/src/entity/index.ts +++ b/packages/catalog-model/src/entity/index.ts @@ -17,6 +17,8 @@ export { ENTITY_DEFAULT_NAMESPACE, ENTITY_META_GENERATED_FIELDS, + VIEW_URL_ANNOTATION, + EDIT_URL_ANNOTATION, } from './constants'; export type { Entity, diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx index 393f3f2576..449d3c1fc9 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx @@ -15,7 +15,10 @@ */ import { EntityProvider } from '@backstage/plugin-catalog-react'; -import { SOURCE_LOCATION_ANNOTATION } from '@backstage/catalog-model'; +import { + SOURCE_LOCATION_ANNOTATION, + EDIT_URL_ANNOTATION, +} from '@backstage/catalog-model'; import { render } from '@testing-library/react'; import React from 'react'; import { AboutCard } from './AboutCard'; @@ -135,7 +138,7 @@ describe(' custom links', () => { annotations: { 'backstage.io/managed-by-location': 'bitbucket:https://bitbucket.org/backstage/backstage/src/master/software.yaml', - 'backstage.io/edit-url': 'https://another.place', + [EDIT_URL_ANNOTATION]: 'https://another.place', [SOURCE_LOCATION_ANNOTATION]: 'url:https://another.place/backstage.git', }, diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index b77dd2b8a0..ffd5f3d190 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -14,7 +14,11 @@ * limitations under the License. */ -import { Entity } from '@backstage/catalog-model'; +import { + Entity, + VIEW_URL_ANNOTATION, + EDIT_URL_ANNOTATION, +} from '@backstage/catalog-model'; import { act, fireEvent } from '@testing-library/react'; import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; import * as React from 'react'; @@ -86,7 +90,7 @@ describe('CatalogTable component', () => { kind: 'Component', metadata: { name: 'component1', - annotations: { 'backstage.io/edit-url': 'https://other.place' }, + annotations: { [EDIT_URL_ANNOTATION]: 'https://other.place' }, }, }; @@ -115,7 +119,7 @@ describe('CatalogTable component', () => { kind: 'Component', metadata: { name: 'component1', - annotations: { 'backstage.io/view-url': 'https://other.place' }, + annotations: { [VIEW_URL_ANNOTATION]: 'https://other.place' }, }, }; diff --git a/plugins/catalog/src/components/actions.ts b/plugins/catalog/src/components/actions.ts index c7fbfac8e2..13e235d46e 100644 --- a/plugins/catalog/src/components/actions.ts +++ b/plugins/catalog/src/components/actions.ts @@ -14,7 +14,12 @@ * limitations under the License. */ -import { LocationSpec, Entity } from '@backstage/catalog-model'; +import { + LocationSpec, + Entity, + EDIT_URL_ANNOTATION, + VIEW_URL_ANNOTATION, +} from '@backstage/catalog-model'; import parseGitUrl from 'git-url-parse'; /** @@ -82,7 +87,7 @@ export const findEditUrl = ( ): string | undefined => { const annotations = metadata.annotations || {}; - const editUrl = annotations['backstage.io/edit-url']; + const editUrl = annotations[EDIT_URL_ANNOTATION]; if (editUrl) return editUrl; @@ -95,5 +100,5 @@ export const findViewUrl = ( ): string | undefined => { const annotations = metadata.annotations || {}; - return annotations['backstage.io/view-url'] || location?.target; + return annotations[VIEW_URL_ANNOTATION] || location?.target; };