-
Notifications
You must be signed in to change notification settings - Fork 147
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
Fixed scoremeter readings limit check and playground controls #27
base: main
Are you sure you want to change the base?
Conversation
imanshu03
commented
Jul 11, 2022
- Added logic to check if our readings are within the specified lowerLimit and upperLimit as follows:
- If oldReading prop does not exists, set the sanitizedOldReading value to LOWER_THRESHOLD.
- If oldReading prop exists, check if its values is greater than upperLimit or less than lowerLimit and set the sanitizedOldReading value respectively to upperLimit or lowerLimit. If oldReading falls within the specified limit, set the sanitizedOldReading value to oldReading prop value.
- If reading prop value falls out of the specified limit range( greater than upperLimit or less than lowerLimit) then set the sanitizedReading value to sanitizedOldReading otherwise set it to reading prop value
- Fixed storybook playground controls
src/components/Scoremeter/index.tsx
Outdated
const sanitizedOldReading = oldReading | ||
? oldReading < 0 | ||
? LOWER_THRESHOLD | ||
? oldReading < lowerLimit |
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 can you simplify the logic or wrap the truthy and falsy blocks in braces, to make it more readable. (I would advocate for simplification of logic) Thanks!
Something like:
const sanitizedOldReading = oldReading
? (oldReading < lowerLimit
? lowerLimit
: (
oldReading > upperLimit
? upperLimit
: oldReading
)
)
: LOWER_THRESHOLD;
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.
Eslint rules does not allow us to add braces for ternary expression. I had added braces but they got removed while committing the files