diff --git a/.changeset/tiny-llamas-boil.md b/.changeset/tiny-llamas-boil.md new file mode 100644 index 0000000000..97c4ddb7fe --- /dev/null +++ b/.changeset/tiny-llamas-boil.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': minor +--- + +Allow providing `kind` parameters to replace the default `Component` kind for `SubComponents` card diff --git a/plugins/catalog/report.api.md b/plugins/catalog/report.api.md index 3692a919b3..05972eecad 100644 --- a/plugins/catalog/report.api.md +++ b/plugins/catalog/report.api.md @@ -577,6 +577,8 @@ export interface HasSubcomponentsCardProps { // (undocumented) columns?: TableColumn[]; // (undocumented) + kind?: string; + // (undocumented) tableOptions?: TableOptions; // (undocumented) title?: string; diff --git a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx index 07193b841f..2357a34dcd 100644 --- a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx +++ b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx @@ -117,4 +117,53 @@ describe('', () => { 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( + + + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, + ); + + await waitFor(() => { + expect(screen.getByText('Has subcomponents')).toBeInTheDocument(); + expect(screen.getByText(/target-name/i)).toBeInTheDocument(); + }); + }); }); diff --git a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.tsx b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.tsx index ceab037a45..c678e45c7c 100644 --- a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.tsx +++ b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.tsx @@ -35,6 +35,7 @@ export interface HasSubcomponentsCardProps { title?: string; columns?: TableColumn[]; 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 (