feat: support type override in the convertLegacyEntityCardExtension

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-07-16 12:21:47 +02:00
parent 191e881f55
commit 1f76587a10
2 changed files with 38 additions and 5 deletions
@@ -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 () => () => <div>Hello</div>,
}),
);
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');
});
});
@@ -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 = <LegacyExtension />;
@@ -63,6 +65,7 @@ export function convertLegacyEntityCardExtension(
params: {
filter: overrides?.filter,
loader: async () => compatWrapper(element),
type: overrides?.type,
},
});
}