mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
Merge branch '2.0' of github.com:nocobase/nocobase into 2.0
This commit is contained in:
commit
f0083cb1a3
@ -9,17 +9,19 @@
|
|||||||
|
|
||||||
import { Button, ButtonProps, Input, Popover } from 'antd';
|
import { Button, ButtonProps, Input, Popover } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { FC } from 'react';
|
import React, { FC, useContext } from 'react';
|
||||||
import { GlobalActionModel } from '../base/ActionModel';
|
import { GlobalActionModel } from '../base/ActionModel';
|
||||||
import { useToken } from '../../../style/useToken';
|
import { useToken } from '../../../style/useToken';
|
||||||
import { CloseCircleOutlined } from '@ant-design/icons';
|
import { CloseCircleOutlined } from '@ant-design/icons';
|
||||||
import { Trans, useTranslation } from 'react-i18next';
|
import { Trans, useTranslation } from 'react-i18next';
|
||||||
import { Cascader, Select, Space } from 'antd';
|
import { Cascader, Select, Space } from 'antd';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { useApp } from '../../../application/hooks/useApp';
|
|
||||||
import { observer } from '@formily/reactive-react';
|
import { observer } from '@formily/reactive-react';
|
||||||
import { useFlowModel, useStepSettingContext } from '@nocobase/flow-engine';
|
import { useFlowModel, useStepSettingContext } from '@nocobase/flow-engine';
|
||||||
|
|
||||||
|
// TODO: 需要重构,使用新的方式获取组件实例
|
||||||
|
const AppContext = React.createContext(null);
|
||||||
|
|
||||||
const findOperator = (obj) => {
|
const findOperator = (obj) => {
|
||||||
let current = 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 FieldComponent: FC<{ component: string; value: any; onChange: any; [key: string]: any }> = (props) => {
|
||||||
const { component, ...others } = props;
|
const { component, ...others } = props;
|
||||||
|
|
||||||
const app = useApp();
|
const app = useContext(AppContext);
|
||||||
const Component = app.getComponent(component);
|
const Component = app.getComponent(component);
|
||||||
|
|
||||||
if (!Component) {
|
if (!Component) {
|
||||||
@ -298,6 +300,7 @@ const FilterItem: FC<{
|
|||||||
const FilterGroup: FC<{
|
const FilterGroup: FC<{
|
||||||
value: any;
|
value: any;
|
||||||
options: any[];
|
options: any[];
|
||||||
|
app: any;
|
||||||
showBorder?: boolean;
|
showBorder?: boolean;
|
||||||
onRemove?: () => void;
|
onRemove?: () => void;
|
||||||
onChange?: (value: any) => void;
|
onChange?: (value: any) => void;
|
||||||
@ -342,68 +345,71 @@ const FilterGroup: FC<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={style}>
|
<AppContext.Provider value={props.app}>
|
||||||
{props.showBorder && (
|
<div style={style}>
|
||||||
<a role="button" aria-label="icon-close">
|
{props.showBorder && (
|
||||||
<CloseCircleOutlined
|
<a role="button" aria-label="icon-close">
|
||||||
style={{
|
<CloseCircleOutlined
|
||||||
position: 'absolute',
|
style={{
|
||||||
right: 10,
|
position: 'absolute',
|
||||||
top: 10,
|
right: 10,
|
||||||
color: '#bfbfbf',
|
top: 10,
|
||||||
}}
|
color: '#bfbfbf',
|
||||||
onClick={props.onRemove}
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
<div style={{ marginBottom: 8, color: token.colorText }}>
|
|
||||||
<Trans>
|
|
||||||
{'Meet '}
|
|
||||||
<Select
|
|
||||||
// @ts-ignore
|
|
||||||
role="button"
|
|
||||||
data-testid="filter-select-all-or-any"
|
|
||||||
style={{ width: 'auto' }}
|
|
||||||
value={logic}
|
|
||||||
onChange={onChangeLogic}
|
|
||||||
>
|
|
||||||
<Select.Option value={'$and'}>All</Select.Option>
|
|
||||||
<Select.Option value={'$or'}>Any</Select.Option>
|
|
||||||
</Select>
|
|
||||||
{' conditions in the group'}
|
|
||||||
</Trans>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{items.map((item, index) =>
|
|
||||||
item.$and || item.$or ? (
|
|
||||||
<FilterGroup
|
|
||||||
key={index}
|
|
||||||
value={item}
|
|
||||||
showBorder
|
|
||||||
options={props.options}
|
|
||||||
onRemove={() => {
|
|
||||||
items.splice(index, 1);
|
|
||||||
}}
|
}}
|
||||||
onChange={props.onChange}
|
onClick={props.onRemove}
|
||||||
/>
|
/>
|
||||||
) : (
|
</a>
|
||||||
<FilterItem
|
|
||||||
key={index}
|
|
||||||
value={item}
|
|
||||||
options={props.options}
|
|
||||||
onRemove={() => {
|
|
||||||
items.splice(index, 1);
|
|
||||||
}}
|
|
||||||
onChange={props.onChange}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
)}
|
)}
|
||||||
|
<div style={{ marginBottom: 8, color: token.colorText }}>
|
||||||
|
<Trans>
|
||||||
|
{'Meet '}
|
||||||
|
<Select
|
||||||
|
// @ts-ignore
|
||||||
|
role="button"
|
||||||
|
data-testid="filter-select-all-or-any"
|
||||||
|
style={{ width: 'auto' }}
|
||||||
|
value={logic}
|
||||||
|
onChange={onChangeLogic}
|
||||||
|
>
|
||||||
|
<Select.Option value={'$and'}>All</Select.Option>
|
||||||
|
<Select.Option value={'$or'}>Any</Select.Option>
|
||||||
|
</Select>
|
||||||
|
{' conditions in the group'}
|
||||||
|
</Trans>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{items.map((item, index) =>
|
||||||
|
item.$and || item.$or ? (
|
||||||
|
<FilterGroup
|
||||||
|
key={index}
|
||||||
|
value={item}
|
||||||
|
showBorder
|
||||||
|
options={props.options}
|
||||||
|
onRemove={() => {
|
||||||
|
items.splice(index, 1);
|
||||||
|
}}
|
||||||
|
onChange={props.onChange}
|
||||||
|
app={props.app}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<FilterItem
|
||||||
|
key={index}
|
||||||
|
value={item}
|
||||||
|
options={props.options}
|
||||||
|
onRemove={() => {
|
||||||
|
items.splice(index, 1);
|
||||||
|
}}
|
||||||
|
onChange={props.onChange}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Space size={16} style={{ marginTop: 8, marginBottom: 8 }}>
|
||||||
|
<a onClick={onAddCondition}>{t('Add condition')}</a>
|
||||||
|
<a onClick={onAddConditionGroup}>{t('Add condition group')}</a>
|
||||||
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
<Space size={16} style={{ marginTop: 8, marginBottom: 8 }}>
|
</AppContext.Provider>
|
||||||
<a onClick={onAddCondition}>{t('Add condition')}</a>
|
|
||||||
<a onClick={onAddConditionGroup}>{t('Add condition group')}</a>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -422,7 +428,7 @@ const FilterContent: FC<{ value: any }> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FilterGroup value={props.value} options={options} />
|
<FilterGroup value={props.value} options={options} app={modelInstance.ctx.globals.app} />
|
||||||
<Space style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
|
<Space style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
|
||||||
<Button onClick={() => modelInstance.dispatchEvent('reset')}>Reset</Button>
|
<Button onClick={() => modelInstance.dispatchEvent('reset')}>Reset</Button>
|
||||||
<Button type="primary" onClick={() => modelInstance.dispatchEvent('submit')}>
|
<Button type="primary" onClick={() => modelInstance.dispatchEvent('submit')}>
|
||||||
@ -516,7 +522,7 @@ FilterActionModel.registerFlow({
|
|||||||
currentBlockModel.ctx.globals.app.dataSourceManager,
|
currentBlockModel.ctx.globals.app.dataSourceManager,
|
||||||
).filter(Boolean);
|
).filter(Boolean);
|
||||||
|
|
||||||
return <FilterGroup value={props.value} options={options} />;
|
return <FilterGroup value={props.value} options={options} app={modelInstance.ctx.globals.app} />;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user