fix: conditionBuilder 弹层问题 (#3778)

This commit is contained in:
Allen 2022-03-16 19:18:44 +08:00 committed by GitHub
parent 03e18f0d44
commit ea1f47d91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 12 deletions

View File

@ -45,6 +45,7 @@ export interface ExpressionProps extends ThemeProps {
searchable?: boolean; searchable?: boolean;
fieldClassName?: string; fieldClassName?: string;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
const fieldMap = { const fieldMap = {
@ -135,7 +136,8 @@ export class Expression extends React.Component<ExpressionProps> {
data, data,
disabled, disabled,
searchable, searchable,
formula formula,
popOverContainer
} = this.props; } = this.props;
const inputType = const inputType =
((value as any)?.type === 'field' ((value as any)?.type === 'field'
@ -166,6 +168,7 @@ export class Expression extends React.Component<ExpressionProps> {
data={data} data={data}
disabled={disabled} disabled={disabled}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
) : null} ) : null}
@ -176,6 +179,7 @@ export class Expression extends React.Component<ExpressionProps> {
fieldClassName={fieldClassName} fieldClassName={fieldClassName}
disabled={disabled} disabled={disabled}
searchable={searchable} searchable={searchable}
popOverContainer={popOverContainer}
options={ options={
valueField valueField
? filterTree( ? filterTree(
@ -214,6 +218,7 @@ export class Expression extends React.Component<ExpressionProps> {
<InputSwitch <InputSwitch
disabled={disabled} disabled={disabled}
value={inputType} value={inputType}
popOverContainer={popOverContainer}
onChange={this.handleInputTypeChange} onChange={this.handleInputTypeChange}
options={types.map(item => ({ options={types.map(item => ({
label: fieldMap[item], label: fieldMap[item],

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import {findDOMNode} from 'react-dom';
import PopOverContainer from '../PopOverContainer'; import PopOverContainer from '../PopOverContainer';
import ListSelection from '../GroupedSelection'; import ListSelection from '../GroupedSelection';
import ResultBox from '../ResultBox'; import ResultBox from '../ResultBox';
@ -15,6 +16,7 @@ export interface ConditionFieldProps extends ThemeProps, LocaleProps {
disabled?: boolean; disabled?: boolean;
fieldClassName?: string; fieldClassName?: string;
searchable?: boolean; searchable?: boolean;
popOverContainer?: any;
} }
export interface ConditionFieldState { export interface ConditionFieldState {
@ -86,11 +88,13 @@ export class ConditionField extends React.Component<
fieldClassName, fieldClassName,
disabled, disabled,
translate: __, translate: __,
searchable searchable,
popOverContainer
} = this.props; } = this.props;
return ( return (
<PopOverContainer <PopOverContainer
popOverContainer={popOverContainer || (() => findDOMNode(this))}
popOverRender={({onClose}) => ( popOverRender={({onClose}) => (
<> <>
{searchable ? ( {searchable ? (

View File

@ -26,6 +26,7 @@ export interface ConditionGroupProps extends ThemeProps, LocaleProps {
onDragStart?: (e: React.MouseEvent) => void; onDragStart?: (e: React.MouseEvent) => void;
fieldClassName?: string; fieldClassName?: string;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
export class ConditionGroup extends React.Component<ConditionGroupProps> { export class ConditionGroup extends React.Component<ConditionGroupProps> {
@ -134,7 +135,8 @@ export class ConditionGroup extends React.Component<ConditionGroupProps> {
disabled, disabled,
searchable, searchable,
translate: __, translate: __,
formula formula,
popOverContainer
} = this.props; } = this.props;
return ( return (
<div className={cx('CBGroup')} data-group-id={value?.id}> <div className={cx('CBGroup')} data-group-id={value?.id}>
@ -222,6 +224,7 @@ export class ConditionGroup extends React.Component<ConditionGroupProps> {
searchable={searchable} searchable={searchable}
builderMode={builderMode} builderMode={builderMode}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
)) ))
) : ( ) : (

View File

@ -25,6 +25,7 @@ export interface CBGroupOrItemProps extends ThemeProps {
onRemove?: (index: number) => void; onRemove?: (index: number) => void;
fieldClassName?: string; fieldClassName?: string;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
export class CBGroupOrItem extends React.Component<CBGroupOrItemProps> { export class CBGroupOrItem extends React.Component<CBGroupOrItemProps> {
@ -52,7 +53,8 @@ export class CBGroupOrItem extends React.Component<CBGroupOrItemProps> {
disabled, disabled,
searchable, searchable,
onDragStart, onDragStart,
formula formula,
popOverContainer
} = this.props; } = this.props;
return ( return (
@ -101,6 +103,7 @@ export class CBGroupOrItem extends React.Component<CBGroupOrItemProps> {
funcs={funcs} funcs={funcs}
data={data} data={data}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
<a className={cx('CBDelete')} onClick={this.handleItemRemove}> <a className={cx('CBDelete')} onClick={this.handleItemRemove}>
<Icon icon="close" className="icon" /> <Icon icon="close" className="icon" />

View File

@ -7,6 +7,7 @@ import {ClassNamesFn, themeable, ThemeProps} from '../../theme';
export interface InputSwitchProps extends ThemeProps { export interface InputSwitchProps extends ThemeProps {
options: Array<any>; options: Array<any>;
disabled?: boolean; disabled?: boolean;
popOverContainer?: any;
value: any; value: any;
onChange: (value: any) => void; onChange: (value: any) => void;
} }
@ -18,10 +19,12 @@ export function InputSwitch({
value, value,
onChange, onChange,
classnames: cx, classnames: cx,
disabled disabled,
popOverContainer
}: InputSwitchProps) { }: InputSwitchProps) {
return ( return (
<PopOverContainer <PopOverContainer
popOverContainer={popOverContainer}
popOverRender={({onClose}) => ( popOverRender={({onClose}) => (
<GroupedSelection <GroupedSelection
onClick={onClose} onClick={onClose}

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import {findDOMNode} from 'react-dom';
import { import {
Fields, Fields,
ConditionRule, ConditionRule,
@ -37,6 +38,7 @@ export interface ConditionItemProps extends ThemeProps, LocaleProps {
onChange: (value: ConditionRule, index?: number) => void; onChange: (value: ConditionRule, index?: number) => void;
fieldClassName?: string; fieldClassName?: string;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
export class ConditionItem extends React.Component<ConditionItemProps> { export class ConditionItem extends React.Component<ConditionItemProps> {
@ -102,8 +104,16 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
} }
renderLeft() { renderLeft() {
const {value, fields, funcs, config, disabled, fieldClassName, searchable} = const {
this.props; value,
fields,
funcs,
config,
disabled,
fieldClassName,
searchable,
popOverContainer
} = this.props;
return ( return (
<Expression <Expression
config={config} config={config}
@ -114,6 +124,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
fields={fields} fields={fields}
disabled={disabled} disabled={disabled}
searchable={searchable} searchable={searchable}
popOverContainer={popOverContainer}
allowedTypes={ allowedTypes={
['field', 'func'].filter( ['field', 'func'].filter(
type => type === 'field' || type === 'func' type => type === 'field' || type === 'func'
@ -124,7 +135,15 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
} }
renderOperator() { renderOperator() {
const {funcs, config, fields, value, classnames: cx, disabled} = this.props; const {
funcs,
config,
fields,
value,
classnames: cx,
disabled,
popOverContainer
} = this.props;
const left = value?.left; const left = value?.left;
let operators: Array<string> = []; let operators: Array<string> = [];
@ -152,6 +171,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
const __ = this.props.translate; const __ = this.props.translate;
return ( return (
<PopOverContainer <PopOverContainer
popOverContainer={popOverContainer || (() => findDOMNode(this))}
popOverRender={({onClose}) => ( popOverRender={({onClose}) => (
<GroupedSelection <GroupedSelection
onClick={onClose} onClick={onClose}
@ -242,7 +262,8 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
config, config,
classnames: cx, classnames: cx,
disabled, disabled,
formula formula,
popOverContainer
} = this.props; } = this.props;
let field = { let field = {
...config.types[type], ...config.types[type],
@ -282,6 +303,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
} }
disabled={disabled} disabled={disabled}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
<span className={cx('CBSeprator')}>~</span> <span className={cx('CBSeprator')}>~</span>
@ -300,6 +322,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
} }
disabled={disabled} disabled={disabled}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
</> </>
); );
@ -321,6 +344,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
} }
disabled={disabled} disabled={disabled}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
); );
} }

View File

@ -17,6 +17,7 @@ export interface ValueProps extends ThemeProps, LocaleProps {
op?: OperatorType; op?: OperatorType;
disabled?: boolean; disabled?: boolean;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
export class Value extends React.Component<ValueProps> { export class Value extends React.Component<ValueProps> {
@ -30,7 +31,8 @@ export class Value extends React.Component<ValueProps> {
translate: __, translate: __,
data, data,
disabled, disabled,
formula formula,
popOverContainer
} = this.props; } = this.props;
let input: JSX.Element | undefined = undefined; let input: JSX.Element | undefined = undefined;
if (formula) { if (formula) {
@ -76,6 +78,7 @@ export class Value extends React.Component<ValueProps> {
onChange={onChange} onChange={onChange}
timeFormat="" timeFormat=""
disabled={disabled} disabled={disabled}
popOverContainer={popOverContainer}
/> />
); );
} else if (field.type === 'time') { } else if (field.type === 'time') {
@ -90,6 +93,7 @@ export class Value extends React.Component<ValueProps> {
dateFormat="" dateFormat=""
timeFormat={field.format || 'HH:mm'} timeFormat={field.format || 'HH:mm'}
disabled={disabled} disabled={disabled}
popOverContainer={popOverContainer}
/> />
); );
} else if (field.type === 'datetime') { } else if (field.type === 'datetime') {
@ -102,6 +106,7 @@ export class Value extends React.Component<ValueProps> {
onChange={onChange} onChange={onChange}
timeFormat={field.timeFormat || 'HH:mm'} timeFormat={field.timeFormat || 'HH:mm'}
disabled={disabled} disabled={disabled}
popOverContainer={popOverContainer}
/> />
); );
} else if (field.type === 'select') { } else if (field.type === 'select') {
@ -119,6 +124,7 @@ export class Value extends React.Component<ValueProps> {
onChange={onChange} onChange={onChange}
multiple={op === 'select_any_in' || op === 'select_not_any_in'} multiple={op === 'select_any_in' || op === 'select_not_any_in'}
disabled={disabled} disabled={disabled}
popOverContainer={popOverContainer}
/> />
); );
} else if (field.type === 'boolean') { } else if (field.type === 'boolean') {

View File

@ -13,7 +13,6 @@ import {
mapTree, mapTree,
guid guid
} from '../../utils/helper'; } from '../../utils/helper';
import {findDOMNode} from 'react-dom';
import animtion from '../../utils/Animation'; import animtion from '../../utils/Animation';
import {FormulaPickerProps} from '../formula/Picker'; import {FormulaPickerProps} from '../formula/Picker';
@ -31,6 +30,7 @@ export interface ConditionBuilderProps extends ThemeProps, LocaleProps {
searchable?: boolean; searchable?: boolean;
fieldClassName?: string; fieldClassName?: string;
formula?: FormulaPickerProps; formula?: FormulaPickerProps;
popOverContainer?: any;
} }
export class QueryBuilder extends React.Component<ConditionBuilderProps> { export class QueryBuilder extends React.Component<ConditionBuilderProps> {
@ -210,7 +210,8 @@ export class QueryBuilder extends React.Component<ConditionBuilderProps> {
disabled, disabled,
searchable, searchable,
builderMode, builderMode,
formula formula,
popOverContainer
} = this.props; } = this.props;
const normalizedValue = Array.isArray(value?.children) const normalizedValue = Array.isArray(value?.children)
@ -247,6 +248,7 @@ export class QueryBuilder extends React.Component<ConditionBuilderProps> {
disabled={disabled} disabled={disabled}
searchable={searchable} searchable={searchable}
formula={formula} formula={formula}
popOverContainer={popOverContainer}
/> />
); );
} }