create a FormProps intersection type to augment next/Router props

Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
Paul Cowan
2022-12-19 16:46:32 +00:00
parent 0fb3edbda2
commit 1469f0b2de
7 changed files with 41 additions and 16 deletions
+7 -5
View File
@@ -11,7 +11,6 @@ import { BackstagePlugin } from '@backstage/core-plugin-api';
import { ComponentType } from 'react';
import { DiscoveryApi } from '@backstage/core-plugin-api';
import { Entity } from '@backstage/catalog-model';
import type { ErrorTransformer } from '@rjsf/utils';
import { Extension } from '@backstage/core-plugin-api';
import { ExternalRouteRef } from '@backstage/core-plugin-api';
import { FetchApi } from '@backstage/core-plugin-api';
@@ -19,7 +18,8 @@ import { FieldProps } from '@rjsf/core';
import { FieldProps as FieldProps_2 } from '@rjsf/utils';
import { FieldValidation } from '@rjsf/core';
import { FieldValidation as FieldValidation_2 } from '@rjsf/utils';
import type { FormProps } from '@rjsf/core';
import type { FormProps as FormProps_2 } from '@rjsf/core';
import type { FormProps as FormProps_3 } from '@rjsf/core-v5';
import { IdentityApi } from '@backstage/core-plugin-api';
import { JsonObject } from '@backstage/types';
import { JSONSchema7 } from 'json-schema';
@@ -167,6 +167,9 @@ export interface FieldSchema<TReturn, TUiOptions> {
readonly uiOptionsType: TUiOptions;
}
// @alpha
export type FormProps = Pick<FormProps_3, 'transformErrors'>;
// @public
export type LayoutComponent<_TInputProps> = () => null;
@@ -179,7 +182,7 @@ export interface LayoutOptions<P = any> {
}
// @public
export type LayoutTemplate<T = any> = FormProps<T>['ObjectFieldTemplate'];
export type LayoutTemplate<T = any> = FormProps_2<T>['ObjectFieldTemplate'];
// @public
export type ListActionsResponse = Array<{
@@ -264,8 +267,7 @@ export type NextRouterProps = {
TaskPageComponent?: React_2.ComponentType<{}>;
};
groups?: TemplateGroupFilter[];
transformErrors?: ErrorTransformer;
};
} & FormProps;
// @alpha
export const NextScaffolderPage: (
+1
View File
@@ -74,6 +74,7 @@ export type { TaskPageProps } from './components/TaskPage';
export { NextScaffolderPage } from './plugin';
export type { NextRouterProps } from './next';
export type { TemplateGroupFilter } from './next';
export type { FormProps } from './next';
export {
createNextScaffolderFieldExtension,
type NextCustomFieldValidator,
@@ -30,7 +30,7 @@ import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import { TemplateGroupFilter } from '../TemplateListPage/TemplateGroups';
import { nextSelectedTemplateRouteRef } from '../../routes';
import { SecretsContextProvider } from '../../components/secrets/SecretsContext';
import type { ErrorTransformer } from '@rjsf/utils';
import type { FormProps } from '../types';
/**
* The Props for the Scaffolder Router
@@ -45,8 +45,7 @@ export type NextRouterProps = {
TaskPageComponent?: React.ComponentType<{}>;
};
groups?: TemplateGroupFilter[];
transformErrors?: ErrorTransformer;
};
} & FormProps;
/**
* The Scaffolder Router
@@ -36,9 +36,9 @@ import { useTemplateSchema } from './useTemplateSchema';
import { ReviewState } from './ReviewState';
import validator from '@rjsf/validator-ajv8';
import { selectedTemplateRouteRef } from '../../../routes';
import type { ErrorTransformer } from '@rjsf/utils';
import { getDefaultFormState } from '@rjsf/utils';
import { useFormData } from './useFormData';
import { FormProps } from '../../types';
const useStyles = makeStyles(theme => ({
backButton: {
@@ -55,12 +55,11 @@ const useStyles = makeStyles(theme => ({
},
}));
export interface StepperProps {
export type StepperProps = {
manifest: TemplateParameterSchema;
extensions: NextFieldExtensionOptions<any, any>[];
onComplete: (values: Record<string, JsonValue>) => Promise<void>;
transformErrors?: ErrorTransformer;
}
} & FormProps;
// TODO(blam): We require here, as the types in this package depend on @rjsf/core explicitly
// which is what we're using here as the default types, it needs to depend on @rjsf/core-v5 because
@@ -44,12 +44,11 @@ import {
} from '../../routes';
import { SecretsContext } from '../../components/secrets/SecretsContext';
import { JsonValue } from '@backstage/types';
import type { ErrorTransformer } from '@rjsf/utils';
import type { FormProps } from '../types';
export interface TemplateWizardPageProps {
export type TemplateWizardPageProps = {
customFieldExtensions: NextFieldExtensionOptions<any, any>[];
transformErrors?: ErrorTransformer;
}
} & FormProps;
const useStyles = makeStyles<BackstageTheme>(() => ({
markdown: {
+2
View File
@@ -16,3 +16,5 @@
export * from './Router';
export * from './TemplateListPage';
export * from './TemplateWizardPage';
export type { FormProps } from './types';
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2022 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 type { FormProps as SchemaFormProps } from '@rjsf/core-v5';
/**
* Any `@rjsf/core` form properties that are publicly exposed to the `NextScaffolderpage`
*
* @alpha
*/
export type FormProps = Pick<SchemaFormProps, 'transformErrors'>;