From e67a6862312469b6ce6ef8ca3b8c7f8b1de65bdb Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 7 Apr 2022 18:12:35 +0800 Subject: [PATCH] feat: add non-filterable config for the filter action --- .../client/src/block-provider/BlockProvider.tsx | 2 +- .../antd/filter/Filter.Action.Designer.tsx | 17 ++++++++--------- .../antd/filter/useFilterActionProps.ts | 11 +++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/client/src/block-provider/BlockProvider.tsx b/packages/client/src/block-provider/BlockProvider.tsx index 5ba7e5151..1ba482776 100644 --- a/packages/client/src/block-provider/BlockProvider.tsx +++ b/packages/client/src/block-provider/BlockProvider.tsx @@ -106,7 +106,7 @@ const BlockRequestProvider = (props) => { ); const __parent = useContext(BlockRequestContext); return ( - + {props.children} ); diff --git a/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx b/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx index 912f2f8e5..db2cf9af4 100644 --- a/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx +++ b/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx @@ -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 ( {fields.map((field) => { - const checked = fieldNames.includes(field.name); + const checked = !nonfilterable.includes(field.name); return ( { 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'], diff --git a/packages/client/src/schema-component/antd/filter/useFilterActionProps.ts b/packages/client/src/schema-component/antd/filter/useFilterActionProps.ts index 2190414a1..97e08e89d 100644 --- a/packages/client/src/schema-component/antd/filter/useFilterActionProps.ts +++ b/packages/client/src/schema-component/antd/filter/useFilterActionProps.ts @@ -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(); 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'); }, };