Use JsonSchema maxItems instead of defining a maxNoOfEntities prop
Signed-off-by: Raghunandan Balachandran <raghunandan@spotify.com>
This commit is contained in:
+3
-5
@@ -743,10 +743,7 @@ describe('<MultiEntityPicker />', () => {
|
||||
});
|
||||
|
||||
it('limit the number of selected entities when maxNoOfEntities is specified', async () => {
|
||||
const uiOptions = props.uiSchema['ui:options'];
|
||||
if (uiOptions) {
|
||||
uiOptions.maxNoOfEntities = 2;
|
||||
}
|
||||
props.schema.maxItems = 2;
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
<MultiEntityPicker {...props} />
|
||||
@@ -782,7 +779,8 @@ describe('<MultiEntityPicker />', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not limit the number of selected entities when maxNoOfEntities is not specified', async () => {
|
||||
it('does not limit the number of selected entities when maxItems is not specified', async () => {
|
||||
props.schema.maxItems = undefined;
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
<MultiEntityPicker {...props} />
|
||||
|
||||
@@ -93,8 +93,8 @@ export const MultiEntityPicker = (props: MultiEntityPickerProps) => {
|
||||
const allowArbitraryValues =
|
||||
uiSchema['ui:options']?.allowArbitraryValues ?? true;
|
||||
|
||||
// if not specified, default to undefined
|
||||
const maxNoOfEntities = uiSchema['ui:options']?.maxNoOfEntities ?? undefined;
|
||||
// if not specified, maxItems defaults to undefined
|
||||
const maxItems = props.schema.maxItems;
|
||||
|
||||
const onSelect = useCallback(
|
||||
(_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {
|
||||
@@ -164,7 +164,7 @@ export const MultiEntityPicker = (props: MultiEntityPickerProps) => {
|
||||
?.entityRef!
|
||||
}
|
||||
getOptionDisabled={_options =>
|
||||
maxNoOfEntities ? noOfItemsSelected >= maxNoOfEntities : false
|
||||
maxItems ? noOfItemsSelected >= maxItems : false
|
||||
}
|
||||
autoSelect
|
||||
freeSolo={allowArbitraryValues}
|
||||
|
||||
@@ -47,10 +47,6 @@ export const MultiEntityPickerFieldSchema = makeFieldSchemaFromZod(
|
||||
.or(entityQueryFilterExpressionSchema)
|
||||
.optional()
|
||||
.describe('List of key-value filter expression for entities'),
|
||||
maxNoOfEntities: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe('The maximum number of entities that can be selected'),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user