Skip to content

Commit

Permalink
Merge pull request #20029 from wordpress-mobile/issue/20018-add-monit…
Browse files Browse the repository at this point in the history
…oring-to-site-menu

Site Monitoring: Add item to "more" menu
  • Loading branch information
AjeshRPai authored Jan 25, 2024
2 parents 3ba9ad8 + dfe3b6f commit c3f4075
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,11 @@ class ActivityNavigator @Inject constructor() {
mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
return mainActivityIntent
}

fun navigateToSiteMonitoring(context: Context, site: SiteModel) {
// todo: Implement this method after the SiteMonitorActivity is available and remove the lines below
site.name
context.packageName
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment),
.newInstance(action.isPromptsEnabled)
.show(requireActivity().supportFragmentManager, BloganuaryNudgeLearnMoreOverlayFragment.TAG)
}

is SiteNavigationAction.OpenSiteMonitoring -> activityNavigator.navigateToSiteMonitoring(
requireActivity(),
action.site
)
}

private fun handleNavigation(action: BloggingPromptCardNavigationAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ sealed class SiteNavigationAction {
object OpenDashboardPersonalization : SiteNavigationAction()

data class OpenBloganuaryNudgeOverlay(val isPromptsEnabled: Boolean): SiteNavigationAction()
data class OpenSiteMonitoring(val site: SiteModel) : SiteNavigationAction()
}

sealed class BloggingPromptCardNavigationAction: SiteNavigationAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ListItemActionHandler @Inject constructor(
ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite)
ListItemAction.BLAZE -> onBlazeMenuItemClick()
ListItemAction.MORE -> SiteNavigationAction.OpenMore(selectedSite, quickStartEvent)
ListItemAction.SITE_MONITORING -> SiteNavigationAction.OpenSiteMonitoring(selectedSite)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ enum class ListItemAction (val trackingLabel: String) {
BLAZE("blaze"),
ME("me"),
MORE("more"),
SITE_MONITORING("site_monitoring"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SiteItemsBuilder @Inject constructor(
private fun getManageSiteItems(
params: SiteItemsBuilderParams
): List<MySiteCardAndItem> {
val siteMonitoring = buildSiteMonitoringOptionsIfNeeded(params)
val manageSiteItems = buildManageSiteItems(params)

val emptyHeaderItem1 = CategoryEmptyHeaderItem(UiString.UiStringText(""))
Expand All @@ -101,6 +102,7 @@ class SiteItemsBuilder @Inject constructor(
val emptyHeaderItem2 = CategoryEmptyHeaderItem(UiString.UiStringText(""))
val admin = siteListItemBuilder.buildAdminItemIfAvailable(params.site, params.onClick)
return listOf(manageHeader) +
siteMonitoring +
manageSiteItems +
emptyHeaderItem1 +
jetpackConfiguration +
Expand All @@ -126,6 +128,12 @@ class SiteItemsBuilder @Inject constructor(
)
}

private fun buildSiteMonitoringOptionsIfNeeded(params: SiteItemsBuilderParams): List<MySiteCardAndItem> {
return listOfNotNull(
siteListItemBuilder.buildSiteMonitoringItemIfAvailable(params.site, params.onClick)
)
}

private fun buildManageSiteItems(params: SiteItemsBuilderParams): List<MySiteCardAndItem>{
if(jetpackFeatureRemovalOverlayUtil.shouldHideJetpackFeatures())
return emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ class SiteListItemBuilder @Inject constructor(
} else null
}

fun buildSiteMonitoringItemIfAvailable(site: SiteModel, onClick: (ListItemAction) -> Unit): MySiteCardAndItem? {
// todo: Add the feature flag wrapper once it is available
return if (buildConfigWrapper.isJetpackApp && site.isWPComAtomic && site.isAdmin) {
ListItem(
R.drawable.gb_ic_tool,
UiStringRes(R.string.site_monitoring),
onClick = ListItemInteraction.create(ListItemAction.SITE_MONITORING, onClick),
listItemAction = ListItemAction.SITE_MONITORING
)
} else null
}

companion object {
const val HIDE_WP_ADMIN_YEAR = 2015
const val HIDE_WP_ADMIN_MONTH = 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class MenuActivity : AppCompatActivity() {
this,
action.campaignListingPageSource
)
is SiteNavigationAction.OpenSiteMonitoring -> activityNavigator.navigateToSiteMonitoring(this, action.site)
else -> {}
}
}
Expand Down
10 changes: 10 additions & 0 deletions WordPress/src/main/res/drawable/gb_ic_tool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#FF000000"
android:pathData="M14.103,7.128l2.26,-2.26a4,4 0,0 0,-5.207 4.804L5.828,15a2,2 0,1 0,2.828 2.828l5.329,-5.328a4,4 0,0 0,4.804 -5.208l-2.261,2.26 -1.912,-0.512 -0.513,-1.912zM6.889,16.768a0.5,0.5 0,1 1,0.707 -0.707,0.5 0.5,0 0,1 -0.707,0.707z" />
</vector>
2 changes: 2 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4854,4 +4854,6 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->
<string name="gutenberg_native_working_offline" tools:ignore="UnusedResources" a8c-src-lib="gutenberg">Working Offline</string>
<string name="gutenberg_native_waiting_for_connection" tools:ignore="UnusedResources" a8c-src-lib="gutenberg">Waiting for connection</string>

<!-- Site Monitoring -->
<string name="site_monitoring">Site Monitoring</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ class ListItemActionHandlerTest: BaseUnitTest() {
)
}

private fun invokeItemClickAction(action: ListItemAction, ): SiteNavigationAction {
@Test
fun `when site monitoring item click, then emits OpenSiteMonitoring navigation event`() {
val navigationAction = invokeItemClickAction(action = ListItemAction.SITE_MONITORING)

assertEquals(navigationAction, SiteNavigationAction.OpenSiteMonitoring(site))
}

private fun invokeItemClickAction(action: ListItemAction): SiteNavigationAction {
return listItemActionHandler.handleAction(action, site)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ val DOMAINS_ITEM = ListItem(
onClick = ListItemInteraction.create(DOMAINS, SITE_ITEM_ACTION),
listItemAction = DOMAINS
)
val SITE_MONITORING_ITEM = ListItem(
R.drawable.gb_ic_tool,
UiStringRes(R.string.site_monitoring),
onClick = ListItemInteraction.create(ListItemAction.SITE_MONITORING, SITE_ITEM_ACTION),
listItemAction = ListItemAction.SITE_MONITORING
)
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class SiteItemsBuilderTest {
@Test
fun `adds all the items in the correct order`() {
setupHeaders(
addSiteMonitoringItem = true,
addActivityLogItem = true,
addPlanItem = false,
addPagesItem = true,
Expand Down Expand Up @@ -106,6 +107,7 @@ class SiteItemsBuilderTest {
TRAFFIC_HEADER,
STATS_ITEM,
MANAGE_HEADER,
SITE_MONITORING_ITEM,
ACTIVITY_ITEM,
BACKUP_ITEM,
SCAN_ITEM,
Expand Down Expand Up @@ -229,6 +231,7 @@ class SiteItemsBuilderTest {

@Suppress("ComplexMethod", "LongMethod")
private fun setupHeaders(
addSiteMonitoringItem: Boolean = false,
addActivityLogItem: Boolean = false,
addPlanItem: Boolean = false,
addPagesItem: Boolean = false,
Expand All @@ -255,6 +258,11 @@ class SiteItemsBuilderTest {
PLAN_ITEM.copy(showFocusPoint = showPlansFocusPoint)
)
}
if (addSiteMonitoringItem) {
whenever(siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)).thenReturn(
SITE_MONITORING_ITEM
)
}
if (addActivityLogItem) {
whenever(siteListItemBuilder.buildActivityLogItemIfAvailable(siteModel, SITE_ITEM_ACTION)).thenReturn(
ACTIVITY_ITEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.wordpress.android.ui.mysite.items.PLUGINS_ITEM
import org.wordpress.android.ui.mysite.items.SCAN_ITEM
import org.wordpress.android.ui.mysite.items.SHARING_ITEM
import org.wordpress.android.ui.mysite.items.SITE_ITEM_ACTION
import org.wordpress.android.ui.mysite.items.SITE_MONITORING_ITEM
import org.wordpress.android.ui.mysite.items.SITE_SETTINGS_ITEM
import org.wordpress.android.ui.plugins.PluginUtilsWrapper
import org.wordpress.android.ui.themes.ThemeBrowserUtils
Expand Down Expand Up @@ -414,6 +415,58 @@ class SiteListItemBuilderTest {
assertThat(item).isNull()
}

/* SITE MONITORING */
@Test
fun `give jetpack app, when is atomic and admin, then site monitoring item is built`() {
setupSiteMonitoringItems()

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)

assertThat(item).isEqualTo(SITE_MONITORING_ITEM)
}

@Test
fun `give jetpack app, when is not atomic, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isAtomic = false
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)

assertThat(item).isNull()
}

@Test
fun `give jetpack app, when is not admin, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isAdmin = false
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)

assertThat(item).isNull()
}

@Test
fun `give not jetpack app, when site monitoring item requested, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isJetpackApp = false
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)

assertThat(item).isNull()
}

private fun setupSiteMonitoringItems(
isJetpackApp: Boolean = true,
isAtomic: Boolean = true,
isAdmin: Boolean = true
) {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(isJetpackApp)
whenever(siteModel.isAdmin).thenReturn(isAdmin)
whenever(siteModel.isWPComAtomic).thenReturn(isAtomic)
}
private fun setupSiteSettings(canManageOptions: Boolean = false, isAccessedViaWPComRest: Boolean = true) {
whenever(siteModel.hasCapabilityManageOptions).thenReturn(canManageOptions)
whenever(siteUtilsWrapper.isAccessedViaWPComRest(siteModel)).thenReturn(isAccessedViaWPComRest)
Expand Down

0 comments on commit c3f4075

Please sign in to comment.