Skip to content

WordPress to Jetpack flow: main flow implementation#19563

Merged
Gio2018 merged 36 commits intotrunkfrom
task/migration-notifications-permission
Nov 8, 2022
Merged

WordPress to Jetpack flow: main flow implementation#19563
Gio2018 merged 36 commits intotrunkfrom
task/migration-notifications-permission

Conversation

@Gio2018
Copy link
Contributor

@Gio2018 Gio2018 commented Nov 6, 2022

Ref #19517
Ref #19518

This PR implements the remaining wp-to-jp flow

NOTE: the UI is not finalized (text and images can be missing or wrong in the notifications and all done screens), nor optimized for landscape and multiple screens, the notifications permissions is not there yet, and the migration flow is shown by default at each launch. All these points will be addressed in separate PRs

To test:
Scenario A - Notifications permissions undetermined (user has not made a decision)
Case 1: skip notifications permission decision:

  1. checkout this branch and build/run the Jetpack target
  2. In the welcome screen, tap Continue and make sure the Notifications permissions screen appears
  3. In the Notifications permissions screen, tap decide later and make sure the all done screen appears.
  4. In the all done screen, tap Finish and make sure the migration UI gets dismissed and the app UI appears.

Case 2: skip notifications permission decision:
same as above, except on step 3, tap "Continue" and make sure the notifications permission alert shows up, then:

  • Make a decision
  • Regardless the decision, make sure the all done screen appears, and continue from step 4 above

Scenario B - Notifications permissions determined (user has already made a decision)
Same as Scenario A - Case 1, except step 3 is missing: after tapping Continue in the welcome screen, make sure the all done screen appears. After that, continue normally with step 4

  • Optional: do a smoke test and make sure the app behaves correctly.

Regression Notes

  1. Potential unintended areas of impact
    None other the migration itself

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary. Not released

Giorgio Ruscigno added 15 commits November 6, 2022 16:01
…to-jp migration-notifications permissions step
@Gio2018 Gio2018 added this to the 21.2 milestone Nov 6, 2022
@Gio2018 Gio2018 self-assigned this Nov 6, 2022
@Gio2018 Gio2018 changed the base branch from trunk to task/wp-migration-welcome November 6, 2022 22:22
@Gio2018 Gio2018 marked this pull request as draft November 6, 2022 22:24
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 6, 2022

You can test the changes in Jetpack from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19563-670a52e on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 6, 2022

You can test the changes in WordPress from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr19563-670a52e on your iPhone

If you need access to App Center, please ask a maintainer to add you.


func makeInitialViewController() -> UIViewController {
MigrationNavigationController(coordinator: migrationCoordinator,
migrationStack: [.welcome: makeWelcomeViewController(),
Copy link
Contributor

@salimbraksa salimbraksa Nov 7, 2022

Choose a reason for hiding this comment

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

I'm not opposed to this approach of having a dictionary mapping MigrationStep to a UIViewController but I just want to point out that these view controllers will stay in memory even when they're dismissed ( not visible ).

Perhaps we can optimize this by injecting a closure like this:

let closure = { [weak self] (step: MigrationStep) -> UIViewController? in 
     switch step {
           case .welcome: return self?.makeWelcomeViewController()
           ...
     }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea: I added a factory that does exactly that, and we don't retain any unused vc in memory!

import Combine

/// Coordinator for the migration to jetpack flow
final class MigrationFlowCoordinator: ObservableObject {
Copy link
Contributor

@salimbraksa salimbraksa Nov 7, 2022

Choose a reason for hiding this comment

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

My understanding of Coordinator objects in the MVVM-C architecture is that they can instantiate and work with UIViewController objects ( e.g. this article and this ). That's why in the previous implementation, the coordinator was responsible for mapping a MigrationStep to a UIViewController and also pushing the view controllers to the navigation stack.

But I also like the idea of a UI-agnostic coordinator. But in this case, this object seems to me more of a ViewModel than a Coordinator. Maybe we should rename it to MigrationFlowViewModel?

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the thoughtful design review and the following discussion we had on Slack! As discussed, we'll leave the current naming for now and re-consider it together with Tanner (avoid direct pinging on purpose 😄 ) when he comes back from the meetup!

},
secondaryHandler: {

}))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a nice-to-have, but I honestly find this code a bit hard to read 🙈

Maybe we should breakdown this complex expression into multiple variables, something like this:

let headerConfig = MigrationHeaderConfiguration(step: .welcome, multiSite: blogListDataSource.visibleBlogsCount > 1)
let actionsConfig = MigrationActionsViewConfiguration(step: .welcome, primaryHandler:...)
configuration = MigrationStepConfiguration(headerConfiguration: headerConfig, actionsConfig: actionsConfig)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree. I did this in all view models

@Gio2018 Gio2018 marked this pull request as ready for review November 7, 2022 21:47
@Gio2018 Gio2018 requested a review from salimbraksa November 7, 2022 21:47
@Gio2018
Copy link
Contributor Author

Gio2018 commented Nov 7, 2022

Thank you for the thorough review @salimbraksa !!
I addressed the comments, change base to trunk and put it in ready for review, now ready for another pass!!

migrationStack: [.welcome: makeWelcomeViewController(),
.notifications: makeNotificationsViewController(),
.done: makeDoneViewController()])
factory: MigrationViewControllerFactory(coordinator: migrationCoordinator))
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this, it's better than passing a closure 👍

self?.updateStack(for: step)
DispatchQueue.main.async {
self?.updateStack(for: step)
}
Copy link
Contributor

@salimbraksa salimbraksa Nov 8, 2022

Choose a reason for hiding this comment

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

We can also use .receive(on:) if you prefer:

publisher
.receive(on: DispatchQueue.main)
.sink { value in
}

Source: https://developer.apple.com/documentation/combine/fail/receive(on:options:)

/// Coordinator for the migration to jetpack flow
final class MigrationFlowCoordinator: ObservableObject {

@Published private(set) var currentStep = MigrationStep.welcome
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should add a documentation here mentioning that currentStep values are published in a background thread.

I'm pretty sure future developers can easily know this by reading the transitionToNextStep implementation details but it would be great to make finding about this detail extra easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

salimbraksa
salimbraksa previously approved these changes Nov 8, 2022
@salimbraksa salimbraksa self-requested a review November 8, 2022 15:15
@salimbraksa salimbraksa dismissed their stale review November 8, 2022 15:15

Just realized there is a tiny UI glitch

@salimbraksa
Copy link
Contributor

salimbraksa commented Nov 8, 2022

@Gio2018 The latest changes look good to me and I actually went ahead and approved the PR but then I discovered there is a tiny UI glitch where the app appears black for a second before the Welcome Screen shows up.

And I think the bug's root cause is:

init(coordinator: MigrationFlowCoordinator, factory: MigrationViewControllerFactory) {
   self.coordinator = coordinator
   self.factory = factory
   // `super.init(rootViewController:)` should be called for a smooth launch
   super.init(nibName: nil, bundle: nil)
   configure()
}

@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@Gio2018
Copy link
Contributor Author

Gio2018 commented Nov 8, 2022

there is a tiny UI glitch

good catch @salimbraksa ! I went ahead and changed the init to assign a root right away!

@salimbraksa
Copy link
Contributor

@Gio2018 LGTM! 🚀

@Gio2018 Gio2018 merged commit b675bf8 into trunk Nov 8, 2022
@Gio2018 Gio2018 deleted the task/migration-notifications-permission branch November 8, 2022 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants