diff --git a/.changeset/grumpy-bikes-beg.md b/.changeset/grumpy-bikes-beg.md new file mode 100644 index 0000000000..6fe44ee748 --- /dev/null +++ b/.changeset/grumpy-bikes-beg.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': patch +--- + +Restored functionality to `OwnedEntityPicker` by converting deprecated `ui:options` input to `catalogFilter`. diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index 59d2d54fcc..a776628da5 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -241,6 +241,24 @@ export const OwnedEntityPickerFieldExtension: FieldExtensionComponent_2< defaultKind?: string | undefined; allowArbitraryValues?: boolean | undefined; defaultNamespace?: string | false | undefined; + catalogFilter?: + | Record< + string, + | string + | string[] + | { + exists?: boolean | undefined; + } + > + | Record< + string, + | string + | string[] + | { + exists?: boolean | undefined; + } + >[] + | undefined; } >; @@ -252,6 +270,24 @@ export const OwnedEntityPickerFieldSchema: FieldSchema< defaultKind?: string | undefined; allowArbitraryValues?: boolean | undefined; defaultNamespace?: string | false | undefined; + catalogFilter?: + | Record< + string, + | string + | string[] + | { + exists?: boolean | undefined; + } + > + | Record< + string, + | string + | string[] + | { + exists?: boolean | undefined; + } + >[] + | undefined; } >; diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx index 0122f015a3..d7999c8c0c 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/OwnedEntityPicker.tsx @@ -22,6 +22,7 @@ import useAsync from 'react-use/lib/useAsync'; import { EntityPicker } from '../EntityPicker/EntityPicker'; import { OwnedEntityPickerProps } from './schema'; +import { EntityPickerProps } from '../EntityPicker/schema'; export { OwnedEntityPickerSchema } from './schema'; @@ -44,7 +45,6 @@ export const OwnedEntityPicker = (props: OwnedEntityPickerProps) => { return identity.ownershipEntityRefs; }); - const allowedKinds = uiSchema['ui:options']?.allowedKinds; if (loading) return ( { /> ); - return ( - + const entityPickerUISchema = buildEntityPickerUISchema( + uiSchema, + identityRefs, ); + + return ; }; + +/** + * Builds a `uiSchema` for an `EntityPicker` from a parent `OwnedEntityPicker`. + * Migrates deprecated parameters such as `allowedKinds` to `catalogFilter` structure. + * + * @param uiSchema The `uiSchema` of an `OwnedEntityPicker` component. + * @param identityRefs The user and group entities that the user claims ownership through. + * @returns The `uiSchema` for an `EntityPicker` component. + */ +function buildEntityPickerUISchema( + uiSchema: OwnedEntityPickerProps['uiSchema'], + identityRefs: string[] | undefined, +): EntityPickerProps['uiSchema'] { + // Note: This is typed to avoid es-lint rule TS2698 + const uiOptions: EntityPickerProps['uiSchema']['ui:options'] = + uiSchema?.['ui:options'] || {}; + const allowedKinds = uiOptions.allowedKinds; + + const catalogFilter = { + ...uiOptions.catalogFilter, + ...(allowedKinds + ? { + kind: allowedKinds, + [`relations.${RELATION_OWNED_BY}`]: identityRefs || [], + } + : { + [`relations.${RELATION_OWNED_BY}`]: identityRefs || [], + }), + }; + + return { + 'ui:options': { + catalogFilter, + }, + }; +} diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts index 4190b89f95..2bb75db263 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts @@ -15,6 +15,7 @@ */ import { z } from 'zod'; import { makeFieldSchemaFromZod } from '../utils'; +import { entityQueryFilterExpressionSchema } from '../EntityPicker/schema'; /** * @public @@ -25,7 +26,9 @@ export const OwnedEntityPickerFieldSchema = makeFieldSchemaFromZod( allowedKinds: z .array(z.string()) .optional() - .describe('List of kinds of entities to derive options from'), + .describe( + 'DEPRECATED: Use `catalogFilter` instead. List of kinds of entities to derive options from', + ), defaultKind: z .string() .optional() @@ -42,6 +45,11 @@ export const OwnedEntityPickerFieldSchema = makeFieldSchemaFromZod( .describe( 'The default namespace. Options with this namespace will not be prefixed.', ), + catalogFilter: z + .array(entityQueryFilterExpressionSchema) + .or(entityQueryFilterExpressionSchema) + .optional() + .describe('List of key-value filter expression for entities'), }), );