From 1f76587a10e20f896a72b961bff3ab80e3ece457 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Wed, 16 Jul 2025 12:21:47 +0200 Subject: [PATCH] feat: support `type` override in the `convertLegacyEntityCardExtension` Signed-off-by: benjdlambert --- .../convertLegacyEntityCardExtension.test.tsx | 40 ++++++++++++++++--- .../convertLegacyEntityCardExtension.tsx | 3 ++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.test.tsx b/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.test.tsx index 9e97412f92..fc7bed6281 100644 --- a/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.test.tsx +++ b/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.test.tsx @@ -26,7 +26,7 @@ import { import { screen } from '@testing-library/react'; import { convertLegacyEntityCardExtension } from './convertLegacyEntityCardExtension'; import { convertLegacyRouteRef } from '@backstage/core-compat-api'; -import { EntityContentBlueprint } from '../blueprints'; +import { EntityCardBlueprint } from '../blueprints'; const routeRef = createLegacyRouteRef({ id: 'test' }); const legacyPlugin = createLegacyPlugin({ @@ -60,12 +60,14 @@ describe('convertLegacyEntityCardExtension', () => { await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); - expect(tester.get(EntityContentBlueprint.dataRefs.filterExpression)).toBe( + expect(tester.get(EntityCardBlueprint.dataRefs.filterExpression)).toBe( undefined, ); - expect(tester.get(EntityContentBlueprint.dataRefs.filterFunction)).toBe( + expect(tester.get(EntityCardBlueprint.dataRefs.filterFunction)).toBe( undefined, ); + + expect(tester.get(EntityCardBlueprint.dataRefs.type)).toBe(undefined); }); it('should convert an entity card extension with overrides', async () => { @@ -94,10 +96,10 @@ describe('convertLegacyEntityCardExtension', () => { await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); - expect(tester.get(EntityContentBlueprint.dataRefs.filterExpression)).toBe( + expect(tester.get(EntityCardBlueprint.dataRefs.filterExpression)).toBe( 'my-filter', ); - expect(tester.get(EntityContentBlueprint.dataRefs.filterFunction)).toBe( + expect(tester.get(EntityCardBlueprint.dataRefs.filterFunction)).toBe( undefined, ); }); @@ -123,4 +125,32 @@ describe('convertLegacyEntityCardExtension', () => { expect(getDiscoveredId('EntityExAmpleCard')).toBe('entity-card:ex-ample'); expect(getDiscoveredId('ExampleCard')).toBe('entity-card:example-card'); }); + + it('should support the type override', async () => { + const LegacyExtension = legacyPlugin.provide( + createRoutableExtension({ + name: 'EntityExampleCard', + mountPoint: routeRef, + component: async () => () =>
Hello
, + }), + ); + + const converted = convertLegacyEntityCardExtension(LegacyExtension, { + type: 'info', + }); + + const tester = createExtensionTester(converted); + + expect(tester.query(converted).node.spec.id).toBe('entity-card:example'); + + await renderInTestApp(tester.reactElement(), { + mountedRoutes: { + '/': convertLegacyRouteRef(routeRef), + }, + }); + + await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); + + expect(tester.get(EntityCardBlueprint.dataRefs.type)).toBe('info'); + }); }); diff --git a/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.tsx b/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.tsx index fe0c386aea..9b343db469 100644 --- a/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.tsx +++ b/plugins/catalog-react/src/alpha/converters/convertLegacyEntityCardExtension.tsx @@ -22,6 +22,7 @@ import { EntityCardBlueprint } from '../blueprints/EntityCardBlueprint'; import kebabCase from 'lodash/kebabCase'; import { EntityPredicate } from '../predicates/types'; import { Entity } from '@backstage/catalog-model'; +import { EntityCardType } from '../blueprints/extensionData'; /** @alpha */ export function convertLegacyEntityCardExtension( @@ -29,6 +30,7 @@ export function convertLegacyEntityCardExtension( overrides?: { name?: string; filter?: string | EntityPredicate | ((entity: Entity) => boolean); + type?: EntityCardType; }, ): ExtensionDefinition { const element = ; @@ -63,6 +65,7 @@ export function convertLegacyEntityCardExtension( params: { filter: overrides?.filter, loader: async () => compatWrapper(element), + type: overrides?.type, }, }); }