Skip to content
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 #4883

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

coalest
Copy link
Collaborator

@coalest coalest commented Dec 21, 2024

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:

  1. Added an event listener so that whenever a item name dropdown option is selected, if the id of that item matches in the list of new options, select that option. (Note: This is enough to fix the bug)
  2. But during investigation I found that when adding a new item, two ajax calls are fired off (to /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

  • Bug fix (non-breaking change which fixes an issue)

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 inputevent isn't being triggered by cuprite. In my case the select2:select event isn't being triggered for some reason.

@cielf
Copy link
Collaborator

cielf commented Jan 5, 2025

It does, however, mean you can end up with this situation, which would be most confusing.
Screenshot 2025-01-05 at 1 56 16 PM

@coalest
Copy link
Collaborator Author

coalest commented Jan 6, 2025

@cielf Can you share the steps to reproduce that issue?

@cielf
Copy link
Collaborator

cielf commented Jan 6, 2025

Huh -- I am having trouble reproducing it myself.

@cielf
Copy link
Collaborator

cielf commented Jan 6, 2025

Got it.
New Distribution
Enter a line item
In another browser, enter a donation including some of that line item (for the same storage location)
In your distribution, Add Another Item

@coalest
Copy link
Collaborator Author

coalest commented Jan 7, 2025

@cielf That issue isn't introduced by these changes—it already exists on main. Could we create a separate issue for that?

Also, it wouldn't occur with the refactoring I previously added on the now closed PR, but I removed all refactoring so this PR would be smaller and still provide the bug fix for the #4547 issue.

@cielf
Copy link
Collaborator

cielf commented Jan 8, 2025

It is definitely an edge case . I'll throw it in the in-box for writeup.

(Terminology note: I don't consider it refactoring if it introduces functional changes, but that's a discussion for a different forum )

@cielf
Copy link
Collaborator

cielf commented Jan 8, 2025

Ok. Other than that, this seems to do the job. over to @dorner for tech eval.

@cielf cielf requested a review from dorner January 8, 2025 16:24
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

A question around how this would interact with #4882 - should we just reuse the Option class from there?

@@ -5,9 +5,15 @@ module Types
module View
# A wrapper around event-driven InventoryAggregate for use in views.
class Inventory
ItemDropdownOption = Struct.new(:id, :name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this clash with the OpenStruct PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR was created before creating the generic Option class was introduced. Fixed.

@coalest coalest requested a review from dorner January 12, 2025 14:37
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Looks good!

@dorner dorner merged commit e8820e3 into rubyforgood:main Jan 16, 2025
11 checks passed
Copy link
Contributor

@coalest: Your PR Fix problem with item name dropdown selection is part of today's Human Essentials production release: 2025.01.19.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with item dropdowns
3 participants