-
Notifications
You must be signed in to change notification settings - Fork 316
fix: LEAP-447: Fix Number tag validation #1649
Conversation
Improved the validation logic in ClassificationBase.js, DateTime.js, and PerRegion.js. Provided distinct validation scenarios for classifications, including per region and per object, and streamlined the date validation in DateTime.js for better precision and simplicity.
The Number model was modified to improve validation logic. 'validateValue' function was added to cover more number validation cases such as minimum, maximum, and step checks. Furthermore, some parameter descriptions were adjusted for better clarity, namely the 'required' parameter definition.
Makes it be able to work in chain with other validations
A new feature flag controlled code block was introduced to enable the validation of per-item tags as part of the Classification Base and Per Item Mixin. If the feature flag FF_LSDV_4583 is active and self.peritem is true, the new `_validatePerItem` method is used to validate each region result.
This commit introduces functional tests for various configurations of the number control tag. It covers setting and loading of values, validation against min/max and steps, perRegion and perItem validation, and proper error display for each case.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1649 +/- ##
==========================================
+ Coverage 68.27% 68.36% +0.08%
==========================================
Files 443 443
Lines 28690 28735 +45
Branches 7633 7642 +9
==========================================
+ Hits 19589 19644 +55
+ Misses 7849 7841 -8
+ Partials 1252 1250 -2 ☔ View full report in Codecov by Sentry. |
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.
leaving only linting comments for now, but blocking PR to check the actual validation, change here is pretty big and important
@@ -22,6 +22,26 @@ const PerItemMixin = types | |||
}, | |||
})) | |||
.actions(self => ({ | |||
_validatePerItem() { |
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.
what's the idea behind underscore here? we use underscores rarely and for purely internal things, and those are called from other models using this mixin.
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 idea was to prevent using this method outside of the bundle PerItemMixin <-> ClassificationBase
. I'm not sure how to prevent it in better way.
return self._validatePerObject(); | ||
} | ||
}, | ||
validateValue() { |
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.
comment on underscores: feels especially wrong to see those methods one by one with different styles
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.
It's great 'cause validateValue
should be overridden and _validatePerObject
should not. It's good if you can feel that something here must to be taken in account.
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.
add a comment that this method is the one to override in inheritors, not validate()
Co-authored-by: yyassi-heartex <[email protected]>
…s/label-studio-frontend into fb-leap-447/number-validation
return self._validatePerObject(); | ||
} | ||
}, | ||
validateValue() { |
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.
add a comment that this method is the one to override in inheritors, not validate()
/git merge master
|
Signed-off-by: Sergey <[email protected]>
Signed-off-by: Sergey <[email protected]>
Signed-off-by: Sergey <[email protected]>
Signed-off-by: Sergey <[email protected]>
# Conflicts: # tests/functional/package.json # tests/functional/yarn.lock
Signed-off-by: Sergey <[email protected]>
Signed-off-by: Sergey <[email protected]>
Co-authored-by: hlomzik <[email protected]>
* refactor: LEAP-447: Refactor validation method across control tags Improved the validation logic in ClassificationBase.js, DateTime.js, and PerRegion.js. Provided distinct validation scenarios for classifications, including per region and per object, and streamlined the date validation in DateTime.js for better precision and simplicity. * fix: LEAP-447: Improve Number tag validation The Number model was modified to improve validation logic. 'validateValue' function was added to cover more number validation cases such as minimum, maximum, and step checks. Furthermore, some parameter descriptions were adjusted for better clarity, namely the 'required' parameter definition. * Improve validation method of Required mixin Makes it be able to work in chain with other validations * Add validation for per-item tags A new feature flag controlled code block was introduced to enable the validation of per-item tags as part of the Classification Base and Per Item Mixin. If the feature flag FF_LSDV_4583 is active and self.peritem is true, the new `_validatePerItem` method is used to validate each region result. * Update ls-test dependency in functional tests * Add functional tests for number control tag This commit introduces functional tests for various configurations of the number control tag. It covers setting and loading of values, validation against min/max and steps, perRegion and perItem validation, and proper error display for each case. * Fix linting issues * Fix the accidental deletion of a line of code * Refactor with simplifying Co-authored-by: yyassi-heartex <[email protected]> * Fix linting problems and texts * Update @heartexlabs/ls-test version Signed-off-by: Sergey <[email protected]> * Add comments about new methods and tricky changes Signed-off-by: Sergey <[email protected]> * Make validation tests more intuitive Signed-off-by: Sergey <[email protected]> * Remove unused import in number.cy Signed-off-by: Sergey <[email protected]> * Fix comments for validation methods Signed-off-by: Sergey <[email protected]> * Update @heartexlabs/ls-test package version Signed-off-by: Sergey <[email protected]> --------- Signed-off-by: Sergey <[email protected]> Co-authored-by: yyassi-heartex <[email protected]>
PR fulfills these requirements
[fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made
ex.fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors
Change has impacts in these area(s)
(check all that apply)
Describe the reason for change
The change was necessary due to failures of the number validation in some cases that resulted in the ability to save invalid values.
What does this fix?
This fix introduces value validation for the Number tag, conducts a refactoring of the existing validation code, and implements a per-item mode validation.
Does this change affect performance?
Nope
Does this change affect security?
Nope
What alternative approaches were there?
N/A
What feature flags were used to cover this change?
N/A
Does this PR introduce a breaking change?
(check only one)
At least it should not.
What level of testing was included in the change?
(check all that apply)
Which logical domain(s) does this change affect?
Number
,DateTime
,Validation
,Required
,perItem