Simplify URL lookup functions
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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<EntityRow>['actions'] = [
|
||||
({ entity }) => {
|
||||
const location = findLocationForEntityMeta(entity.metadata);
|
||||
const url = findViewUrl(entity, location);
|
||||
const url = findViewUrl(entity);
|
||||
return {
|
||||
icon: () => <OpenInNew fontSize="small" />,
|
||||
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: () => <Edit fontSize="small" />,
|
||||
tooltip: 'Edit',
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user