scaffolder-react: migrate to use exports

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-16 00:46:59 +01:00
parent 817a5cde69
commit 2113984b96
13 changed files with 275 additions and 222 deletions
@@ -0,0 +1,225 @@
## API Report File for "@backstage/plugin-scaffolder-react"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="react" />
import { ApiHolder } from '@backstage/core-plugin-api';
import { ComponentType } from 'react';
import { CustomFieldExtensionSchema } from '@backstage/plugin-scaffolder-react';
import { Dispatch } from 'react';
import { Extension } from '@backstage/core-plugin-api';
import { FieldExtensionComponent } from '@backstage/plugin-scaffolder-react';
import { FieldProps } from '@rjsf/utils';
import { FieldValidation } from '@rjsf/utils';
import { FormProps as FormProps_2 } from '@rjsf/core-v5';
import { IconComponent } from '@backstage/core-plugin-api';
import { JsonObject } from '@backstage/types';
import { JsonValue } from '@backstage/types';
import { LayoutOptions } from '@backstage/plugin-scaffolder-react';
import { PropsWithChildren } from 'react';
import { default as React_2 } from 'react';
import { ReactNode } from 'react';
import { RJSFSchema } from '@rjsf/utils';
import { SetStateAction } from 'react';
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
import { UIOptionsType } from '@rjsf/utils';
import { UiSchema } from '@rjsf/utils';
// @alpha
export const createFieldValidation: () => FieldValidation;
// @alpha
export function createNextScaffolderFieldExtension<
TReturnValue = unknown,
TInputProps extends UIOptionsType = {},
>(
options: NextFieldExtensionOptions<TReturnValue, TInputProps>,
): Extension<FieldExtensionComponent<TReturnValue, TInputProps>>;
// @alpha
export const DefaultTemplateOutputs: (props: {
output?: ScaffolderTaskOutput;
}) => JSX.Element | null;
// @alpha (undocumented)
export const EmbeddableWorkflow: (props: WorkflowProps) => JSX.Element;
// @alpha
export const extractSchemaFromStep: (inputStep: JsonObject) => {
uiSchema: UiSchema;
schema: JsonObject;
};
// @alpha (undocumented)
export const Form: ComponentType<FormProps_2<any, RJSFSchema, any>>;
// @alpha
export type FormProps = Pick<
FormProps_2,
'transformErrors' | 'noHtml5Validate'
>;
// @alpha
export type NextCustomFieldValidator<TFieldReturnValue> = (
data: TFieldReturnValue,
field: FieldValidation,
context: {
apiHolder: ApiHolder;
formData: JsonObject;
schema: JsonObject;
},
) => void | Promise<void>;
// @alpha
export interface NextFieldExtensionComponentProps<
TFieldReturnValue,
TUiOptions = {},
> extends PropsWithChildren<FieldProps<TFieldReturnValue>> {
// (undocumented)
uiSchema?: UiSchema<TFieldReturnValue> & {
'ui:options'?: TUiOptions & UIOptionsType;
};
}
// @alpha
export type NextFieldExtensionOptions<
TFieldReturnValue = unknown,
TInputProps = unknown,
> = {
name: string;
component: (
props: NextFieldExtensionComponentProps<TFieldReturnValue, TInputProps>,
) => JSX.Element | null;
validation?: NextCustomFieldValidator<TFieldReturnValue>;
schema?: CustomFieldExtensionSchema;
};
// @alpha
export interface ParsedTemplateSchema {
// (undocumented)
description?: string;
// (undocumented)
mergedSchema: JsonObject;
// (undocumented)
schema: JsonObject;
// (undocumented)
title: string;
// (undocumented)
uiSchema: UiSchema;
}
// @alpha
export const ReviewState: (props: ReviewStateProps) => JSX.Element;
// @alpha
export type ReviewStateProps = {
schemas: ParsedTemplateSchema[];
formState: JsonObject;
};
// @alpha
export const Stepper: (stepperProps: StepperProps) => JSX.Element;
// @alpha
export type StepperProps = {
manifest: TemplateParameterSchema;
extensions: NextFieldExtensionOptions<any, any>[];
templateName?: string;
FormProps?: FormProps;
initialState?: Record<string, JsonValue>;
onCreate: (values: Record<string, JsonValue>) => Promise<void>;
components?: {
ReviewStateComponent?: (props: ReviewStateProps) => JSX.Element;
createButtonText?: ReactNode;
reviewButtonText?: ReactNode;
};
layouts?: LayoutOptions[];
};
// @alpha
export const TemplateCard: (props: TemplateCardProps) => JSX.Element;
// @alpha
export interface TemplateCardProps {
// (undocumented)
additionalLinks?: {
icon: IconComponent;
text: string;
url: string;
}[];
// (undocumented)
onSelected?: (template: TemplateEntityV1beta3) => void;
// (undocumented)
template: TemplateEntityV1beta3;
}
// @alpha
export const TemplateGroup: (props: TemplateGroupProps) => JSX.Element;
// @alpha
export interface TemplateGroupProps {
// (undocumented)
components?: {
CardComponent?: React_2.ComponentType<TemplateCardProps>;
};
// (undocumented)
onSelected: (template: TemplateEntityV1beta3) => void;
// (undocumented)
templates: {
template: TemplateEntityV1beta3;
additionalLinks?: {
icon: IconComponent;
text: string;
url: string;
}[];
}[];
// (undocumented)
title: React_2.ReactNode;
}
// @alpha
export const useFormDataFromQuery: (
initialState?: Record<string, JsonValue>,
) => [Record<string, any>, Dispatch<SetStateAction<Record<string, any>>>];
// @alpha (undocumented)
export const useTemplateParameterSchema: (templateRef: string) => {
manifest: TemplateParameterSchema;
loading: boolean;
error: Error | undefined;
};
// @alpha
export const useTemplateSchema: (manifest: TemplateParameterSchema) => {
steps: ParsedTemplateSchema[];
};
// @alpha (undocumented)
export const Workflow: (workflowProps: WorkflowProps) => JSX.Element | null;
// @alpha (undocumented)
export type WorkflowProps = {
title?: string;
description?: string;
namespace: string;
templateName: string;
onError(error: Error | undefined): JSX.Element | null;
} & Pick<
StepperProps,
| 'extensions'
| 'FormProps'
| 'components'
| 'onCreate'
| 'initialState'
| 'layouts'
>;
// Warnings were encountered during analysis:
//
// src/next/components/TemplateOutputs/DefaultTemplateOutputs.d.ts:9:5 - (ae-forgotten-export) The symbol "ScaffolderTaskOutput" needs to be exported by the entry point alpha.d.ts
// (No @packageDocumentation comment for this package)
```
+2 -202
View File
@@ -7,29 +7,18 @@
import { ApiHolder } from '@backstage/core-plugin-api';
import { ApiRef } from '@backstage/core-plugin-api';
import { ComponentType } from 'react';
import { Dispatch } from 'react';
import { Extension } from '@backstage/core-plugin-api';
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 { FormProps as FormProps_2 } from '@rjsf/core-v5';
import { IconComponent } from '@backstage/core-plugin-api';
import type { FormProps } from '@rjsf/core-v5';
import { JsonObject } from '@backstage/types';
import { JSONSchema7 } from 'json-schema';
import { JsonValue } from '@backstage/types';
import { Observable } from '@backstage/types';
import { PropsWithChildren } from 'react';
import { default as React_2 } from 'react';
import { ReactNode } from 'react';
import { RJSFSchema } from '@rjsf/utils';
import { SetStateAction } from 'react';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskStep } from '@backstage/plugin-scaffolder-common';
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import { UIOptionsType } from '@rjsf/utils';
import { UiSchema } from '@rjsf/utils';
// @public
export type Action = {
@@ -48,17 +37,6 @@ export type ActionExample = {
example: string;
};
// @alpha
export const createFieldValidation: () => FieldValidation_2;
// @alpha
export function createNextScaffolderFieldExtension<
TReturnValue = unknown,
TInputProps extends UIOptionsType = {},
>(
options: NextFieldExtensionOptions<TReturnValue, TInputProps>,
): Extension<FieldExtensionComponent<TReturnValue, TInputProps>>;
// @public
export function createScaffolderFieldExtension<
TReturnValue = unknown,
@@ -87,20 +65,6 @@ export type CustomFieldValidator<TFieldReturnValue> = (
},
) => void | Promise<void>;
// @alpha
export const DefaultTemplateOutputs: (props: {
output?: ScaffolderTaskOutput;
}) => JSX.Element | null;
// @alpha (undocumented)
export const EmbeddableWorkflow: (props: WorkflowProps) => JSX.Element;
// @alpha
export const extractSchemaFromStep: (inputStep: JsonObject) => {
uiSchema: UiSchema;
schema: JsonObject;
};
// @public
export type FieldExtensionComponent<_TReturnValue, _TInputProps> = () => null;
@@ -128,15 +92,6 @@ export type FieldExtensionOptions<
schema?: CustomFieldExtensionSchema;
};
// @alpha (undocumented)
export const Form: ComponentType<FormProps_2<any, RJSFSchema, any>>;
// @public
export type FormProps = Pick<
FormProps_2,
'transformErrors' | 'noHtml5Validate'
>;
// @public
export type LayoutComponent<_TInputProps> = () => null;
@@ -150,7 +105,7 @@ export interface LayoutOptions<P = any> {
// @public
export type LayoutTemplate<T = any> = NonNullable<
FormProps_2<T>['uiSchema']
FormProps<T>['uiSchema']
>['ui:ObjectFieldTemplate'];
// @public
@@ -169,64 +124,6 @@ export type LogEvent = {
taskId: string;
};
// @alpha
export type NextCustomFieldValidator<TFieldReturnValue> = (
data: TFieldReturnValue,
field: FieldValidation_2,
context: {
apiHolder: ApiHolder;
formData: JsonObject;
schema: JsonObject;
},
) => void | Promise<void>;
// @alpha
export interface NextFieldExtensionComponentProps<
TFieldReturnValue,
TUiOptions = {},
> extends PropsWithChildren<FieldProps_2<TFieldReturnValue>> {
// (undocumented)
uiSchema?: UiSchema<TFieldReturnValue> & {
'ui:options'?: TUiOptions & UIOptionsType;
};
}
// @alpha
export type NextFieldExtensionOptions<
TFieldReturnValue = unknown,
TInputProps = unknown,
> = {
name: string;
component: (
props: NextFieldExtensionComponentProps<TFieldReturnValue, TInputProps>,
) => JSX.Element | null;
validation?: NextCustomFieldValidator<TFieldReturnValue>;
schema?: CustomFieldExtensionSchema;
};
// @alpha
export interface ParsedTemplateSchema {
// (undocumented)
description?: string;
// (undocumented)
mergedSchema: JsonObject;
// (undocumented)
schema: JsonObject;
// (undocumented)
title: string;
// (undocumented)
uiSchema: UiSchema;
}
// @alpha
export const ReviewState: (props: ReviewStateProps) => JSX.Element;
// @alpha
export type ReviewStateProps = {
schemas: ParsedTemplateSchema[];
formState: JsonObject;
};
// @public
export interface ScaffolderApi {
// (undocumented)
@@ -380,66 +277,6 @@ export const SecretsContextProvider: ({
children,
}: PropsWithChildren<{}>) => JSX.Element;
// @alpha
export const Stepper: (stepperProps: StepperProps) => JSX.Element;
// @alpha
export type StepperProps = {
manifest: TemplateParameterSchema;
extensions: NextFieldExtensionOptions<any, any>[];
templateName?: string;
FormProps?: FormProps;
initialState?: Record<string, JsonValue>;
onCreate: (values: Record<string, JsonValue>) => Promise<void>;
components?: {
ReviewStateComponent?: (props: ReviewStateProps) => JSX.Element;
createButtonText?: ReactNode;
reviewButtonText?: ReactNode;
};
layouts?: LayoutOptions[];
};
// @alpha
export const TemplateCard: (props: TemplateCardProps) => JSX.Element;
// @alpha
export interface TemplateCardProps {
// (undocumented)
additionalLinks?: {
icon: IconComponent;
text: string;
url: string;
}[];
// (undocumented)
onSelected?: (template: TemplateEntityV1beta3) => void;
// (undocumented)
template: TemplateEntityV1beta3;
}
// @alpha
export const TemplateGroup: (props: TemplateGroupProps) => JSX.Element;
// @alpha
export interface TemplateGroupProps {
// (undocumented)
components?: {
CardComponent?: React_2.ComponentType<TemplateCardProps>;
};
// (undocumented)
onSelected: (template: TemplateEntityV1beta3) => void;
// (undocumented)
templates: {
template: TemplateEntityV1beta3;
additionalLinks?: {
icon: IconComponent;
text: string;
url: string;
}[];
}[];
// (undocumented)
title: React_2.ReactNode;
}
// @public
export type TemplateParameterSchema = {
title: string;
@@ -463,45 +300,8 @@ export const useCustomLayouts: <TComponentDataType = LayoutOptions<any>>(
outlet: React.ReactNode,
) => TComponentDataType[];
// @alpha
export const useFormDataFromQuery: (
initialState?: Record<string, JsonValue>,
) => [Record<string, any>, Dispatch<SetStateAction<Record<string, any>>>];
// @alpha (undocumented)
export const useTemplateParameterSchema: (templateRef: string) => {
manifest: TemplateParameterSchema | undefined;
loading: boolean;
error: Error | undefined;
};
// @alpha
export const useTemplateSchema: (manifest: TemplateParameterSchema) => {
steps: ParsedTemplateSchema[];
};
// @public
export const useTemplateSecrets: () => ScaffolderUseTemplateSecrets;
// @alpha (undocumented)
export const Workflow: (workflowProps: WorkflowProps) => JSX.Element | null;
// @alpha (undocumented)
export type WorkflowProps = {
title?: string;
description?: string;
namespace: string;
templateName: string;
onError(error: Error | undefined): JSX.Element | null;
} & Pick<
StepperProps,
| 'extensions'
| 'FormProps'
| 'components'
| 'onCreate'
| 'initialState'
| 'layouts'
>;
// (No @packageDocumentation comment for this package)
```
+17 -7
View File
@@ -6,10 +6,21 @@
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts",
"alphaTypes": "dist/index.alpha.d.ts"
"access": "public"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts"
},
"typesVersions": {
"*": {
"*": [
"src/index.ts"
],
"alpha": [
"src/alpha.ts"
]
}
},
"backstage": {
"role": "web-library"
@@ -24,7 +35,7 @@
"backstage"
],
"scripts": {
"build": "backstage-cli package build --experimental-type-build",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
@@ -80,7 +91,6 @@
"@testing-library/user-event": "^14.0.0"
},
"files": [
"dist",
"alpha"
"dist"
]
}
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
export * from './next';
export type { FormProps } from './next';
-2
View File
@@ -20,5 +20,3 @@ export * from './secrets';
export * from './api';
export * from './hooks';
export * from './layouts';
export * from './next';
@@ -26,7 +26,7 @@ import { type IChangeEvent } from '@rjsf/core-v5';
import { ErrorSchema } from '@rjsf/utils';
import React, { useCallback, useMemo, useState, type ReactNode } from 'react';
import { NextFieldExtensionOptions } from '../../extensions';
import { TemplateParameterSchema } from '../../../types';
import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
import {
createAsyncValidators,
type FormValidation,
@@ -36,7 +36,7 @@ import { useTemplateSchema } from '../../hooks/useTemplateSchema';
import validator from '@rjsf/validator-ajv8';
import { useFormDataFromQuery } from '../../hooks';
import { FormProps } from '../../types';
import { LayoutOptions } from '../../../layouts';
import { LayoutOptions } from '@backstage/plugin-scaffolder-react';
import { useTransformSchemaToProps } from '../../hooks/useTransformSchemaToProps';
import { hasErrors } from './utils';
import * as FieldOverrides from './FieldOverrides';
@@ -21,7 +21,8 @@ import {
} from './types';
import { Extension, attachComponentData } from '@backstage/core-plugin-api';
import { UIOptionsType } from '@rjsf/utils';
import { FieldExtensionComponent } from '../../extensions';
// eslint-disable-next-line import/no-extraneous-dependencies
import { FieldExtensionComponent } from '@backstage/plugin-scaffolder-react';
import { FIELD_EXTENSION_KEY } from '../../extensions/keys';
/**
@@ -22,7 +22,7 @@ import {
} from '@rjsf/utils';
import { PropsWithChildren } from 'react';
import { JsonObject } from '@backstage/types';
import { CustomFieldExtensionSchema } from '../../extensions';
import { CustomFieldExtensionSchema } from '@backstage/plugin-scaffolder-react';
/**
* Type for Field Extension Props for RJSF v5
@@ -1,5 +1,3 @@
import { useApi } from '@backstage/core-plugin-api';
/*
* Copyright 2023 The Backstage Authors
*
@@ -15,8 +13,11 @@ import { useApi } from '@backstage/core-plugin-api';
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import useAsync from 'react-use/lib/useAsync';
import { scaffolderApiRef } from '../../api/ref';
import { useApi } from '@backstage/core-plugin-api';
import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
/**
* @alpha
@@ -28,5 +29,5 @@ export const useTemplateParameterSchema = (templateRef: string) => {
[scaffolderApi, templateRef],
);
return { manifest: value, loading, error };
return { manifest: value as TemplateParameterSchema, loading, error };
};
@@ -18,7 +18,7 @@ import { renderHook } from '@testing-library/react-hooks';
import { TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { featureFlagsApiRef } from '@backstage/core-plugin-api';
import { TemplateParameterSchema } from '../../types';
import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
describe('useTemplateSchema', () => {
it('should generate the correct schema', () => {
@@ -16,7 +16,7 @@
import { featureFlagsApiRef, useApi } from '@backstage/core-plugin-api';
import { JsonObject } from '@backstage/types';
import { UiSchema } from '@rjsf/utils';
import { TemplateParameterSchema } from '../../types';
import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
import { extractSchemaFromStep } from '../lib';
/**
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { type ParsedTemplateSchema } from './useTemplateSchema';
import { type LayoutOptions } from '../../layouts';
import { type LayoutOptions } from '@backstage/plugin-scaffolder-react';
interface Options {
layouts?: LayoutOptions[];
+1 -1
View File
@@ -23,7 +23,7 @@ import type { FormProps as SchemaFormProps } from '@rjsf/core-v5';
/**
* Any `@rjsf/core` form properties that are publicly exposed to the `NextScaffolderpage`
*
* @public
* @alpha
*/
export type FormProps = Pick<
SchemaFormProps,