fix: various fixes and tweaks (#701)
This commit is contained in:
committed by
GitHub
parent
422b7798da
commit
364612e9ae
@ -293,7 +293,7 @@ const ListControl: FC<WidgetControlProps<ValueOrNestedValue[], ListField>> = ({
|
||||
[onChange, internalValue, keys],
|
||||
);
|
||||
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n);
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n, false);
|
||||
|
||||
if (valueType === null) {
|
||||
return null;
|
||||
|
@ -165,7 +165,7 @@ const ListItem: FC<ListItemProps> = ({
|
||||
}
|
||||
}, [entry, field, index, value, valueType]);
|
||||
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n);
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n, false);
|
||||
|
||||
const finalValue = useMemo(() => {
|
||||
if (field.fields && field.fields.length === 1) {
|
||||
|
@ -31,7 +31,7 @@ const ObjectControl: FC<WidgetControlProps<ObjectValue, ObjectField>> = ({
|
||||
|
||||
const fields = useMemo(() => field.fields, [field.fields]);
|
||||
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n);
|
||||
const hasChildErrors = useHasChildErrors(path, fieldsErrors, i18n, false);
|
||||
|
||||
const renderedField = useMemo(() => {
|
||||
return (
|
||||
|
@ -179,11 +179,15 @@ const RelationControl: FC<WidgetControlProps<string | string[], RelationField>>
|
||||
);
|
||||
|
||||
const [options, setOptions] = useState<HitOption[]>([]);
|
||||
const [entries, setEntries] = useState<Entry[]>([]);
|
||||
const loading = useMemo(() => options.length === 0, [options.length]);
|
||||
const [entries, setEntries] = useState<Entry[] | null>(null);
|
||||
const loading = useMemo(() => !entries, [entries]);
|
||||
|
||||
const filterOptions = useCallback(
|
||||
(inputValue: string) => {
|
||||
if (!entries) {
|
||||
return;
|
||||
}
|
||||
|
||||
const searchFields = field.search_fields;
|
||||
const limit = field.options_length || DEFAULT_OPTIONS_LIMIT;
|
||||
const expandedEntries = expandSearchEntries(entries, searchFields);
|
||||
@ -334,6 +338,7 @@ const RelationControl: FC<WidgetControlProps<string | string[], RelationField>>
|
||||
key="loading-indicator"
|
||||
className="absolute inset-y-0 right-4 flex items-center pr-2"
|
||||
data-testid="relation-loading-indicator"
|
||||
size="small"
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
|
@ -306,6 +306,21 @@ describe(RelationControl.name, () => {
|
||||
expect(queryByTestId('relation-loading-indicator')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should stop showing loading indicator if no entries found', async () => {
|
||||
mockListAllEntries.mockReturnValue([]);
|
||||
const { getByTestId, queryByTestId } = renderControl({ value: 'Post 1' });
|
||||
|
||||
const input = getByTestId('autocomplete-input');
|
||||
|
||||
expect(input).toHaveValue('');
|
||||
|
||||
getByTestId('relation-loading-indicator');
|
||||
|
||||
await waitFor(() =>
|
||||
expect(queryByTestId('relation-loading-indicator')).not.toBeInTheDocument(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should not try to load entiries if search collection does not exist', () => {
|
||||
const field: RelationField = {
|
||||
label: 'Relation',
|
||||
|
Reference in New Issue
Block a user