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) => {
|
export const useCollectionFilterOptions = (collectionName: string) => {
|
||||||
const { getCollectionFields, getInterface } = useCollectionManager();
|
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||||
const fields = getCollectionFields(collectionName);
|
const fields = getCollectionFields(collectionName);
|
||||||
let depth = 0;
|
const field2option = (field, depth) => {
|
||||||
const field2option = (field) => {
|
|
||||||
if (!field.interface) {
|
if (!field.interface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,24 +110,23 @@ export const useCollectionFilterOptions = (collectionName: string) => {
|
|||||||
}
|
}
|
||||||
if (nested) {
|
if (nested) {
|
||||||
const targetFields = getCollectionFields(field.target);
|
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'] = option['children'] || [];
|
||||||
option['children'].push(...options);
|
option['children'].push(...options);
|
||||||
}
|
}
|
||||||
return option;
|
return option;
|
||||||
};
|
};
|
||||||
const getOptions = (fields) => {
|
const getOptions = (fields, depth) => {
|
||||||
++depth;
|
|
||||||
const options = [];
|
const options = [];
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
const option = field2option(field);
|
const option = field2option(field, depth);
|
||||||
if (option) {
|
if (option) {
|
||||||
options.push(option);
|
options.push(option);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
return getOptions(fields);
|
return getOptions(fields, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFilterDataSource = (options) => {
|
export const useFilterDataSource = (options) => {
|
||||||
|
@ -10,8 +10,7 @@ export const useFilterOptions = (collectionName: string) => {
|
|||||||
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
|
||||||
const { getCollectionFields, getInterface } = useCollectionManager();
|
const { getCollectionFields, getInterface } = useCollectionManager();
|
||||||
const fields = getCollectionFields(collectionName);
|
const fields = getCollectionFields(collectionName);
|
||||||
let depth = 0;
|
const field2option = (field, depth) => {
|
||||||
const field2option = (field) => {
|
|
||||||
if (nonfilterable.length && depth !== 1 && nonfilterable.includes(field.name)) {
|
if (nonfilterable.length && depth !== 1 && nonfilterable.includes(field.name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -43,24 +42,23 @@ export const useFilterOptions = (collectionName: string) => {
|
|||||||
}
|
}
|
||||||
if (nested) {
|
if (nested) {
|
||||||
const targetFields = getCollectionFields(field.target);
|
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'] = option['children'] || [];
|
||||||
option['children'].push(...options);
|
option['children'].push(...options);
|
||||||
}
|
}
|
||||||
return option;
|
return option;
|
||||||
};
|
};
|
||||||
const getOptions = (fields) => {
|
const getOptions = (fields, depth) => {
|
||||||
++depth;
|
|
||||||
const options = [];
|
const options = [];
|
||||||
fields.forEach((field) => {
|
fields.forEach((field) => {
|
||||||
const option = field2option(field);
|
const option = field2option(field, depth);
|
||||||
if (option) {
|
if (option) {
|
||||||
options.push(option);
|
options.push(option);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
return getOptions(fields);
|
return getOptions(fields, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isEmpty = (obj) => {
|
const isEmpty = (obj) => {
|
||||||
|
@ -8,6 +8,15 @@ export default {
|
|||||||
createdBy: true,
|
createdBy: true,
|
||||||
updatedBy: true,
|
updatedBy: true,
|
||||||
fields: [
|
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',
|
interface: 'input',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
Loading…
Reference in New Issue
Block a user