feat: recordblockinitializers fields pick (#558)

Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
金昶 2022-07-11 20:55:38 +08:00 committed by GitHub
parent 45bcfe241c
commit 8e5334bc9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,33 @@
import { Schema, useFieldSchema } from '@formily/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { SchemaInitializer, useCollection } from '../..';
import { SchemaInitializer, useCollection, useCollectionManager } from '../..';
import { gridRowColWrap } from '../utils';
const recursiveParent = (schema: Schema) => {
if (!schema) return null;
if (schema['x-decorator']?.endsWith('BlockProvider')) {
return schema['x-decorator-props']?.['collection'];
} else {
return recursiveParent(schema.parent);
}
}
const useRelationFields = () => {
const { fields } = useCollection();
const fieldSchema = useFieldSchema();
const { getCollectionFields } = useCollectionManager();
let fields = [];
if (fieldSchema['x-initializer']) {
fields = useCollection().fields;
} else {
const collection = recursiveParent(fieldSchema.parent);
if (collection) {
fields = getCollectionFields(collection);
}
}
const relationFields = fields
.filter((field) => ['linkTo', 'subTable', 'o2m', 'm2m', 'obo', 'oho', 'o2o', 'm2o'].includes(field.interface))
.map((field) => {