From 5785f300754fd4d13f3bfc8d405e855e284d171c Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 2 Mar 2022 22:49:10 +0800 Subject: [PATCH] feat(client): improve sub table --- .../src/collection-manager/interfaces/input.ts | 8 ++++---- .../src/collection-manager/sub-table.tsx | 18 +++++++++++++++--- .../Items/SubTableFieldInitializer.tsx | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/client/src/collection-manager/interfaces/input.ts b/packages/client/src/collection-manager/interfaces/input.ts index 97f6d093a..feedabecb 100644 --- a/packages/client/src/collection-manager/interfaces/input.ts +++ b/packages/client/src/collection-manager/interfaces/input.ts @@ -22,9 +22,9 @@ export const input: IField = { operators: [ { label: '{{t("contains")}}', value: '$includes', selected: true }, { label: '{{t("does not contain")}}', value: '$notIncludes' }, - { label: '{{t("is")}}', value: 'eq' }, - { label: '{{t("is not")}}', value: 'ne' }, - { label: '{{t("is empty")}}', value: '$null', noValue: true }, - { label: '{{t("is not empty")}}', value: '$notNull', noValue: true }, + { label: '{{t("is")}}', value: '$eq' }, + { label: '{{t("is not")}}', value: '$ne' }, + { label: '{{t("is empty")}}', value: '$empty', noValue: true }, + { label: '{{t("is not empty")}}', value: '$notEmpty', noValue: true }, ], }; diff --git a/packages/client/src/collection-manager/sub-table.tsx b/packages/client/src/collection-manager/sub-table.tsx index caec3cd1d..bbe9a1d35 100644 --- a/packages/client/src/collection-manager/sub-table.tsx +++ b/packages/client/src/collection-manager/sub-table.tsx @@ -1,7 +1,15 @@ import { observer, useForm } from '@formily/react'; import { cloneDeep } from 'lodash'; import React, { createContext, useContext, useState } from 'react'; -import { CollectionOptions, CollectionProvider, useActionContext, useRecord, useRecordIndex, useRequest } from '../'; +import { + CollectionOptions, + CollectionProvider, + useActionContext, + useCollectionManager, + useRecord, + useRecordIndex, + useRequest +} from '../'; import { useAPIClient } from '../api-client'; import { options } from './Configuration/interfaces'; @@ -219,16 +227,20 @@ export const DataSourceProvider = observer((props: any) => { const [dataSource, setDataSource] = useState([]); const record = useRecord(); const api = useAPIClient(); + const { getCollection } = useCollectionManager(); + const coll = getCollection(collection); const resourceOf = record?.[association.targetKey || 'id']; - console.log('record', record); const service = useRequest( () => { if (resourceOf) { return api .request({ - resource: `${collection}.${association.name}`, + resource: `${association.collectionName}.${association.name}`, resourceOf, action: 'list', + params: { + appends: coll?.fields?.filter((field) => field.target)?.map((field) => field.name), + }, }) .then((res) => res.data); } diff --git a/packages/client/src/schema-initializer/Initializers/Items/SubTableFieldInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/SubTableFieldInitializer.tsx index 55ca58eb2..8934adefb 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/SubTableFieldInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/SubTableFieldInitializer.tsx @@ -28,6 +28,7 @@ export const SubTableFieldInitializer = (props) => { 'x-component-props': { collection: item?.field?.target, association: { + collectionName: item.field.collectionName, name: item.field.name, sourceKey: item.field.sourceKey, targetKey: item.field.targetKey,