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

View File

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