Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r220107724
--- 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 --
@aledsage you're asking what if the default value is invalid? i think it
would be weird to give a user error in that case. it probably is an error, but
on the upstream blueprint author's part, not the consumer's part. so i think
we shouldn't -- and we don't currently -- test the default value.
---