Merge pull request #29050 from backstage/blam/support-additional-types

Support additional `kind` prop to `Subcomponents` card
This commit is contained in:
Patrik Oldsberg
2025-03-04 17:25:02 +01:00
committed by GitHub
4 changed files with 59 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': minor
---
Allow providing `kind` parameters to replace the default `Component` kind for `SubComponents` card
+2
View File
@@ -577,6 +577,8 @@ export interface HasSubcomponentsCardProps {
// (undocumented)
columns?: TableColumn<ComponentEntity>[];
// (undocumented)
kind?: string;
// (undocumented)
tableOptions?: TableOptions;
// (undocumented)
title?: string;
@@ -117,4 +117,53 @@ describe('<HasSubcomponentsCard />', () => {
expect(screen.getByText(/target-name/i)).toBeInTheDocument();
});
});
it('allows overriding the entity kind', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-component',
namespace: 'my-namespace',
},
relations: [
{
targetRef: 'custom:my-namespace/target-name',
type: RELATION_HAS_PART,
},
],
};
catalogApi.getEntitiesByRefs.mockResolvedValue({
items: [
{
apiVersion: 'v1',
kind: 'Custom',
metadata: {
name: 'target-name',
namespace: 'my-namespace',
},
spec: {},
},
],
});
await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<HasSubcomponentsCard kind="Custom" />
</EntityProvider>
</Wrapper>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
await waitFor(() => {
expect(screen.getByText('Has subcomponents')).toBeInTheDocument();
expect(screen.getByText(/target-name/i)).toBeInTheDocument();
});
});
});
@@ -35,6 +35,7 @@ export interface HasSubcomponentsCardProps {
title?: string;
columns?: TableColumn<ComponentEntity>[];
tableOptions?: TableOptions;
kind?: string;
}
export function HasSubcomponentsCard(props: HasSubcomponentsCardProps) {
@@ -44,12 +45,13 @@ export function HasSubcomponentsCard(props: HasSubcomponentsCardProps) {
title = t('hasSubcomponentsCard.title'),
columns = componentEntityColumns,
tableOptions = {},
kind = 'Component',
} = props;
return (
<RelatedEntitiesCard
variant={variant}
title={title}
entityKind="Component"
entityKind={kind}
relationType={RELATION_HAS_PART}
columns={columns}
asRenderableEntities={asComponentEntities}