Allow custom edit and view source links on AboutCard

This commit is contained in:
James Turley
2021-02-16 15:40:32 +00:00
parent 0fc2a84352
commit a51094aac8
2 changed files with 48 additions and 7 deletions
@@ -123,3 +123,41 @@ describe('<AboutCard /> BitBucket', () => {
);
});
});
describe('<AboutCard /> custom links', () => {
it('renders info and "view source" link', () => {
const entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'software',
annotations: {
'backstage.io/managed-by-location':
'bitbucket:https://bitbucket.org/backstage/backstage/src/master/software.yaml',
'backstage.io/browser-edit-url': 'https://another.place',
'backstage.io/browser-source-url':
'https://another.place/backstage.git',
},
},
spec: {
owner: 'guest',
type: 'service',
lifecycle: 'production',
},
};
const { getByText } = render(
<EntityProvider entity={entity}>
<AboutCard />
</EntityProvider>,
);
expect(getByText('service')).toBeInTheDocument();
expect(getByText('View Source').closest('a')).toHaveAttribute(
'href',
'https://another.place/backstage.git',
);
expect(getByText('View Source').closest('a')).toHaveAttribute(
'edithref',
'https://another.place',
);
});
});
@@ -35,7 +35,7 @@ import ExtensionIcon from '@material-ui/icons/Extension';
import GitHubIcon from '@material-ui/icons/GitHub';
import React from 'react';
import { findLocationForEntityMeta } from '../../data/utils';
import { createEditLink, determineUrlType } from '../actions';
import { findEditUrl, determineUrlType } from '../actions';
import { AboutContent } from './AboutContent';
const useStyles = makeStyles({
@@ -61,19 +61,22 @@ type CodeLinkInfo = {
};
function getCodeLinkInfo(entity: Entity): CodeLinkInfo {
let sourceUrl =
entity.metadata?.annotations?.['backstage.io/browser-source-url'];
const location = findLocationForEntityMeta(entity?.metadata);
const editUrl = findEditUrl(entity, location);
if (location) {
sourceUrl = sourceUrl || location.target;
const type =
location.type === 'url'
? determineUrlType(location.target)
: location.type;
location.type === 'url' ? determineUrlType(sourceUrl) : location.type;
return {
edithref: editUrl,
icon: iconMap[type],
edithref: createEditLink(location),
href: location.target,
href: sourceUrl,
};
}
return {};
return { edithref: editUrl, href: sourceUrl };
}
type AboutCardProps = {