This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git
commit e189b375524677ed86f5863d784ffbd9397901d5 Author: Alex Heneveld <[email protected]> AuthorDate: Tue Apr 27 12:57:29 2021 +0100 update miscData.config on parameter refresh, and do validation after quick fixes validation pathway working nicely now --- .../providers/blueprint-service.provider.js | 35 +++++------ .../app/components/quick-fix/quick-fix.js | 1 - .../spec-editor/spec-editor.directive.js | 2 + .../app/components/util/model/entity.model.js | 71 ++++++++++++---------- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js index 0132a85..47e7fa3 100644 --- a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js +++ b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js @@ -297,19 +297,23 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService) }).catch(function (error) { deferred.resolve(populateEntityFromApiError(entity, error)); }); - } else if (entity.parent) { - entity.clearIssues({group: 'type'}).addIssue(Issue.builder().group('type').message('Entity needs a type').level(ISSUE_LEVEL.WARN).build()); - entity.miscData.set('sensors', []); - entity.miscData.set('traits', []); - deferred.resolve(entity); - addUnlistedConfigKeysDefinitions(entity); - addUnlistedParameterDefinitions(entity); } else { + if (entity.parent) { + entity.clearIssues({group: 'type'}).addIssue(Issue.builder().group('type').message('Entity needs a type').level(ISSUE_LEVEL.WARN).build()); + } entity.miscData.set('sensors', []); entity.miscData.set('traits', []); - deferred.resolve(entity); + + entity.clearIssues({group: 'config'}); + entity.miscData.set('config', []); + entity.miscData.set('configMap', {}); + entity.miscData.set('parameters', []); + entity.miscData.set('parametersMap', {}); + addUnlistedConfigKeysDefinitions(entity); addUnlistedParameterDefinitions(entity); + + deferred.resolve(entity); } return deferred.promise; @@ -585,7 +589,6 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService) } function addConfigKeyDefinition(entity, key) { - // TODO return type, and below entity.addConfigKeyDefinition(key, false); } @@ -597,24 +600,18 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService) // copy config key definitions set on this entity into the miscData aggregated view let allConfig = entity.miscDataOrDefault('configMap', {}); entity.config.forEach((value, key) => { - if (!allConfig[key]) { - entity.addConfigKeyDefinition(key); - } + entity.addConfigKeyDefinition(key, false, true); }); - entity.miscData.set('config', Object.values(allConfig)); - + entity.addConfigKeyDefinition(null, false, false); } function addUnlistedParameterDefinitions(entity) { // copy parameter definitions set on this entity into the miscData aggregated view; // see discussions in PR 112 about whether this is necessary and/or there is a better way; but note, this is much updated since - let allParams = entity.miscDataOrDefault('parametersMap', {}); entity.parameters.forEach((param) => { - if (!allParams[param.name]) { - allParams[param.name] = param; - } + entity.addParameterDefinition(param, false, true); }); - entity.miscData.set('parameters', Object.values(allParams)); + entity.addParameterDefinition(null, false, false); } function populateEntityFromApiSuccess(entity, data) { diff --git a/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js b/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js index ffcaa60..5204052 100644 --- a/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js +++ b/ui-modules/blueprint-composer/app/components/quick-fix/quick-fix.js @@ -124,7 +124,6 @@ function proposeSetFrom() { let createable = qfdef['source-key-createable']; - // TODO if root param is required, show error // TODO make default id contain type name // TODO show default id if no id present diff --git a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js index b1e556f..1f71e62 100644 --- a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js +++ b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js @@ -268,6 +268,7 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani scope.applyQuickFix = (issue, fix) => { fix.apply(issue, scope.model); + blueprintService.refreshBlueprintMetadata(); } scope.getObjectSize = (object) => { @@ -1217,6 +1218,7 @@ export function specEditorDirective($rootScope, $templateCache, $injector, $sani if (scope.state.parameters.focus === name) { scope.state.parameters.focus = ''; } + blueprintService.refreshBlueprintMetadata(scope.model); } } } diff --git a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js index 1eb2343..71a5912 100644 --- a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js +++ b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js @@ -653,46 +653,53 @@ function addConfig(key, value) { } } -function addConfigKeyDefinition(param, overwrite) { - if (typeof param === 'string') { - param = { - "name": param, - "label": param, - "description": "", - "priority": 1, - "pinned": true, - "type": "java.lang.String", - "constraints": [], - }; - overwrite = false; - } - let key = (param || {}).name; - if (!key) throw new Error("'name' field must be included when adding parameter; was", param); - +function addConfigKeyDefinition(param, overwrite, skipUpdatesDuringBatch) { let allConfig = this.miscDataOrDefault('configMap', {}); - allConfig[key] = Object.assign(allConfig[key] || {}, param, overwrite ? null : allConfig[key]); - this.miscData.set('config', Object.values(allConfig)); + if (param) { + if (typeof param === 'string') { + param = { + "name": param, + "label": param, + "description": "", + "priority": 1, + "pinned": true, + "type": "java.lang.String", + "constraints": [], + }; + overwrite = false; + } + 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]); + } + if (!skipUpdatesDuringBatch) { + this.miscData.set('config', Object.values(allConfig)); + } this.touch(); return this; } -function addParameterDefinition(param, overwrite) { - if (typeof param === 'string') { - param = {name: key, type: 'string'}; - overwrite = false; - } - let key = (param || {}).name; - if (!key) throw new Error("'name' field must be included when adding parameter"); - +function addParameterDefinition(param, overwrite, skipUpdatesDuringBatch) { let allParams = this.miscDataOrDefault('parametersMap', {}); - allParams[key] = Object.assign(allParams[key] || {}, param, overwrite ? null : allParams[key]); - this.miscData.set('parameters', Object.values(allParams)); + if (param) { + if (typeof param === 'string') { + param = {name: key, type: 'string'}; + overwrite = false; + } + let key = (param || {}).name; + if (!key) throw new Error("'name' field must be included when adding parameter"); + + param = allParams[key] = Object.assign(allParams[key] || {}, param, overwrite ? null : allParams[key]); - let eps = PARAMETERS.get(this); - this.updateParameter(key, allParams[key], true); + this.updateParameter(key, param, true); + } + if (!skipUpdatesDuringBatch) { + this.miscData.set('parameters', Object.values(allParams)); + } - this.addConfigKeyDefinition(allParams[key], overwrite); + this.addConfigKeyDefinition(param, overwrite, skipUpdatesDuringBatch); this.touch(); return this; @@ -721,7 +728,7 @@ function removeConfig(key) { } /** - * Remove an entry from brooklyn.parameters + * Remove an entry from brooklyn.parameters; note the model needs an update after this * @param {string} name * @returns {Entity} */
