OBPIH-5981 Improve redirect for e-request edit action for a requestor…#4423
OBPIH-5981 Improve redirect for e-request edit action for a requestor…#4423awalkowiak merged 2 commits intofeature/upgrade-to-grails-3.3.10from
Conversation
… in a ward location (request approval feature) + refactor redirect logic for SM edit action
drodzewicz
left a comment
There was a problem hiding this comment.
Thanks for doing the refactor, I had to dos some mental gymnastics to compare the old and the new versions of this redirect logic and it wasn't easy.
In general I think it looks good and does cover all of the old cases, but please take a look at the empty default cases, I think there should be something in case we land in that default case, as unlikely as it may seem.
| default: | ||
| break | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
something feels off here, I feel like this should have some default redirect
| default: | ||
| break |
There was a problem hiding this comment.
Same here, I think a default redirect should be present here.
getStockMovementDirection can return a null value and there is no redirect handler at the end, so I think the app would crash because no redirects are specified at the end.
|
@drodzewicz I've had the same feeling about it and expected someone of you to point that out, because I have not had idea what the default redirect should be, because as far as I'm concerned, the old code did not have a special handling for that case, did it? |
|
Was playing around with rearranging these if statements to avoid any more indentation to make the code more readable at a glance and came to this version. if (stockMovement?.electronicType) {
switch (stockMovementDirection) {
case StockMovementDirection.INBOUND:
User currentUser = AuthService.currentUser
RequisitionStatus requisitionStatus = stockMovement.requisition?.status
// If a request's status is created or a user is a requestor logged in, in a location
// with submit request and without manage inventory, and the request has waiting for approval
// status, we want to redirect to add items page (OBPIH-5981)
if (requisitionStatus == RequisitionStatus.CREATED) {
redirect(action: "createRequest", params: params)
return
}
if (requisitionStatus == RequisitionStatus.PENDING_APPROVAL
&& userService.isUserRequestor(currentUser)
&& currentLocation.downstreamConsumer
) {
redirect(action: "createRequest", params: params)
return
}
break
case StockMovementDirection.OUTBOUND:
break
default:
break
}
redirect(action: "verifyRequest", params: params)
return
} |
|
@drodzewicz thanks for the proactivity. I agree separating the case StockMovementDirection.OUTBOUND:
breakat first sight it would mean that we don't care about the if (stockMovement?.electronicType) {
switch (stockMovementDirection) {
case StockMovementDirection.INBOUND:
User currentUser = AuthService.currentUser
RequisitionStatus requisitionStatus = stockMovement.requisition?.status
// If a request's status is created or a user is a requestor logged in, in a location
// with submit request and without manage inventory, and the request has waiting for approval
// status, we want to redirect to add items page (OBPIH-5981)
if (requisitionStatus == RequisitionStatus.CREATED) {
redirect(action: "createRequest", params: params)
return
}
if (requisitionStatus == RequisitionStatus.PENDING_APPROVAL
&& userService.isUserRequestor(currentUser)
&& currentLocation.downstreamConsumer
) {
redirect(action: "createRequest", params: params)
return
}
redirect(action: "verifyRequest", params: params)
break
default:
redirect(action: "verifyRequest", params: params)
}
return
}Now I've even started to realize if the switch/case makes sense here. What do you think? it'd look like this: if (stockMovement?.electronicType) {
if (stockMovementDirection == StockMovementDirection.INBOUND) {
User currentUser = AuthService.currentUser
RequisitionStatus requisitionStatus = stockMovement.requisition?.status
// If a request's status is created or a user is a requestor logged in, in a location
// with submit request and without manage inventory, and the request has waiting for approval
// status, we want to redirect to add items page (OBPIH-5981)
if (requisitionStatus == RequisitionStatus.CREATED) {
redirect(action: "createRequest", params: params)
return
}
if (requisitionStatus == RequisitionStatus.PENDING_APPROVAL
&& userService.isUserRequestor(currentUser)
&& currentLocation.downstreamConsumer
) {
redirect(action: "createRequest", params: params)
return
}
}
redirect(action: "verifyRequest", params: params)
return
} |
|
@kchelstowski looks good, let's proceed with that |
|
@awalkowiak @jmiranda do you also agree with our latest proposition? I want to make sure everyone agrees, before I make the change. |
There was a problem hiding this comment.
My first thought when seeing this was "rendering a view should not be this complicated".
Can we reduce the complexity by creating separate URLs for the different types of requests / transfers and not using the stock movement controller as a central hub? If not, is there another way to reduce the complexity.
|
@jmiranda since for "Edit stock movement" our url is Since the current else-if logic drove us nuts and I had to add one more case there, I decided to refactor it a bit, so it becomes more readable. |
awalkowiak
left a comment
There was a problem hiding this comment.
I am very "pro" these changes. I think this part was getting worse and worse.
@kchelstowski lets finalize the refactoring that you started, if there are any improvements left from Dariusz's review. And please make double check locally on every branch we had previously, that it is still working correctly.
@jmiranda I think that the issue here is that we rather wanted to keep various workflows under one stock movement. And it kept growing and expanding. I think ideally we could think about the separation of the pages or other type of the refactor, but there are to many of "what ifs". For now I would go with this cleanup for 0.9.1, since it is already done, and I think looks good. We can come back to this chunk of code, as tech debt and discuss on the tech huddle. I feel we might run into few use cases from past, where we get some answers why its like that. We need to dig it out a bit from tickets and perhaps test/use cases.
… in a ward location (request approval feature) + refactor redirect logic for SM edit action
Since it's targeting the 0.9.1, and I had to touch this code, I decided to refactor this part to improve the readability of the redirect logic which was like this:
and after my changes (I paste it since the changes in the github might be difficult to read):
the part that is the scope of the ticket is this: