From 65555af78014d828b7a260a2815ab3e03d2fffec Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Wed, 30 Apr 2025 15:48:23 -0500 Subject: [PATCH] remove entityQueryFilterExpressionSchema export; refactor DRY for specialized EntityPicker fields Signed-off-by: Matt Benson --- .../components/fields/EntityPicker/schema.ts | 9 +---- .../fields/OwnedEntityPicker/schema.ts | 37 +------------------ .../components/fields/OwnerPicker/schema.ts | 10 ++--- 3 files changed, 8 insertions(+), 48 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/schema.ts b/plugins/scaffolder/src/components/fields/EntityPicker/schema.ts index 26e11d651f..5102d248b7 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/schema.ts +++ b/plugins/scaffolder/src/components/fields/EntityPicker/schema.ts @@ -16,7 +16,7 @@ import { z as zod } from 'zod'; import { makeFieldSchema } from '@backstage/plugin-scaffolder-react'; -const createEntityQueryFilterExpressionSchema = (z: typeof zod) => +export const createEntityQueryFilterExpressionSchema = (z: typeof zod) => z.record( z .string() @@ -24,13 +24,6 @@ const createEntityQueryFilterExpressionSchema = (z: typeof zod) => .or(z.array(z.string())), ); -/** - * @public - * @deprecated - */ -export const entityQueryFilterExpressionSchema = - createEntityQueryFilterExpressionSchema(zod); - /** * @public */ diff --git a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts index ad5ee34ce1..6dd00df49d 100644 --- a/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts +++ b/plugins/scaffolder/src/components/fields/OwnedEntityPicker/schema.ts @@ -13,45 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { entityQueryFilterExpressionSchema } from '../EntityPicker/schema'; -import { makeFieldSchema } from '@backstage/plugin-scaffolder-react'; +import { EntityPickerFieldSchema } from '../EntityPicker/schema'; /** * @public */ -export const OwnedEntityPickerFieldSchema = makeFieldSchema({ - output: z => z.string(), - uiOptions: z => - z.object({ - allowedKinds: z - .array(z.string()) - .optional() - .describe( - 'DEPRECATED: Use `catalogFilter` instead. List of kinds of entities to derive options from', - ), - defaultKind: z - .string() - .optional() - .describe( - 'The default entity kind. Options of this kind will not be prefixed.', - ), - allowArbitraryValues: z - .boolean() - .optional() - .describe('Whether to allow arbitrary user input. Defaults to true'), - defaultNamespace: z - .union([z.string(), z.literal(false)]) - .optional() - .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'), - }), -}); +export const OwnedEntityPickerFieldSchema = EntityPickerFieldSchema; /** * The input props that can be specified under `ui:options` for the diff --git a/plugins/scaffolder/src/components/fields/OwnerPicker/schema.ts b/plugins/scaffolder/src/components/fields/OwnerPicker/schema.ts index 3bcb63c91f..76389216ba 100644 --- a/plugins/scaffolder/src/components/fields/OwnerPicker/schema.ts +++ b/plugins/scaffolder/src/components/fields/OwnerPicker/schema.ts @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { entityQueryFilterExpressionSchema } from '../EntityPicker/schema'; import { makeFieldSchema } from '@backstage/plugin-scaffolder-react'; +import { createEntityQueryFilterExpressionSchema } from '../EntityPicker/schema'; /** * @public @@ -43,9 +43,9 @@ export const OwnerPickerFieldSchema = makeFieldSchema({ .describe( 'The default namespace. Options with this namespace will not be prefixed.', ), - catalogFilter: z - .array(entityQueryFilterExpressionSchema) - .or(entityQueryFilterExpressionSchema) + catalogFilter: (t => t.or(t.array()))( + createEntityQueryFilterExpressionSchema(z), + ) .optional() .describe('List of key-value filter expression for entities'), }), @@ -61,6 +61,6 @@ export type OwnerPickerUiOptions = NonNullable< (typeof OwnerPickerFieldSchema.TProps.uiSchema)['ui:options'] >; -export type OwnerPickerProps = typeof OwnerPickerFieldSchema.type; +export type OwnerPickerProps = typeof OwnerPickerFieldSchema.TProps; export const OwnerPickerSchema = OwnerPickerFieldSchema.schema;