From 6bb6a7c7c31ee35611461e7508f984d5617eace8 Mon Sep 17 00:00:00 2001 From: Tim Hansen Date: Fri, 20 Dec 2024 08:04:26 -0700 Subject: [PATCH] Add FormDecoratorBlueprint Signed-off-by: Tim Hansen Co-authored-by: blam --- .../blueprints/FormDecoratorBlueprint.tsx | 41 +++++++++++++++++++ .../src/next/blueprints/index.ts | 1 + .../src/alpha/api/FormDecoratorsApi.ts | 12 +++--- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 plugins/scaffolder-react/src/next/blueprints/FormDecoratorBlueprint.tsx diff --git a/plugins/scaffolder-react/src/next/blueprints/FormDecoratorBlueprint.tsx b/plugins/scaffolder-react/src/next/blueprints/FormDecoratorBlueprint.tsx new file mode 100644 index 0000000000..73e55948bb --- /dev/null +++ b/plugins/scaffolder-react/src/next/blueprints/FormDecoratorBlueprint.tsx @@ -0,0 +1,41 @@ +/* + * 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 { + createExtensionBlueprint, + createExtensionDataRef, +} from '@backstage/frontend-plugin-api'; +import { ScaffolderFormDecorator } from '../extensions'; + +const formDecoratorExtensionDataRef = + createExtensionDataRef().with({ + id: 'scaffolder.form-decorator-loader', + }); + +/** + * @alpha + * Creates extensions that are Field Extensions for the Scaffolder + * */ +export const FormDecoratorBlueprint = createExtensionBlueprint({ + kind: 'scaffolder-form-decorator', + attachTo: { id: 'api:scaffolder/form-decorator', input: 'formDecorators' }, + dataRefs: { + formDecoratorLoader: formDecoratorExtensionDataRef, + }, + output: [formDecoratorExtensionDataRef], + *factory(params: { decorator: ScaffolderFormDecorator }) { + yield formDecoratorExtensionDataRef(params.decorator); + }, +}); diff --git a/plugins/scaffolder-react/src/next/blueprints/index.ts b/plugins/scaffolder-react/src/next/blueprints/index.ts index 165c583ac8..d9d0d2e0b3 100644 --- a/plugins/scaffolder-react/src/next/blueprints/index.ts +++ b/plugins/scaffolder-react/src/next/blueprints/index.ts @@ -14,5 +14,6 @@ * limitations under the License. */ +export * from './FormDecoratorBlueprint'; export * from './FormFieldBlueprint'; export * from './types'; diff --git a/plugins/scaffolder/src/alpha/api/FormDecoratorsApi.ts b/plugins/scaffolder/src/alpha/api/FormDecoratorsApi.ts index bc48ee3436..41bf91dba0 100644 --- a/plugins/scaffolder/src/alpha/api/FormDecoratorsApi.ts +++ b/plugins/scaffolder/src/alpha/api/FormDecoratorsApi.ts @@ -22,6 +22,7 @@ import { import { ScaffolderFormDecoratorsApi } from './types'; import { ScaffolderFormDecorator } from '@backstage/plugin-scaffolder-react/alpha'; import { formDecoratorsApiRef } from './ref'; +import { FormDecoratorBlueprint } from '@backstage/plugin-scaffolder-react/alpha'; /** @alpha */ export class DefaultScaffolderFormDecoratorsApi @@ -48,13 +49,14 @@ export class DefaultScaffolderFormDecoratorsApi export const formDecoratorsApi = ApiBlueprint.makeWithOverrides({ name: 'form-decorators', inputs: { - // TODO: this should come from the inputs that the form decorators use - formDecorators: createExtensionInput([]), + formDecorators: createExtensionInput([ + FormDecoratorBlueprint.dataRefs.formDecoratorLoader, + ]), }, factory(originalFactory, { inputs }) { - // TODO: this should come from the inputs that the form decorators use - const formDecorators = - inputs.formDecorators as unknown as ScaffolderFormDecorator[]; + const formDecorators = inputs.formDecorators.map(e => + e.get(FormDecoratorBlueprint.dataRefs.formDecoratorLoader), + ); return originalFactory({ factory: createApiFactory({