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 Distribution#new,#create,#edit to only show active items #4848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coalest
Copy link
Collaborator

@coalest coalest commented Dec 12, 2024

Resolves #3988

Description

Previously we were showing inactive items in the item dropdown for distributions in some situations. When we render the page, inactive items were shown, but after the ajax call to fetch inventory quantities (like when a storage location is selected) the inactive items were removed.

After this change, inactive items are never shown.

Type of change

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

How Has This Been Tested?

Added new request specs and tested manually.

An easy way to test this manually is to disable Javascript in the browser (I used ublock origin for ad blocking and it provides an easy way to toggle javascript on and off).

Otherwise if you try to edit a distribution currently, the ajax call to update the item dropdown might occur too fast for you to see the inactive items.

If testing manually, the /distributions, /distributions/new (both before clicking save and after clicking save with validation errors), and /distributions/edit pages all had this issue.

@coalest coalest force-pushed the 3988-inactive-items-should-not-appear-in-item-selection-drop-downs-for-distributions branch from e7d9bf3 to 9908943 Compare December 12, 2024 10:08
@@ -46,7 +46,6 @@ class Distribution < ApplicationRecord

enum state: { scheduled: 5, complete: 10 }
enum delivery_method: { pick_up: 0, delivery: 1, shipped: 2 }
scope :active, -> { joins(:line_items).joins(:items).where(items: { active: true }) }
Copy link
Collaborator Author

@coalest coalest Dec 12, 2024

Choose a reason for hiding this comment

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

I can remove this change if preferred as it's unrelated to this PR. But it looks like a piece of dead code—I can't find it being used anywhere.

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

@coalest -- I haven't dug in as yet -- does this cover off the "gotcha" mentioned in the comments -- i.e. that there could be inactive items in distributions that are being edited? (I expect its in the rare-but-could-happen category).

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

@cielf Whoops, I missed that comment about inactive items wanted to appear when editing distributions.

What about the /distributions index page? Should users be able to see inactive items in the filter?

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

@cielf Regarding showing inactive items in a distribution.

If a distribution has inactive items then it is not editable right?
image

But we want to allow users to be able to edit a previous distribution that didn't have inactive items to now have inactive items?

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

I remembered that after I'd walked away from my machine. (It's a realtively recent change.) No -- we don't want them to be able to add new inactive items to a distribution.

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

Ok, so then there isn't really a gotcha here anymore? We never want to show inactive items in the dropdown when creating a new distribution or editing an old distribution?

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

Right. Stopping people from editting old distributions with inactive items rendered the gotcha moot.

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

I guess the current flow for a user wants to add inactive items to an old distribution:

  1. Make inactive item now active
  2. Edit the distribution to include it
  3. Make the item inactive again.

Which I guess is ok. Because it's probably not a thing that happens often. And we would rather prevent issues for most used behaviors.

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

So I will inactive items visible in the item dropdown filter on the distributions index page, because the issue didn't say anything about changing that?

@coalest coalest force-pushed the 3988-inactive-items-should-not-appear-in-item-selection-drop-downs-for-distributions branch from 9908943 to 654d0d4 Compare December 12, 2024 17:12
@coalest coalest changed the title Fix Distribution#new,#create,#edit,#index to only show active items Fix Distribution#new,#create,#edit to only show active items Dec 12, 2024
@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

Technically more than that. That's the workflow if you want to edit a distribution that happens to have inactive items (for some other reason). All inactive items by rule have zero inventory, so if you actually needed to add inactive items to a distribution, you'd have to add the inventory. But if you're doing that, the item really isn't inactive, anyway...

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

I think they should be able to see inactive items in the filter, because they might be looking to export the information about them.

@coalest
Copy link
Collaborator Author

coalest commented Dec 12, 2024

In that case, this PR is now ready for review. (I force pushed and reverted the change I had made to the index page)

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

LGTM functionally

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.

Inactive items should not appear in item selection drop downs for distributions.
2 participants