diff --git a/packages/frontend-plugin-api/src/extensions/ApiBlueprint.test.ts b/packages/frontend-plugin-api/src/extensions/ApiBlueprint.test.ts index 99369c6acd..c85c021c08 100644 --- a/packages/frontend-plugin-api/src/extensions/ApiBlueprint.test.ts +++ b/packages/frontend-plugin-api/src/extensions/ApiBlueprint.test.ts @@ -32,7 +32,27 @@ describe('ApiBlueprint', () => { }, }); - expect(extension).toMatchInlineSnapshot(); + expect(extension).toMatchInlineSnapshot(` + { + "$$type": "@backstage/ExtensionDefinition", + "attachTo": { + "id": "app", + "input": "apis", + }, + "configSchema": undefined, + "disabled": false, + "factory": [Function], + "inputs": {}, + "kind": "api", + "name": undefined, + "namespace": "test", + "output": [ + [Function], + ], + "toString": [Function], + "version": "v2", + } + `); }); it('should create an extension with custom factory', () => { @@ -48,19 +68,62 @@ describe('ApiBlueprint', () => { inputs: { test: createExtensionInput([ApiBlueprint.dataRefs.factory]), }, + namespace: api.id, factory(originalFactory, { config: _config, inputs: _inputs }) { return originalFactory({ - api, - factory: () => - createApiFactory({ - api, - deps: {}, - factory, - }), + factory: createApiFactory({ + api, + deps: {}, + factory, + }), }); }, }); - expect(extension).toMatchInlineSnapshot(); + expect(extension).toMatchInlineSnapshot(` + { + "$$type": "@backstage/ExtensionDefinition", + "attachTo": { + "id": "app", + "input": "apis", + }, + "configSchema": { + "parse": [Function], + "schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "additionalProperties": false, + "properties": { + "test": { + "default": "test", + "type": "string", + }, + }, + "type": "object", + }, + }, + "disabled": false, + "factory": [Function], + "inputs": { + "test": { + "$$type": "@backstage/ExtensionInput", + "config": { + "optional": false, + "singleton": false, + }, + "extensionData": [ + [Function], + ], + }, + }, + "kind": "api", + "name": undefined, + "namespace": "test", + "output": [ + [Function], + ], + "toString": [Function], + "version": "v2", + } + `); }); }); diff --git a/packages/frontend-plugin-api/src/extensions/ApiBlueprint.ts b/packages/frontend-plugin-api/src/extensions/ApiBlueprint.ts index dd2130f2cb..16a20b5130 100644 --- a/packages/frontend-plugin-api/src/extensions/ApiBlueprint.ts +++ b/packages/frontend-plugin-api/src/extensions/ApiBlueprint.ts @@ -15,7 +15,7 @@ */ import { createExtensionBlueprint } from '../wiring'; import { createApiExtension } from './createApiExtension'; -import { AnyApiFactory, AnyApiRef } from '@backstage/core-plugin-api'; +import { AnyApiFactory } from '@backstage/core-plugin-api'; export const ApiBlueprint = createExtensionBlueprint({ kind: 'api', @@ -24,27 +24,8 @@ export const ApiBlueprint = createExtensionBlueprint({ dataRefs: { factory: createApiExtension.factoryDataRef, }, - *factory( - params: // remove this form. - | { - api: AnyApiRef; - factory: (params: unknown) => AnyApiFactory; - } - | { - factory: AnyApiFactory; - }, - { config, inputs }, - ) { - yield createApiExtension.factoryDataRef( - typeof params.factory === 'function' - ? params.factory({ config, inputs }) - : params.factory, - ); - }, - namespace: params => { - const apiRef = - 'api' in params ? params.api : (params.factory as { api: AnyApiRef }).api; - - return apiRef.id; + *factory(params: { factory: AnyApiFactory }) { + yield createApiExtension.factoryDataRef(params.factory); }, + namespace: ({ factory }) => factory.api.id, }); diff --git a/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.test.tsx b/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.test.tsx new file mode 100644 index 0000000000..d9c7d296cc --- /dev/null +++ b/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.test.tsx @@ -0,0 +1,48 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { AppRootElementBlueprint } from './AppRootElementBlueprint'; + +describe('AppRootElementBlueprint', () => { + it('should create an extension with sensible defaults', () => { + const extension = AppRootElementBlueprint.make({ + params: { + element:
, + }, + }); + expect(extension).toMatchInlineSnapshot(` + { + "$$type": "@backstage/ExtensionDefinition", + "attachTo": { + "id": "app/root", + "input": "elements", + }, + "configSchema": undefined, + "disabled": false, + "factory": [Function], + "inputs": {}, + "kind": "app-root-element", + "name": undefined, + "namespace": undefined, + "output": [ + [Function], + ], + "toString": [Function], + "version": "v2", + } + `); + }); +}); diff --git a/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.ts b/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.ts new file mode 100644 index 0000000000..1048d531ab --- /dev/null +++ b/packages/frontend-plugin-api/src/extensions/AppRootElementBlueprint.ts @@ -0,0 +1,27 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { coreExtensionData, createExtensionBlueprint } from '../wiring'; + +export const AppRootElementBlueprint = createExtensionBlueprint({ + kind: 'app-root-element', + attachTo: { id: 'app/root', input: 'elements' }, + output: [coreExtensionData.reactElement], + *factory(params: { element: JSX.Element | (() => JSX.Element) }) { + yield coreExtensionData.reactElement( + typeof params.element === 'function' ? params.element() : params.element, + ); + }, +}); diff --git a/packages/frontend-plugin-api/src/extensions/ComponentBlueprint.tsx b/packages/frontend-plugin-api/src/extensions/ComponentBlueprint.tsx deleted file mode 100644 index 614196fc09..0000000000 --- a/packages/frontend-plugin-api/src/extensions/ComponentBlueprint.tsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2024 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { ComponentRef } from '../components'; -import { createExtensionBlueprint } from '../wiring'; -import { createComponentExtension } from './createComponentExtension'; -import { lazy, ComponentType } from 'react'; - -// this is hard to do with blueprints... no TProps for the elements -export const ComponentBlueprint = createExtensionBlueprint({ - kind: 'component', - attachTo: { id: 'app', input: 'components' }, - output: [createComponentExtension.componentDataRef], - dataRefs: { - component: createComponentExtension.componentDataRef, - }, - factory( - { - ref, - loader, - }: { - ref: ComponentRef