-
-
Notifications
You must be signed in to change notification settings - Fork 275
[WiP] Textfield to support RegExp validation #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bugy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me, just a couple of improvement suggestions
src/model/parameter_config.py
Outdated
| if is_empty(value): | ||
| if self.required and not ignore_required: | ||
| return 'is not specified' | ||
| if self.regex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant
src/model/parameter_config.py
Outdated
| if self.regex is not None: | ||
| regex_pattern = self.regex.get('pattern', None) | ||
| if (not is_empty(regex_pattern)): | ||
| regex_matched = bool(re.match(regex_pattern, value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bool is not needed here
| title="Excluded files" | ||
| @error="handleError('Excluded files', $event)"/> | ||
| </div> | ||
| <div v-if="selectedType === 'text' || selectedType === undefined" class="row"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be you could combine it with the max length row?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, move both regex_pattern & regex_description textfields under the same div with max_length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
| let regexPattern = new RegExp(regex.pattern); | ||
| let matchFound = regexPattern.test(value); | ||
| if (!matchFound) { | ||
| return regex.description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since description can be empty, please provide a fallback value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When/if description is left empty, regex.description is the regex pattern itself. The idea is to provide the end-user with a meaningful error message when it comes to regex validation but if, for some reason, you don't, shouldn't print the regex pattern is enough of a fallback value?
script-server/src/model/parameter_config.py
Line 302 in 8ade772
| return 'does not match regex pattern: ' + self.regex.get('description', regex_pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python code you are referencing is a backend validation, a user should never see it. It's just an additional safety net.
| function getValidByTypeError(value, type, min, max, max_length) { | ||
| function getValidByTypeError(value, type, min, max, max_length, regex) { | ||
| if (type === 'text') { | ||
| if (regex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test to https://github.com/bugy/script-server/blob/master/web-src/tests/unit/textfield_test.js ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I get started with tests? How do I run them locally on my dev env?
It would be nice to document this on the Wiki somewhere :-)
| return None | ||
|
|
||
| if self.type == 'text': | ||
| if self.regex is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a couple of tests?
| self.min = config.get('min') | ||
| self.max = config.get('max') | ||
| self.max_length = config.get('max_length') | ||
| self.regex = config.get('regex') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the method "get_sorted_config" below
| this.min = config['min']; | ||
| this.max = config['max']; | ||
| this.max_length = config['max_length']; | ||
| this.regex_pattern = get(config, 'regex.pattern', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use camelCase for naming in javascript
|
Hello , The parameter section below : - "parameters": [ Regards, |
|
Hi @ashishp0911, how did you test it? This PR was not merged, i.e. not available in script server builds. |
# Conflicts: # src/model/parameter_config.py # src/tests/test_utils.py # web-src/src/admin/components/scripts-config/ParameterConfigForm.vue
…ther minor fixes
|
I have to apologize to @drehelis for missing that one. To be honest I was waiting for "review request", but I had to check this ticket on my own. Totally my fault for not tracking the project properly. I made some minor adjustments, and will wait for build before merging. Probably tomorrow. |
I was in a need for special form of
textfield validation done on the frontend. This PR tries to solve this by adding regular-expression validation capabilities.Couple of caveats -
\when editing JSON config manually is required.Can't get the Admin UI properly generateregexobject. Hence, WiP :-)Parameter config should look like:
Small demo:
Screen.Recording.2021-06-14.at.15.48.54.mov