remove entityQueryFilterExpressionSchema export; refactor DRY for specialized EntityPicker fields

Signed-off-by: Matt Benson <gudnabrsam@gmail.com>
This commit is contained in:
Matt Benson
2025-04-30 15:48:23 -05:00
parent 419163d48c
commit 65555af780
3 changed files with 8 additions and 48 deletions
@@ -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
*/
@@ -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
@@ -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;