Merge pull request #19860 from devonpaluso/owned-entity-picker
Restore functionality to OwnedEntityPicker
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Restored functionality to `OwnedEntityPicker` by converting deprecated `ui:options` input to `catalogFilter`.
|
||||
@@ -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;
|
||||
}
|
||||
>;
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<Autocomplete
|
||||
@@ -65,25 +65,46 @@ export const OwnedEntityPicker = (props: OwnedEntityPickerProps) => {
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<EntityPicker
|
||||
{...props}
|
||||
schema={{ title, description }}
|
||||
allowedKinds={allowedKinds}
|
||||
catalogFilter={
|
||||
allowedKinds
|
||||
? {
|
||||
filter: {
|
||||
kind: allowedKinds,
|
||||
[`relations.${RELATION_OWNED_BY}`]: identityRefs || [],
|
||||
},
|
||||
}
|
||||
: {
|
||||
filter: {
|
||||
[`relations.${RELATION_OWNED_BY}`]: identityRefs || [],
|
||||
},
|
||||
}
|
||||
}
|
||||
/>
|
||||
const entityPickerUISchema = buildEntityPickerUISchema(
|
||||
uiSchema,
|
||||
identityRefs,
|
||||
);
|
||||
|
||||
return <EntityPicker {...props} uiSchema={entityPickerUISchema} />;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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'),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user