@@ -22,7 +22,7 @@ import { TextField } from '@material-ui/core';
|
||||
import FormControl from '@material-ui/core/FormControl';
|
||||
import Autocomplete from '@material-ui/lab/Autocomplete';
|
||||
import { FieldProps } from '@rjsf/core';
|
||||
import React from 'react';
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
|
||||
export const EntityPicker = ({
|
||||
@@ -48,9 +48,18 @@ export const EntityPicker = ({
|
||||
formatEntityRefTitle(e, { defaultKind }),
|
||||
);
|
||||
|
||||
const onSelect = (_: any, value: string | null) => {
|
||||
onChange(value || '');
|
||||
};
|
||||
const onSelect = useCallback(
|
||||
(_: any, value: string | null) => {
|
||||
onChange(value || '');
|
||||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (entityRefs?.length === 1) {
|
||||
onSelect('', entityRefs[0]);
|
||||
}
|
||||
}, [entityRefs, onSelect]);
|
||||
|
||||
return (
|
||||
<FormControl
|
||||
@@ -59,6 +68,7 @@ export const EntityPicker = ({
|
||||
error={rawErrors?.length > 0 && !formData}
|
||||
>
|
||||
<Autocomplete
|
||||
disabled={entityRefs?.length === 1}
|
||||
id={idSchema?.$id}
|
||||
value={(formData as string) || ''}
|
||||
loading={loading}
|
||||
|
||||
Reference in New Issue
Block a user