Skip to content

Commit

Permalink
Fix bug with func arg with 1 value source (#415)
Browse files Browse the repository at this point in the history
* Fix bug with func arg with 1 value source

* Update CHANGELOG.md

* Update package.json
  • Loading branch information
ukrbublik authored Jun 15, 2021
1 parent bc50a8e commit b62bc03
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
- 4.0.4
- Fixed issue #413 with func arg with 1 value source which is not value
- 4.0.3
- Fixed issue #386 with import select field from JsonLogic (reason: bug with func/field widget in getWidgetForFieldOp)
- Fixed issue #387 with subgroups in Material UI
Expand Down
15 changes: 12 additions & 3 deletions modules/components/rule/FuncWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ export default class FuncWidget extends PureComponent {
};

setArgValue = (argKey, argVal) => {
this.props.setValue( setArgValue(this.props.value, argKey, argVal) );
const {funcDefinition} = this.meta;
const {args} = funcDefinition;
const argDefinition = args[argKey];

this.props.setValue( setArgValue(this.props.value, argKey, argVal, argDefinition) );
};

setArgValueSrc = (argKey, argValSrc) => {
this.props.setValue( setArgValueSrc(this.props.value, argKey, argValSrc) );
const {funcDefinition} = this.meta;
const {args} = funcDefinition;
const argDefinition = args[argKey];

this.props.setValue( setArgValueSrc(this.props.value, argKey, argValSrc, argDefinition) );
};

renderFuncSelect = () => {
Expand Down Expand Up @@ -108,7 +116,8 @@ export default class FuncWidget extends PureComponent {
const {config, field, operator, value, readonly} = this.props;
const arg = value ? value.getIn(["args", argKey]) : null;
const argVal = arg ? arg.get("value") : undefined;
const argValSrc = arg ? (arg.get("valueSrc") || "value") : undefined;
const defaultValueSource = argDefinition.valueSources.length == 1 ? argDefinition.valueSources[0] : undefined;
const argValSrc = arg ? (arg.get("valueSrc") || defaultValueSource || "value") : defaultValueSource;

const widgetProps = {
config,
Expand Down
15 changes: 12 additions & 3 deletions modules/utils/funcUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export const completeFuncValue = (value, config) => {
for (const argKey in funcConfig.args) {
const argConfig = funcConfig.args[argKey];
const args = complValue.get("args");
const argDefaultValueSrc = argConfig.valueSources.length == 1 ? argConfig.valueSources[0] : undefined;
const argVal = args ? args.get(argKey) : undefined;
const argValue = argVal ? argVal.get("value") : undefined;
const argValueSrc = argVal ? argVal.get("valueSrc") : undefined;
const argValueSrc = (argVal ? argVal.get("valueSrc") : undefined) || argDefaultValueSrc;
if (argValue !== undefined) {
const completeArgValue = completeValue(argValue, argValueSrc, config);
if (completeArgValue === undefined) {
Expand Down Expand Up @@ -134,10 +135,17 @@ export const setFunc = (value, funcKey, config) => {
* @param {Immutable.Map} value
* @param {string} argKey
* @param {*} argVal
* @param {object} argConfig
*/
export const setArgValue = (value, argKey, argVal) => {
export const setArgValue = (value, argKey, argVal, argConfig) => {
if (value && value.get("func")) {
value = value.setIn(["args", argKey, "value"], argVal);

// set default arg value sorce
const argDefaultValueSrc = argConfig.valueSources.length == 1 ? argConfig.valueSources[0] : undefined;
if (argDefaultValueSrc) {
value = value.setIn(["args", argKey, "valueSrc"], argDefaultValueSrc);
}
}
return value;
};
Expand All @@ -147,8 +155,9 @@ export const setArgValue = (value, argKey, argVal) => {
* @param {Immutable.Map} value
* @param {string} argKey
* @param {string} argValSrc
* @param {object} argConfig
*/
export const setArgValueSrc = (value, argKey, argValSrc) => {
export const setArgValueSrc = (value, argKey, argValSrc, argConfig) => {
if (value && value.get("func")) {
value = value.setIn(["args", argKey], new Immutable.Map({valueSrc: argValSrc}));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-awesome-query-builder",
"version": "4.0.3",
"version": "4.0.4",
"description": "User-friendly query builder for React. Demo: https://ukrbublik.github.io/react-awesome-query-builder",
"keywords": [
"query-builder",
Expand Down

0 comments on commit b62bc03

Please sign in to comment.