From 1d6417f7f9a5b5ed7a4d2ce528efbabe91dc0758 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 7 Apr 2023 16:48:32 +0800 Subject: [PATCH] feat: support tableoid filter (#1657) * feat: support inherited collection filter * refactor: improve translation * chore: filter inherted collectiion * feat: data scope support inherited collection filter --- .../src/collection-manager/action-hooks.ts | 44 ++++++++++++++++++- packages/core/client/src/locale/en_US.ts | 1 + packages/core/client/src/locale/ja_JP.ts | 1 + packages/core/client/src/locale/zh_CN.ts | 1 + .../antd/filter/FilterItem.tsx | 2 +- .../antd/filter/useFilterActionProps.ts | 44 ++++++++++++++++++- 6 files changed, 90 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/collection-manager/action-hooks.ts b/packages/core/client/src/collection-manager/action-hooks.ts index 2f63dfba3..9a182e36d 100644 --- a/packages/core/client/src/collection-manager/action-hooks.ts +++ b/packages/core/client/src/collection-manager/action-hooks.ts @@ -5,6 +5,7 @@ import { useEffect } from 'react'; import { useCollection, useCollectionManager } from '.'; import { useRequest } from '../api-client'; import { useRecord } from '../record-provider'; +import { useCompile } from '..'; import { useActionContext } from '../schema-component'; import { useFilterFieldOptions, useFilterFieldProps } from '../schema-component/antd/filter/useFilterActionProps'; import { useResourceActionContext, useResourceContext } from './ResourceActionProvider'; @@ -155,7 +156,48 @@ export const useCollectionFilterOptions = (collectionName: string) => { }); return options; }; - return getOptions(fields, 1); + const options = getOptions(fields, 1); + const compile = useCompile(); + const { getChildrenCollections } = useCollectionManager(); + const collection = useCollection(); + const childrenCollections = getChildrenCollections(collection.name); + if (childrenCollections.length > 0 && !options.find((v) => v.name == 'tableoid')) { + options.push({ + name: 'tableoid', + type: 'string', + title: '{{t("Table OID(Inheritance)")}}', + schema: { + 'x-component': 'Select', + enum: [{ value: collection.name, label: compile(collection.title) }].concat( + childrenCollections.map((v) => { + return { + value: v.name, + label: compile(v.title), + }; + }), + ), + }, + operators: [ + { + label: '{{t("contains")}}', + value: '$childIn', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + { + label: '{{t("does not contain")}}', + value: '$childNotIn', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + ], + }); + } + return options; }; export const useFilterDataSource = (options) => { diff --git a/packages/core/client/src/locale/en_US.ts b/packages/core/client/src/locale/en_US.ts index 604fe75e1..a1cbb36f6 100644 --- a/packages/core/client/src/locale/en_US.ts +++ b/packages/core/client/src/locale/en_US.ts @@ -99,6 +99,7 @@ export default { "Data blocks": "Data blocks", "Filter blocks": "Filter blocks", "Table": "Table", + "Table OID(Inheritance)":"Table OID(Inheritance)", "Form": "Form", "Collapse": "Collapse", "Select data source": "Select data source", diff --git a/packages/core/client/src/locale/ja_JP.ts b/packages/core/client/src/locale/ja_JP.ts index 36b2dee3d..c1254ec21 100644 --- a/packages/core/client/src/locale/ja_JP.ts +++ b/packages/core/client/src/locale/ja_JP.ts @@ -102,6 +102,7 @@ export default { "Set the data scope": "データ範囲の設定", "Data blocks": "データブロック", "Filter blocks": "フィルターブロック", + "Table OID(Inheritance)":"データテーブルOID(継承)", "Table": "テーブル", "Form": "フォーム", "Collapse": "折りたたみ", diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index 63c81d998..da2a36438 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -111,6 +111,7 @@ export default { "Filter blocks": "筛选区块", "Table": "表格", "Form": "表单", + "Table OID(Inheritance)":"数据表 OID(继承)", "Collapse": "折叠面板", "Select data source": "选择数据源", "Calendar": "日历", diff --git a/packages/core/client/src/schema-component/antd/filter/FilterItem.tsx b/packages/core/client/src/schema-component/antd/filter/FilterItem.tsx index 0af7c87d3..a0ebc2179 100644 --- a/packages/core/client/src/schema-component/antd/filter/FilterItem.tsx +++ b/packages/core/client/src/schema-component/antd/filter/FilterItem.tsx @@ -2,7 +2,7 @@ import { CloseCircleOutlined } from '@ant-design/icons'; import { css } from '@emotion/css'; import { observer } from '@formily/react'; import { Cascader, Select, Space } from 'antd'; -import React, { useContext } from 'react'; +import React, { useContext, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useCompile } from '../..'; import { RemoveConditionContext } from './context'; diff --git a/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts b/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts index 7fd625f75..e74cfd0dd 100644 --- a/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts +++ b/packages/core/client/src/schema-component/antd/filter/useFilterActionProps.ts @@ -2,6 +2,7 @@ import { Field } from '@formily/core'; import { useField, useFieldSchema } from '@formily/react'; import flat from 'flat'; import { useTranslation } from 'react-i18next'; +import { useCompile } from '../..'; import { useBlockRequestContext } from '../../../block-provider'; import { mergeFilter } from '../../../block-provider/SharedFilterProvider'; import { useCollection, useCollectionManager } from '../../../collection-manager'; @@ -9,7 +10,48 @@ import { useCollection, useCollectionManager } from '../../../collection-manager export const useFilterOptions = (collectionName: string) => { const { getCollectionFields } = useCollectionManager(); const fields = getCollectionFields(collectionName); - return useFilterFieldOptions(fields); + const options=useFilterFieldOptions(fields) + const compile = useCompile(); + const { getChildrenCollections } = useCollectionManager(); + const collection = useCollection(); + const childrenCollections = getChildrenCollections(collection.name); + if (childrenCollections.length > 0 && !options.find((v) => v.name == 'tableoid')) { + options.push({ + name: 'tableoid', + type: 'string', + title: '{{t("Table OID(Inheritance)")}}', + schema: { + 'x-component': 'Select', + enum: [{ value: collection.name, label: compile(collection.title) }].concat( + childrenCollections.map((v) => { + return { + value: v.name, + label: compile(v.title), + }; + }), + ), + }, + operators: [ + { + label: '{{t("contains")}}', + value: '$childIn', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + { + label: '{{t("does not contain")}}', + value: '$childNotIn', + schema: { + 'x-component': 'Select', + 'x-component-props': { mode: 'tags' }, + }, + }, + ], + }); + } + return options; }; export const useFilterFieldOptions = (fields) => {