Extract view/edit annotations to constants
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
export {
|
||||
ENTITY_DEFAULT_NAMESPACE,
|
||||
ENTITY_META_GENERATED_FIELDS,
|
||||
VIEW_URL_ANNOTATION,
|
||||
EDIT_URL_ANNOTATION,
|
||||
} from './constants';
|
||||
export type {
|
||||
Entity,
|
||||
|
||||
@@ -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('<AboutCard /> 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',
|
||||
},
|
||||
|
||||
@@ -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' },
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user