-
-
Notifications
You must be signed in to change notification settings - Fork 498
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
Fix problem with item name dropdown selection #4797
base: main
Are you sure you want to change the base?
Conversation
Looks great on the technical side - @cielf did you want to test this out manually? |
Actually, I might I have a better way to resolve this issue. Instead of using an the |
I would - but now I'll wait. |
e5203c1
to
e913553
Compare
e858028
to
71698f4
Compare
So I tried to update the opened dropdown options, but I couldn't find a way to do so using select2's api. I tested out a hacky way (closing and opening the dropdown to refresh), and it kinda works but is a little glitchy if the user is currently scrolling or typing something in dropdown. In summary, we can fix the bug by matching the options (option 1), or by rerendering the options with some jankiness (option 2). Here are two videos showing the difference from a user standpoint. I used Chrome and changed the network setting to have 3 seconds of latency. Video of what option 1 looks like (commit 71698f4): Screencast.from.2024-11-24.19-35-28.webmVideo of what option 2 looks like (commit bdd3a6a): Screencast.from.2024-11-24.19-37-16.webm@dorner @cielf Do y'all have a preference from a functional standpoint? (Keep in mind I do think this issue will be less common going forward with the change I made to only fetch inventory quantities on storage location change not when adding a new item. So either way, this should occur less often.) P.S. Sorry for the force pushing, I had an annoying issue with Rails serving stale JS assets and while debugging it I made some weird commits that I cleaned up. |
I think it's more smooth for the users to see the number of items available as they are picking them, so option # 2, please. |
Updated to use the workaround for option 2. This is now ready for functional and technical review |
LGTM from functional pov |
@cielf FYI - the changes in this PR basically completely rewrite the distributions/transfers dropdown logic. Might be worth some extra cycles to regression test it before merging. |
Agreed. Thanks for pointing that out. |
@dorner If we want to play it safe for production, I can split this into two PRs (one to refresh dropdowns and fix the bug and one with the refactoring). |
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.
Mostly working like a charm -checked transfers, distributions, and inventory adjustments but found one thing that needs to be addressed on the sequence for distributions made from requests, if you have an error.
Here's the sequence:
sign in as [email protected]
click on Requests
click on view
click Fulfill request
Pick a storage location
Make one of the items have a bigger quantity than is allowed (i.e. we are forcing an error)
Save
Yes, it's correct
The quantities for the items disappear.
@cielf Good catch. I didn't think about the pages with turbo streams, those aren't triggering the Javascript that is supposed to execute on page load. The same thing happens when saving a new distribution with errors. (Distributions index => New distribution => Select storage location => Save with an error => Quantities disappear) Does this work currently in production? I feel like this issue should be occurring on the |
@coalest Yup -- confirmed It's happening on staging. Do you think you can fix it within the bounds of this PR, or do we need to split it up? |
@cielf I just pushed a commit on this branch that should fix the issue. Ideally, I would like to refactor things a little bit. I don't like the current flow on some pages. Currently (like when we get a request to show the page to edit a distribution), we have access to what the dropdown options should be on the backend if there is a storage location selected (item names + quantities). But instead of providing the HTML with those dropdown options included, we send back default options (with missing quantities) and an ajax request gets triggered via javascript to update labels. Not a big deal, but I think it could be improved. But I think that could be a future PR. |
@dorner I'm taking this out for a spin, but could you do another technical pass in parallel? Thx. |
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.
LGTM. Thanks!
@coalest if we can separate out the behavior changes from the refactor, I'd much rather do that. |
content += "</option>\n"; | ||
return content; | ||
function newOption(item, selectedValue, includeQuantity) { | ||
const text = includeQuantity ? item.item_name + ` (${item.quantity})` : item.item_name; |
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.
The middle clause looks a bit weird - I'd expect to see `${item.item_name} (${item.quantity})`
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.
Very true, not sure what happened there. Will fix.
@@ -699,6 +699,34 @@ | |||
end | |||
end | |||
|
|||
context "with dropdown options changed while open", skip: "select2 not working correctly with cuprite" do |
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.
Really don't understand why I can't get this system spec to work. These steps work in a browser locally. I notice some weird behavior with select2 though. It seems like those events aren't being triggered in cuprite.
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 should probably just delete this?
Tests aren't passing due to a flaky test. Here is a PR to fix that: #4816 |
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.
Huh. I could have sworn this was working earlier -- but now it isn't, with the case of fulfilling a request, picking a storage location, putting a riduculously high number in a quantity, saving, confirming, Comes back with an error as expected, but the inventory values do not appear.
Same with the case of an error on a new distribution.
@cielf I put that change back in. So it's ready for review again. Sorry for the confusion. |
(nods) it's still part of fixing the item dropdown selection, imo. I can see where it might not have been clear where to draw the line, though. |
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.
LGTM from a functional pov
Resolves #4547
Description
This issue occurs when an ajax call to populate the item names in the dropdown options occurs while the dropdown has been opened. Selecting an option doesn't work because that option no longer exists, so nothing happens (so item selected in the field will be the first item from the list of new options).
To fix this I made two changes:
/inventory.json
) every time you click "Add Another Item". And an ajax call is made to fetch the inventory whenever the storage location changes. I'm assuming it's not needed to fetch the inventory so often. So I changed it to only fetch the inventory item names/quantities on storage location field change, then we store those dropdown options and reuse them whenever a new line item is added.This will make adding new line items more responsive, and with less jank (from the reduced number of ajax calls) (ie. the item name changing from "XL Diapers" to "XL Diapers (1353)").
Type of change
How Has This Been Tested?
Tested manually in Chrome on my local machine, using the reproduction steps provided here.
Testing has been tough. I see a similar issue to the one I'm having where the
input
event isn't being triggered by cuprite. In my case theselect2:select
event isn't being triggered for some reason.