Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219920469
--- Diff:
ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
---
@@ -275,20 +275,54 @@ function BlueprintService($log, $q, $sce, paletteApi,
iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints &&
Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints &&
config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of
Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
let message = null;
+ let key = null, args = null;
+ if (constraintO instanceof String) {
+ key = constraintO;
+ } else if (Object.keys(constraintO).length==1)
{
+ key = Object.keys(constraintO)[0];
+ args = constraintO[key];
+ } else {
+ $log.warn("Unknown constraint object",
constraintO);
+ key = constraintO;
+ }
+ let val = (k) => entity.config.get(k ||
config.name);
+ let isSet = (k) => entity.config.has(k ||
config.name) && angular.isDefined(val(k));
+ let hasDefault = () =>
angular.isDefined(config.defaultValue);
switch (key) {
case 'Predicates.notNull()':
case 'required':
- if
(!angular.isDefined(config.defaultValue) && (!entity.config.has(config.name) ||
!angular.isDefined(entity.config.get(config.name)))) {
+ if (!isSet() && !hasDefault() &&
val()!='') {
+ // "required" also means that it
must not be the empty string
message =
`<samp>${config.name}</samp> is required`;
}
break;
case 'regex':
- if (!entity.config.has(config.name) ||
!angular.isDefined(entity.config.get(config.name)) || !(new
RegExp(constraint).test(entity.config.get(config.name)))) {
- message =
`<samp>${config.name}</samp> does not match the required format:
<samp>${config.constraints.regex}</samp>`;
+ if (isSet() && !(new
RegExp(args).test(val))) {
--- End diff --
Should the regex constraint respect default values? e.g. if a `username`
config key has a default of `brooklyn` and a constraint of `regex: [a-z]+`,
then I think we should not force the user to override the default. I can
imagine other defaults, like a default cidr with a regex enforcing that a
user-supplied cidr is in the right format.
---