-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix the script to treat the value 0 not as falsy values. #441
Conversation
ed98b33
to
4eb8092
Compare
e54e036
to
3e8ee4e
Compare
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.
as the styling/linting blurred the changes differential, some comments to clarify what I added
"prettier": { | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 4, | ||
"useTabs": true |
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.
to help with consistent styling
const checkforInvalid = entry => { | ||
const entryAsNumber = parseFloat($field); // to validate it as a numnber | ||
|
||
const recordHasTreatments = !arrayItemsInSecondArray( | ||
treatmentExceptionTypes, | ||
treatmentTypes, | ||
); | ||
return ( | ||
[null, undefined, ''].includes($field) || // first dispose of the regular falsy values | ||
(!isNaN(entryAsNumber) && entryAsNumber < 0) || // checks for valid numbers | ||
/^\s+$/g.test(decodeURI(entry).replace(/^"(.*)"$/, '$1')) | ||
); // whitespace-filled strings | ||
}; |
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.
This checkForInvalid
function now checks beyond whitespace strings whether there's falsy
values given, while allowing 0+
to pass.
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.
sorry @justincorrigible I forgot to mention that the intervals have been adjusted to accept negative numbers: #436
By definition, all intervals are allowed to accept integers including negative, positive and 0. For example:
- treatment_start_interval: https://github.com/icgc-argo/argo-dictionary/blob/develop/schemas/treatment.json#L127
- specimen_acquisition_interval: https://github.com/icgc-argo/argo-dictionary/blob/develop/schemas/specimen.json#L144
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.
ahh! good to know! the code should reflect that 👍
I'll make the changes and document as a comment for future reference
(using explanation in #432)
[ | ||
'treatment_start_interval is submitted to be a fraction when treatment was given', | ||
true, | ||
loadObjects(treatment, { | ||
treatment_start_interval: 0.5, | ||
treatment_type: ['Surgery'], | ||
}), | ||
], | ||
[ | ||
'treatment_start_interval is submitted to be negative when treatment was given', | ||
false, | ||
loadObjects(treatment, { | ||
treatment_start_interval: -0.2, | ||
treatment_type: ['Ablation'], | ||
}), | ||
], | ||
], |
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.
a couple of additional tests to ensure even fractions pass, but not negative numbers.
3e8ee4e
to
43b12c7
Compare
fix the treatment interval validation script to accept 0 (#441)
fix the treatment interval validation script to accept 0 (#441)
postmortem comment: this PR removed a parenthesis that wraps the script, which we've realised was mandatory, and had to re-add afterwards. Tabs indentation is okay though, which is great for accessibility. |
The issue (#440) arises because the script treats the value
0
as falsy in the condition (!$field || $field === null || checkforEmpty($field)), so it incorrectly triggers the validation error.Steps To Test
Context:
Steps to test the behaviour:
0