From d56cc66ef95ccc5e1f79035e66c1c68226adf9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Wed, 30 Aug 2023 23:26:51 +0800 Subject: [PATCH] fix(FilterDynamicComponent): avoid crashing (#2566) --- .../Configuration/FilterDynamicComponent.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/acl/Configuration/FilterDynamicComponent.tsx b/packages/core/client/src/acl/Configuration/FilterDynamicComponent.tsx index a88b857c5..0751dfabb 100644 --- a/packages/core/client/src/acl/Configuration/FilterDynamicComponent.tsx +++ b/packages/core/client/src/acl/Configuration/FilterDynamicComponent.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { useCompile } from '../../schema-component'; -import { useFilterOptions } from '../../schema-component/antd/filter'; +import { useGetFilterOptions } from '../../schema-component/antd/filter'; import { useValues } from '../../schema-component/antd/filter/useValues'; import { Variable } from '../../schema-component/antd/variable'; @@ -8,31 +8,36 @@ interface GetOptionsParams { schema: any; operator: string; maxDepth: number; + getFilterOptions: (collectionName: string) => any[]; count?: number; } -const useOptions = (collectionName: string, { schema, operator, maxDepth, count = 1 }: GetOptionsParams) => { +const getOptions = ( + collectionName: string, + { schema, operator, maxDepth, getFilterOptions, count = 1 }: GetOptionsParams, +) => { if (count > maxDepth) { return []; } - const result = useFilterOptions(collectionName).map((option) => { + const result = getFilterOptions(collectionName).map((option) => { if ((option.type !== 'belongsTo' && option.type !== 'hasOne') || !option.target) { return { key: option.name, value: option.name, label: option.title, // TODO: 现在是通过组件的名称来过滤能够被选择的选项,这样的坏处是不够精确,后续可以优化 - disabled: schema?.['x-component'] !== option.schema['x-component'], + disabled: schema?.['x-component'] !== option.schema?.['x-component'], }; } const children = - useOptions(option.target, { + getOptions(option.target, { schema, operator, maxDepth, count: count + 1, + getFilterOptions, }) || []; return { @@ -48,7 +53,8 @@ const useOptions = (collectionName: string, { schema, operator, maxDepth, count }; const useUserVariable = ({ schema, operator }) => { - const options = useOptions('users', { schema, operator, maxDepth: 1 }) || []; + const getFilterOptions = useGetFilterOptions(); + const options = getOptions('users', { schema, operator, maxDepth: 1, getFilterOptions }) || []; return { label: `{{t("Current user")}}`,