-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[MBL-1601] Filter Rewards By Selected Shipping Location #2114
Conversation
02bf3a3
to
553126a
Compare
@@ -549,7 +549,7 @@ public struct Service: ServiceType { | |||
let query = GraphAPI | |||
.FetchProjectRewardsByIdQuery( | |||
projectId: projectId, | |||
includeShippingRules: false, | |||
includeShippingRules: 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.
Tested around the app and made sure tests passed to make sure this didn't impact anything unexpectedly. All this does is include shipping rule/location data in each reward for a project.
In theory, this might slow down project load time. I haven't seen a notable difference, but I will keep an eye on it.
private func filteredRewardsByLocation( | ||
_ rewards: [Reward], | ||
shippingRule: ShippingRule? | ||
) -> [Reward] { | ||
return rewards.filter { reward in | ||
var shouldDisplayReward = false | ||
|
||
let isRewardLocalOrDigital = isRewardDigital(reward) || isRewardLocalPickup(reward) | ||
let isUnrestrictedShippingReward = reward.isUnRestrictedShippingPreference | ||
let isRestrictedShippingReward = reward.isRestrictedShippingPreference | ||
|
||
// return all rewards that are digital or ship anywhere in the world. | ||
if isRewardLocalOrDigital || isUnrestrictedShippingReward { | ||
shouldDisplayReward = true | ||
|
||
// if add on is local pickup, ensure locations are equal. | ||
if isRewardLocalPickup(reward) { | ||
if let rewardLocation = reward.localPickup?.country, | ||
let shippingRuleLocation = shippingRule?.location.country, rewardLocation == shippingRuleLocation { | ||
shouldDisplayReward = true | ||
} else { | ||
shouldDisplayReward = false | ||
} | ||
} | ||
// If restricted shipping, compare against selected shipping location. | ||
} else if isRestrictedShippingReward { | ||
shouldDisplayReward = rewardShipsTo(selectedLocation: shippingRule?.location.id, reward) | ||
} | ||
|
||
return shouldDisplayReward | ||
} | ||
} |
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.
This logic is mostly from the existing AddOns screen filtering logic with minor adjustments.
If there are any suggestions for simplifying or making this easier to understand, please suggest them!
📲 What
Filters the displayed rewards based on the selected shipping location.
🤔 Why
We only want users to select rewards that they can actually get.
🛠 How
The shipping dropdown is already on this screen. We need to filter based on the currently selected location.
The types of rewards are:
Right now, we pull in a project's rewards using this GraphQL Query
FetchProjectRewardsById
.This returns all rewards for a project and has an option to
includeShippingRules
.Flipping this to
true
allows us to compare individual reward shipping info to the selected location and filter accordingly.👀 See
I created a test project, A Really Cool Proj, that has the following reward types.
✅ Acceptance criteria