-
Notifications
You must be signed in to change notification settings - Fork 35
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
MB-13125 - handle state for weightTickets #8873
Conversation
if (mtoShipment?.ppmShipment?.weightTickets) { | ||
mtoShipment?.ppmShipment?.weightTickets.push(resp); | ||
} else { | ||
mtoShipment.ppmShipment.weightTickets = [resp]; | ||
} |
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 logic may not be necessary if weightTickets defaults to returning an empty array
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.
thought: We return an empty array for other things like orders and MTOShipments, so I feel like we should probably remain consistent with that for weight tickets.
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.
I'll leave this here for now, since we can't ensure that within this PR. But we can likely remove this during the integration story.
const mtoShipment = useSelector((state) => selectMTOShipmentById(state, mtoShipmentId)); | ||
// TODO add selector for selecting weight ticket from Redux store when data changes are solidified | ||
const currentWeightTicket = useSelector((state) => selectWeightTicketById(state, mtoShipmentId, weightTicketId)); |
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 may be worth having a selector for getting all weightTickets and then another selector for getting the current weight ticket
it('displays an error if the createWeightTicket request fails', async () => { | ||
createWeightTicket.mockRejectedValueOnce('an error occurred'); | ||
|
||
render(<WeightTickets />, { wrapper: MockProviders }); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Failed to create trip record')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
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.
I don't think this test matches what the user would see. If we were to change the mockRejectedValueOnce
to mockRejectedValue
you would see that the test would fail. On the UI we wouldn't show the error message because the page would still be in the state where we show the loading screen.
We can likely update the UI to conditionally show the error msg or the loading in this circumstance.
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.
praise: nice catch!
@@ -120,7 +124,7 @@ const WeightTickets = () => { | |||
trailerMeetsCriteria, | |||
}; | |||
|
|||
patchWeightTicket(mtoShipment.id, weightTicket.id, payload, weightTicket.eTag) | |||
patchWeightTicket(mtoShipment.id, currentWeightTicket.id, payload, currentWeightTicket.eTag) | |||
.then(() => { |
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.
Could you add in what the updating of the shipment weight ticket would look like?
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.
Added. There are quite a few ways to handle this, happy to discuss alternatives.
To test locally relax the UI restrictions(remove yup validation/disabled condition) and ensure that the create and patch call return promises with the same ID.
What is the plan for when the user adds a file and that request completes will you add that to the document uploads array in Redux? How about for the scenario where an upload is deleted? I think my suggestion would still be to have weight tickets broken out into their own entities in Redux and be fetched separately in an endpoint that returns all weight tickets for a move/shipment instead of having that nested in the shipment response. That way not every fetch or update of a shipment will be required to re-fetch all of the weight tickets/pro-gear/expenses uploads every time. And like we talked about the customer and office apps share a service object and adding on those fetched associations will mean you have a lot of office endpoints that now need to return closeout docs when it's not needed for most functionality. |
Yeah that's likely the plan so we don't have to make a separate API call on each upload to fetch the latest info. Let me add examples of this.
I think that's a reasonable approach though I have some concerns about the tradeoff between time and performance. Will schedule ~20 min to chat if that works for you. |
@duncan-truss an I just had a chat about the above. There are two options that were discussed:
SummaryI'm leaning towards going with 2 since imo its likely less time consuming and it provides us a way to get there and iterate as we come across pain points. This approach means that we likely need to make some modifications/work arounds when we get to the office portion. Additional Context (examples of what each approach may look like, implementation details could change):
|
I think for the sake of time, I'm leaning toward option 2 as well. I wonder if we do need to add workarounds for the office or if the extra calls will add much since they will only really affect PPMShipments. Like maybe we should check to see how much that actually affects things. If we chose not to go with option 2, I think another option would be to add the |
@@ -96,9 +108,27 @@ const WeightTickets = () => { | |||
}; | |||
|
|||
const handleUploadDelete = (uploadId, fieldName, values, setFieldTouched, setFieldValue) => { | |||
const remainingUploads = values[`${fieldName}`]?.filter((upload) => upload.id !== uploadId); |
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.
Is there a reason that something like values[`${fieldName}`]
is used over values[fieldName]
?
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 usually to avoid eslint detect-object-injection errors because fieldName, if provided by the user or other malicious source, might not be a string eslint-community/eslint-plugin-security#21
history.push(generatePath(customerRoutes.SHIPMENT_PPM_REVIEW_PATH, { moveId, mtoShipmentId })); | ||
dispatch(updateMTOShipment(mtoShipment)); |
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.
I don't know if this is reachable if it comes after history.push(), it might need moved before the history call.
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.
When I tested this, it seemed to work as expected. I'll double check the behavior during the integration.
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.
Thumbs up.
Jira ticket for this change
Summary
Adds weightTicket info into the redux state. This change is still dependent on the integration to ensure that appropriate API calls are being made.
Setup to Run Your Code
💻 You will need to use two separate terminals to test this locally.
Terminal 1
Start the UI locally.
Terminal 2
Start the Go server locally.
Additional steps
[email protected]
createWeightTicket
function.Example action:
Verification Steps for Author
These are to be checked by the author.
Verification Steps for Reviewers
These are to be checked by a reviewer.
Frontend
officeApp
class or custommin-width
styling is used to hide any states the would not be visible to the user.Screenshots