From aac1e45bc586467fbda1ed0f50cc19b3f32968ce Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 19 Nov 2024 09:51:15 +0100 Subject: [PATCH] chore: small cleanup Signed-off-by: blam --- .../createScaffolderFormDecorator.ts | 28 ++++++++----------- .../src/alpha/hooks/useFormDecorators.ts | 2 +- .../src/components/Router/Router.tsx | 1 - 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/plugins/scaffolder-react/src/next/extensions/createScaffolderFormDecorator.ts b/plugins/scaffolder-react/src/next/extensions/createScaffolderFormDecorator.ts index 20da932c05..2c0a43b24d 100644 --- a/plugins/scaffolder-react/src/next/extensions/createScaffolderFormDecorator.ts +++ b/plugins/scaffolder-react/src/next/extensions/createScaffolderFormDecorator.ts @@ -32,11 +32,8 @@ export type ScaffolderFormDecoratorContext = { /** @alpha */ export type ScaffolderFormDecorator< - TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {}, - TDeps extends { [key in string]: AnyApiRef } = { [key in string]: AnyApiRef }, - TInput extends {} = { - [key in keyof TInputSchema]: z.infer>; - }, + TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }, + TDeps extends { [key in string]: AnyApiRef }, > = { version: 'v1'; id: string; @@ -45,7 +42,9 @@ export type ScaffolderFormDecorator< }; deps?: TDeps; fn: ( - ctx: ScaffolderFormDecoratorContext, + ctx: ScaffolderFormDecoratorContext<{ + [key in keyof TInputSchema]: z.infer>; + }>, deps: TDeps extends { [key in string]: AnyApiRef } ? { [key in keyof TDeps]: TDeps[key]['T'] } : never, @@ -53,22 +52,15 @@ export type ScaffolderFormDecorator< }; /** @alpha */ -export type AnyScaffolderFormDecorator = ScaffolderFormDecorator< - { [key in string]: (zImpl: typeof z) => z.ZodType }, - { [key in string]: AnyApiRef }, - any ->; +export type AnyScaffolderFormDecorator = ScaffolderFormDecorator; /** * Method for creating decorators which can be used to collect * secrets from the user before submitting to the backend. * @alpha */ export function createScaffolderFormDecorator< - TDeps extends { [key in string]: AnyApiRef }, TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }, - TInput extends {} = { - [key in keyof TInputSchema]: z.infer>; - }, + TDeps extends { [key in string]: AnyApiRef }, >(options: { id: string; schema?: { @@ -76,12 +68,14 @@ export function createScaffolderFormDecorator< }; deps?: TDeps; fn: ( - ctx: ScaffolderFormDecoratorContext, + ctx: ScaffolderFormDecoratorContext<{ + [key in keyof TInputSchema]: z.infer>; + }>, deps: TDeps extends { [key in string]: AnyApiRef } ? { [key in keyof TDeps]: TDeps[key]['T'] } : never, ) => Promise; -}): ScaffolderFormDecorator { +}): ScaffolderFormDecorator { return { ...options, version: 'v1', diff --git a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts index 293c81996d..50fc6bfde0 100644 --- a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts +++ b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { useApi, useApiHolder } from '@backstage/core-plugin-api'; +import { AnyApiRef, useApi, useApiHolder } from '@backstage/core-plugin-api'; import { formDecoratorsApiRef } from '../api/ref'; import useAsync from 'react-use/esm/useAsync'; import { useMemo } from 'react'; diff --git a/plugins/scaffolder/src/components/Router/Router.tsx b/plugins/scaffolder/src/components/Router/Router.tsx index a02473b534..6c06322867 100644 --- a/plugins/scaffolder/src/components/Router/Router.tsx +++ b/plugins/scaffolder/src/components/Router/Router.tsx @@ -64,7 +64,6 @@ import { taskReadPermission, templateManagementPermission, } from '@backstage/plugin-scaffolder-common/alpha'; -import { ScaffolderFormHook } from '@backstage/plugin-scaffolder-react/alpha'; /** * The Props for the Scaffolder Router