From f34c9943aeb2c3124ee0a93f6eb2d462b8f32e49 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Wed, 25 Jun 2025 09:52:28 +0800 Subject: [PATCH] fix: refactor FilterActionModel to use AppContext for component instance retrieval --- .../flow/models/actions/FilterActionModel.tsx | 132 +++++++++--------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/packages/core/client/src/flow/models/actions/FilterActionModel.tsx b/packages/core/client/src/flow/models/actions/FilterActionModel.tsx index 66f2165098..85ec214075 100644 --- a/packages/core/client/src/flow/models/actions/FilterActionModel.tsx +++ b/packages/core/client/src/flow/models/actions/FilterActionModel.tsx @@ -9,17 +9,19 @@ import { Button, ButtonProps, Input, Popover } from 'antd'; import _ from 'lodash'; -import React, { FC } from 'react'; +import React, { FC, useContext } from 'react'; import { GlobalActionModel } from '../base/ActionModel'; import { useToken } from '../../../style/useToken'; import { CloseCircleOutlined } from '@ant-design/icons'; import { Trans, useTranslation } from 'react-i18next'; import { Cascader, Select, Space } from 'antd'; import { css } from '@emotion/css'; -import { useApp } from '../../../application/hooks/useApp'; import { observer } from '@formily/reactive-react'; import { useFlowModel, useStepSettingContext } from '@nocobase/flow-engine'; +// TODO: 需要重构,使用新的方式获取组件实例 +const AppContext = React.createContext(null); + const findOperator = (obj) => { let current = obj; @@ -166,7 +168,7 @@ const getOptions = (fields, depth, nonfilterable, dataSourceManager) => { const FieldComponent: FC<{ component: string; value: any; onChange: any; [key: string]: any }> = (props) => { const { component, ...others } = props; - const app = useApp(); + const app = useContext(AppContext); const Component = app.getComponent(component); if (!Component) { @@ -298,6 +300,7 @@ const FilterItem: FC<{ const FilterGroup: FC<{ value: any; options: any[]; + app: any; showBorder?: boolean; onRemove?: () => void; onChange?: (value: any) => void; @@ -342,68 +345,71 @@ const FilterGroup: FC<{ }; return ( -
- {props.showBorder && ( - - - - )} -
- - {'Meet '} - - {' conditions in the group'} - -
-
- {items.map((item, index) => - item.$and || item.$or ? ( - { - items.splice(index, 1); + +
+ {props.showBorder && ( + + - ) : ( - { - items.splice(index, 1); - }} - onChange={props.onChange} - /> - ), + )} +
+ + {'Meet '} + + {' conditions in the group'} + +
+
+ {items.map((item, index) => + item.$and || item.$or ? ( + { + items.splice(index, 1); + }} + onChange={props.onChange} + app={props.app} + /> + ) : ( + { + items.splice(index, 1); + }} + onChange={props.onChange} + /> + ), + )} +
+ + {t('Add condition')} + {t('Add condition group')} +
- - {t('Add condition')} - {t('Add condition group')} - -
+ ); }, { @@ -422,7 +428,7 @@ const FilterContent: FC<{ value: any }> = (props) => { return ( <> - +