Skip to content

Commit

Permalink
Use func arg type in field selection (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukrbublik committed Mar 15, 2022
1 parent 043048c commit 0a54e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added config `removeIncompleteRulesOnLoad` (default false) (PR #661) (issue #642)
- Fix error when using same field for comparison as argument of function (PR #662) (issue #612)
- Set missing `id` in `fixPathsInTree()` (PR #665) (issue #664)
- Use func arg type in field selection (PR #666) (issue #615)
- 5.1.1
- Fix value null instead of undefined in JSON (PR #657) (issue #653)
- 5.1.0
Expand Down
15 changes: 8 additions & 7 deletions modules/components/rule/ValueField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default class ValueField extends PureComponent {

onPropsChanged(nextProps) {
const prevProps = this.props;
const keysForItems = ["config", "field", "operator", "isFuncArg", "placeholder"];
const keysForMeta = ["config", "field", "operator", "value", "parentField"];
const keysForItems = ["config", "field", "operator", "isFuncArg", "parentField"];
const keysForMeta = ["config", "field", "operator", "value", "placeholder", "isFuncArg", "parentField"];
const needUpdateItems = !this.items || keysForItems.map(k => (nextProps[k] !== prevProps[k])).filter(ch => ch).length > 0;
const needUpdateMeta = !this.meta || keysForMeta.map(k => (nextProps[k] !== prevProps[k])).filter(ch => ch).length > 0;

Expand All @@ -46,15 +46,14 @@ export default class ValueField extends PureComponent {
}
}

getItems({config, field, operator, parentField, isFuncArg}) {
getItems({config, field, operator, parentField, isFuncArg, fieldDefinition}) {
const {canCompareFieldWithField} = config.settings;

const fieldSeparator = config.settings.fieldSeparator;
const parentFieldPath = typeof parentField == "string" ? parentField.split(fieldSeparator) : parentField;
const parentFieldConfig = parentField ? getFieldConfig(config, parentField) : null;
const sourceFields = parentField ? parentFieldConfig && parentFieldConfig.subfields : config.fields;

const filteredFields = this.filterFields(config, sourceFields, field, parentField, parentFieldPath, operator, canCompareFieldWithField, isFuncArg);
const filteredFields = this.filterFields(config, sourceFields, field, parentField, parentFieldPath, operator, canCompareFieldWithField, isFuncArg, fieldDefinition);
const items = this.buildOptions(parentFieldPath, config, filteredFields, parentFieldPath);
return items;
}
Expand Down Expand Up @@ -87,13 +86,15 @@ export default class ValueField extends PureComponent {
};
}

filterFields(config, fields, leftFieldFullkey, parentField, parentFieldPath, operator, canCompareFieldWithField, isFuncArg) {
filterFields(config, fields, leftFieldFullkey, parentField, parentFieldPath, operator, canCompareFieldWithField, isFuncArg, fieldDefinition) {
fields = clone(fields);
const fieldSeparator = config.settings.fieldSeparator;
const leftFieldConfig = getFieldConfig(config, leftFieldFullkey);
let expectedType;
const widget = getWidgetForFieldOp(config, leftFieldFullkey, operator, "value");
if (widget) {
if (isFuncArg && fieldDefinition) {
expectedType = fieldDefinition.type;
} else if (widget) {
let widgetConfig = config.widgets[widget];
let widgetType = widgetConfig.type;
//expectedType = leftFieldConfig.type;
Expand Down

0 comments on commit 0a54e42

Please sign in to comment.