You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2022/05/28 19:39:15 UTC

[GitHub] [brooklyn-ui] geomacy commented on a diff in pull request #327: WIP: Added logic to check extra contraints

geomacy commented on code in PR #327:
URL: https://github.com/apache/brooklyn-ui/pull/327#discussion_r884170944


##########
ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js:
##########
@@ -520,6 +523,70 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService,
                             message = `<samp>${config.name}</samp> cannot be set if any of <samp>${args}</samp> are set`;
                         }
                         break;
+                    // needed to support error messages for extra constraints, optimisation: maybe add the constraint types to Brooklyn catalog.
+                    case '$brooklyn:object':
+                        if(args["type"] != null && EXTRA_CONSTRAINTS.includes(args["factoryMethod.name"])) {
+                            let fct = args["factoryMethod.name"];
+                            let constrVals = args["factoryMethod.args"];
+                            switch (fct) {
+                                case 'equal':
+                                    if (!isSet() || isSet() && val() !== constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> must be equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than':
+                                    if (!isSet() || isSet() && val() <= constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> must be greater than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than_or_equal':
+                                    if (!isSet() || isSet() && val() < constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> must be greater than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than':
+                                    if (!isSet() || isSet() && val() >= constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> must be less than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than_or_equal':
+                                    if (!isSet() || isSet() && val() > constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> must be less than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'in_range':
+                                    if (!isSet() || isSet() && val() >= constrVals[0] && val() <= constrVals[1]) {

Review Comment:
   Yeah but since we want to be inclusive to be valid, we shouldn't be using `>=` and `<=` to check for the invalid case. E.g. if `constrVals === [1, 10]` then 10 is valid (inclusive), but `val() <= constrVals[1]` will be `true` so the `if` will be true and you'll get the error message.
   
   As this `if` is a quite a big chunk of JS, it would be nice to pull it out into a separate function and add some unit tests for it in the `.spec.js`.
   



-- 
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: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org