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

Budget screen logic #10709

Merged
merged 15 commits into from
Feb 9, 2024
Merged

Budget screen logic #10709

merged 15 commits into from
Feb 9, 2024

Conversation

JorgeMucientes
Copy link
Contributor

@JorgeMucientes JorgeMucientes commented Feb 7, 2024

Part of: #10574

Description

This PR adds the following missing logic to the Blaze budget screen:

  • The main budget slider now replicates the behavior of the Blaze webview slider:
    • Min and Max values are dynamically calculated based on the campaign duration
    • The budget value is updated according to to the duration step, that is, if the duration is 7n days for example, the total budget value will be increased or decreased in steps of 7. This part is trickier than it looks. More on this below.
  • The duration bottom sheet now updates all the budget content once the slider is released, but not while drawing the slider.
  • Implemented updating the campaign start date
  • All the data from the Blaze budget screen is now passed back to the campaign preview screen.

The forecast updates are not part of the scope of this PR.

About the budget slider
Due to how the Composable slider works using a Float value to set the slider's position, whereas the budget value is an integer (that has to change in chunks/steps equal to the duration of the campaign), there's some flakiness to how slider responds. Between those 2 values there's some conversion from float to int and some rounding that causes the total budget value displayed to skip some steps. You'll see what I mean when scrolling back and forth in the budget slider. I tested different approaches (even using the steps property from the slider), but none worked perfectly. The current solution is the one that works best. Of course, any ideas for improvement are welcome. Its possible I might be missing something.

UPDATE: About the above. There are some real problems with the current slider implementation from this PR as explained in #10709 (comment). I fixed them in this other PR: #10739.

Testing instructions

  • Open Blaze campaign creation flow
  • Open edit budget screen
  • Play around with all the sliders and editable info
  • Click Update and check that all the update data is reflected in campaign preview screen.

Images/gif

demoBudgetScreen.mp4

@JorgeMucientes JorgeMucientes added the feature: blaze Related to the Blaze project label Feb 7, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 7, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commitf2535b0
Direct Downloadwoocommerce-prototype-build-pr10709-f2535b0.apk

# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewFragment.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewViewModel.kt
@JorgeMucientes JorgeMucientes marked this pull request as ready for review February 8, 2024 00:35
@JorgeMucientes JorgeMucientes added this to the 17.3 milestone Feb 8, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 8, 2024

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

Comment on lines +82 to +89
fun onBudgetUpdated(sliderValue: Float) {
if (sliderValue.toInt().mod(viewState.value?.durationInDays!!) == 0) {
val dailySpending = sliderValue / viewState.value?.durationInDays!!
_viewState.value = _viewState.value?.copy(
totalBudget = sliderValue,
dailySpending = formatDailySpend(dailySpending)
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the tricky part that handles updating the slider value and the budget value independently.

Copy link
Contributor Author

@JorgeMucientes JorgeMucientes Feb 8, 2024

Choose a reason for hiding this comment

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

Ok, for some reason I just noticed that Total Spend value is not properly updated when the duration for the campaign has larger value.
For example, set the duration to something like 25 days and then proceed to play around with the budget slider. The amount won't get correctly refreshed, it will seem unresponsive.
I'll look again into fixing that.

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2024

Codecov Report

Attention: 70 lines in your changes are missing coverage. Please review.

Comparison is base (541c2d0) 41.44% compared to head (f2535b0) 41.41%.
Report is 4 commits behind head on trunk.

Files Patch % Lines
...ze/creation/budget/BlazeCampaignBudgetViewModel.kt 0.00% 52 Missing ⚠️
...n/preview/BlazeCampaignCreationPreviewViewModel.kt 0.00% 18 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #10709      +/-   ##
============================================
- Coverage     41.44%   41.41%   -0.04%     
  Complexity     5017     5017              
============================================
  Files          1016     1016              
  Lines         58364    58414      +50     
  Branches       7803     7810       +7     
============================================
  Hits          24190    24190              
- Misses        32030    32080      +50     
  Partials       2144     2144              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JorgeMucientes JorgeMucientes modified the milestones: 17.3, 17.4 Feb 9, 2024
@0nko 0nko self-assigned this Feb 9, 2024
# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/preview/BlazeCampaignCreationPreviewViewModel.kt
@JorgeMucientes
Copy link
Contributor Author

Heads up @0nko, in case you are reviewing this or looking into the issues with the budget slider. I just want to let you know that I've implemented a different approach here: #10739, which fixes all the problems with the budget slider. I'll set the PR ready for review soon.

Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

I've tested the PR with the slider fix and it works. I'll go ahead and merge this then. :shipit:

@0nko 0nko merged commit e31d0dc into trunk Feb 9, 2024
16 checks passed
@0nko 0nko deleted the issue/10574-budget-screen-logic branch February 9, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: blaze Related to the Blaze project unit-tests-exemption
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants