Skip to content

OBPIH-7039 Populate Root Cause dropdown with proper values when recounting#5074

Merged
awalkowiak merged 5 commits intodevelopfrom
ft/OBPIH-7039-proper-root-cause-values
Mar 4, 2025
Merged

OBPIH-7039 Populate Root Cause dropdown with proper values when recounting#5074
awalkowiak merged 5 commits intodevelopfrom
ft/OBPIH-7039-proper-root-cause-values

Conversation

@ewaterman
Copy link
Member

@ewaterman ewaterman commented Feb 27, 2025

✨ 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)

image

@ewaterman ewaterman self-assigned this Feb 27, 2025
@github-actions github-actions bot added type: feature A new piece of functionality for the app domain: frontend Changes or discussions relating to the frontend UI domain: backend Changes or discussions relating to the backend server domain: l10n Changes or discussions relating to localization & Internationalization labels Feb 27, 2025
@codecov
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 6.66667% with 14 lines in your changes missing coverage. Please review.

Project coverage is 8.01%. Comparing base (dc344fb) to head (f30a6ee).
Report is 205 commits behind head on develop.

Files with missing lines Patch % Lines
...house/inventory/CycleCountUpdateItemCommand.groovy 0.00% 6 Missing ⚠️
.../org/pih/warehouse/inventory/CycleCountItem.groovy 16.66% 5 Missing ⚠️
...h/warehouse/inventory/CycleCountItemCommand.groovy 0.00% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -67,7 +67,7 @@ const useResolveStepTable = ({

useEffect(() => {
if (!reasonCodes.length) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ewaterman ewaterman added the warn: do not merge Marks a pull request that is not yet ready to be merged label Feb 27, 2025
@ewaterman ewaterman marked this pull request as ready for review February 28, 2025 21:03
@ewaterman ewaterman removed the warn: do not merge Marks a pull request that is not yet ready to be merged label Feb 28, 2025
Comment on lines 106 to 109
let url = '/api/reasonCodes';
if (activityCode) {
url += `?activityCode=${activityCode}`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of mutating values, so I prefer something like:

const url = `/api/reasonCodes${activityCode ? `?activityCode=${activityCode}` : ''}`

Comment on lines 113 to 131
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: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +11 to +15
return {
...state,
data: action.payload,
fetched: true,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't that change break the use cases for reason codes in other places?

Comment on lines +44 to +48
discrepancyReasonCode(nullable: true, validator: { ReasonCode discrepancyReasonCode ->
return ReasonCode.listInventoryAdjustmentReasonCodes().contains(discrepancyReasonCode) ?
true :
['cycleCountItemCommand.discrepancyReasonCode.invalid']
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@awalkowiak awalkowiak merged commit 947e106 into develop Mar 4, 2025
9 checks passed
@awalkowiak awalkowiak deleted the ft/OBPIH-7039-proper-root-cause-values branch March 4, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server domain: frontend Changes or discussions relating to the frontend UI domain: l10n Changes or discussions relating to localization & Internationalization type: feature A new piece of functionality for the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants