Skip to content

Commit 1258d15

Browse files
committed
Ability to view Code References by Owner
1 parent b40ac1d commit 1258d15

File tree

3 files changed

+83
-23
lines changed

3 files changed

+83
-23
lines changed

invert-report/src/jsMain/kotlin/com/squareup/invert/common/ReportDataRepo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import com.squareup.invert.common.pages.InvertedDependenciesNavRoute
66
import com.squareup.invert.common.utils.DependencyComputations
77
import com.squareup.invert.models.ConfigurationName
88
import com.squareup.invert.models.DependencyId
9-
import com.squareup.invert.models.ModulePath
109
import com.squareup.invert.models.GradlePluginId
10+
import com.squareup.invert.models.ModulePath
1111
import com.squareup.invert.models.OwnerName
1212
import com.squareup.invert.models.Stat
1313
import com.squareup.invert.models.StatKey
@@ -161,17 +161,15 @@ class ReportDataRepo(
161161
moduleToOwnerMap.first().also { moduleToOwnerMap ->
162162
statsJsReportModel?.statsByModule?.map { moduleToStatsMap ->
163163
moduleToStatsMap.value[statKey]?.let { stat: Stat ->
164-
println(stat)
165164
val moduleName = moduleToStatsMap.key
166-
val ownerName = moduleToOwnerMap?.get(moduleName) ?: ""
167165

168166
if (stat is Stat.CodeReferencesStat) {
169167
stat.value.forEach { codeReference ->
170168
allForKey.add(
171169
ModuleOwnerAndCodeReference(
172170
codeReference = codeReference,
173171
module = moduleName,
174-
owner = ownerName,
172+
owner = codeReference.owner ?: moduleToOwnerMap?.get(moduleName) ?: "",
175173
metadata = statsJsReportModel.statInfos[statKey]!!
176174
)
177175
)

invert-report/src/jsMain/kotlin/com/squareup/invert/common/pages/CodeReferencesReportPage.kt

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,49 @@ import com.squareup.invert.models.OwnerName
1818
import com.squareup.invert.models.StatDataType
1919
import org.jetbrains.compose.web.dom.A
2020
import org.jetbrains.compose.web.dom.H1
21+
import org.jetbrains.compose.web.dom.H3
2122
import org.jetbrains.compose.web.dom.Text
23+
import ui.BootstrapColumn
2224
import ui.BootstrapLoadingMessageWithSpinner
2325
import ui.BootstrapLoadingSpinner
26+
import ui.BootstrapRow
27+
import ui.BootstrapSelectDropdown
28+
import ui.BootstrapSelectOption
2429
import ui.BootstrapTable
2530
import kotlin.reflect.KClass
2631

2732
data class CodeReferencesNavRoute(
28-
val statKey: String? = null
33+
val statKey: String? = null,
34+
val owner: String? = null,
2935
) : BaseNavRoute(CodeReferencesReportPage.navPage) {
3036

3137
override fun toSearchParams(): Map<String, String> = toParamsWithOnlyPageId(this)
3238
.also { params ->
3339
statKey?.let {
3440
params[STATKEY_PARAM] = it
3541
}
42+
if (!owner.isNullOrBlank()) {
43+
params[OWNER_PARAM] = owner
44+
}
3645
}
3746

3847
companion object {
3948

4049
private const val STATKEY_PARAM = "statkey"
50+
private const val OWNER_PARAM = "owner"
4151

4252
fun parser(params: Map<String, String?>): CodeReferencesNavRoute {
4353
val statKey = params[STATKEY_PARAM]
54+
val owner = params[OWNER_PARAM]?.trim()?.let {
55+
if (it.isNotBlank()) {
56+
it
57+
} else {
58+
null
59+
}
60+
}
4461
return CodeReferencesNavRoute(
4562
statKey = statKey,
63+
owner = owner,
4664
)
4765
}
4866
}
@@ -70,10 +88,11 @@ fun CodeReferencesComposable(
7088
navRouteRepo: NavRouteRepo = DependencyGraph.navRouteRepo,
7189
) {
7290
val allModulesOrig by reportDataRepo.allModules.collectAsState(null)
91+
val allOwnerNames by reportDataRepo.allOwnerNames.collectAsState(null)
7392
val moduleToOwnerMapFlowValue: Map<ModulePath, OwnerName>? by reportDataRepo.moduleToOwnerMap.collectAsState(null)
7493

7594
val statInfosOrig by reportDataRepo.statInfos.collectAsState(null)
76-
if (statInfosOrig == null) {
95+
if (statInfosOrig == null || allOwnerNames == null) {
7796
BootstrapLoadingMessageWithSpinner("Loading Stats")
7897
return
7998
}
@@ -98,6 +117,7 @@ fun CodeReferencesComposable(
98117
}
99118
}
100119

120+
101121
if (moduleToOwnerMapFlowValue == null || metadata == null) {
102122
BootstrapLoadingSpinner()
103123
return
@@ -137,24 +157,61 @@ fun CodeReferencesComposable(
137157
return
138158
}
139159

160+
val allCodeReferencesForStat: Set<ModuleOwnerAndCodeReference> = statsForKey!!.toSet()
161+
140162
val extraKeys = mutableSetOf<ExtraKey>()
141-
statsForKey!!.forEach { moduleOwnerAndCodeReference ->
142-
moduleOwnerAndCodeReference.codeReference.extras.forEach {
143-
extraKeys.add(it.key)
163+
allCodeReferencesForStat
164+
.forEach { moduleOwnerAndCodeReference ->
165+
moduleOwnerAndCodeReference.codeReference.extras.forEach {
166+
extraKeys.add(it.key)
167+
}
168+
}
169+
170+
val filteredByOwner: List<ModuleOwnerAndCodeReference> = allCodeReferencesForStat
171+
.filter { ownerAndCodeReference: ModuleOwnerAndCodeReference ->
172+
if (!codeReferencesNavRoute.owner.isNullOrBlank()) {
173+
ownerAndCodeReference.codeReference.owner == codeReferencesNavRoute.owner || codeReferencesNavRoute.owner == ownerAndCodeReference.owner
174+
} else {
175+
true
176+
}
177+
}
178+
179+
val codeReferencesByOwner = allCodeReferencesForStat.groupBy { it.owner }
180+
val totalCount = allCodeReferencesForStat.size
181+
BootstrapRow {
182+
BootstrapColumn(12) {
183+
H3 {
184+
Text("Filter by Owner")
185+
BootstrapSelectDropdown(
186+
placeholderText = "-- All Owners ($totalCount Total) --",
187+
currentValue = codeReferencesNavRoute.owner ?: "",
188+
options = codeReferencesByOwner.map {
189+
BootstrapSelectOption(
190+
value = it.key,
191+
displayText = "${it.key} (${it.value.size} of $totalCount)"
192+
)
193+
}.sortedBy { it.displayText }
194+
) {
195+
navRouteRepo.updateNavRoute(
196+
codeReferencesNavRoute.copy(owner = it)
197+
)
198+
}
199+
}
144200
}
145201
}
146202

147203
BootstrapTable(
148204
headers = listOf("Module", "Owner", "File", "Code") + extraKeys,
149-
rows = statsForKey!!.map {
150-
val listOfExtraValues: List<String> = extraKeys.map { key -> it.codeReference.extras[key] ?: "" }
151-
listOf(
152-
it.module,
153-
it.codeReference.owner ?: (it.owner + " (Module Owner)"),
154-
it.codeReference.toHrefLink(projectMetadata!!, false),
155-
it.codeReference.code ?: ""
156-
) + listOfExtraValues
157-
},
205+
rows = filteredByOwner
206+
.map {
207+
val listOfExtraValues: List<String> = extraKeys.map { key -> it.codeReference.extras[key] ?: "" }
208+
listOf(
209+
it.module,
210+
it.codeReference.owner ?: (it.owner + " (Module Owner)"),
211+
it.codeReference.toHrefLink(projectMetadata!!, false),
212+
it.codeReference.code ?: ""
213+
) + listOfExtraValues
214+
},
158215
maxResultsLimitConstant = PagingConstants.MAX_RESULTS,
159216
sortAscending = true,
160217
sortByColumn = 2,

invert-report/src/jsMain/kotlin/ui/BootstrapComposables.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,15 @@ fun BootstrapSearchBox(
512512
}
513513
}
514514

515+
data class BootstrapSelectOption(
516+
val value: String,
517+
val displayText: String
518+
)
519+
515520
@Composable
516521
fun BootstrapSelectDropdown(
517522
placeholderText: String,
518-
options: List<String>,
523+
options: List<BootstrapSelectOption>,
519524
currentValue: String,
520525
onValueChange: (String?) -> Unit
521526
) {
@@ -528,13 +533,13 @@ fun BootstrapSelectDropdown(
528533
Option(value = "") {
529534
Text(placeholderText)
530535
}
531-
options.forEach { optionText ->
532-
Option(value = optionText, {
533-
if (optionText == currentValue) {
536+
options.forEach { option ->
537+
Option(value = option.value, {
538+
if (option.value == currentValue) {
534539
selected()
535540
}
536541
}) {
537-
Text(optionText)
542+
Text(option.displayText)
538543
}
539544
}
540545
}

0 commit comments

Comments
 (0)