diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index 6a13d78d14..64564f5ec4 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -74,7 +74,7 @@ function getSourceLocationForEntity( function getCodeLinkInfo(entity: Entity): CodeLinkInfo { const location = findLocationForEntityMeta(entity?.metadata); - const editUrl = findEditUrl(entity, location); + const editUrl = findEditUrl(entity); let sourceLocation = getSourceLocationForEntity(entity, location); if (location) { diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index ca40648ecb..7d693d1bc8 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -38,7 +38,6 @@ import { Chip } from '@material-ui/core'; import Edit from '@material-ui/icons/Edit'; import OpenInNew from '@material-ui/icons/OpenInNew'; import React from 'react'; -import { findLocationForEntityMeta } from '../../data/utils'; import { findViewUrl, findEditUrl } from '../actions'; import { favouriteEntityIcon, @@ -152,8 +151,7 @@ export const CatalogTable = ({ const actions: TableProps['actions'] = [ ({ entity }) => { - const location = findLocationForEntityMeta(entity.metadata); - const url = findViewUrl(entity, location); + const url = findViewUrl(entity); return { icon: () => , tooltip: 'View', @@ -164,8 +162,7 @@ export const CatalogTable = ({ }; }, ({ entity }) => { - const location = findLocationForEntityMeta(entity.metadata); - const url = findEditUrl(entity, location); + const url = findEditUrl(entity); return { icon: () => , tooltip: 'Edit', diff --git a/plugins/catalog/src/components/actions.ts b/plugins/catalog/src/components/actions.ts index 13e235d46e..72e1bf67ec 100644 --- a/plugins/catalog/src/components/actions.ts +++ b/plugins/catalog/src/components/actions.ts @@ -20,6 +20,7 @@ import { EDIT_URL_ANNOTATION, VIEW_URL_ANNOTATION, } from '@backstage/catalog-model'; +import { findLocationForEntityMeta } from '../data/utils'; import parseGitUrl from 'git-url-parse'; /** @@ -81,24 +82,21 @@ export const determineUrlType = (url: string): string => { return 'url'; }; -export const findEditUrl = ( - { metadata }: Entity, - location?: LocationSpec, -): string | undefined => { +export const findEditUrl = ({ metadata }: Entity): string | undefined => { const annotations = metadata.annotations || {}; const editUrl = annotations[EDIT_URL_ANNOTATION]; if (editUrl) return editUrl; + const location = findLocationForEntityMeta(metadata); + return location && createEditLink(location); }; -export const findViewUrl = ( - { metadata }: Entity, - location?: LocationSpec, -): string | undefined => { +export const findViewUrl = ({ metadata }: Entity): string | undefined => { const annotations = metadata.annotations || {}; + const location = findLocationForEntityMeta(metadata); return annotations[VIEW_URL_ANNOTATION] || location?.target; };