-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
#4398: Support units in requests #4510
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
704ad63
#4398: Support units in requests
dorner ab8315c
fix style
dorner 895c980
fixes
dorner 3b44c02
Merge branch 'main' into 4398-pack-requests
dorner 9b929c4
Add specs
dorner 3529e4c
Fix error case
dorner e043ede
Fix test
dorner 0a74e07
CR changes
dorner 270c28f
Fix tests
dorner 9ce328e
Update based on feedback
dorner 71d7626
Merge branch 'main' into 4398-pack-requests
awwaiid 5799256
Update request verification pop-up and specs [#4398]
awwaiid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
// Connects to data-controller="form-input" | ||
export default class extends Controller { | ||
static targets = ["itemSelect", "requestSelect"] | ||
static values = { | ||
// hash of (item ID => hash of (request unit name => request unit plural name)) | ||
"itemUnits": Object | ||
} | ||
|
||
addOption(val, text) { | ||
let option = document.createElement("option"); | ||
option.value = val; | ||
option.text = text; | ||
this.requestSelectTarget.appendChild(option); | ||
} | ||
|
||
clearOptions() { | ||
while (this.requestSelectTarget.options.length > 0) { | ||
this.requestSelectTarget.remove(this.requestSelectTarget.options[0]) | ||
} | ||
} | ||
|
||
connect() { | ||
this.itemSelected(); | ||
} | ||
|
||
itemSelected() { | ||
if (!this.hasRequestSelectTarget) { | ||
return; | ||
} | ||
let option = this.itemSelectTarget.options[this.itemSelectTarget.selectedIndex] | ||
let units = this.itemUnitsValue[option.value] | ||
if (!units || Object.keys(units).length === 0) { | ||
this.requestSelectTarget.style.display = 'none'; | ||
this.requestSelectTarget.selectedIndex = -1; | ||
} | ||
else { | ||
this.requestSelectTarget.style.display = 'inline'; | ||
this.clearOptions() | ||
this.addOption('-1', 'Please select a unit') | ||
this.addOption('', 'Units') | ||
for (const [index, [name, displayName]] of Object.entries(Object.entries(units))) { | ||
this.addOption(name, displayName) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
db/migrate/20240704214509_backfill_partner_child_requested_items.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
RSpec.describe "Partners profile served area behaviour", type: :system, js: true do | ||
let(:organization) { create(:organization) } | ||
let(:partner) { create(:partner, organization: organization) } | ||
let(:partner_user) { partner.primary_user } | ||
|
||
before(:each) do | ||
sign_in(partner_user) | ||
end | ||
|
||
describe "GET #index" do | ||
let!(:item1) { FactoryBot.create(:item, organization: organization, name: "Item 1") } | ||
let!(:item2) { FactoryBot.create(:item, organization: organization, name: "Item 2") } | ||
before(:each) do | ||
FactoryBot.create(:item_unit, name: "pack", item: item1) | ||
end | ||
|
||
context "with packs off" do | ||
before(:each) do | ||
Flipper.disable(:enable_packs) | ||
end | ||
|
||
it "should not show packs on selection" do | ||
visit new_partners_request_path | ||
select "Item 1", from: "request_item_requests_attributes_0_item_id" | ||
expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) | ||
end | ||
end | ||
|
||
context "with packs on" do | ||
before(:each) do | ||
Flipper.enable(:enable_packs) | ||
end | ||
|
||
it "should require a unit selection" do | ||
visit new_partners_request_path | ||
expect(Request.count).to eq(0) | ||
expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) | ||
select "Item 1", from: "request_item_requests_attributes_0_item_id" | ||
expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) | ||
expect(page).to have_select("request_item_requests_attributes_0_request_unit", | ||
selected: "Please select a unit", | ||
options: ["Please select a unit", "Units", "packs"]) | ||
fill_in "request_item_requests_attributes_0_quantity", with: 50 | ||
click_on "Submit Essentials Request" | ||
|
||
expect(page).to have_text "Please ensure a unit is selected for each item that supports it." | ||
expect(Request.count).to eq(0) | ||
end | ||
|
||
it "should show packs on selection" do | ||
visit new_partners_request_path | ||
expect(Request.count).to eq(0) | ||
expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) | ||
select "Item 1", from: "request_item_requests_attributes_0_item_id" | ||
expect(page).to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) | ||
expect(page).to have_select("request_item_requests_attributes_0_request_unit", | ||
selected: "Please select a unit", | ||
options: ["Please select a unit", "Units", "packs"]) | ||
select "packs", from: "request_item_requests_attributes_0_request_unit" | ||
click_on "Add Another Item" | ||
|
||
# get selector to use in subsequent steps | ||
new_item = find_all(:css, "select[data-item-units-target=itemSelect]")[1] | ||
id = new_item[:id].match(/\d+/)[0] | ||
|
||
expect(page).not_to have_selector("request_item_requests_attributes_#{id}_request_unit", visible: true) | ||
select "Item 2", from: "request_item_requests_attributes_#{id}_item_id" | ||
expect(page).not_to have_selector("request_item_requests_attributes_#{id}_request_unit", visible: true) | ||
fill_in "request_item_requests_attributes_0_quantity", with: 50 | ||
fill_in "request_item_requests_attributes_#{id}_quantity", with: 20 | ||
click_on "Submit Essentials Request" | ||
click_on "Yes, it's correct" | ||
expect(page).to have_text "Request has been successfully created" | ||
|
||
expect(Request.count).to eq(1) | ||
request = Request.last | ||
expect(request.item_requests[0].quantity).to eq("50") | ||
expect(request.item_requests[0].item_id).to eq(item1.id) | ||
expect(request.item_requests[0].request_unit).to eq("pack") | ||
expect(request.item_requests[1].quantity).to eq("20") | ||
expect(request.item_requests[1].item_id).to eq(item2.id) | ||
expect(request.item_requests[1].request_unit).to eq(nil) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So here we already only show the
@requestable_items
in the item select drop-down, so that already narrows down what we might show in the units drop down. So the generated@item_units
having all possible items it works fine, but could be narrowed down to building off of@requestable_items