@@ -18,31 +18,49 @@ import com.squareup.invert.models.OwnerName
18
18
import com.squareup.invert.models.StatDataType
19
19
import org.jetbrains.compose.web.dom.A
20
20
import org.jetbrains.compose.web.dom.H1
21
+ import org.jetbrains.compose.web.dom.H3
21
22
import org.jetbrains.compose.web.dom.Text
23
+ import ui.BootstrapColumn
22
24
import ui.BootstrapLoadingMessageWithSpinner
23
25
import ui.BootstrapLoadingSpinner
26
+ import ui.BootstrapRow
27
+ import ui.BootstrapSelectDropdown
28
+ import ui.BootstrapSelectOption
24
29
import ui.BootstrapTable
25
30
import kotlin.reflect.KClass
26
31
27
32
data class CodeReferencesNavRoute (
28
- val statKey : String? = null
33
+ val statKey : String? = null ,
34
+ val owner : String? = null ,
29
35
) : BaseNavRoute(CodeReferencesReportPage .navPage) {
30
36
31
37
override fun toSearchParams (): Map <String , String > = toParamsWithOnlyPageId(this )
32
38
.also { params ->
33
39
statKey?.let {
34
40
params[STATKEY_PARAM ] = it
35
41
}
42
+ if (! owner.isNullOrBlank()) {
43
+ params[OWNER_PARAM ] = owner
44
+ }
36
45
}
37
46
38
47
companion object {
39
48
40
49
private const val STATKEY_PARAM = " statkey"
50
+ private const val OWNER_PARAM = " owner"
41
51
42
52
fun parser (params : Map <String , String ?>): CodeReferencesNavRoute {
43
53
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
+ }
44
61
return CodeReferencesNavRoute (
45
62
statKey = statKey,
63
+ owner = owner,
46
64
)
47
65
}
48
66
}
@@ -70,10 +88,11 @@ fun CodeReferencesComposable(
70
88
navRouteRepo : NavRouteRepo = DependencyGraph .navRouteRepo,
71
89
) {
72
90
val allModulesOrig by reportDataRepo.allModules.collectAsState(null )
91
+ val allOwnerNames by reportDataRepo.allOwnerNames.collectAsState(null )
73
92
val moduleToOwnerMapFlowValue: Map <ModulePath , OwnerName >? by reportDataRepo.moduleToOwnerMap.collectAsState(null )
74
93
75
94
val statInfosOrig by reportDataRepo.statInfos.collectAsState(null )
76
- if (statInfosOrig == null ) {
95
+ if (statInfosOrig == null || allOwnerNames == null ) {
77
96
BootstrapLoadingMessageWithSpinner (" Loading Stats" )
78
97
return
79
98
}
@@ -98,6 +117,7 @@ fun CodeReferencesComposable(
98
117
}
99
118
}
100
119
120
+
101
121
if (moduleToOwnerMapFlowValue == null || metadata == null ) {
102
122
BootstrapLoadingSpinner ()
103
123
return
@@ -137,24 +157,61 @@ fun CodeReferencesComposable(
137
157
return
138
158
}
139
159
160
+ val allCodeReferencesForStat: Set <ModuleOwnerAndCodeReference > = statsForKey!! .toSet()
161
+
140
162
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
+ }
144
200
}
145
201
}
146
202
147
203
BootstrapTable (
148
204
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
+ },
158
215
maxResultsLimitConstant = PagingConstants .MAX_RESULTS ,
159
216
sortAscending = true ,
160
217
sortByColumn = 2 ,
0 commit comments