feat: allow custom title for DomainCard

Signed-off-by: Chris Langhout <clanghout@bol.com>
This commit is contained in:
Chris Langhout
2023-04-25 10:49:06 +02:00
parent 16685cf8a2
commit 36a0f6e0a6
2 changed files with 32 additions and 2 deletions
@@ -51,4 +51,31 @@ describe('<DomainCard />', () => {
'/catalog/default/domain/artists',
);
});
it('renders a domain card with custom title', async () => {
const entity: DomainEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Domain',
metadata: {
name: 'artists',
},
spec: {
owner: 'guest',
},
};
const { getByText } = await renderInTestApp(
<DomainCard entity={entity} title="my Custom Title" />,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(getByText('Explore').parentElement).toHaveAttribute(
'href',
'/catalog/default/domain/artists',
);
expect(getByText('my Custom Title')).toBeInTheDocument();
});
});
@@ -35,7 +35,7 @@ import { LinkButton, ItemCardHeader } from '@backstage/core-components';
import { useRouteRef } from '@backstage/core-plugin-api';
/** @public */
export const DomainCard = (props: { entity: DomainEntity }) => {
export const DomainCard = (props: { entity: DomainEntity; title?: string }) => {
const { entity } = props;
const catalogEntityRoute = useRouteRef(entityRouteRef);
@@ -53,7 +53,10 @@ export const DomainCard = (props: { entity: DomainEntity }) => {
return (
<Card>
<CardMedia>
<ItemCardHeader title={entity.metadata.name} subtitle={owner} />
<ItemCardHeader
title={props.title ?? entity.metadata.name}
subtitle={owner}
/>
</CardMedia>
<CardContent>
{entity.metadata.tags?.length ? (