From 048d7d5b4e543c4a20789e155ec744aa6959a42d Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Tue, 4 Mar 2025 16:30:07 +0100 Subject: [PATCH 1/2] feat: supporting additional kinds in subcomponents card Signed-off-by: benjdlambert --- plugins/catalog/report.api.md | 2 + .../HasSubcomponentsCard.test.tsx | 49 +++++++++++++++++++ .../HasSubcomponentsCard.tsx | 4 +- 3 files changed, 54 insertions(+), 1 deletion(-) 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 ( Date: Tue, 4 Mar 2025 16:31:06 +0100 Subject: [PATCH 2/2] chore: added chanteset Signed-off-by: benjdlambert --- .changeset/tiny-llamas-boil.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tiny-llamas-boil.md 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