jathanasiou commented on a change in pull request #263:
URL: https://github.com/apache/brooklyn-ui/pull/263#discussion_r683580595
##########
File path:
ui-modules/blueprint-composer/app/components/util/model/entity.model.js
##########
@@ -685,7 +685,17 @@ function addConfigKeyDefinition(param, overwrite,
skipUpdatesDuringBatch) {
let key = (param || {}).name;
if (!key) throw new Error("'name' field must be included when adding
parameter; was", param);
- allConfig[key] = Object.assign(allConfig[key] || {}, param, overwrite
? null : allConfig[key]);
+ let paramMapped = Object.assign({}, param);
Review comment:
I feel confident the below would be a much cleaner version of this
function with the same behaviour. I'd really suggest something closer to this
for maintenance purposes if it feels accurate logic-wise.
```javascript
function addConfigKeyDefinition(param, overwrite, skipUpdatesDuringBatch) {
const allConfig = this.miscDataOrDefault('configMap', {});
if (typeof param !== 'undefined') {
const parameterItem = (typeof param !== 'string')
? { ...param } // shallow copy as object
: {
"name": param,
"label": param,
"description": "",
"priority": 1,
"pinned": true,
"type": "java.lang.String",
"constraints": [],
};
const key = get(parameterItem, 'name'); // import { get } from
'lodash' at top, defaults to undef.
// this will also throw if original `param` is neither object nor
string due to previous statement
if (!key) throw new Error("'name' field must be included when adding
parameter; was", param);
if (typeof parameterItem.default !== 'undefined') {
/* Annoyingly, in parameters, we call the default value
"default",
* but in config, we call them "defaultValue";
* when params are merged to config we need to rename
*/
parameterItem.defaultValue = parameterItem.default;
delete parameterItem.default;
}
Object.assign(allConfig[key], parameterItem);
}
if (!skipUpdatesDuringBatch) {
this.miscData.set('config', Object.values(allConfig));
}
this.touch();
return this;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]