From 9db654047a95040fa9b44c037fbeaf48308c8037 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 2 Mar 2022 13:22:30 +0800 Subject: [PATCH] feat(client): improve linkTo field Initializer --- .../src/collection-manager/action-hooks.ts | 13 +- .../interfaces/chinaRegion.ts | 1 + .../collection-manager/interfaces/linkTo.ts | 10 +- packages/client/src/locale/zh_CN.json | 1 + .../antd/filter/SaveDefaultValue.tsx | 5 +- .../antd/record-picker/RecordPicker.tsx | 29 +-- .../core/SchemaComponentProvider.tsx | 1 - .../Items/FilterActionInitializer.tsx | 4 +- .../LinkToCollectionFieldInitializer.tsx | 205 ++++++++++++++++++ .../Initializers/Items/index.ts | 1 + .../schema-initializer/Initializers/utils.ts | 47 +++- 11 files changed, 285 insertions(+), 32 deletions(-) create mode 100644 packages/client/src/schema-initializer/Initializers/Items/LinkToCollectionFieldInitializer.tsx diff --git a/packages/client/src/collection-manager/action-hooks.ts b/packages/client/src/collection-manager/action-hooks.ts index b214a8a8d..08686cfc4 100644 --- a/packages/client/src/collection-manager/action-hooks.ts +++ b/packages/client/src/collection-manager/action-hooks.ts @@ -39,12 +39,12 @@ export const useCollectionFilterOptions = (collectionName: string) => { operators: fieldInterface.operators || [], }; return option; - } - fields.forEach(field => { + }; + fields.forEach((field) => { options.push(field2option(field)); }); return options; -} +}; export const useFilterDataSource = (options) => { const { name } = useCollection(); @@ -56,17 +56,20 @@ export const useFilterDataSource = (options) => { }), options, ); -} +}; export const useFilterAction = () => { + const { run, params } = useResourceActionContext(); const form = useForm(); const ctx = useActionContext(); + const [first, ...others] = params; return { async run() { + run({ ...first, filter: form.values.filter }, ...others); ctx.setVisible(false); }, }; -} +}; export const useCreateAction = () => { const form = useForm(); diff --git a/packages/client/src/collection-manager/interfaces/chinaRegion.ts b/packages/client/src/collection-manager/interfaces/chinaRegion.ts index ee03f8d1a..d270d6bc2 100644 --- a/packages/client/src/collection-manager/interfaces/chinaRegion.ts +++ b/packages/client/src/collection-manager/interfaces/chinaRegion.ts @@ -14,6 +14,7 @@ export const chinaRegion: IField = { type: 'belongsToMany', target: 'chinaRegions', targetKey: 'code', + sortBy: 'level', // name, uiSchema: { type: 'array', diff --git a/packages/client/src/collection-manager/interfaces/linkTo.ts b/packages/client/src/collection-manager/interfaces/linkTo.ts index 88b1c48e2..ff95b28e8 100644 --- a/packages/client/src/collection-manager/interfaces/linkTo.ts +++ b/packages/client/src/collection-manager/interfaces/linkTo.ts @@ -13,10 +13,16 @@ export const linkTo: IField = { type: 'belongsToMany', // name, uiSchema: { - type: 'array', // title, 'x-component': 'RecordPicker', - 'x-component-props': {}, + 'x-component-props': { + // mode: 'tags', + multiple: true, + fieldNames: { + label: 'id', + value: 'id', + }, + }, }, }, initialize: (values: any) => { diff --git a/packages/client/src/locale/zh_CN.json b/packages/client/src/locale/zh_CN.json index 51f5f6c69..3f2a24fd8 100644 --- a/packages/client/src/locale/zh_CN.json +++ b/packages/client/src/locale/zh_CN.json @@ -24,6 +24,7 @@ "Icon": "图标", "Group": "分组", "Link": "链接", + "Save conditions": "保存筛选条件", "Edit menu item": "编辑菜单项", "Move to": "移动到", "Insert left": "在左边插入", diff --git a/packages/client/src/schema-component/antd/filter/SaveDefaultValue.tsx b/packages/client/src/schema-component/antd/filter/SaveDefaultValue.tsx index f9c2337b7..c2c7f9482 100644 --- a/packages/client/src/schema-component/antd/filter/SaveDefaultValue.tsx +++ b/packages/client/src/schema-component/antd/filter/SaveDefaultValue.tsx @@ -7,9 +7,12 @@ import { useDesignable } from '../../hooks'; export const SaveDefaultValue = (props) => { const { t } = useTranslation(); - const { dn, refresh } = useDesignable(); + const { designable, dn, refresh } = useDesignable(); const fieldSchema = useFieldSchema(); const form = useForm(); + if (!designable) { + return null; + } return (