Skip to content

Commit

Permalink
#1666 Fixed bug setDefaultValues option clears all the existing prope…
Browse files Browse the repository at this point in the history
…rties (#1667)
  • Loading branch information
nmgokhale authored Jan 16, 2024
1 parent ba48b61 commit c2e6645
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { expect } from "chai";
import sinon from "sinon";
import deepFreeze from "deep-freeze";
import { merge } from "lodash";
import propertyUtils from "../_utils_/property-utils";
import Controller from "../../src/common-properties/properties-controller";
import Form from "../../src/common-properties/form/Form";
Expand Down Expand Up @@ -1209,11 +1210,16 @@ describe("Properties Controller handlers", () => {
controller.setPropertyValues(filteredValues);
// Verify value is not set for checkbox_hidden
expect(controller.getPropertyValues()).not.to.have.property("checkbox_hidden");
// Verify filteredValues are set
expect(controller.getPropertyValues()).to.eql(filteredValues);

// setDefaultValues is set to true
controller.setPropertyValues(filteredValues, { setDefaultValues: true });
// Verify a value is set for checkbox_hidden
expect(controller.getPropertyValues()).to.have.property("checkbox_hidden", true);
// Verify filteredValues and default values are set
const allProperties = merge({ "checkbox_hidden": true }, filteredValues);
expect(controller.getPropertyValues()).to.eql(allProperties);

// Verify there's a single call to the propertyListener()
expect(propertyListener.calledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { STATES, ACTIONS, CONDITION_TYPE, PANEL_TREE_ROOT, CONDITION_MESSAGE_TYP
import CommandStack from "../command-stack/command-stack.js";
import ControlFactory from "./controls/control-factory";
import { Type, ParamRole, ControlType, ItemType } from "./constants/form-constants";
import { has, cloneDeep, assign, isEmpty, isEqual, isUndefined, get, difference } from "lodash";
import { has, cloneDeep, assign, isEmpty, isEqual, isUndefined, get, difference, merge } from "lodash";
import Form from "./form/Form";
import { getConditionOps } from "./ui-conditions/condition-ops/condition-ops";
import { DEFAULT_LOCALE } from "./constants/constants";
Expand Down Expand Up @@ -441,22 +441,10 @@ export default class PropertiesController {
}

if (setDefaultValues) {
this.setDefaultControlValues(defaultControlValues);
return defaultControlValues;
}
}

setDefaultControlValues(defaultControlValues) {
// Update all default values
this.propertiesStore.setPropertyValues(defaultControlValues);

// Single call to the propertyListener
if (this.handlers.propertyListener) {
this.handlers.propertyListener(
{
action: ACTIONS.SET_PROPERTIES // Setting the default control values
}
);
}
return null;
}

_populateFieldData(controlValue, control) {
Expand Down Expand Up @@ -1254,6 +1242,11 @@ export default class PropertiesController {
}
}

if (options && options.setDefaultValues) {
const defaultValues = this._addToControlValues(false, false, true);
inValues = merge(defaultValues, inValues);
}

this.propertiesStore.setPropertyValues(inValues);

if (options && options.isInitProps) {
Expand Down Expand Up @@ -1291,10 +1284,6 @@ export default class PropertiesController {
}
);
}

if (options && options.setDefaultValues) {
this._addToControlValues(false, false, true);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setup_git_branch
checkout_branch ${MAIN}

cd ./canvas_modules/common-canvas
npm version minor
npm version patch
NPM_VERSION=`node -p "require('./package.json').version"`
echo "Updated main build $NPM_VERSION"
commit_changes ${MAIN} "Update Elyra Canvas to version ${NPM_VERSION} [skip ci]"
Expand Down

0 comments on commit c2e6645

Please sign in to comment.