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