feat: add non-filterable config for the filter action
This commit is contained in:
parent
4e6d1d6fac
commit
e67a686231
@ -106,7 +106,7 @@ const BlockRequestProvider = (props) => {
|
||||
);
|
||||
const __parent = useContext(BlockRequestContext);
|
||||
return (
|
||||
<BlockRequestContext.Provider value={{ block: props.block, field, service, resource, __parent }}>
|
||||
<BlockRequestContext.Provider value={{ block: props.block, props, field, service, resource, __parent }}>
|
||||
{props.children}
|
||||
</BlockRequestContext.Provider>
|
||||
);
|
||||
|
@ -25,27 +25,26 @@ export const FilterActionDesigner = (props) => {
|
||||
const { dn } = useDesignable();
|
||||
const { name } = useCollection();
|
||||
const fields = useFilterableFields(name);
|
||||
const fieldNames = fieldSchema?.['x-component-props']?.fieldNames || [];
|
||||
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
||||
return (
|
||||
<GeneralSchemaDesigner {...props}>
|
||||
<SchemaSettings.ItemGroup title={'可筛选字段'}>
|
||||
{fields.map((field) => {
|
||||
const checked = fieldNames.includes(field.name);
|
||||
const checked = !nonfilterable.includes(field.name);
|
||||
return (
|
||||
<SchemaSettings.SwitchItem
|
||||
checked={checked}
|
||||
title={field?.uiSchema?.title}
|
||||
onChange={(value) => {
|
||||
fieldSchema['x-component-props'] = fieldSchema?.['x-component-props'] || {};
|
||||
const fieldNames = fieldSchema?.['x-component-props']?.fieldNames || [];
|
||||
console.log('fieldNames.checked', value)
|
||||
if (value) {
|
||||
fieldNames.push(field.name);
|
||||
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
||||
if (!value) {
|
||||
nonfilterable.push(field.name);
|
||||
} else {
|
||||
const index = fieldNames.indexOf(field.name);
|
||||
fieldNames.splice(index, 1);
|
||||
const index = nonfilterable.indexOf(field.name);
|
||||
nonfilterable.splice(index, 1);
|
||||
}
|
||||
fieldSchema['x-component-props'].fieldNames = fieldNames;
|
||||
fieldSchema['x-component-props'].nonfilterable = nonfilterable;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
|
@ -7,11 +7,11 @@ import { useCollection, useCollectionManager } from '../../../collection-manager
|
||||
|
||||
export const useFilterOptions = (collectionName: string) => {
|
||||
const fieldSchema = useFieldSchema();
|
||||
const fieldNames = fieldSchema?.['x-component-props']?.fieldNames || [];
|
||||
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
||||
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||
const fields = getCollectionFields(collectionName);
|
||||
const field2option = (field, nochildren) => {
|
||||
if (fieldNames.length && !nochildren && !fieldNames.includes(field.name)) {
|
||||
if (nonfilterable.length && !nochildren && nonfilterable.includes(field.name)) {
|
||||
return;
|
||||
}
|
||||
if (!field.interface) {
|
||||
@ -88,7 +88,7 @@ export const mergeFilter = (filter1, filter2) => {
|
||||
export const useFilterActionProps = () => {
|
||||
const { name } = useCollection();
|
||||
const options = useFilterOptions(name);
|
||||
const { service } = useBlockRequestContext();
|
||||
const { service, props } = useBlockRequestContext();
|
||||
const field = useField<Field>();
|
||||
const { t } = useTranslation();
|
||||
return {
|
||||
@ -105,9 +105,8 @@ export const useFilterActionProps = () => {
|
||||
}
|
||||
},
|
||||
onReset(values) {
|
||||
const filter = removeNullCondition(values?.filter);
|
||||
const f1 = service.params?.[0]?.filter;
|
||||
service.run({ ...service.params?.[0], filter: mergeFilter(f1, filter) });
|
||||
const filter = removeNullCondition(props.params.filter);
|
||||
service.run({ ...service.params?.[0], filter });
|
||||
field.title = t('Filter');
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user