Skip to content

Commit

Permalink
Fixes sorting of "extras" for code references and displays the Descri…
Browse files Browse the repository at this point in the history
…ption (key) as the column header.
  • Loading branch information
handstandsam committed Dec 5, 2024
1 parent 885023e commit 92c9015
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import com.squareup.invert.common.navigation.routes.BaseNavRoute
import com.squareup.invert.common.pages.CodeReferencesNavRoute.Companion.parser
import com.squareup.invert.common.utils.FormattingUtils.formatEpochToDate
import com.squareup.invert.models.ExtraDataType
import com.squareup.invert.models.ExtraKey
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.OwnerName
import com.squareup.invert.models.StatDataType
import com.squareup.invert.models.StatKey
import com.squareup.invert.models.StatMetadata
import com.squareup.invert.models.js.StatTotalAndMetadata
import org.jetbrains.compose.web.dom.A
import org.jetbrains.compose.web.dom.H1
import org.jetbrains.compose.web.dom.H3
import org.jetbrains.compose.web.dom.H4
import org.jetbrains.compose.web.dom.Li
Expand Down Expand Up @@ -153,16 +153,19 @@ fun CodeReferencesComposable(
val historicalData = historicalDataOrig!!

val currentStatMetadata: StatMetadata? = statInfos.firstOrNull { it.key == codeReferencesNavRoute.statKey }
if (currentStatMetadata == null) {
H1 { Text("No stat with key ${codeReferencesNavRoute.statKey} found") }
return
}


val metadata by reportDataRepo.reportMetadata.collectAsState(null)
BootstrapRow {
BootstrapColumn(8) {
H4 {
Text(buildString {
append("Code References")
currentStatMetadata?.let {
append(" for ${currentStatMetadata.description} (${codeReferencesNavRoute.statKey})")
}
append(" for ${currentStatMetadata.description} (${codeReferencesNavRoute.statKey})")
})
}
}
Expand Down Expand Up @@ -288,14 +291,6 @@ fun CodeReferencesComposable(

val allCodeReferencesForStat: Set<ModuleOwnerAndCodeReference> = statsForKey!!.toSet()

val extraKeys = mutableSetOf<ExtraKey>()
allCodeReferencesForStat
.forEach { moduleOwnerAndCodeReference ->
moduleOwnerAndCodeReference.codeReference.extras.forEach {
extraKeys.add(it.key)
}
}

val filteredByOwner: List<ModuleOwnerAndCodeReference> = allCodeReferencesForStat
// Filter By Module
.filter { moduleOwnerAndCodeReference: ModuleOwnerAndCodeReference ->
Expand Down Expand Up @@ -398,7 +393,7 @@ fun CodeReferencesComposable(
options = codeReferencesByModule.map {
BootstrapSelectOption(
value = it.key,
displayText = "${it.key}",// (${it.value.size} of $totalCodeReferenceCount)"
displayText = it.key,// (${it.value.size} of $totalCodeReferenceCount)"
)
}.sortedBy { it.displayText }
) {
Expand All @@ -412,19 +407,17 @@ fun CodeReferencesComposable(
}
}

val extraTypes = currentStatMetadata?.extras?.map { extra ->
if (extra.type == ExtraDataType.NUMERIC) {
Int::class
} else {
String::class
}
} ?: emptyList()

BootstrapTable(
headers = listOf("Module", "Owner", "File", "Code") + extraKeys,
headers = listOf(
"Module",
"Owner",
"File",
"Code"
) + currentStatMetadata.extras.map { "${it.description} (${it.key})" },
rows = filteredByOwner
.map {
val listOfExtraValues: List<String> = extraKeys.map { key -> it.codeReference.extras[key] ?: "" }
val listOfExtraValues: List<String> =
currentStatMetadata.extras.map { extra -> it.codeReference.extras[extra.key] ?: "" }
listOf(
it.module,
it.codeReference.owner ?: (it.owner + " (Owns Module)"),
Expand All @@ -435,7 +428,18 @@ fun CodeReferencesComposable(
maxResultsLimitConstant = PagingConstants.MAX_RESULTS,
sortAscending = true,
sortByColumn = 2,
types = listOf(String::class, String::class, String::class, String::class) + extraTypes
types = listOf(
String::class,
String::class,
String::class,
String::class
) + currentStatMetadata.extras.map { extra ->
when (extra.type) {
ExtraDataType.BOOLEAN -> Boolean::class
ExtraDataType.NUMERIC -> Int::class
ExtraDataType.STRING -> String::class
}
}
)
}
}

0 comments on commit 92c9015

Please sign in to comment.