Skip to content

Commit

Permalink
Merge pull request baidu#9535 from 2betop/fix-condition-builder
Browse files Browse the repository at this point in the history
fix: 修复 condition-builder 切换字段选项不更新问题问题 Close: baidu#9455 baidu#9478
  • Loading branch information
hsm-lv committed Jan 30, 2024
2 parents c6bbbdb + c79a65f commit add8cd2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/amis-ui/src/components/condition-builder/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
const value = {
...this.props.value,
left: leftValue,
op: field?.defaultOp || config.types[field?.type]?.defaultOp || undefined,
op:
field?.defaultOp ??
(Array.isArray(field?.operators) && field.operators.length === 1
? field.operators[0].value || field.operators[0]
: undefined) ??
config.types[field?.type]?.defaultOp ??
undefined,
right: undefined
};
const onChange = this.props.onChange;
Expand Down Expand Up @@ -246,8 +252,8 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
ref={ref}
allowInput={false}
result={
__(OperationMap[value?.op as keyof typeof OperationMap]) ||
options.find(option => option.value === value.op)?.label
options.find(option => option.value === value.op)?.label ||
__(OperationMap[value?.op as keyof typeof OperationMap])
}
onResultChange={noop}
onResultClick={onClick}
Expand Down Expand Up @@ -350,6 +356,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
return (
<>
<Expression
key={`${field.name}-0`}
config={config}
funcs={funcs}
valueField={field}
Expand All @@ -370,6 +377,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
<span className={cx('CBSeprator')}>~</span>

<Expression
key={`${field.name}-1`}
config={config}
funcs={funcs}
valueField={field}
Expand All @@ -393,6 +401,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
return (
<span key={i}>
<Expression
key={`${field.name}-${i}`}
config={config}
op={op}
funcs={funcs}
Expand All @@ -416,6 +425,7 @@ export class ConditionItem extends React.Component<ConditionItemProps> {
}
return (
<Expression
key={`${field.name}-0`}
config={config}
op={op}
funcs={funcs}
Expand Down

0 comments on commit add8cd2

Please sign in to comment.