diff --git a/packages/frontend-app-api/src/wiring/createApp.tsx b/packages/frontend-app-api/src/wiring/createApp.tsx index decf0a657e..9a4f5bc303 100644 --- a/packages/frontend-app-api/src/wiring/createApp.tsx +++ b/packages/frontend-app-api/src/wiring/createApp.tsx @@ -174,13 +174,8 @@ export function createApp(options: { return { createRoot() { const rootComponents = rootInstances - .map( - e => - e.data.get( - coreExtensionData.reactComponent.id, - ) as typeof coreExtensionData.reactComponent.T, - ) - .filter(Boolean); + .map(e => e.getData(coreExtensionData.reactComponent)) + .filter((x): x is React.ComponentType => !!x); return ( @@ -254,13 +249,8 @@ function createApiHolder( const apiFactories = coreExtension.attachments .get('apis') - ?.map( - e => - e.data.get( - coreExtensionData.apiFactory.id, - ) as typeof coreExtensionData.apiFactory.T, - ) - .filter(Boolean) ?? []; + ?.map(e => e.getData(coreExtensionData.apiFactory)) + .filter((x): x is AnyApiFactory => !!x) ?? []; for (const factory of apiFactories) { factoryRegistry.register('default', factory); @@ -307,10 +297,8 @@ export function extractRouteInfoFromInstanceTree( const results = new Map(); function visit(current: ExtensionInstance, basePath: string) { - const routePath = current.data.get(coreExtensionData.routePath.id) ?? ''; - const routeRef = current.data.get( - coreExtensionData.routeRef.id, - ) as RouteRef; + const routePath = current.getData(coreExtensionData.routePath) ?? ''; + const routeRef = current.getData(coreExtensionData.routeRef); // TODO: join paths in a more robust way const fullPath = basePath + routePath; diff --git a/packages/frontend-app-api/src/wiring/createExtensionInstance.ts b/packages/frontend-app-api/src/wiring/createExtensionInstance.ts index d767f21d58..2cae60c1e6 100644 --- a/packages/frontend-app-api/src/wiring/createExtensionInstance.ts +++ b/packages/frontend-app-api/src/wiring/createExtensionInstance.ts @@ -14,16 +14,20 @@ * limitations under the License. */ -import { BackstagePlugin, Extension } from '@backstage/frontend-plugin-api'; +import { + BackstagePlugin, + Extension, + ExtensionDataRef, +} from '@backstage/frontend-plugin-api'; import mapValues from 'lodash/mapValues'; /** @internal */ export interface ExtensionInstance { readonly id: string; /** - * Maps extension data ref IDs to extensions produced. + * Get concrete value for the given extension data reference. Returns undefined if no value is available. */ - readonly data: Map; + getData(ref: ExtensionDataRef): T | undefined; /** * Maps input names to the actual instances given to them. */ @@ -70,7 +74,7 @@ export function createExtensionInstance(options: { ({ extensionData: pointData }, inputName) => { // TODO: validation return (attachments.get(inputName) ?? []).map(attachment => - mapValues(pointData, ref => attachment.data.get(ref.id)), + mapValues(pointData, ref => attachment.getData(ref)), ); }, ), @@ -83,7 +87,10 @@ export function createExtensionInstance(options: { return { id: options.extension.id, - data: extensionData, + getData(ref: ExtensionDataRef): T | undefined { + return extensionData.get(ref.id) as T | undefined; + }, + attachments, $$type: 'extension-instance', };