Skip to content

Commit

Permalink
Dynamic loading of each stat.
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Feb 10, 2025
1 parent 743b9a9 commit 8e22b6d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.squareup.invert.models.js.CollectedStatTotalsJsReportModel
import com.squareup.invert.models.js.HistoricalData
import com.squareup.invert.models.js.MetadataJsReportModel
import com.squareup.invert.models.js.PluginsJsReportModel
import com.squareup.invert.models.js.StatJsReportModel
import com.squareup.invert.models.js.StatsJsReportModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -45,10 +46,10 @@ class ReportDataRepo(

val historicalData: Flow<List<HistoricalData>?> = collectedDataRepo.historicalData.mapLatest { it }

val statInfos: Flow<Collection<StatMetadata>?> = collectedDataRepo.statsData.mapLatest { it?.statInfos?.values }

val statTotals: Flow<CollectedStatTotalsJsReportModel?> = collectedDataRepo.statTotals

val statInfos: Flow<Collection<StatMetadata>?> = statTotals.mapLatest { it?.statTotals?.values?.map { it.metadata } }

val collectedPluginInfoReport: Flow<PluginsJsReportModel?> = collectedDataRepo.collectedPluginInfoReport

val moduleToOwnerMap: Flow<Map<ModulePath, OwnerName>?> = collectedDataRepo.ownersInfo.mapLatest {
Expand Down Expand Up @@ -101,6 +102,9 @@ class ReportDataRepo(
it?.allConfigurationNames
}

fun statForKey(statKey: StatKey): Flow<StatJsReportModel?> =
collectedDataRepo.statData(statKey).mapLatest { it?.get(statKey) }

val pluginIdToAllModulesMap: Flow<Map<GradlePluginId, List<ModulePath>>?> =
collectedDataRepo.collectedPluginInfoReport
.mapLatest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ object InvertedDependenciesReportPage : InvertReportPage<InvertedDependenciesNav
override val navRouteKClass: KClass<InvertedDependenciesNavRoute> = InvertedDependenciesNavRoute::class

override val composableContent: @Composable (InvertedDependenciesNavRoute) -> Unit = { navRoute ->
InverteDependenciesComposable(navRoute)
InvertDependenciesComposable(navRoute)
}
}


@Composable
fun InverteDependenciesComposable(
fun InvertDependenciesComposable(
navRoute: InvertedDependenciesNavRoute,
reportDataRepo: ReportDataRepo = DependencyGraph.reportDataRepo,
navRouteRepo: NavRouteRepo = DependencyGraph.navRouteRepo,
Expand All @@ -111,7 +111,6 @@ fun InverteDependenciesComposable(
BootstrapLoadingMessageWithSpinner()
return
}
println("1")
if (allConfigurationNames!!.isEmpty()) {
H1 { Text("No analyzed configurations found.") }
return
Expand All @@ -123,7 +122,6 @@ fun InverteDependenciesComposable(
if (navRoute.pluginGroupByFilter.isEmpty() || navRoute.configurations.isEmpty()) {
BootstrapJumbotron(
headerContent = {
// BootstrapIcon("exclamation-triangle", 48)
Text(" Inverted Dependency Search")
}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.squareup.invert.models.Stat
import com.squareup.invert.models.Stat.CodeReferencesStat.CodeReference
import com.squareup.invert.models.StatDataType
import com.squareup.invert.models.StatKey
import com.squareup.invert.models.StatMetadata
import org.jetbrains.compose.web.attributes.ATarget
import org.jetbrains.compose.web.attributes.target
import org.jetbrains.compose.web.css.px
Expand All @@ -35,6 +36,7 @@ import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.dom.Ul
import ui.BootstrapColumn
import ui.BootstrapLoadingMessageWithSpinner
import ui.BootstrapLoadingSpinner
import ui.BootstrapRow
import ui.BootstrapSelectDropdown
import ui.BootstrapSelectOption
Expand Down Expand Up @@ -100,17 +102,15 @@ object OwnerBreakdownReportPage : InvertReportPage<OwnerBreakdownNavRoute> {
}

private fun getCodeReferenceOwnerToModulePlusCodeReferencesList(
statKey: StatKey,
statMetadata: StatMetadata,
moduleToOwnerMap: Map<ModulePath, OwnerName>,
statsByModuleParam: Map<ModulePath, Map<StatKey, Stat>>
moduleToStat: Map<ModulePath, Stat>,
): Map<OwnerName, Map<ModulePath, Set<CodeReference>>> {
val toReturnOwnerNameToModuleAndCodeReferencesMap = mutableMapOf<OwnerName, Map<ModulePath, Set<CodeReference>>>()

statsByModuleParam.entries.forEach { (modulePath: ModulePath, moduleStatsByKey: Map<StatKey, Stat>) ->
moduleToStat.entries.forEach { (modulePath: ModulePath, stat: Stat) ->
val moduleOwner = moduleToOwnerMap[modulePath] ?: ""
val codeReferences =
(moduleStatsByKey.entries.firstOrNull { it.key == statKey }?.value as? Stat.CodeReferencesStat)?.value

val codeReferences = (stat as? Stat.CodeReferencesStat)?.value

codeReferences?.forEach { newCodeReference: CodeReference ->
val owner = newCodeReference.owner ?: moduleOwner
Expand All @@ -136,7 +136,6 @@ fun ByOwnerComposable(
reportDataRepo: ReportDataRepo = DependencyGraph.reportDataRepo,
navRouteRepo: NavRouteRepo = DependencyGraph.navRouteRepo
) {
val statsOrig by reportDataRepo.statsData.collectAsState(null)
val statInfosOrig by reportDataRepo.statInfos.collectAsState(null)
val moduleToOwnerMapOrig by reportDataRepo.moduleToOwnerMap.collectAsState(null)
val allOwnerNames by reportDataRepo.allOwnerNames.collectAsState(null)
Expand All @@ -146,7 +145,6 @@ fun ByOwnerComposable(
allOwnerNames,
moduleToOwnerMapOrig,
statInfosOrig,
statsOrig
).any { it == null }
) {
BootstrapLoadingMessageWithSpinner()
Expand Down Expand Up @@ -277,12 +275,18 @@ fun ByOwnerComposable(
BootstrapTabPane(
codeReferenceStatTypesFilteredByNavParams
.mapNotNull { statKey ->
val statInfoForKey by reportDataRepo.statForKey(statKey).collectAsState(null)
if (statInfoForKey == null) {
BootstrapLoadingSpinner()
return
}

val statMetadata = statInfosOrig!!.firstOrNull { it.key == statKey }
val ownerToModulePathToCodeReferences: Map<OwnerName, Map<ModulePath, Set<CodeReference>>> =
getCodeReferenceOwnerToModulePlusCodeReferencesList(
statKey = statKey,
statMetadata = statMetadata!!,
moduleToOwnerMap = moduleToOwnerMapOrig!!,
statsByModuleParam = statsOrig!!.statsByModule
moduleToStat = statInfoForKey!!.statsByModule
)
val filteredByOwners = ownerToModulePathToCodeReferences.filter {
if (!ownerParamValue.isNullOrBlank()) {
Expand Down
34 changes: 21 additions & 13 deletions invert-report/src/jsMain/kotlin/ui/NavBarComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,28 @@ import org.jetbrains.compose.web.dom.Text

@Composable
fun NavBarComposable(loadingProgressFlow: Flow<List<FileKey>>) {
val outstandingCalls by loadingProgressFlow.collectAsState(listOf())
if (outstandingCalls.isNotEmpty()) {
H4 {
Span({ classes("pe-4") }) { Text("Loading... ${outstandingCalls.map { it }}") }
Div({
classes("spinner-border text-light".split(" "))
attr("role", "status")
}) {
Span({
classes("visually-hidden")
}) {
Text("Loading...")
}
val outstandingCalls by loadingProgressFlow.collectAsState(listOf())
if (outstandingCalls.isNotEmpty()) {
H4 {
Span({ classes("pe-4") }) {
Text(
"Loading... ${
outstandingCalls.map { fileKey ->
JsReportFileKey.entries.firstOrNull { it.key == fileKey }?.description ?: fileKey
}
}"
)
}
Div({
classes("spinner-border text-light".split(" "))
attr("role", "status")
}) {
Span({
classes("visually-hidden")
}) {
Text("Loading...")
}
}
}
}
}

0 comments on commit 8e22b6d

Please sign in to comment.