From 3bd848159abde2c76632f4fe6b0195da2de6ed95 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Feb 2022 16:59:31 +0100 Subject: [PATCH 01/14] chore: updating type parameters names to be TReturnValue Signed-off-by: blam --- plugins/scaffolder/src/extensions/index.tsx | 4 ++-- plugins/scaffolder/src/extensions/types.ts | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/scaffolder/src/extensions/index.tsx b/plugins/scaffolder/src/extensions/index.tsx index f9c167a6b0..1b3b845b4d 100644 --- a/plugins/scaffolder/src/extensions/index.tsx +++ b/plugins/scaffolder/src/extensions/index.tsx @@ -25,8 +25,8 @@ import { Extension, attachComponentData } from '@backstage/core-plugin-api'; export const FIELD_EXTENSION_WRAPPER_KEY = 'scaffolder.extensions.wrapper.v1'; export const FIELD_EXTENSION_KEY = 'scaffolder.extensions.field.v1'; -export function createScaffolderFieldExtension( - options: FieldExtensionOptions, +export function createScaffolderFieldExtension( + options: FieldExtensionOptions, ): Extension<() => null> { return { expose() { diff --git a/plugins/scaffolder/src/extensions/types.ts b/plugins/scaffolder/src/extensions/types.ts index e1da9889e7..26fdbb1b23 100644 --- a/plugins/scaffolder/src/extensions/types.ts +++ b/plugins/scaffolder/src/extensions/types.ts @@ -21,13 +21,11 @@ import { FieldValidation, FieldProps } from '@rjsf/core'; * * @public */ -export type CustomFieldValidator = - | ((data: T, field: FieldValidation) => void) - | (( - data: T, - field: FieldValidation, - context: { apiHolder: ApiHolder }, - ) => void); +export type CustomFieldValidator = ( + data: TReturnValue, + field: FieldValidation, + context: { apiHolder: ApiHolder }, +) => void; /** * Type for the Custom Field Extension with the @@ -35,10 +33,10 @@ export type CustomFieldValidator = * * @public */ -export type FieldExtensionOptions = { +export type FieldExtensionOptions = { name: string; - component: (props: FieldProps) => JSX.Element | null; - validation?: CustomFieldValidator; + component: (props: FieldProps) => JSX.Element | null; + validation?: CustomFieldValidator; }; /** From 7517c93c09174ecd53553e2e901e5d4a04395ec0 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 22 Feb 2022 17:04:39 +0100 Subject: [PATCH 02/14] chore: using unknown type instead of any for declaring the return value Signed-off-by: blam --- plugins/scaffolder/api-report.md | 26 +++++---- plugins/scaffolder/src/extensions/default.ts | 57 ++++++++++---------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index 0a9145c780..3d2fa4982c 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -32,20 +32,18 @@ import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common'; // Warning: (ae-missing-release-tag) "createScaffolderFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export function createScaffolderFieldExtension( - options: FieldExtensionOptions, +export function createScaffolderFieldExtension( + options: FieldExtensionOptions, ): Extension<() => null>; // @public -export type CustomFieldValidator = - | ((data: T, field: FieldValidation) => void) - | (( - data: T, - field: FieldValidation, - context: { - apiHolder: ApiHolder; - }, - ) => void); +export type CustomFieldValidator = ( + data: TReturnValue, + field: FieldValidation, + context: { + apiHolder: ApiHolder; + }, +) => void; // Warning: (ae-missing-release-tag) "EntityNamePicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -106,10 +104,10 @@ export interface FieldExtensionComponentProps< } // @public -export type FieldExtensionOptions = { +export type FieldExtensionOptions = { name: string; - component: (props: FieldProps) => JSX.Element | null; - validation?: CustomFieldValidator; + component: (props: FieldProps) => JSX.Element | null; + validation?: CustomFieldValidator; }; // Warning: (ae-missing-release-tag) "OwnedEntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/plugins/scaffolder/src/extensions/default.ts b/plugins/scaffolder/src/extensions/default.ts index 820cc0e6d3..10c0746e41 100644 --- a/plugins/scaffolder/src/extensions/default.ts +++ b/plugins/scaffolder/src/extensions/default.ts @@ -27,31 +27,32 @@ import { import { FieldExtensionOptions } from './types'; import { OwnedEntityPicker } from '../components/fields/OwnedEntityPicker'; -export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS: FieldExtensionOptions[] = [ - { - component: EntityPicker, - name: 'EntityPicker', - }, - { - component: EntityNamePicker, - name: 'EntityNamePicker', - validation: entityNamePickerValidation, - }, - { - component: EntityTagsPicker, - name: 'EntityTagsPicker', - }, - { - component: RepoUrlPicker, - name: 'RepoUrlPicker', - validation: repoPickerValidation, - }, - { - component: OwnerPicker, - name: 'OwnerPicker', - }, - { - component: OwnedEntityPicker, - name: 'OwnedEntityPicker', - }, -]; +export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS: FieldExtensionOptions[] = + [ + { + component: EntityPicker, + name: 'EntityPicker', + }, + { + component: EntityNamePicker, + name: 'EntityNamePicker', + validation: entityNamePickerValidation, + }, + { + component: EntityTagsPicker, + name: 'EntityTagsPicker', + }, + { + component: RepoUrlPicker, + name: 'RepoUrlPicker', + validation: repoPickerValidation, + }, + { + component: OwnerPicker, + name: 'OwnerPicker', + }, + { + component: OwnedEntityPicker, + name: 'OwnedEntityPicker', + }, + ]; From 61d091e7051a0a2ab8ab2292214be55ba3a8b41e Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 08:31:47 +0100 Subject: [PATCH 03/14] chore: reworking these types a little bit now so that we can expose the uiSchema props in the api-report Signed-off-by: blam --- plugins/scaffolder/src/extensions/index.tsx | 9 ++++++--- plugins/scaffolder/src/extensions/types.ts | 17 ++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/scaffolder/src/extensions/index.tsx b/plugins/scaffolder/src/extensions/index.tsx index 1b3b845b4d..ad8177ef65 100644 --- a/plugins/scaffolder/src/extensions/index.tsx +++ b/plugins/scaffolder/src/extensions/index.tsx @@ -25,9 +25,12 @@ import { Extension, attachComponentData } from '@backstage/core-plugin-api'; export const FIELD_EXTENSION_WRAPPER_KEY = 'scaffolder.extensions.wrapper.v1'; export const FIELD_EXTENSION_KEY = 'scaffolder.extensions.field.v1'; -export function createScaffolderFieldExtension( - options: FieldExtensionOptions, -): Extension<() => null> { +export function createScaffolderFieldExtension< + TReturnValue = unknown, + TInputProps = unknown, +>( + options: FieldExtensionOptions, +): Extension { return { expose() { const FieldExtensionDataHolder: any = () => null; diff --git a/plugins/scaffolder/src/extensions/types.ts b/plugins/scaffolder/src/extensions/types.ts index 26fdbb1b23..1a48525b18 100644 --- a/plugins/scaffolder/src/extensions/types.ts +++ b/plugins/scaffolder/src/extensions/types.ts @@ -33,9 +33,12 @@ export type CustomFieldValidator = ( * * @public */ -export type FieldExtensionOptions = { +export type FieldExtensionOptions< + TReturnValue = unknown, + TProps = FieldProps, +> = { name: string; - component: (props: FieldProps) => JSX.Element | null; + component: (props: TProps) => JSX.Element | null; validation?: CustomFieldValidator; }; @@ -46,10 +49,10 @@ export type FieldExtensionOptions = { * @public */ export interface FieldExtensionComponentProps< - ReturnValue, - UiOptions extends {} = {}, -> extends FieldProps { - uiSchema: { - 'ui:options'?: UiOptions; + TReturnValue, + TUiOptions extends {} = {}, +> extends FieldProps { + uiSchema: FieldProps['uiSchema'] & { + 'ui:options'?: TUiOptions; }; } From 4bf93e6c29d348b932273c61024437decd7275c5 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 08:32:28 +0100 Subject: [PATCH 04/14] chore: reworking all the types for the different field extensions Signed-off-by: blam --- .../EntityNamePicker/EntityNamePicker.tsx | 4 +- .../fields/EntityPicker/EntityPicker.test.tsx | 36 +----------------- .../fields/EntityPicker/EntityPicker.tsx | 37 +++++++++++-------- .../components/fields/EntityPicker/index.ts | 1 + .../EntityTagsPicker/EntityTagsPicker.tsx | 16 ++++---- .../fields/EntityTagsPicker/index.ts | 1 + .../OwnedEntityPicker/OwnedEntityPicker.tsx | 34 +++++++++++------ .../fields/OwnedEntityPicker/index.ts | 1 + .../fields/OwnerPicker/OwnerPicker.tsx | 22 +++++++---- .../components/fields/OwnerPicker/index.ts | 1 + .../TextValuePicker/TextValuePicker.tsx | 4 +- .../scaffolder/src/components/fields/index.ts | 12 +++--- 12 files changed, 82 insertions(+), 87 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx index 8e7c0b0bea..f64c91b77f 100644 --- a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx @@ -14,12 +14,12 @@ * limitations under the License. */ import React from 'react'; -import { FieldProps } from '@rjsf/core'; import { TextValuePicker } from '../TextValuePicker'; +import { FieldExtensionComponentProps } from '../../../extensions'; export const EntityNamePicker = ({ schema: { title = 'Name', description = 'Unique name of the component' }, ...props -}: FieldProps) => ( +}: FieldExtensionComponentProps) => ( ); diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx index 82f12ac0a3..48e642cb44 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx @@ -20,7 +20,7 @@ import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; import { FieldProps } from '@rjsf/core'; import userEvent from '@testing-library/user-event'; import React from 'react'; -import { EntityPicker, allowArbitraryValues } from './EntityPicker'; +import { EntityPicker } from './EntityPicker'; const makeEntity = (kind: string, namespace: string, name: string): Entity => ({ apiVersion: 'backstage.io/v1beta1', @@ -136,37 +136,3 @@ describe('', () => { }); }); }); - -describe('allowArbitraryValues', () => { - describe('without ui:options', () => { - it('defaults to true', () => { - const uiSchema = {}; - const result = allowArbitraryValues(uiSchema); - expect(result).toBe(true); - }); - }); - - describe('without ui:options.allowArbitraryValues', () => { - it('defaults to true', () => { - const uiSchema = { 'ui:options': {} }; - const result = allowArbitraryValues(uiSchema); - expect(result).toBe(true); - }); - }); - - describe('with ui:options.allowArbitraryValues set to true', () => { - it('is true', () => { - const uiSchema = { 'ui:options': { allowArbitraryValues: true } }; - const result = allowArbitraryValues(uiSchema); - expect(result).toBe(true); - }); - }); - - describe('with ui:options.allowArbitraryValues set to false', () => { - it('is false', () => { - const uiSchema = { 'ui:options': { allowArbitraryValues: false } }; - const result = allowArbitraryValues(uiSchema); - expect(result).toBe(false); - }); - }); -}); diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx index 959e7883c0..3786d8d4a2 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx @@ -21,24 +21,31 @@ import { import { TextField } from '@material-ui/core'; import FormControl from '@material-ui/core/FormControl'; import Autocomplete from '@material-ui/lab/Autocomplete'; -import { FieldProps, UiSchema } from '@rjsf/core'; import React, { useCallback, useEffect } from 'react'; import useAsync from 'react-use/lib/useAsync'; +import { FieldExtensionComponentProps } from '../../../extensions'; -export const allowArbitraryValues = (uiSchema: UiSchema): boolean => - (uiSchema['ui:options']?.allowArbitraryValues as boolean) ?? true; +export interface EntityPickerUiOptions { + allowedKinds?: string[]; + defaultKind?: string; + allowArbitraryValues?: boolean; +} + +export const EntityPicker = ( + props: FieldExtensionComponentProps, +) => { + const { + onChange, + schema: { title = 'Entity', description = 'An entity from the catalog' }, + required, + uiSchema, + rawErrors, + formData, + idSchema, + } = props; + const allowedKinds = uiSchema['ui:options']?.allowedKinds ?? []; + const defaultKind = uiSchema['ui:options']?.defaultKind; -export const EntityPicker = ({ - onChange, - schema: { title = 'Entity', description = 'An entity from the catalog' }, - required, - uiSchema, - rawErrors, - formData, - idSchema, -}: FieldProps) => { - const allowedKinds = uiSchema['ui:options']?.allowedKinds as string[]; - const defaultKind = uiSchema['ui:options']?.defaultKind as string | undefined; const catalogApi = useApi(catalogApiRef); const { value: entities, loading } = useAsync(() => @@ -78,7 +85,7 @@ export const EntityPicker = ({ onChange={onSelect} options={entityRefs || []} autoSelect - freeSolo={allowArbitraryValues(uiSchema)} + freeSolo={uiSchema['ui:options']?.allowArbitraryValues} renderInput={params => ( ) => { +export const EntityTagsPicker = ( + props: FieldExtensionComponentProps, +) => { + const { formData, onChange, uiSchema } = props; const catalogApi = useApi(catalogApiRef); const [inputValue, setInputValue] = useState(''); const [inputError, setInputError] = useState(false); const tagValidator = makeValidator().isValidTag; - const kinds = uiSchema['ui:options']?.kinds as string[]; + const kinds = uiSchema['ui:options']?.kinds; const { loading, value: existingTags } = useAsync(async () => { const tagsRequest: GetEntitiesRequest = { fields: ['metadata.tags'] }; diff --git a/plugins/scaffolder/src/components/fields/EntityTagsPicker/index.ts b/plugins/scaffolder/src/components/fields/EntityTagsPicker/index.ts index 09f4d5c519..3ba36a2409 100644 --- a/plugins/scaffolder/src/components/fields/EntityTagsPicker/index.ts +++ b/plugins/scaffolder/src/components/fields/EntityTagsPicker/index.ts @@ -14,3 +14,4 @@ * limitations under the License. */ export { EntityTagsPicker } from './EntityTagsPicker'; +export type { EntityTagsPickerUiOptions } from './EntityTagsPicker'; diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx index 3c2fc2b495..71083b596e 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx @@ -20,20 +20,30 @@ import { import { TextField } from '@material-ui/core'; import FormControl from '@material-ui/core/FormControl'; import Autocomplete from '@material-ui/lab/Autocomplete'; -import { FieldProps } from '@rjsf/core'; import React from 'react'; -export const OwnedEntityPicker = ({ - onChange, - schema: { title = 'Entity', description = 'An entity from the catalog' }, - required, - uiSchema, - rawErrors, - formData, - idSchema, -}: FieldProps) => { - const allowedKinds = uiSchema['ui:options']?.allowedKinds as string[]; - const defaultKind = uiSchema['ui:options']?.defaultKind as string | undefined; +import { FieldExtensionComponentProps } from '../../../extensions'; + +export interface OwnedEntityPickerUiOptions { + allowedKinds?: string[]; + defaultKind?: string; +} + +export const OwnedEntityPicker = ( + props: FieldExtensionComponentProps, +) => { + const { + onChange, + schema: { title = 'Entity', description = 'An entity from the catalog' }, + required, + uiSchema, + rawErrors, + formData, + idSchema, + } = props; + + const allowedKinds = uiSchema['ui:options']?.allowedKinds; + const defaultKind = uiSchema['ui:options']?.defaultKind; const { ownedEntities, loading } = useOwnedEntities(allowedKinds); const entityRefs = ownedEntities?.items diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/index.ts b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/index.ts index 7cf5add6eb..125f6fdef0 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/index.ts +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/index.ts @@ -14,3 +14,4 @@ * limitations under the License. */ export { OwnedEntityPicker } from './OwnedEntityPicker'; +export type { OwnedEntityPickerUiOptions } from './OwnedEntityPicker'; diff --git a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx index dd02622ae9..cde1eba132 100644 --- a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx +++ b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx @@ -13,15 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { FieldProps } from '@rjsf/core'; import React from 'react'; import { EntityPicker } from '../EntityPicker'; +import { FieldExtensionComponentProps } from '../../../extensions'; + +export interface OwnerPickerUiOptions { + allowedKinds?: string[]; +} + +export const OwnerPicker = ( + props: FieldExtensionComponentProps, +) => { + const { + schema: { title = 'Owner', description = 'The owner of the component' }, + uiSchema, + ...restProps + } = props; -export const OwnerPicker = ({ - schema: { title = 'Owner', description = 'The owner of the component' }, - uiSchema, - ...props -}: FieldProps) => { const ownerUiSchema = { ...uiSchema, 'ui:options': { @@ -35,7 +43,7 @@ export const OwnerPicker = ({ return ( diff --git a/plugins/scaffolder/src/components/fields/OwnerPicker/index.ts b/plugins/scaffolder/src/components/fields/OwnerPicker/index.ts index 801ed59c93..b8cb97eb97 100644 --- a/plugins/scaffolder/src/components/fields/OwnerPicker/index.ts +++ b/plugins/scaffolder/src/components/fields/OwnerPicker/index.ts @@ -14,3 +14,4 @@ * limitations under the License. */ export { OwnerPicker } from './OwnerPicker'; +export type { OwnerPickerUiOptions } from './OwnerPicker'; diff --git a/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx b/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx index 7bed7eedb9..fe81649132 100644 --- a/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx +++ b/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx @@ -14,8 +14,8 @@ * limitations under the License. */ import { TextField } from '@material-ui/core'; -import { FieldProps } from '@rjsf/core'; import React from 'react'; +import { FieldExtensionComponentProps } from '../../../extensions'; export const TextValuePicker = ({ onChange, @@ -26,7 +26,7 @@ export const TextValuePicker = ({ uiSchema: { 'ui:autofocus': autoFocus }, idSchema, placeholder, -}: FieldProps) => ( +}: FieldExtensionComponentProps) => ( Date: Wed, 23 Feb 2022 08:32:49 +0100 Subject: [PATCH 05/14] chore: updating api report Signed-off-by: blam --- plugins/scaffolder/api-report.md | 149 ++++++++++++++----------------- plugins/scaffolder/src/index.ts | 11 +-- 2 files changed, 67 insertions(+), 93 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index 3d2fa4982c..d6a3edc1f2 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -32,9 +32,12 @@ import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common'; // Warning: (ae-missing-release-tag) "createScaffolderFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export function createScaffolderFieldExtension( - options: FieldExtensionOptions, -): Extension<() => null>; +export function createScaffolderFieldExtension< + TReturnValue = unknown, + TInputProps = unknown, +>( + options: FieldExtensionOptions, +): Extension; // @public export type CustomFieldValidator = ( @@ -45,46 +48,41 @@ export type CustomFieldValidator = ( }, ) => void; -// Warning: (ae-missing-release-tag) "EntityNamePicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const EntityNamePicker: ({ - schema: { title, description }, - ...props -}: FieldProps) => JSX.Element; - // Warning: (ae-missing-release-tag) "EntityNamePickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const EntityNamePickerFieldExtension: () => null; - -// Warning: (ae-missing-release-tag) "EntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const EntityPicker: ({ - onChange, - schema: { title, description }, - required, - uiSchema, - rawErrors, - formData, - idSchema, -}: FieldProps) => JSX.Element; +export const EntityNamePickerFieldExtension: FieldExtensionComponentProps< + string, + {} +>; // Warning: (ae-missing-release-tag) "EntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const EntityPickerFieldExtension: () => null; +export const EntityPickerFieldExtension: FieldExtensionComponentProps< + string, + EntityPickerUiOptions +>; -// @public -export const EntityTagsPicker: ({ - formData, - onChange, - uiSchema, -}: FieldProps) => JSX.Element; +// Warning: (ae-missing-release-tag) "EntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface EntityPickerUiOptions { + // (undocumented) + allowArbitraryValues?: boolean; + // (undocumented) + allowedKinds?: string[]; + // (undocumented) + defaultKind?: string; +} +// Warning: (ae-forgotten-export) The symbol "EntityTagsPickerUiOptions" needs to be exported by the entry point index.d.ts +// // @public -export const EntityTagsPickerFieldExtension: () => null; +export const EntityTagsPickerFieldExtension: FieldExtensionComponentProps< + string[], + EntityTagsPickerUiOptions +>; // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "FavouriteTemplate" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -94,65 +92,66 @@ export const FavouriteTemplate: (props: Props) => JSX.Element; // @public export interface FieldExtensionComponentProps< - ReturnValue, - UiOptions extends {} = {}, -> extends FieldProps { + TReturnValue, + TUiOptions extends {} = {}, +> extends FieldProps { // (undocumented) - uiSchema: { - 'ui:options'?: UiOptions; + uiSchema: FieldProps['uiSchema'] & { + 'ui:options'?: TUiOptions; }; } // @public -export type FieldExtensionOptions = { +export type FieldExtensionOptions< + TReturnValue = unknown, + TProps = FieldProps, +> = { name: string; - component: (props: FieldProps) => JSX.Element | null; + component: (props: TProps) => JSX.Element | null; validation?: CustomFieldValidator; }; -// Warning: (ae-missing-release-tag) "OwnedEntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const OwnedEntityPicker: ({ - onChange, - schema: { title, description }, - required, - uiSchema, - rawErrors, - formData, - idSchema, -}: FieldProps) => JSX.Element; - // Warning: (ae-missing-release-tag) "OwnedEntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const OwnedEntityPickerFieldExtension: () => null; +export const OwnedEntityPickerFieldExtension: FieldExtensionComponentProps< + string, + OwnedEntityPickerUiOptions +>; -// Warning: (ae-missing-release-tag) "OwnerPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "OwnedEntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const OwnerPicker: ({ - schema: { title, description }, - uiSchema, - ...props -}: FieldProps) => JSX.Element; +export interface OwnedEntityPickerUiOptions { + // (undocumented) + allowedKinds?: string[]; + // (undocumented) + defaultKind?: string; +} // Warning: (ae-missing-release-tag) "OwnerPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const OwnerPickerFieldExtension: () => null; +export const OwnerPickerFieldExtension: FieldExtensionComponentProps< + string, + OwnerPickerUiOptions +>; -// Warning: (ae-missing-release-tag) "RepoUrlPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "OwnerPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const RepoUrlPicker: ( - props: FieldExtensionComponentProps, -) => JSX.Element; +export interface OwnerPickerUiOptions { + // (undocumented) + allowedKinds?: string[]; +} // Warning: (ae-missing-release-tag) "RepoUrlPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const RepoUrlPickerFieldExtension: () => null; +export const RepoUrlPickerFieldExtension: FieldExtensionComponentProps< + string, + RepoUrlPickerUiOptions +>; // Warning: (ae-missing-release-tag) "RepoUrlPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -274,7 +273,7 @@ export const ScaffolderPage: ({ // Warning: (ae-missing-release-tag) "scaffolderPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -const scaffolderPlugin: BackstagePlugin< +export const scaffolderPlugin: BackstagePlugin< { root: RouteRef; }, @@ -282,8 +281,6 @@ const scaffolderPlugin: BackstagePlugin< registerComponent: ExternalRouteRef; } >; -export { scaffolderPlugin as plugin }; -export { scaffolderPlugin }; // @public export const TaskPage: ({ loadingText }: TaskPageProps) => JSX.Element; @@ -322,20 +319,6 @@ export type TemplateListProps = { // @public (undocumented) export const TemplateTypePicker: () => JSX.Element | null; -// Warning: (ae-missing-release-tag) "TextValuePicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const TextValuePicker: ({ - onChange, - required, - schema: { title, description }, - rawErrors, - formData, - uiSchema: { 'ui:autofocus': autoFocus }, - idSchema, - placeholder, -}: FieldProps) => JSX.Element; - // @public export const useTemplateSecrets: () => { setSecret: (input: Record) => void; diff --git a/plugins/scaffolder/src/index.ts b/plugins/scaffolder/src/index.ts index adb2aab035..34091b3fea 100644 --- a/plugins/scaffolder/src/index.ts +++ b/plugins/scaffolder/src/index.ts @@ -39,18 +39,9 @@ export { OwnedEntityPickerFieldExtension, RepoUrlPickerFieldExtension, ScaffolderPage, - scaffolderPlugin as plugin, scaffolderPlugin, } from './plugin'; -export { - EntityNamePicker, - EntityPicker, - EntityTagsPicker, - OwnerPicker, - RepoUrlPicker, - TextValuePicker, - OwnedEntityPicker, -} from './components/fields'; +export * from './components/fields'; export type { RepoUrlPickerUiOptions } from './components/fields'; export { FavouriteTemplate } from './components/FavouriteTemplate'; export { TemplateList } from './components/TemplateList'; From a2589000ee9db1ea5fe417d7b07353518e2db556 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 08:36:19 +0100 Subject: [PATCH 06/14] chore: added changesets Signed-off-by: blam --- .changeset/sharp-bottles-tan.md | 7 +++++++ .changeset/wise-jars-reflect.md | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/sharp-bottles-tan.md create mode 100644 .changeset/wise-jars-reflect.md diff --git a/.changeset/sharp-bottles-tan.md b/.changeset/sharp-bottles-tan.md new file mode 100644 index 0000000000..1fcd3dd380 --- /dev/null +++ b/.changeset/sharp-bottles-tan.md @@ -0,0 +1,7 @@ +--- +'@backstage/plugin-scaffolder': patch +--- + +- Reworking the `FieldExtensionComponentType` so we can export the `ui:schema:options` props in the `api-report.md`. +- Exporting all of the `UiOptions` types for the `FieldExtensions` so we can see them in the `api-report.md`. +- Removing the redundant type in the `CustomFieldValidator` union. diff --git a/.changeset/wise-jars-reflect.md b/.changeset/wise-jars-reflect.md new file mode 100644 index 0000000000..49e19e96df --- /dev/null +++ b/.changeset/wise-jars-reflect.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': minor +--- + +- **BREAKING** - Removed the `plugin` export, use `scaffolderPlugin` instead. From ce18146fa2cd66851dc9244879bb66f8cb8d1fdf Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 10:16:52 +0100 Subject: [PATCH 07/14] chore: removing text value picker Signed-off-by: blam --- .../scaffolder/customScaffolderExtensions.tsx | 34 ++++++++++++++- .../src/scaffolder/actions/builtin/helpers.ts | 1 + plugins/scaffolder/api-report.md | 10 ++++- .../EntityNamePicker/EntityNamePicker.tsx | 37 ++++++++++++---- .../TextValuePicker/TextValuePicker.tsx | 42 ------------------- .../fields/TextValuePicker/index.ts | 16 ------- 6 files changed, 71 insertions(+), 69 deletions(-) delete mode 100644 plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx delete mode 100644 plugins/scaffolder/src/components/fields/TextValuePicker/index.ts diff --git a/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx b/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx index 1c96e9325c..61407e2918 100644 --- a/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx +++ b/packages/app/src/components/scaffolder/customScaffolderExtensions.tsx @@ -13,14 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +import React from 'react'; import type { FieldValidation } from '@rjsf/core'; import { createScaffolderFieldExtension, - TextValuePicker, + FieldExtensionComponentProps, scaffolderPlugin, } from '@backstage/plugin-scaffolder'; +import { TextField } from '@material-ui/core'; + +const TextValuePicker = (props: FieldExtensionComponentProps) => { + const { + onChange, + required, + schema: { title, description }, + rawErrors, + formData, + uiSchema: { 'ui:autofocus': autoFocus }, + idSchema, + placeholder, + } = props; + + return ( + onChange(value)} + margin="normal" + error={rawErrors?.length > 0 && !formData} + inputProps={{ autoFocus }} + /> + ); +}; + export const LowerCaseValuePickerFieldExtension = scaffolderPlugin.provide( createScaffolderFieldExtension({ name: 'LowerCaseValuePicker', diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts index 7ee334a3f7..307ac5f9b8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts @@ -44,6 +44,7 @@ export const executeShellCommand = async (options: RunCommandOptions) => { options: spawnOptions, logStream = new PassThrough(), } = options; + console.log('in exec shell commabnd'); await new Promise((resolve, reject) => { const process = spawn(command, args, spawnOptions); diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index d6a3edc1f2..1865d28578 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -76,14 +76,20 @@ export interface EntityPickerUiOptions { defaultKind?: string; } -// Warning: (ae-forgotten-export) The symbol "EntityTagsPickerUiOptions" needs to be exported by the entry point index.d.ts -// // @public export const EntityTagsPickerFieldExtension: FieldExtensionComponentProps< string[], EntityTagsPickerUiOptions >; +// Warning: (ae-missing-release-tag) "EntityTagsPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface EntityTagsPickerUiOptions { + // (undocumented) + kinds?: string[]; +} + // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "FavouriteTemplate" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx index f64c91b77f..2b8817aa4b 100644 --- a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx @@ -14,12 +14,35 @@ * limitations under the License. */ import React from 'react'; -import { TextValuePicker } from '../TextValuePicker'; import { FieldExtensionComponentProps } from '../../../extensions'; +import { TextField } from '@material-ui/core'; -export const EntityNamePicker = ({ - schema: { title = 'Name', description = 'Unique name of the component' }, - ...props -}: FieldExtensionComponentProps) => ( - -); +export const EntityNamePicker = ( + props: FieldExtensionComponentProps, +) => { + const { + onChange, + required, + schema: { title = 'Name', description = 'Unique name of the component' }, + rawErrors, + formData, + uiSchema: { 'ui:autofocus': autoFocus }, + idSchema, + placeholder, + } = props; + + return ( + onChange(value)} + margin="normal" + error={rawErrors?.length > 0 && !formData} + inputProps={{ autoFocus }} + /> + ); +}; diff --git a/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx b/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx deleted file mode 100644 index fe81649132..0000000000 --- a/plugins/scaffolder/src/components/fields/TextValuePicker/TextValuePicker.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2021 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 { TextField } from '@material-ui/core'; -import React from 'react'; -import { FieldExtensionComponentProps } from '../../../extensions'; - -export const TextValuePicker = ({ - onChange, - required, - schema: { title, description }, - rawErrors, - formData, - uiSchema: { 'ui:autofocus': autoFocus }, - idSchema, - placeholder, -}: FieldExtensionComponentProps) => ( - onChange(value)} - margin="normal" - error={rawErrors?.length > 0 && !formData} - inputProps={{ autoFocus }} - /> -); diff --git a/plugins/scaffolder/src/components/fields/TextValuePicker/index.ts b/plugins/scaffolder/src/components/fields/TextValuePicker/index.ts deleted file mode 100644 index 8ab810b6ed..0000000000 --- a/plugins/scaffolder/src/components/fields/TextValuePicker/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2021 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 { TextValuePicker } from './TextValuePicker'; From ebdec41e447e42fbc9effaf14e81deb36f994e05 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 10:18:43 +0100 Subject: [PATCH 08/14] chore: updating changeset signed-off-by: blam --- .changeset/wise-jars-reflect.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/wise-jars-reflect.md b/.changeset/wise-jars-reflect.md index 49e19e96df..e23542cb17 100644 --- a/.changeset/wise-jars-reflect.md +++ b/.changeset/wise-jars-reflect.md @@ -3,3 +3,4 @@ --- - **BREAKING** - Removed the `plugin` export, use `scaffolderPlugin` instead. +- **BREAKING** - Removed the `TextValuePicker` component export, you can inline this component instead as it's a simple wrapper around a `TextField` from `@material-ui/core`. From b698a20195d8883abe3b7b18c8513fcbcbfa2b2e Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 10:41:07 +0100 Subject: [PATCH 09/14] hack to get something working Signed-off-by: blam --- plugins/scaffolder/api-report.md | 20 +++++++++++++------- plugins/scaffolder/src/extensions/index.tsx | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index 1865d28578..07b60c67db 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -37,7 +37,7 @@ export function createScaffolderFieldExtension< TInputProps = unknown, >( options: FieldExtensionOptions, -): Extension; +): Extension null)>; // @public export type CustomFieldValidator = ( @@ -54,7 +54,8 @@ export type CustomFieldValidator = ( export const EntityNamePickerFieldExtension: FieldExtensionComponentProps< string, {} ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "EntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -62,7 +63,8 @@ export const EntityNamePickerFieldExtension: FieldExtensionComponentProps< export const EntityPickerFieldExtension: FieldExtensionComponentProps< string, EntityPickerUiOptions ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "EntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -80,7 +82,8 @@ export interface EntityPickerUiOptions { export const EntityTagsPickerFieldExtension: FieldExtensionComponentProps< string[], EntityTagsPickerUiOptions ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "EntityTagsPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -123,7 +126,8 @@ export type FieldExtensionOptions< export const OwnedEntityPickerFieldExtension: FieldExtensionComponentProps< string, OwnedEntityPickerUiOptions ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "OwnedEntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -141,7 +145,8 @@ export interface OwnedEntityPickerUiOptions { export const OwnerPickerFieldExtension: FieldExtensionComponentProps< string, OwnerPickerUiOptions ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "OwnerPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -157,7 +162,8 @@ export interface OwnerPickerUiOptions { export const RepoUrlPickerFieldExtension: FieldExtensionComponentProps< string, RepoUrlPickerUiOptions ->; +> & + (() => null); // Warning: (ae-missing-release-tag) "RepoUrlPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/plugins/scaffolder/src/extensions/index.tsx b/plugins/scaffolder/src/extensions/index.tsx index ad8177ef65..55be17cb77 100644 --- a/plugins/scaffolder/src/extensions/index.tsx +++ b/plugins/scaffolder/src/extensions/index.tsx @@ -30,7 +30,8 @@ export function createScaffolderFieldExtension< TInputProps = unknown, >( options: FieldExtensionOptions, -): Extension { + // TODO: need know how to embed these types nicely so the api report looks nice. +): Extension null)> { return { expose() { const FieldExtensionDataHolder: any = () => null; From 3825dab8d9ec66963093cd4798f45a7151e798e3 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 11:39:53 +0100 Subject: [PATCH 10/14] chore: fix free solo Signed-off-by: blam --- .../fields/EntityPicker/EntityPicker.test.tsx | 11 ++++++----- .../components/fields/EntityPicker/EntityPicker.tsx | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx index 48e642cb44..942eef9d82 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx @@ -18,7 +18,7 @@ import { Entity } from '@backstage/catalog-model'; import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; import { FieldProps } from '@rjsf/core'; -import userEvent from '@testing-library/user-event'; +import { fireEvent } from '@testing-library/react'; import React from 'react'; import { EntityPicker } from './EntityPicker'; @@ -92,15 +92,16 @@ describe('', () => { }); it('updates even if there is not an exact match', async () => { - const { getByLabelText } = await renderInTestApp( + const { getByRole } = await renderInTestApp( , ); - const input = getByLabelText('Entity'); - userEvent.type(input, 'squ'); - input.blur(); + const input = getByRole('textbox'); + + fireEvent.change(input, { target: { value: 'squ' } }); + fireEvent.blur(input); expect(onChange).toHaveBeenCalledWith('squ'); }); diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx index 3786d8d4a2..e991d6d097 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx @@ -43,7 +43,7 @@ export const EntityPicker = ( formData, idSchema, } = props; - const allowedKinds = uiSchema['ui:options']?.allowedKinds ?? []; + const allowedKinds = uiSchema['ui:options']?.allowedKinds; const defaultKind = uiSchema['ui:options']?.defaultKind; const catalogApi = useApi(catalogApiRef); @@ -85,7 +85,7 @@ export const EntityPicker = ( onChange={onSelect} options={entityRefs || []} autoSelect - freeSolo={uiSchema['ui:options']?.allowArbitraryValues} + freeSolo={uiSchema['ui:options']?.allowArbitraryValues ?? true} renderInput={params => ( Date: Wed, 23 Feb 2022 15:18:09 +0100 Subject: [PATCH 11/14] chore: code review comments Signed-off-by: blam --- plugins/scaffolder/src/extensions/types.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder/src/extensions/types.ts b/plugins/scaffolder/src/extensions/types.ts index 1a48525b18..574ce7ea64 100644 --- a/plugins/scaffolder/src/extensions/types.ts +++ b/plugins/scaffolder/src/extensions/types.ts @@ -21,8 +21,8 @@ import { FieldValidation, FieldProps } from '@rjsf/core'; * * @public */ -export type CustomFieldValidator = ( - data: TReturnValue, +export type CustomFieldValidator = ( + data: TFieldReturnValue, field: FieldValidation, context: { apiHolder: ApiHolder }, ) => void; @@ -34,12 +34,12 @@ export type CustomFieldValidator = ( * @public */ export type FieldExtensionOptions< - TReturnValue = unknown, - TProps = FieldProps, + TFieldReturnValue = unknown, + TProps = FieldProps, > = { name: string; component: (props: TProps) => JSX.Element | null; - validation?: CustomFieldValidator; + validation?: CustomFieldValidator; }; /** @@ -49,9 +49,9 @@ export type FieldExtensionOptions< * @public */ export interface FieldExtensionComponentProps< - TReturnValue, + TFieldReturnValue, TUiOptions extends {} = {}, -> extends FieldProps { +> extends FieldProps { uiSchema: FieldProps['uiSchema'] & { 'ui:options'?: TUiOptions; }; From 8e6a8352727aabf24f4f1c7373ed0ef1032da7b0 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 23 Feb 2022 16:03:23 +0100 Subject: [PATCH 12/14] chore: changing types Signed-off-by: blam --- plugins/scaffolder/api-report.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index 07b60c67db..b38684c84e 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -40,8 +40,8 @@ export function createScaffolderFieldExtension< ): Extension null)>; // @public -export type CustomFieldValidator = ( - data: TReturnValue, +export type CustomFieldValidator = ( + data: TFieldReturnValue, field: FieldValidation, context: { apiHolder: ApiHolder; @@ -101,9 +101,9 @@ export const FavouriteTemplate: (props: Props) => JSX.Element; // @public export interface FieldExtensionComponentProps< - TReturnValue, + TFieldReturnValue, TUiOptions extends {} = {}, -> extends FieldProps { +> extends FieldProps { // (undocumented) uiSchema: FieldProps['uiSchema'] & { 'ui:options'?: TUiOptions; @@ -112,12 +112,12 @@ export interface FieldExtensionComponentProps< // @public export type FieldExtensionOptions< - TReturnValue = unknown, - TProps = FieldProps, + TFieldReturnValue = unknown, + TProps = FieldProps, > = { name: string; component: (props: TProps) => JSX.Element | null; - validation?: CustomFieldValidator; + validation?: CustomFieldValidator; }; // Warning: (ae-missing-release-tag) "OwnedEntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) From 209b13774c9ca90c0e6cd7a4f70bb34c7309975b Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Feb 2022 11:10:15 +0100 Subject: [PATCH 13/14] chore: fallback to just exporting the components as before for now, and work out how to embed the types later Signed-off-by: blam --- plugins/scaffolder/api-report.md | 84 ++++++++++++------- .../EntityNamePicker/EntityNamePicker.tsx | 3 + .../fields/EntityPicker/EntityPicker.tsx | 3 + .../EntityTagsPicker/EntityTagsPicker.tsx | 1 - .../OwnedEntityPicker/OwnedEntityPicker.tsx | 3 + .../fields/OwnerPicker/OwnerPicker.tsx | 3 + .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 3 + .../scaffolder/src/components/fields/index.ts | 10 +-- plugins/scaffolder/src/extensions/index.tsx | 3 +- 9 files changed, 75 insertions(+), 38 deletions(-) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index b38684c84e..fb3fd830f7 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -37,7 +37,7 @@ export function createScaffolderFieldExtension< TInputProps = unknown, >( options: FieldExtensionOptions, -): Extension null)>; +): Extension<() => null>; // @public export type CustomFieldValidator = ( @@ -51,20 +51,19 @@ export type CustomFieldValidator = ( // Warning: (ae-missing-release-tag) "EntityNamePickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const EntityNamePickerFieldExtension: FieldExtensionComponentProps< - string, - {} -> & - (() => null); +export const EntityNamePickerFieldExtension: () => null; + +// Warning: (ae-missing-release-tag) "EntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export const EntityPicker: ( + props: FieldExtensionComponentProps, +) => JSX.Element; // Warning: (ae-missing-release-tag) "EntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const EntityPickerFieldExtension: FieldExtensionComponentProps< - string, - EntityPickerUiOptions -> & - (() => null); +export const EntityPickerFieldExtension: () => null; // Warning: (ae-missing-release-tag) "EntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -78,12 +77,15 @@ export interface EntityPickerUiOptions { defaultKind?: string; } +// Warning: (ae-missing-release-tag) "EntityTagsPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// // @public -export const EntityTagsPickerFieldExtension: FieldExtensionComponentProps< - string[], - EntityTagsPickerUiOptions -> & - (() => null); +export const EntityTagsPicker: ( + props: FieldExtensionComponentProps, +) => JSX.Element; + +// @public +export const EntityTagsPickerFieldExtension: () => null; // Warning: (ae-missing-release-tag) "EntityTagsPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -120,14 +122,17 @@ export type FieldExtensionOptions< validation?: CustomFieldValidator; }; +// Warning: (ae-missing-release-tag) "OwnedEntityPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export const OwnedEntityPicker: ( + props: FieldExtensionComponentProps, +) => JSX.Element; + // Warning: (ae-missing-release-tag) "OwnedEntityPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const OwnedEntityPickerFieldExtension: FieldExtensionComponentProps< - string, - OwnedEntityPickerUiOptions -> & - (() => null); +export const OwnedEntityPickerFieldExtension: () => null; // Warning: (ae-missing-release-tag) "OwnedEntityPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -139,14 +144,17 @@ export interface OwnedEntityPickerUiOptions { defaultKind?: string; } +// Warning: (ae-missing-release-tag) "OwnerPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export const OwnerPicker: ( + props: FieldExtensionComponentProps, +) => JSX.Element; + // Warning: (ae-missing-release-tag) "OwnerPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const OwnerPickerFieldExtension: FieldExtensionComponentProps< - string, - OwnerPickerUiOptions -> & - (() => null); +export const OwnerPickerFieldExtension: () => null; // Warning: (ae-missing-release-tag) "OwnerPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -156,14 +164,28 @@ export interface OwnerPickerUiOptions { allowedKinds?: string[]; } +// Warning: (ae-missing-release-tag) "repoPickerValidation" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const repoPickerValidation: ( + value: string, + validation: FieldValidation, + context: { + apiHolder: ApiHolder; + }, +) => void; + +// Warning: (ae-missing-release-tag) "RepoUrlPicker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export const RepoUrlPicker: ( + props: FieldExtensionComponentProps, +) => JSX.Element; + // Warning: (ae-missing-release-tag) "RepoUrlPickerFieldExtension" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const RepoUrlPickerFieldExtension: FieldExtensionComponentProps< - string, - RepoUrlPickerUiOptions -> & - (() => null); +export const RepoUrlPickerFieldExtension: () => null; // Warning: (ae-missing-release-tag) "RepoUrlPickerUiOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx index 2b8817aa4b..802135a863 100644 --- a/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityNamePicker/EntityNamePicker.tsx @@ -17,6 +17,9 @@ import React from 'react'; import { FieldExtensionComponentProps } from '../../../extensions'; import { TextField } from '@material-ui/core'; +/** + * EntityName Picker + */ export const EntityNamePicker = ( props: FieldExtensionComponentProps, ) => { diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx index e991d6d097..31c44bfe97 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx @@ -31,6 +31,9 @@ export interface EntityPickerUiOptions { allowArbitraryValues?: boolean; } +/** + * Entity Picker + */ export const EntityPicker = ( props: FieldExtensionComponentProps, ) => { diff --git a/plugins/scaffolder/src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx b/plugins/scaffolder/src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx index 2d0acecbaf..41369a58eb 100644 --- a/plugins/scaffolder/src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx @@ -29,7 +29,6 @@ export interface EntityTagsPickerUiOptions { } /** * EntityTagsPicker - * @public */ export const EntityTagsPicker = ( props: FieldExtensionComponentProps, diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx index 71083b596e..80f63efaf9 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx @@ -29,6 +29,9 @@ export interface OwnedEntityPickerUiOptions { defaultKind?: string; } +/** + * Owned Entity Picker + */ export const OwnedEntityPicker = ( props: FieldExtensionComponentProps, ) => { diff --git a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx index cde1eba132..9012ed149e 100644 --- a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx +++ b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.tsx @@ -21,6 +21,9 @@ export interface OwnerPickerUiOptions { allowedKinds?: string[]; } +/** + * Owner Picker + */ export const OwnerPicker = ( props: FieldExtensionComponentProps, ) => { diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 1ccaed4e86..fe7c4b18a4 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -44,6 +44,9 @@ export interface RepoUrlPickerUiOptions { }; } +/** + * Repo Url Picker + */ export const RepoUrlPicker = ( props: FieldExtensionComponentProps, ) => { diff --git a/plugins/scaffolder/src/components/fields/index.ts b/plugins/scaffolder/src/components/fields/index.ts index 0d4de41493..6358934025 100644 --- a/plugins/scaffolder/src/components/fields/index.ts +++ b/plugins/scaffolder/src/components/fields/index.ts @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export type { EntityPickerUiOptions } from './EntityPicker'; -export type { OwnerPickerUiOptions } from './OwnerPicker'; -export type { RepoUrlPickerUiOptions } from './RepoUrlPicker'; -export type { OwnedEntityPickerUiOptions } from './OwnedEntityPicker'; -export type { EntityTagsPickerUiOptions } from './EntityTagsPicker'; +export * from './EntityPicker'; +export * from './OwnerPicker'; +export * from './RepoUrlPicker'; +export * from './OwnedEntityPicker'; +export * from './EntityTagsPicker'; diff --git a/plugins/scaffolder/src/extensions/index.tsx b/plugins/scaffolder/src/extensions/index.tsx index 55be17cb77..fd816681ea 100644 --- a/plugins/scaffolder/src/extensions/index.tsx +++ b/plugins/scaffolder/src/extensions/index.tsx @@ -31,7 +31,8 @@ export function createScaffolderFieldExtension< >( options: FieldExtensionOptions, // TODO: need know how to embed these types nicely so the api report looks nice. -): Extension null)> { + // then we can remove the export of the components +): Extension<() => null> { return { expose() { const FieldExtensionDataHolder: any = () => null; From ab30d1a8597b9f22500d28661e0772986bbb2d4d Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 24 Feb 2022 11:16:23 +0100 Subject: [PATCH 14/14] revert console Signed-off-by: blam --- .../scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts index 307ac5f9b8..7ee334a3f7 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts @@ -44,7 +44,6 @@ export const executeShellCommand = async (options: RunCommandOptions) => { options: spawnOptions, logStream = new PassThrough(), } = options; - console.log('in exec shell commabnd'); await new Promise((resolve, reject) => { const process = spawn(command, args, spawnOptions);