Skip to content

Conversation

@albertchae
Copy link
Collaborator

WIP, seeking feedback on UX, then will flesh out spec coverage

diaperbase_partner_groups

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

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

TODO:

Screenshots

TODO:

- 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
@armahillo
Copy link
Collaborator

@albertchae

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.
I'll defer to @edwinthinks since he's the boss now ( ;) )

Codewise, the PR looks solid; all the associations and forms look good, nice work.

@edwinthinks
Copy link
Collaborator

edwinthinks commented Jan 23, 2021

@albertchae @armahillo replied. I do agree with @armahillo that we probably don't mean PartnerGroup and I think we could change the name and the way we think about getting to the desired outcome.

Let's talk about in our coding session later :)

@edwinthinks
Copy link
Collaborator

@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 BaseItem is still something we want to require or keep? I've heard more use cases in which Organizations want to define their own Categories for Items so that in their reports it can be on Category not Item.

Let's talk about this :)!

@edwinthinks edwinthinks force-pushed the 2059-partner-groups branch from 1a7e8fe to 07354ab Compare July 29, 2021 00:46
@edwinthinks edwinthinks force-pushed the 2059-partner-groups branch from c3c973a to fc68ff7 Compare July 31, 2021 13:43
@edwinthinks
Copy link
Collaborator

A few things left to do to keep track:

  • Include information on the partners#show about which group they are in and what items they can request
  • Be able to select which item categories PartnerGroups can request.

@edwinthinks edwinthinks force-pushed the 2059-partner-groups branch 2 times, most recently from 678e55c to 8b291c7 Compare August 22, 2021 22:06
@edwinthinks edwinthinks changed the title WIP: Implement partner groups Implement partner groups Aug 25, 2021
@edwinthinks
Copy link
Collaborator

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.

@edwinthinks
Copy link
Collaborator

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.

Copy link
Collaborator Author

@albertchae albertchae left a 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
Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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!"
Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Comment on lines +40 to +42
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end
Copy link
Collaborator Author

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?

Comment on lines +7 to +9
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end
Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Comment on lines +9 to +10
@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)
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Comment on lines 1 to 10
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
Copy link
Collaborator

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.

Comment on lines 3 to 8
create_table :partner_group_memberships do |t|
t.references :partner_group, foreign_key: true
t.references :partner, foreign_key: true

t.timestamps
end
Copy link
Collaborator

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!"
Copy link
Collaborator

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.

Comment on lines +7 to +9
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

@albertchae albertchae left a 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

@edwinthinks edwinthinks merged commit 407b128 into main Sep 21, 2021
@SCDB
Copy link
Collaborator

SCDB commented Sep 21, 2021

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!

@edwinthinks
Copy link
Collaborator

@SCDB thanks for the feedback :)! Would a workaround be to create PartnerGroups for each program/category combination?

@SCDB
Copy link
Collaborator

SCDB commented Sep 22, 2021

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.

@SCDB
Copy link
Collaborator

SCDB commented Sep 22, 2021

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!!

@seanmarcia seanmarcia deleted the 2059-partner-groups branch October 30, 2021 17:05
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.

Partner Groups: Classification Tags for Partners

5 participants