Skip to content

Commit 4a62d8d

Browse files
authored
Merge pull request #7765 from woocommerce/issue/7612-store-picker-crash
Store picker: Fix crash when selecting a store in the store picker
2 parents 78ef6c8 + 26cc53d commit 4a62d8d

File tree

4 files changed

+6
-53
lines changed

4 files changed

+6
-53
lines changed

RELEASE-NOTES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*** PLEASE FOLLOW THIS FORMAT: [<priority indicator, more stars = higher priority>] <description> [<PR URL>]
22

3+
10.6
4+
-----
5+
- [*] Fixed a rare crash when selecting a store in the store picker. [https://github.com/woocommerce/woocommerce-ios/pull/7765]
6+
37
10.5
48
-----
59
- [**] Products: Now you can duplicate products from the More menu of the product detail screen. [https://github.com/woocommerce/woocommerce-ios/pull/7727]

WooCommerce/Classes/Authentication/Epilogue/StorePickerViewController.swift

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -406,36 +406,6 @@ private extension StorePickerViewController {
406406
dismissButton.isEnabled = enabled
407407
}
408408

409-
/// This method will reload the [Selected Row]
410-
///
411-
func reloadSelectedStoreRows(afterRunning block: () -> Void) {
412-
/// Preserve: Selected and Checked Rows
413-
///
414-
var rowsToReload = [IndexPath]()
415-
416-
if let oldSiteID = currentlySelectedSite?.siteID,
417-
let oldCheckedRow = viewModel.indexPath(for: oldSiteID) {
418-
rowsToReload.append(oldCheckedRow)
419-
}
420-
421-
if let oldSelectedRow = tableView.indexPathForSelectedRow {
422-
rowsToReload.append(oldSelectedRow)
423-
}
424-
425-
/// Update the Default Store
426-
///
427-
block()
428-
429-
if let newSiteID = currentlySelectedSite?.siteID,
430-
let selectedRow = viewModel.indexPath(for: newSiteID) {
431-
rowsToReload.append(selectedRow)
432-
}
433-
434-
/// Refresh: Selected and Checked Rows
435-
///
436-
tableView.reloadRows(at: rowsToReload, with: .none)
437-
}
438-
439409
/// Re-initializes the Login Flow, forcing a logout. This may be required if the WordPress.com Account has no Stores available.
440410
///
441411
func restartAuthentication() {
@@ -699,12 +669,8 @@ extension StorePickerViewController: UITableViewDelegate {
699669
return tableView.deselectRow(at: indexPath, animated: true)
700670
}
701671

702-
reloadSelectedStoreRows() {
703-
currentlySelectedSite = site
704-
}
705-
706-
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
707-
tableView.deselectRow(at: indexPath, animated: true)
672+
currentlySelectedSite = site
673+
tableView.reloadData()
708674
}
709675

710676
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

WooCommerce/Classes/Authentication/Epilogue/StorePickerViewModel.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,6 @@ extension StorePickerViewModel {
146146
}
147147
return resultsController.safeObject(at: indexPath)
148148
}
149-
150-
/// Returns the IndexPath for the specified Site.
151-
///
152-
func indexPath(for siteID: Int64) -> IndexPath? {
153-
guard resultsController.numberOfObjects > 0 else {
154-
return nil
155-
}
156-
157-
for (sectionIndex, section) in resultsController.sections.enumerated() {
158-
if let rowIndex = section.objects.firstIndex(where: { $0.siteID == siteID }) {
159-
return IndexPath(row: rowIndex, section: sectionIndex)
160-
}
161-
}
162-
return nil
163-
}
164149
}
165150

166151
private extension StorePickerViewModel {

WooCommerce/WooCommerceTests/Authentication/StorePickerViewModelTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ final class StorePickerViewModelTests: XCTestCase {
109109
XCTAssertEqual(viewModel.titleForSection(at: 0), Localization.connectedStore)
110110
XCTAssertEqual(viewModel.numberOfRows(inSection: 0), 1)
111111
XCTAssertEqual(viewModel.site(at: IndexPath(row: 0, section: 0))?.siteID, testSite1.siteID)
112-
XCTAssertEqual(viewModel.indexPath(for: testSite1.siteID), IndexPath(row: 0, section: 0))
113112
}
114113

115114
func test_table_view_configs_are_correct_for_list_with_both_woo_and_non_woo_sites() {
@@ -143,7 +142,6 @@ final class StorePickerViewModelTests: XCTestCase {
143142
XCTAssertEqual(viewModel.numberOfRows(inSection: 1), 1)
144143
XCTAssertEqual(viewModel.site(at: IndexPath(row: 1, section: 0))?.siteID, testSite2.siteID)
145144
XCTAssertEqual(viewModel.site(at: IndexPath(row: 0, section: 1))?.siteID, testSite3.siteID)
146-
XCTAssertEqual(viewModel.indexPath(for: testSite3.siteID), IndexPath(row: 0, section: 1))
147145
}
148146

149147
func test_trackScreenView_tracks_both_number_of_woo_and_non_woo_sites() throws {

0 commit comments

Comments
 (0)