fix(data-templates): fix filter is empty (#2193)
This commit is contained in:
parent
817646d68d
commit
f44c5f3b4a
@ -2,7 +2,7 @@ import { LoadingOutlined } from '@ant-design/icons';
|
||||
import { connect, mapProps, mapReadPretty, useField, useFieldSchema, useForm } from '@formily/react';
|
||||
import { Divider, SelectProps, Tag } from 'antd';
|
||||
import flat from 'flat';
|
||||
import { uniqBy } from 'lodash';
|
||||
import _, { uniqBy } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { ResourceActionOptions, useRequest } from '../../../api-client';
|
||||
@ -11,7 +11,7 @@ import { mergeFilter } from '../../../block-provider/SharedFilterProvider';
|
||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||
import { getInnermostKeyAndValue } from '../../common/utils/uitls';
|
||||
import { useCompile } from '../../hooks';
|
||||
import { defaultFieldNames, Select } from '../select';
|
||||
import { Select, defaultFieldNames } from '../select';
|
||||
import { ReadPretty } from './ReadPretty';
|
||||
import { extractFilterfield, extractValuesByPattern, generatePattern, parseVariables } from './utils';
|
||||
const EMPTY = 'N/A';
|
||||
@ -122,7 +122,8 @@ const InternalRemoteSelect = connect(
|
||||
},
|
||||
[targetField?.uiSchema, fieldNames],
|
||||
);
|
||||
const parseFilter = (rules) => {
|
||||
const parseFilter = useCallback(
|
||||
(rules) => {
|
||||
if (!rules) {
|
||||
return undefined;
|
||||
}
|
||||
@ -173,7 +174,17 @@ const InternalRemoteSelect = connect(
|
||||
}
|
||||
});
|
||||
return { [type]: results };
|
||||
};
|
||||
},
|
||||
[ctx.props?.collection, field.path.segments, form.values, getCollectionJoinField],
|
||||
);
|
||||
|
||||
const filter = useMemo(() => {
|
||||
const filterFromSchema = _.isString(fieldSchema?.['x-component-props']?.service?.params?.filter)
|
||||
? field.componentProps?.service?.params?.filter
|
||||
: fieldSchema?.['x-component-props']?.service?.params?.filter;
|
||||
|
||||
return mergeFilter([parseFilter(filterFromSchema) || service?.params?.filter]);
|
||||
}, [field.componentProps?.service?.params?.filter, fieldSchema, parseFilter, service?.params?.filter]);
|
||||
|
||||
const { data, run, loading } = useRequest(
|
||||
{
|
||||
@ -183,9 +194,7 @@ const InternalRemoteSelect = connect(
|
||||
pageSize: 200,
|
||||
...service?.params,
|
||||
// search needs
|
||||
filter: mergeFilter([
|
||||
parseFilter(fieldSchema?.['x-component-props']?.service?.params?.filter) || service?.params?.filter,
|
||||
]),
|
||||
filter,
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -233,7 +242,7 @@ const InternalRemoteSelect = connect(
|
||||
},
|
||||
}
|
||||
: {},
|
||||
fieldSchema?.['x-component-props']?.service?.params?.filter || service?.params?.filter,
|
||||
filter,
|
||||
]),
|
||||
});
|
||||
searchData.current = search;
|
||||
|
Loading…
Reference in New Issue
Block a user