Skip to content

Commit

Permalink
Merge pull request #13536 from woocommerce/issue/10553-fix-site-picke…
Browse files Browse the repository at this point in the history
…r-crash

Disable the site picker button when no site is selected
  • Loading branch information
irfano authored Feb 18, 2025
2 parents d7f1271 + 81b6957 commit 41ac328
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [*] Updated the notification icon for better readability [https://github.com/woocommerce/woocommerce-android/pull/13516]
- [*] Automatically select the first available order when filtering is active in the two-pane layout.[https://github.com/woocommerce/woocommerce-android/pull/13491]
- [*] [Internal] Removal animation of the items from the cart [https://github.com/woocommerce/woocommerce-android/pull/13442]
- [*] Fixed a rare crash on the site picker screen [https://github.com/woocommerce/woocommerce-android/pull/13536]
- [*] Updated bottom sheet in Scan to update inventory to Material 3 component [https://github.com/woocommerce/woocommerce-android/pull/13554]
- [*] Improved the Authenticated WebView implementation, and it will now handle opening the Analytics reports directly from the app without requiring additional authentication [https://github.com/woocommerce/woocommerce-android/pull/13487]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class SitePickerFragment :
new.isPrimaryBtnVisible.takeIfNotEqualTo(old?.isPrimaryBtnVisible) {
binding.loginEpilogueButtonBar.buttonPrimary.isVisible = it
}
new.isPrimaryBtnEnabled.takeIfNotEqualTo(old?.isPrimaryBtnEnabled) {
binding.loginEpilogueButtonBar.buttonPrimary.isEnabled = it
}
new.isSecondaryBtnVisible.takeIfNotEqualTo(old?.isSecondaryBtnVisible) {
binding.loginEpilogueButtonBar.buttonSecondary.isVisible = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class SitePickerViewModel @Inject constructor(
)
}
val selectedSiteId = selectedSiteId.value ?: wooSites.getOrNull(0)?.id
val isSelectedSiteVisible = getWooVisibleSites().any { it.id == selectedSiteId }
_sites.value = buildSitesList(wooSites, selectedSiteId, nonWooSites)

val isEditListEnabled = FeatureFlag.HIDE_SITES_FROM_SITE_PICKER.isEnabled() &&
Expand All @@ -236,6 +237,7 @@ class SitePickerViewModel @Inject constructor(
sitePickerViewState = sitePickerViewState.copy(
hasConnectedStores = sites.isNotEmpty(),
isPrimaryBtnVisible = wooSites.isNotEmpty(),
isPrimaryBtnEnabled = isSelectedSiteVisible,
isNoStoresViewVisible = false,
currentSitePickerState = SitePickerState.StoreListState,
editStoreListEnabled = isEditListEnabled
Expand Down Expand Up @@ -412,6 +414,7 @@ class SitePickerViewModel @Inject constructor(
}
}
updatedSites?.let { _sites.value = it }
sitePickerViewState = sitePickerViewState.copy(isPrimaryBtnEnabled = true)
}

fun onNonWooSiteSelected(siteModel: SiteModel) {
Expand Down Expand Up @@ -693,6 +696,7 @@ class SitePickerViewModel @Inject constructor(
val isSkeletonViewVisible: Boolean = false,
val isProgressDiaLogVisible: Boolean = false,
val isPrimaryBtnVisible: Boolean = false,
val isPrimaryBtnEnabled: Boolean = true,
val isSecondaryBtnVisible: Boolean = false,
val isNoStoresBtnVisible: Boolean = false,
val showCloseAccountMenuItem: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,4 +835,21 @@ class SitePickerViewModelTest : BaseUnitTest() {
}
Dispatchers.resetMain()
}

@Test
fun `given initiated, when selected site is hidden, then primary button view is disabled`() = testBlocking {
val expectedSites = defaultExpectedSiteList
val selectedSiteModel = expectedSites[0]
whenever(getWooVisibleSites()).thenReturn(expectedSites.minus(selectedSiteModel))

whenSitesAreFetched(sitesFromDb = expectedSites)
whenever(selectedSite.exists()).thenReturn(true)
whenever(selectedSite.getSelectedSiteId()).thenReturn(selectedSiteModel.id)
whenViewModelIsCreated()

var sitePickerData: SitePickerViewModel.SitePickerViewState? = null
viewModel.sitePickerViewStateData.observeForever { _, new -> sitePickerData = new }

assertThat(sitePickerData?.isPrimaryBtnEnabled).isFalse()
}
}

0 comments on commit 41ac328

Please sign in to comment.