From 4ce41cf7b23f8e1ac27d24380a86c13a0c0dba5e Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 6 Mar 2022 19:04:02 +0800 Subject: [PATCH] fix(client): sub table does not work --- .../CollectionManagerProvider.tsx | 2 +- .../collection-manager/hooks/useCollection.ts | 2 +- .../client/src/collection-manager/sub-table.tsx | 2 +- .../antd/table/Table.Array.Designer.tsx | 15 +++++++++++++++ .../src/schema-component/antd/table/index.tsx | 2 ++ .../Items/CalendarBlockInitializer.tsx | 16 +++++++++------- .../Initializers/Items/FormBlockInitializer.tsx | 16 +++++++++------- .../Initializers/Items/TableBlockInitializer.tsx | 16 +++++++++------- .../src/schema-initializer/Initializers/utils.ts | 4 ++-- 9 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 packages/client/src/schema-component/antd/table/Table.Array.Designer.tsx diff --git a/packages/client/src/collection-manager/CollectionManagerProvider.tsx b/packages/client/src/collection-manager/CollectionManagerProvider.tsx index f9fab8687..862a33e83 100644 --- a/packages/client/src/collection-manager/CollectionManagerProvider.tsx +++ b/packages/client/src/collection-manager/CollectionManagerProvider.tsx @@ -35,7 +35,7 @@ export const RemoteCollectionManagerProvider = (props: any) => { paginate: false, appends: ['fields', 'fields.uiSchema'], filter: { - inherit: false, + // inherit: false, }, }, }; diff --git a/packages/client/src/collection-manager/hooks/useCollection.ts b/packages/client/src/collection-manager/hooks/useCollection.ts index 84e731ba1..c2da2258f 100644 --- a/packages/client/src/collection-manager/hooks/useCollection.ts +++ b/packages/client/src/collection-manager/hooks/useCollection.ts @@ -7,7 +7,7 @@ import { CollectionFieldOptions } from '../types'; export const useCollection = () => { const collection = useContext(CollectionContext); const api = useAPIClient(); - const resource = api?.resource(collection.name); + const resource = api?.resource(collection?.name); return { ...collection, resource, diff --git a/packages/client/src/collection-manager/sub-table.tsx b/packages/client/src/collection-manager/sub-table.tsx index bbe9a1d35..f5bec98d2 100644 --- a/packages/client/src/collection-manager/sub-table.tsx +++ b/packages/client/src/collection-manager/sub-table.tsx @@ -255,7 +255,7 @@ export const DataSourceProvider = observer((props: any) => { }, ); return ( - + { + return ( + + + + ); +}; diff --git a/packages/client/src/schema-component/antd/table/index.tsx b/packages/client/src/schema-component/antd/table/index.tsx index 3da80c221..9484edda6 100644 --- a/packages/client/src/schema-component/antd/table/index.tsx +++ b/packages/client/src/schema-component/antd/table/index.tsx @@ -1,4 +1,5 @@ import { TableArray } from './Table.Array'; +import { TableArrayDesigner } from './Table.Array.Designer'; import { TableColumn } from './Table.Column'; import { TableColumnActionBar } from './Table.Column.ActionBar'; import { TableColumnDecorator } from './Table.Column.Decorator'; @@ -23,3 +24,4 @@ Table.Column.Deigner = TableColumnDeigner; Table.RowActionDesigner = TableRowActionDesigner; Table.Designer = TableDesigner; +Table.Array.Designer = TableArrayDesigner; diff --git a/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx index 8671dabf9..83bdb2c71 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/CalendarBlockInitializer.tsx @@ -167,13 +167,15 @@ export const CalendarBlockInitializer = (props) => { { type: 'itemGroup', title: t('Select data source'), - children: collections?.map((item) => { - return { - type: 'item', - name: item.name, - title: item.title, - }; - }), + children: collections + ?.filter((item) => !item.inherit) + ?.map((item) => { + return { + type: 'item', + name: item.name, + title: item.title, + }; + }), }, ]} /> diff --git a/packages/client/src/schema-initializer/Initializers/Items/FormBlockInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/FormBlockInitializer.tsx index 6ce08cda3..77c4244ee 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/FormBlockInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/FormBlockInitializer.tsx @@ -66,13 +66,15 @@ export const FormBlockInitializer = (props) => { { type: 'itemGroup', title: t('Select data source'), - children: collections?.map((item) => { - return { - type: 'item', - name: item.name, - title: item.title, - }; - }), + children: collections + ?.filter((item) => !item.inherit) + ?.map((item) => { + return { + type: 'item', + name: item.name, + title: item.title, + }; + }), }, ]} /> diff --git a/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx b/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx index 51e4ab71e..552a3f019 100644 --- a/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx +++ b/packages/client/src/schema-initializer/Initializers/Items/TableBlockInitializer.tsx @@ -91,13 +91,15 @@ export const TableBlockInitializer = (props) => { { type: 'itemGroup', title: t('Select data source'), - children: collections?.map((item) => { - return { - type: 'item', - name: item.name, - title: item.title, - }; - }), + children: collections + ?.filter((item) => !item.inherit) + ?.map((item) => { + return { + type: 'item', + name: item.name, + title: item.title, + }; + }), }, ]} /> diff --git a/packages/client/src/schema-initializer/Initializers/utils.ts b/packages/client/src/schema-initializer/Initializers/utils.ts index 6fa246441..ed48849f7 100644 --- a/packages/client/src/schema-initializer/Initializers/utils.ts +++ b/packages/client/src/schema-initializer/Initializers/utils.ts @@ -57,7 +57,7 @@ const findTableColumn = (schema: Schema, key: string, action: string, deepth: nu }; export const useTableColumnInitializerFields = () => { - const { name, fields } = useCollection(); + const { name, fields = [] } = useCollection(); return fields .filter((field) => field?.interface && field?.interface !== 'subTable') .map((field) => { @@ -113,7 +113,7 @@ export const useFormItemInitializerFields = () => { schema: { type: 'void', name: field.name, - 'x-designer': 'FormItem.Designer', + 'x-designer': 'Table.Array.Designer', 'x-component': 'div', 'x-decorator': 'FormItem', 'x-collection-field': `${name}.${field.name}`,