OBPIH-7039 Populate Root Cause dropdown with proper values when recounting#5074
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5074 +/- ##
============================================
- Coverage 8.02% 8.01% -0.01%
Complexity 918 918
============================================
Files 634 634
Lines 43050 43064 +14
Branches 10419 10424 +5
============================================
Hits 3453 3453
- Misses 39072 39086 +14
Partials 525 525 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| @@ -67,7 +67,7 @@ const useResolveStepTable = ({ | |||
|
|
|||
| useEffect(() => { | |||
| if (!reasonCodes.length) { | |||
There was a problem hiding this comment.
Line 51 is my current issue.
const {
reasonCodes,
} = useSelector((state) => ({
reasonCodes: state.reasonCodes.data,
}));
reasonCodes is always already populated with the full list of ReasonCode values when we first get here so we never enter the !reasonCodes.length condition to fetch just the ADJUST_INVENTORY ones.
I'm assuming I need to switch this to something like: reasonCodes: state.cycleCountReasonCodes.data,
but I don't know enough about React to know how to set the state properly. Something with "useState" it seems. I'll keep poking around but if anyone has inslight, let me know.
src/js/actions/index.js
Outdated
| let url = '/api/reasonCodes'; | ||
| if (activityCode) { | ||
| url += `?activityCode=${activityCode}`; | ||
| } |
There was a problem hiding this comment.
I am not a big fan of mutating values, so I prefer something like:
const url = `/api/reasonCodes${activityCode ? `?activityCode=${activityCode}` : ''}`
src/js/actions/index.js
Outdated
| if (res.data) { | ||
| // These reason codes are exclusively used in dropdown selectors, so for the sake of | ||
| // convenience, we immediately transform the response to conform to that format. | ||
| const reasonCodes = res.data.data.map((reasonCode) => ( | ||
| { | ||
| id: reasonCode.id, | ||
| value: reasonCode.id, | ||
| label: reasonCode.name, | ||
| } | ||
| )); | ||
| dispatch({ | ||
| type: dispatchType, | ||
| payload: reasonCodes, | ||
| }); | ||
| return; | ||
| } | ||
| dispatch({ | ||
| type: FETCH_REASONCODES, | ||
| payload: res.data, | ||
| type: dispatchType, | ||
| payload: [], |
There was a problem hiding this comment.
I think you should be able to do something like this:
const reasonCodes = res?.data?.data?.map?.((reasonCode) => (
{
id: reasonCode.id,
value: reasonCode.id,
label: reasonCode.name,
}
));
dispatch({
type: dispatchType,
payload: reasonCodes || [],
});
When something from the call chain is null/undefined, it will fall back to [].
Note:
|| use the fallback when the checked value is falsy,
?? use the fallback when the checked value is null.
In this case, I think reasonCodes will fall back to null.
| return { | ||
| ...state, | ||
| data: action.payload, | ||
| fetched: true, | ||
| }; |
There was a problem hiding this comment.
Won't that change break the use cases for reason codes in other places?
| discrepancyReasonCode(nullable: true, validator: { ReasonCode discrepancyReasonCode -> | ||
| return ReasonCode.listInventoryAdjustmentReasonCodes().contains(discrepancyReasonCode) ? | ||
| true : | ||
| ['cycleCountItemCommand.discrepancyReasonCode.invalid'] | ||
| }) |
There was a problem hiding this comment.
This is just an idea, not a change request.
Maybe it will be worth having. a place where we can store our validationrs to keep the classes cleaner? I can see that this closure is duplicated.
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7039
Description: Previously we were using a custom DiscrepancyReasonCode enum to list the possible Root Cause values. This PR switches to use ReasonCode.listInventoryAdjustmentReasonCodes().
📷 Screenshots & Recordings (optional)