fix: options property for filter component
This commit is contained in:
parent
1f12c20838
commit
b45a5d57ea
@ -81,8 +81,7 @@ export const useSortFields = (collectionName: string) => {
|
||||
export const useCollectionFilterOptions = (collectionName: string) => {
|
||||
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||
const fields = getCollectionFields(collectionName);
|
||||
let depth = 0;
|
||||
const field2option = (field) => {
|
||||
const field2option = (field, depth) => {
|
||||
if (!field.interface) {
|
||||
return;
|
||||
}
|
||||
@ -111,24 +110,23 @@ export const useCollectionFilterOptions = (collectionName: string) => {
|
||||
}
|
||||
if (nested) {
|
||||
const targetFields = getCollectionFields(field.target);
|
||||
const options = getOptions(targetFields).filter(Boolean);
|
||||
const options = getOptions(targetFields, depth+1).filter(Boolean);
|
||||
option['children'] = option['children'] || [];
|
||||
option['children'].push(...options);
|
||||
}
|
||||
return option;
|
||||
};
|
||||
const getOptions = (fields) => {
|
||||
++depth;
|
||||
const getOptions = (fields, depth) => {
|
||||
const options = [];
|
||||
fields.forEach((field) => {
|
||||
const option = field2option(field);
|
||||
const option = field2option(field, depth);
|
||||
if (option) {
|
||||
options.push(option);
|
||||
}
|
||||
});
|
||||
return options;
|
||||
};
|
||||
return getOptions(fields);
|
||||
return getOptions(fields, 1);
|
||||
};
|
||||
|
||||
export const useFilterDataSource = (options) => {
|
||||
|
@ -10,8 +10,7 @@ export const useFilterOptions = (collectionName: string) => {
|
||||
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
||||
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||
const fields = getCollectionFields(collectionName);
|
||||
let depth = 0;
|
||||
const field2option = (field) => {
|
||||
const field2option = (field, depth) => {
|
||||
if (nonfilterable.length && depth !== 1 && nonfilterable.includes(field.name)) {
|
||||
return;
|
||||
}
|
||||
@ -43,24 +42,23 @@ export const useFilterOptions = (collectionName: string) => {
|
||||
}
|
||||
if (nested) {
|
||||
const targetFields = getCollectionFields(field.target);
|
||||
const options = getOptions(targetFields).filter(Boolean);
|
||||
const options = getOptions(targetFields, depth+1).filter(Boolean);
|
||||
option['children'] = option['children'] || [];
|
||||
option['children'].push(...options);
|
||||
}
|
||||
return option;
|
||||
};
|
||||
const getOptions = (fields) => {
|
||||
++depth;
|
||||
const getOptions = (fields, depth) => {
|
||||
const options = [];
|
||||
fields.forEach((field) => {
|
||||
const option = field2option(field);
|
||||
const option = field2option(field, depth);
|
||||
if (option) {
|
||||
options.push(option);
|
||||
}
|
||||
});
|
||||
return options;
|
||||
};
|
||||
return getOptions(fields);
|
||||
return getOptions(fields, 1);
|
||||
};
|
||||
|
||||
const isEmpty = (obj) => {
|
||||
|
@ -8,6 +8,15 @@ export default {
|
||||
createdBy: true,
|
||||
updatedBy: true,
|
||||
fields: [
|
||||
{
|
||||
name: 'id',
|
||||
type: 'integer',
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
|
||||
interface: 'id',
|
||||
},
|
||||
{
|
||||
interface: 'input',
|
||||
type: 'string',
|
||||
|
Loading…
Reference in New Issue
Block a user