From c655a133a3b308a58fc199cbd0fd96907bc1cca5 Mon Sep 17 00:00:00 2001 From: Sebastian Qvarfordt Date: Fri, 5 Jun 2020 12:09:07 +0200 Subject: [PATCH 1/2] Slightly more robust edit link creation --- plugins/catalog/src/data/component.ts | 4 ++-- plugins/catalog/src/data/utils.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/catalog/src/data/component.ts b/plugins/catalog/src/data/component.ts index 692176a468..73b349391b 100644 --- a/plugins/catalog/src/data/component.ts +++ b/plugins/catalog/src/data/component.ts @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React from 'react'; +import { ReactNode } from 'react'; import { Location } from '@backstage/catalog-model'; export type Component = { name: string; kind: string; - description: React.ReactNode; + description: ReactNode; location?: Location; }; diff --git a/plugins/catalog/src/data/utils.tsx b/plugins/catalog/src/data/utils.tsx index 8c2476f867..5302fd75c2 100644 --- a/plugins/catalog/src/data/utils.tsx +++ b/plugins/catalog/src/data/utils.tsx @@ -25,7 +25,7 @@ const DescriptionWrapper = styled('span')({ alignItems: 'center', }); -const createEditLink = (url: string): string => url.replace('blob', 'edit'); +const createEditLink = (url: string): string => url.replace('/blob/', '/edit/'); export function envelopeToComponent( envelope: Entity, From bcb50c9325af02146da3ea20ca52595a5fba6145 Mon Sep 17 00:00:00 2001 From: Sebastian Qvarfordt Date: Fri, 5 Jun 2020 12:53:16 +0200 Subject: [PATCH 2/2] Different edit links depending on type. Only github for now though. --- plugins/catalog/src/data/utils.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/catalog/src/data/utils.tsx b/plugins/catalog/src/data/utils.tsx index 5302fd75c2..3f04883e34 100644 --- a/plugins/catalog/src/data/utils.tsx +++ b/plugins/catalog/src/data/utils.tsx @@ -25,7 +25,14 @@ const DescriptionWrapper = styled('span')({ alignItems: 'center', }); -const createEditLink = (url: string): string => url.replace('/blob/', '/edit/'); +const createEditLink = (location: Location): string => { + switch (location.type) { + case 'github': + return location.target.replace('/blob/', '/edit/'); + default: + return location.target; + } +}; export function envelopeToComponent( envelope: Entity, @@ -38,7 +45,7 @@ export function envelopeToComponent( {envelope.metadata?.annotations?.description ?? 'placeholder'} {location?.target ? ( - +