From 2e35947dae450a1289da7848473a41d0571e601a Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 30 Dec 2020 12:02:02 +0800 Subject: [PATCH] fix: Show the number of filters --- packages/app/src/components/actions/Filter.tsx | 4 ++-- packages/app/src/components/views/SimpleTable.tsx | 4 ++++ packages/app/src/components/views/Table.tsx | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/app/src/components/actions/Filter.tsx b/packages/app/src/components/actions/Filter.tsx index 14344fa52..5825b6dbf 100644 --- a/packages/app/src/components/actions/Filter.tsx +++ b/packages/app/src/components/actions/Filter.tsx @@ -8,7 +8,7 @@ export function Filter(props) { const drawerRef = useRef(); const [visible, setVisible] = useState(false); const { title, viewName, collection_name } = props.schema; - const { activeTab = {}, item = {}, associatedName, associatedKey } = props; + const { filterCount, activeTab = {}, item = {}, associatedName, associatedKey } = props; const { associationField } = activeTab; const params = {}; @@ -53,7 +53,7 @@ export function Filter(props) { > + }}>{filterCount ? `${filterCount} 个${title}项` : title} ) diff --git a/packages/app/src/components/views/SimpleTable.tsx b/packages/app/src/components/views/SimpleTable.tsx index d5571e620..0522d0ee4 100644 --- a/packages/app/src/components/views/SimpleTable.tsx +++ b/packages/app/src/components/views/SimpleTable.tsx @@ -31,6 +31,7 @@ export function SimpleTable(props: SimpleTableProps) { const { rowKey = 'id', name: viewName, actionDefaultParams = {}, fields = [], rowViewName, actions = [], paginated = true, defaultPerPage = 10 } = schema; const { sourceKey = 'id' } = activeTab.field||{}; const drawerRef = useRef(); + const [filterCount, setFilterCount] = useState(0); const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; const { data, loading, pagination, mutate, refresh, params, run } = useRequest((params = {}) => { const { current, pageSize, sorter, filter, ...restParams } = params; @@ -78,12 +79,15 @@ export function SimpleTable(props: SimpleTableProps) { {...props} style={{ marginBottom: 14 }} actions={actions} + filterCount={filterCount} onFinish={() => { refresh(); }} onTrigger={{ async filter(values) { console.log('filter', values); + const items = values.filter.and || values.filter.or; + setFilterCount(Object.keys(items).length); // @ts-ignore run({...params[0], filter: values.filter}); }, diff --git a/packages/app/src/components/views/Table.tsx b/packages/app/src/components/views/Table.tsx index c328984d1..ffde74709 100644 --- a/packages/app/src/components/views/Table.tsx +++ b/packages/app/src/components/views/Table.tsx @@ -30,6 +30,7 @@ export function Table(props: TableProps) { // const { data, mutate } = useRequest(() => api.resource(name).list({ // associatedKey, // })); + const [filterCount, setFilterCount] = useState(0); const name = associatedName ? `${associatedName}.${resourceName}` : resourceName; const { data, loading, pagination, mutate, refresh, run, params } = useRequest((params = {}, ...args) => { const { current, pageSize, sorter, filter, ...restParams } = params; @@ -78,6 +79,7 @@ export function Table(props: TableProps) { { @@ -85,6 +87,8 @@ export function Table(props: TableProps) { }} onTrigger={{ async filter(values) { + const items = values.filter.and || values.filter.or; + setFilterCount(Object.keys(items).length); // @ts-ignore run({...params[0], filter: values.filter}); console.log('filter', values);