fix(variable): should show all collection fields (#5310)

This commit is contained in:
Zeke Zhang 2024-09-24 12:29:16 +08:00 committed by GitHub
parent 63444a10ae
commit 35198b715e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 9 deletions

View File

@ -21,9 +21,9 @@ export const useGetFilterOptions = () => {
const { getCollectionFields } = useCollectionManager_deprecated();
const getFilterFieldOptions = useGetFilterFieldOptions();
return (collectionName, dataSource?: string) => {
return (collectionName, dataSource?: string, usedInVariable?: boolean) => {
const fields = getCollectionFields(collectionName, dataSource);
const options = getFilterFieldOptions(fields);
const options = getFilterFieldOptions(fields, usedInVariable);
return options;
};
};
@ -39,18 +39,20 @@ export const useGetFilterFieldOptions = () => {
const fieldSchema = useFieldSchema();
const nonfilterable = fieldSchema?.['x-component-props']?.nonfilterable || [];
const { getCollectionFields, getInterface } = useCollectionManager_deprecated();
const field2option = (field, depth) => {
const field2option = (field, depth, usedInVariable?: boolean) => {
if (nonfilterable.length && depth === 1 && nonfilterable.includes(field.name)) {
return;
}
if (!field.interface) {
return;
}
const fieldInterface = getInterface(field.interface);
if (!fieldInterface?.filterable) {
if (!fieldInterface?.filterable && !usedInVariable) {
return;
}
const { nested, children, operators } = fieldInterface.filterable;
const { nested, children, operators } = fieldInterface?.filterable || {};
const option = {
name: field.name,
type: field.type,
@ -80,17 +82,17 @@ export const useGetFilterFieldOptions = () => {
}
return option;
};
const getOptions = (fields, depth) => {
const getOptions = (fields, depth, usedInVariable?: boolean) => {
const options = [];
fields.forEach((field) => {
const option = field2option(field, depth);
const option = field2option(field, depth, usedInVariable);
if (option) {
options.push(option);
}
});
return options;
};
return (fields) => getOptions(fields, 1);
return (fields, usedInVariable) => getOptions(fields, 1, usedInVariable);
};
export const useFilterFieldOptions = (fields) => {

View File

@ -211,8 +211,9 @@ export const useBaseVariable = ({
const target = option.field.target;
return new Promise((resolve) => {
setTimeout(() => {
const usedInVariable = true;
const children = (
getChildren(returnFields(getFilterOptions(target, dataSource), option), {
getChildren(returnFields(getFilterOptions(target, dataSource, usedInVariable), option), {
collectionField,
uiSchema,
targetFieldSchema,