* fix: temporary solution to APP crash * feat: support dynamic assigned field value * feat: support dynamic assigned field value * fix: useFields filter * fix: dynamic assigned value * fix: dynamic assigned value * fix: fix china region export * fix: fix china region export * fix: change assign value data * fix: custom request use parse instead of SchemaCompile * fix: allow user attribute to be selected * fix: allow DATE field to be select currentUser or CurrentRecord * fix: allow DATE field to be select currentUser or CurrentRecord * fix: change style * feat: package dependencies Co-authored-by: chenos <chenlinxh@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useFieldSchema } from '@formily/react';
|
|
import { useCollectionManager } from '@nocobase/client';
|
|
|
|
export const useFields = (collectionName: string) => {
|
|
const fieldSchema = useFieldSchema();
|
|
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
|
const { getCollectionFields } = useCollectionManager();
|
|
const fields = getCollectionFields(collectionName);
|
|
const field2option = (field, depth) => {
|
|
if (!field.interface) {
|
|
return;
|
|
}
|
|
const option = {
|
|
name: field.name,
|
|
title: field?.uiSchema?.title || field.name,
|
|
schema: field?.uiSchema,
|
|
};
|
|
if (!field.target || depth >= 3) {
|
|
return option;
|
|
}
|
|
|
|
if (field.target) {
|
|
const targetFields = getCollectionFields(field.target);
|
|
const options = getOptions(targetFields, depth + 1).filter(Boolean);
|
|
option['children'] = option['children'] || [];
|
|
option['children'].push(...options);
|
|
}
|
|
return option;
|
|
};
|
|
const getOptions = (fields, depth) => {
|
|
const options = [];
|
|
fields.forEach((field) => {
|
|
const option = field2option(field, depth);
|
|
if (option) {
|
|
options.push(option);
|
|
}
|
|
});
|
|
return options;
|
|
};
|
|
return getOptions(fields, 1);
|
|
};
|