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

Issue/13127 add edit sites button #13135

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,21 @@ class SitePickerFragment :
true
}

R.id.menu_edit_store_list -> {
TODO()
}

else -> false
}
}

override fun onPrepareMenu(menu: Menu) {
menu.findItem(R.id.menu_help).isVisible =
viewModel.sitePickerViewStateData.liveData.value?.isHelpBtnVisible ?: false
viewModel.sitePickerViewStateData.liveData.value?.isHelpBtnVisible == true
menu.findItem(R.id.menu_close_account).isVisible =
viewModel.sitePickerViewStateData.liveData.value?.showCloseAccountMenuItem ?: false
viewModel.sitePickerViewStateData.liveData.value?.showCloseAccountMenuItem == true
menu.findItem(R.id.menu_edit_store_list).isVisible =
viewModel.sitePickerViewStateData.liveData.value?.editStoreListEnabled == true
}

override fun onDestroyView() {
Expand Down Expand Up @@ -197,6 +203,9 @@ class SitePickerFragment :
SimpleWPComState -> updateSimpleWPComView()
}
}
new.editStoreListEnabled.takeIfNotEqualTo(old?.editStoreListEnabled) {
activity?.invalidateMenu()
}
}

viewModel.sites.observe(viewLifecycleOwner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.woocommerce.android.ui.sitepicker.SitePickerViewModel.SitePickerEvent
import com.woocommerce.android.ui.sitepicker.SitePickerViewModel.SitesListItem.Header
import com.woocommerce.android.ui.sitepicker.SitePickerViewModel.SitesListItem.NonWooSiteUiModel
import com.woocommerce.android.ui.sitepicker.SitePickerViewModel.SitesListItem.WooSiteUiModel
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.viewmodel.LiveDataDelegate
import com.woocommerce.android.viewmodel.MultiLiveEvent
Expand Down Expand Up @@ -242,7 +243,8 @@ class SitePickerViewModel @Inject constructor(
hasConnectedStores = sites.isNotEmpty(),
isPrimaryBtnVisible = wooSites.isNotEmpty(),
isNoStoresViewVisible = false,
currentSitePickerState = SitePickerState.StoreListState
currentSitePickerState = SitePickerState.StoreListState,
editStoreListEnabled = FeatureFlag.HIDE_SITES_FROM_SITE_PICKER.isEnabled() && wooSites.size > 1
)
loginSiteAddress?.let {
processLoginSiteAddress(it)
Expand Down Expand Up @@ -666,7 +668,8 @@ class SitePickerViewModel @Inject constructor(
val isSecondaryBtnVisible: Boolean = false,
val isNoStoresBtnVisible: Boolean = false,
val showCloseAccountMenuItem: Boolean = false,
val currentSitePickerState: SitePickerState = SitePickerState.StoreListState
val currentSitePickerState: SitePickerState = SitePickerState.StoreListState,
val editStoreListEnabled: Boolean = false
) : Parcelable

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum class FeatureFlag {
ENDLESS_CAMPAIGNS_SUPPORT,
REVAMP_WOO_SHIPPING,
OBJECTIVE_SECTION,
BULK_UPDATE_ORDERS_STATUS;
BULK_UPDATE_ORDERS_STATUS,
HIDE_SITES_FROM_SITE_PICKER;

fun isEnabled(context: Context? = null): Boolean {
return when (this) {
Expand All @@ -26,7 +27,8 @@ enum class FeatureFlag {
BETTER_CUSTOMER_SEARCH_M2,
ORDER_CREATION_AUTO_TAX_RATE,
REVAMP_WOO_SHIPPING,
BULK_UPDATE_ORDERS_STATUS -> PackageUtils.isDebugBuild()
BULK_UPDATE_ORDERS_STATUS,
HIDE_SITES_FROM_SITE_PICKER -> PackageUtils.isDebugBuild()

NEW_SHIPPING_SUPPORT,
ENDLESS_CAMPAIGNS_SUPPORT,
Expand Down
6 changes: 6 additions & 0 deletions WooCommerce/src/main/res/menu/menu_site_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
android:visible="false"
app:showAsAction="never" />

<item
android:id="@+id/menu_edit_store_list"
android:title="@string/site_picker_edit_store_list"
android:visible="false"
app:showAsAction="always" />

</menu>
14 changes: 9 additions & 5 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,10 @@
<string name="user_role_access_error_link">Learn more about roles and permissions</string>
<string name="user_role_access_error_retry">You don\'t have the correct user role</string>
<string name="user_access_verifying">Verifying role…</string>
<string name="login_site_picker_enter_site_address">Enter a site address</string>
<string name="login_site_picker_add_a_store">Connect another store</string>
<string name="site_discovery_postlogin_failure">A failure occurred, please contact support</string>
<string name="login_site_picker_new_to_woo">New to WooCommerce</string>
<string name="login_simple_wpcom_site">The site %1$s is currently on a WordPress.com plan that does not support plugin installation. Please upgrade your plan to use WooCommerce.</string>
<string name="login_jetpack_connection_verification_failed">Cannot verify your Jetpack connection. Please try again.</string>
<string name="login_jetpack_verify_connection">Verifying Jetpack connection…</string>

Check warning

Code scanning / Android Lint

Unused resources Warning

The resource R.string.site_picker_create_new_store appears to be unused
<string name="login_jetpack_connection_url_failed">Fetching connection data failed…</string>
<string name="login_2fa_not_supported_self_hosted_site">2FA not supported for self-hosted sites. Please use an app-password.</string>
<string name="login_account_mismatch_connect_jetpack">Connect Jetpack to your account</string>
Expand All @@ -305,13 +302,11 @@
<string name="login_account_mismatch_connect_wpcom_dialog_title">Connecting to a WordPress.com site</string>
<string name="login_account_mismatch_connect_wpcom_dialog_message">Please contact the site owner for an invitation to the site as a shop manager or administrator to use the app.</string>
<string name="login_jetpack_connection_consent">By tapping the Connect Jetpack button, you agree to our &lt;a href=\'terms\'&gt;Terms of Service&lt;/a&gt; and to &lt;a href=\'sync\'&gt;share details&lt;/a&gt; with WordPress.com.</string>
<string name="site_picker_create_new_store">Create a new store</string>
<string name="site_picker_connect_existing_store">Connect an existing store</string>
<string name="login_jetpack_installation_screen_title">Connect store</string>
<string name="login_jetpack_installation_explanation">Please install the free Jetpack plugin to access your store on this app.</string>
<string name="login_jetpack_connection_explanation">Please connect your store to Jetpack to access it on this app.</string>
<string name="login_jetpack_installation_credentials_hint">Have your store credentials ready.</string>

Check warning

Code scanning / Android Lint

Unused resources Warning

The resource R.string.login_site_picker_new_to_woo appears to be unused
<string name="login_jetpack_connect">Connect Jetpack</string>

Check warning

Code scanning / Android Lint

Unused resources Warning

The resource R.string.site_picker_connect_existing_store appears to be unused
<string name="login_jetpack_installation_enter_site_credentials">Log in to &lt;b&gt;%1$s&lt;/b&gt; with your store credentials to install Jetpack.</string>
<string name="login_jetpack_connection_enter_site_credentials">Log in to &lt;b&gt;%1$s&lt;/b&gt; with your store credentials to connect Jetpack.</string>
<string name="login_jetpack_steps_installing">Installing Jetpack</string>
Expand Down Expand Up @@ -367,6 +362,15 @@
<string name="login_app_login_malformed_link">We couldn\'t process your app login request</string>
<string name="login_jetpack_connection_create_account">If you don\'t have an account, we\'ll use this email to create one.</string>

<!--
Site picker
-->
<string name="login_site_picker_enter_site_address">Enter a site address</string>
<string name="login_site_picker_add_a_store">Connect another store</string>
<string name="site_picker_create_new_store">Create a new store</string>
<string name="site_picker_connect_existing_store">Connect an existing store</string>
<string name="login_site_picker_new_to_woo">New to WooCommerce</string>
<string name="site_picker_edit_store_list">Edit Stores</string>
<!--
My Store View
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ object SitePickerTestUtils {
isHelpBtnVisible = true,
isSecondaryBtnVisible = true,
isPrimaryBtnVisible = true,
toolbarTitle = ""
toolbarTitle = "",
editStoreListEnabled = true
)

fun getDefaultSwitchStoreViewState(
Expand All @@ -58,7 +59,8 @@ object SitePickerTestUtils {
toolbarTitle = resourceProvider.getString(R.string.site_picker_title),
isHelpBtnVisible = false,
isSecondaryBtnVisible = false,
isPrimaryBtnVisible = true
isPrimaryBtnVisible = true,
editStoreListEnabled = true
)

fun getEmptyViewState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,44 @@ class SitePickerViewModelTest : BaseUnitTest() {
viewModel.sitePickerViewStateData.observeForever { _, new -> sitePickerData = new }

assertThat(sitePickerData).isEqualTo(
SitePickerTestUtils.getDefaultSwitchStoreViewState(defaultSitePickerViewState, resourceProvider)
SitePickerTestUtils
.getDefaultSwitchStoreViewState(defaultSitePickerViewState, resourceProvider)
)
}

@Test
fun `given that user is switching stores, when woo sites greater than 1, then show edit sites button`() =
testBlocking {
givenTheScreenIsFromLogin(false)
whenSitesAreFetched(sitesFromDb = defaultExpectedSiteList)
whenViewModelIsCreated()

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

assertThat(sitePickerData).isEqualTo(
SitePickerTestUtils
.getDefaultSwitchStoreViewState(defaultSitePickerViewState, resourceProvider)
)
}

@Test
fun `given that user is switching stores, when woo sites less than 1, then show edit sites button`() =
testBlocking {
givenTheScreenIsFromLogin(false)
whenSitesAreFetched(sitesFromDb = defaultExpectedSiteList.take(1))
whenViewModelIsCreated()

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

assertThat(sitePickerData).isEqualTo(
SitePickerTestUtils
.getDefaultSwitchStoreViewState(defaultSitePickerViewState, resourceProvider)
.copy(editStoreListEnabled = false)
)
}

@Test
fun `given that the view model is created, when stores fetch succeeds, then stores are displayed correctly`() =
testBlocking {
Expand Down
Loading