Skip to content

Commit

Permalink
Merge branch 'trunk' into gutenberg/disable-story-block
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot authored Jan 26, 2024
2 parents 4bc201c + d1e9ff2 commit a127530
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 23 deletions.
2 changes: 1 addition & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import se.bjurr.violations.comments.github.plugin.gradle.ViolationCommentsToGitHubTask
import se.bjurr.violations.lib.model.SEVERITY
import io.sentry.android.gradle.extensions.InstrumentationFeature

plugins {
id "com.android.application"
Expand Down Expand Up @@ -164,6 +163,7 @@ android {
buildConfigField "boolean", "ENABLE_OPEN_WEB_LINKS_WITH_JP_FLOW", "true"
buildConfigField "boolean", "BLAZE_MANAGE_CAMPAIGNS", "false"
buildConfigField "boolean", "DASHBOARD_PERSONALIZATION", "false"
buildConfigField "boolean", "ENABLE_SITE_MONITORING", "false"

manifestPlaceholders = [magicLinkScheme:"wordpress"]
}
Expand Down
5 changes: 5 additions & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,11 @@
android:label="@string/stats"
android:theme="@style/WordPress.NoActionBar"/>

<activity android:name=".ui.sitemonitor.SiteMonitorParentActivity"
android:exported="false"
android:label="@string/site_monitoring"
android:theme="@style/WordPress.NoActionBar"/>

<meta-data android:name="io.sentry.traces.activity.enable" android:value="false" />

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.wordpress.android.ui.mysite.menu.KEY_QUICK_START_EVENT
import org.wordpress.android.ui.mysite.menu.MenuActivity
import org.wordpress.android.ui.mysite.personalization.PersonalizationActivity
import org.wordpress.android.ui.quickstart.QuickStartEvent
import org.wordpress.android.ui.sitemonitor.SiteMonitorParentActivity
import org.wordpress.android.util.ToastUtils
import org.wordpress.android.util.analytics.AnalyticsUtils
import javax.inject.Inject
Expand Down Expand Up @@ -158,9 +159,9 @@ class ActivityNavigator @Inject constructor() {
}

fun navigateToSiteMonitoring(context: Context, site: SiteModel) {
// todo: Implement this method after the SiteMonitorActivity is available and remove the lines below
site.name
context.packageName
val intent = Intent(context, SiteMonitorParentActivity::class.java)
intent.putExtra(WordPress.SITE, site)
context.startActivity(intent)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.SiteUtilsWrapper
import org.wordpress.android.util.config.SiteMonitoringFeatureConfig
import java.util.GregorianCalendar
import java.util.TimeZone
import javax.inject.Inject
Expand All @@ -39,7 +40,8 @@ class SiteListItemBuilder @Inject constructor(
private val siteUtilsWrapper: SiteUtilsWrapper,
private val buildConfigWrapper: BuildConfigWrapper,
private val themeBrowserUtils: ThemeBrowserUtils,
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper,
private val siteMonitoringFeatureConfig: SiteMonitoringFeatureConfig
) {
fun buildActivityLogItemIfAvailable(site: SiteModel, onClick: (ListItemAction) -> Unit): ListItem? {
val isWpComOrJetpack = siteUtilsWrapper.isAccessedViaWPComRest(
Expand Down Expand Up @@ -245,9 +247,13 @@ class SiteListItemBuilder @Inject constructor(
} else null
}

@Suppress("ComplexCondition")
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) {
return if (buildConfigWrapper.isJetpackApp
&& site.isWPComAtomic
&& site.isAdmin
&& siteMonitoringFeatureConfig.isEnabled()
) {
ListItem(
R.drawable.gb_ic_tool,
UiStringRes(R.string.site_monitoring),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.wordpress.android.ui.sitemonitor

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.TabRow
import androidx.compose.material.Text
import androidx.compose.material3.Tab
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import dagger.hilt.android.AndroidEntryPoint
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.compose.components.MainTopAppBar
import org.wordpress.android.ui.compose.components.NavigationIcons
import org.wordpress.android.ui.compose.theme.AppTheme
import org.wordpress.android.util.extensions.getSerializableExtraCompat

@AndroidEntryPoint
class SiteMonitorParentActivity: AppCompatActivity() {
val viewModel:SiteMonitorParentViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AppTheme {
viewModel.start(getSite())
SiteMonitorScreen()
}
}
}

private fun getSite(): SiteModel {
return requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) as SiteModel
}

@Composable
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
fun SiteMonitorScreen(modifier: Modifier = Modifier) {
Scaffold(
topBar = {
MainTopAppBar(
title = stringResource(id = R.string.site_monitoring),
navigationIcon = NavigationIcons.BackIcon,
onNavigationIconClick = onBackPressedDispatcher::onBackPressed,
)
},
content = {
TabScreen(modifier = modifier)
}
)
}

@Composable
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
fun TabScreen(modifier: Modifier = Modifier) {
var tabIndex by remember { mutableStateOf(0) }

val tabs = listOf(
R.string.site_monitoring_tab_title_metrics,
R.string.site_monitoring_tab_title_php_logs,
R.string.site_monitoring_tab_title_web_server_logs
)

Column(modifier = modifier.fillMaxWidth()) {
TabRow(
selectedTabIndex = tabIndex,
backgroundColor = MaterialTheme.colors.surface,
contentColor = MaterialTheme.colors.onSurface,
) {
tabs.forEachIndexed { index, title ->
Tab(text = { Text(stringResource(id = title)) },
selected = tabIndex == index,
onClick = { tabIndex = index }
)
}
}
when (tabIndex) {
0 -> SiteMonitoringWebView()
1 -> SiteMonitoringWebView()
2 -> SiteMonitoringWebView()
}
}
}

@Composable
fun SiteMonitoringWebView(){
Text(text = "SiteMonitoringWebView")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.wordpress.android.ui.sitemonitor

import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper
import org.wordpress.android.viewmodel.ScopedViewModel
import javax.inject.Inject
import javax.inject.Named

@HiltViewModel
class SiteMonitorParentViewModel @Inject constructor(
@param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper
) : ScopedViewModel(bgDispatcher) {
private lateinit var site: SiteModel

fun start(site: SiteModel) {
this.site = site
trackActivityLaunched()
}

private fun trackActivityLaunched() {
analyticsTrackerWrapper.track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.wordpress.android.util.config

import org.wordpress.android.BuildConfig
import org.wordpress.android.annotation.Feature
import javax.inject.Inject

private const val SITE_MONITORING_FEATURE_REMOTE_FIELD = "site_monitoring"

@Feature(SITE_MONITORING_FEATURE_REMOTE_FIELD, false)
class SiteMonitoringFeatureConfig @Inject constructor(
appConfig: AppConfig
) : FeatureConfig(
appConfig,
BuildConfig.ENABLE_SITE_MONITORING,
SITE_MONITORING_FEATURE_REMOTE_FIELD
)

3 changes: 3 additions & 0 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4856,4 +4856,7 @@ translators: %s: Select control option value e.g: "Auto, 25%". -->

<!-- Site Monitoring -->
<string name="site_monitoring">Site Monitoring</string>
<string name="site_monitoring_tab_title_metrics">Metrics</string>
<string name="site_monitoring_tab_title_php_logs">PHP Logs</string>
<string name="site_monitoring_tab_title_web_server_logs">Web Server Logs</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.wordpress.android.ui.plugins.PluginUtilsWrapper
import org.wordpress.android.ui.themes.ThemeBrowserUtils
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.SiteUtilsWrapper
import org.wordpress.android.util.config.SiteMonitoringFeatureConfig

@RunWith(MockitoJUnitRunner::class)
class SiteListItemBuilderTest {
Expand All @@ -53,6 +54,9 @@ class SiteListItemBuilderTest {
@Mock
lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper

@Mock
lateinit var siteMonitoringFeatureConfig: SiteMonitoringFeatureConfig

private lateinit var siteListItemBuilder: SiteListItemBuilder

@Before
Expand All @@ -63,7 +67,8 @@ class SiteListItemBuilderTest {
siteUtilsWrapper,
buildConfigWrapper,
themeBrowserUtils,
jetpackFeatureRemovalPhaseHelper
jetpackFeatureRemovalPhaseHelper,
siteMonitoringFeatureConfig
)
}

Expand Down Expand Up @@ -417,18 +422,26 @@ class SiteListItemBuilderTest {

/* SITE MONITORING */
@Test
fun `give jetpack app, when is atomic and admin, then site monitoring item is built`() {
setupSiteMonitoringItems()
fun `give jetpack app, when FF is true and site is atomic and admin, then site monitoring item is built`() {
setupSiteMonitoringItems(
isJetpackApp = true,
isSiteMonitoringFeatureFlagEnabled = true,
isAtomic = true,
isAdmin = true
)

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`() {
fun `give jetpack app, when FF is true and site is atomic and NOT admin, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isAtomic = false
isJetpackApp = true,
isSiteMonitoringFeatureFlagEnabled = true,
isAtomic = true,
isAdmin = false
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)
Expand All @@ -437,9 +450,24 @@ class SiteListItemBuilderTest {
}

@Test
fun `give jetpack app, when is not admin, then site monitoring item is not built`() {
fun `give jetpack app, when FF is true and site is admin and NOT atomic, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isAdmin = false
isJetpackApp = true,
isSiteMonitoringFeatureFlagEnabled = true,
isAdmin = true
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)

assertThat(item).isNull()
}

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

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)
Expand All @@ -448,9 +476,12 @@ class SiteListItemBuilderTest {
}

@Test
fun `give not jetpack app, when site monitoring item requested, then site monitoring item is not built`() {
fun `give not jetpack app, when FF is true and site is atomic and admin, then site monitoring item is not built`() {
setupSiteMonitoringItems(
isJetpackApp = false
isJetpackApp = false,
isSiteMonitoringFeatureFlagEnabled = true,
isAtomic = true,
isAdmin = true
)

val item = siteListItemBuilder.buildSiteMonitoringItemIfAvailable(siteModel, SITE_ITEM_ACTION)
Expand All @@ -459,11 +490,13 @@ class SiteListItemBuilderTest {
}

private fun setupSiteMonitoringItems(
isJetpackApp: Boolean = true,
isAtomic: Boolean = true,
isAdmin: Boolean = true
isJetpackApp: Boolean = false,
isSiteMonitoringFeatureFlagEnabled: Boolean = false,
isAtomic: Boolean = false,
isAdmin: Boolean = false
) {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(isJetpackApp)
whenever(siteMonitoringFeatureConfig.isEnabled()).thenReturn(isSiteMonitoringFeatureFlagEnabled)
whenever(siteModel.isAdmin).thenReturn(isAdmin)
whenever(siteModel.isWPComAtomic).thenReturn(isAtomic)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.wordpress.android.ui.sitemonitor

import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper

@ExperimentalCoroutinesApi
@RunWith(MockitoJUnitRunner::class)
class SiteMonitorParentViewModelTest: BaseUnitTest(){
@Mock
private lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper

private lateinit var viewModel: SiteMonitorParentViewModel

@Before
fun setUp() {
viewModel = SiteMonitorParentViewModel(testDispatcher(), analyticsTrackerWrapper)
}

@Test
fun `when viewmodel is started, then screen shown tracking is done`() {
val site = mock<SiteModel>()
viewModel.start(site)

verify(analyticsTrackerWrapper).track(AnalyticsTracker.Stat.SITE_MONITORING_SCREEN_SHOWN)
}
}
Loading

0 comments on commit a127530

Please sign in to comment.