-
-
Notifications
You must be signed in to change notification settings - Fork 571
Implement partner groups #2131
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
Implement partner groups #2131
Conversation
- migrations - factories - validation specs
TODO: add tests TODO: need to be able to add partners
change partners display in group Implement remove partner from partner group
- if the partner is not in any groups, return all items in organization - if the partner is a member in some groups, returns items tagged by those groups
|
I had some suggestion about the naming: #2059 (comment) -- it would be a small lift to change the naming, but much easier to do it now before the migrations get merged in and deployed. Codewise, the PR looks solid; all the associations and forms look good, nice work. |
|
@albertchae @armahillo replied. I do agree with @armahillo that we probably don't mean Let's talk about in our coding session later :) |
|
@albertchae hey there! I've been giving this some thought and maybe a better place to start for this feature is figuring out how we can add ItemCategories and figure out if Let's talk about this :)! |
1a7e8fe to
07354ab
Compare
c3c973a to
fc68ff7
Compare
|
A few things left to do to keep track:
|
678e55c to
8b291c7
Compare
8b291c7 to
e12f0ef
Compare
|
Got this passing. I'll create a video going through the flow as I think its going to help figure out how this is all going to fit together. |
|
Here is a loom video explaining how to use it in practice - https://www.loom.com/share/ab271a1a9abe4e9da42030b5f67d9938. I'am aiming to send this to our stakeholders :)! @albertchae can you please review this. |
albertchae
left a comment
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.
Thanks again for taking over this PR and getting it to the finish line. Everything looks pretty good, I think my biggest question is about the data modeling where currently it seems a partner can only belong to a single partner group and whether that's sufficient.
|
|
||
| belongs_to :organization | ||
| has_many :distributions, dependent: :destroy | ||
| belongs_to :partner_group, optional: true |
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.
does this mean a Partner can only belong to at most one PartnerGroup?
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.
That is correct. The thought behind this is that keeping to a single association might be good enough for today's needs. If we discover it is lacking by complaints, then I think we can update it to include multiple associations.
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.
sounds good
| @partner_group = current_organization.partner_groups.new(partner_group_params) | ||
| if @partner_group.save | ||
| # Redirect to groups tab in Partner page. | ||
| redirect_to partners_path + "#nav-partner-groups", notice: "Partner group added!" |
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 wonder if there's a better way to do this than string concatenating the # anchor, but we can save that for a future improvement
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.
Yeh I wasn't too sure, how to achieve that without making another route.
| @formatted_requestable_items = requestable_items.map do |rt| | ||
| [rt.name, rt.id] | ||
| end |
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.
should we add this as a format method somewhere? then we can reuse between new and edit. We could combine it with the call to PartnerFetchRequestableItemsService and have a fetch_and_format_requestable_items in this controller maybe?
| @formatted_requestable_items = requestable_items.map do |rt| | ||
| [rt.name, rt.id] | ||
| end |
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.
now that I'm seeing the same block here and other controllers, maybe we should have a "presenter" object to do the formatting. Arguably this duplication existed before this PR, so we could do it as a follow up too
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.
Yeh I agree, I think some sort of mechanism to avoid duplication would be good! Will create an issue to handle that in another PR.
| @partners = Partner.includes(:partner_group).where(organization: current_organization).class_filter(filter_params).alphabetized | ||
| @partner_groups = PartnerGroup.includes(:partners, :item_categories).where(organization: current_organization) |
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.
that's interesting we need this given the first query for partners. Could we instead do something like Partner.includes(partner_group: [:item_categories]) and remove @partner_groups? Then we could also go through partner to get the same thing, I think
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.
Oh I see, we are using @partner_groups to give the user a list of groups they can attach a partner to. disregard my comment
| def change | ||
| create_table :partner_groups do |t| | ||
| t.references :organization, foreign_key: true | ||
| t.string :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.
I see that we added a compound uniqueness between organization_id and name via:
validates :name, presence: true, uniqueness: { scope: :organization }
I would add also a uniqueness index so that we add the constraint at the DB level.
| class CreatePartnerGroupItems < ActiveRecord::Migration[6.0] | ||
| def change | ||
| create_table :partner_group_items do |t| | ||
| t.references :partner_group, foreign_key: true, null: false | ||
| t.references :item, foreign_key: true, null: false | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
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.
Going to utilize a join table between PartnerGroup & ItemCategories that indicates which item categories are permitted to be requested.
| create_table :partner_group_memberships do |t| | ||
| t.references :partner_group, foreign_key: true | ||
| t.references :partner, foreign_key: true | ||
|
|
||
| t.timestamps | ||
| end |
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.
Giving this some thought -- I think support multiple memberships to different partner groups isn't needed yet. I'd be interested to make this a 1 to 1 relationship between Partner and PartnerGroup
| @partner_group = current_organization.partner_groups.new(partner_group_params) | ||
| if @partner_group.save | ||
| # Redirect to groups tab in Partner page. | ||
| redirect_to partners_path + "#nav-partner-groups", notice: "Partner group added!" |
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.
Yeh I wasn't too sure, how to achieve that without making another route.
| @formatted_requestable_items = requestable_items.map do |rt| | ||
| [rt.name, rt.id] | ||
| end |
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.
Yeh I agree, I think some sort of mechanism to avoid duplication would be good! Will create an issue to handle that in another PR.
|
|
||
| belongs_to :organization | ||
| has_many :distributions, dependent: :destroy | ||
| belongs_to :partner_group, optional: true |
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.
That is correct. The thought behind this is that keeping to a single association might be good enough for today's needs. If we discover it is lacking by complaints, then I think we can update it to include multiple associations.
albertchae
left a comment
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, I actually can't approve it since I'm the original author but feel free to approve and merge @edwinthinks. Thanks for taking it over the finish line
|
Hey there! Just chiming in to say most of our partner agencies are ordering from multiple programs/categories (diapers and period supplies, and in the future adult supplies as well). We unfortunately won't be able to use this functionality until we're able to assign one partner to multiple groups because reports and filtering results won't be complete if we try to use them before every partner can be properly categorized. Excited that this is so close! |
|
@SCDB thanks for the feedback :)! Would a workaround be to create PartnerGroups for each program/category combination? |
|
Yes!! Thanks for going where my brain could not. For now with only 2 programs that should be fairly simple. Once we add in the third program early next year, the volume of combinations might get a little much, but we can make that work for now. |
|
One other question--will this new functionality be tied to reporting or filtering options? One of the big reasons this feature could be so huge is the ability to save us tons of time counting up different purchases/donations/distributions for a particular program each month for our accountants. So excited!! |
WIP, seeking feedback on UX, then will flesh out spec coverage
draft PR description, delete this and above once UX is settled
Resolves #2059
Partner PR: rubyforgood/partner#531
Description
Implement partner group tagging so diaper bank users can tag partners they work with into groups and also tag items that these partners can request.
I wasn't sure if we also want to enable tagging from the Inventory view and also the partner agencies view.
Type of change
How Has This Been Tested?
TODO:
Screenshots
TODO: