Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

241-Platform side panel badge duplicate and wrong source-sets for KMP headers #55

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ interface PackageSearchModuleVariant : PackageSearchDependencyManager {
fun isCompatible(dependency: ApiPackage, version: ApiPackageVersion): Boolean

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,30 @@ fun Set<MppCompilationInfoModel.Compilation>.buildAttributes(): List<PackageSear
}
}.toSet()

return buildAttributesFromRawStrings(rawStrings)
return rawStrings.parseAttributesFromRawStrings()
}

fun buildAttributesFromRawStrings(rawStrings: Set<String>) = buildList {
var queue = rawStrings.toList()

internal fun PackageSearchModuleVariant.Attribute.flatAttributesNames(): Set<String> {
return when (this) {
is PackageSearchModuleVariant.Attribute.StringAttribute -> setOf(value)
is PackageSearchModuleVariant.Attribute.NestedAttribute -> children.flatMap { it.flatAttributesNames() }.toSet()
}
}

fun List<PackageSearchModuleVariant.Attribute>.mergeAttributes() =
flatMap { it.flatAttributesNames() }
.toSet()
.parseAttributesFromRawStrings()

fun Set<String>.parseAttributesFromRawStrings() = buildList {
var queue = [email protected]()
for (attributeTitle in KMP_ATTRIBUTES_GROUPS) {
val (targets, rest) = queue
.partition { it.contains(attributeTitle.aggregationKeyword, true) }

if (targets.isEmpty()) continue
add(
this.add(
PackageSearchModuleVariant.Attribute.NestedAttribute(
attributeTitle.displayName,
targets.map { PackageSearchModuleVariant.Attribute.StringAttribute(it) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.jetbrains.packagesearch.plugin.core.data.PackageSearchDeclaredPackage
import com.jetbrains.packagesearch.plugin.core.data.listKMPAttributesNames
import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchKnownRepositoriesContext
import com.jetbrains.packagesearch.plugin.core.utils.icon
import com.jetbrains.packagesearch.plugin.gradle.buildAttributesFromRawStrings
import com.jetbrains.packagesearch.plugin.gradle.parseAttributesFromRawStrings
import com.jetbrains.packagesearch.plugin.ui.model.getLatestVersion
import org.jetbrains.packagesearch.api.v3.ApiMavenPackage
import org.jetbrains.packagesearch.api.v3.ApiPackage
Expand Down Expand Up @@ -218,7 +218,7 @@ private fun MutableList<InfoPanelContent>.addAttributesFromNames(
if (attributesNames.isNotEmpty()) add(
InfoPanelContent.Attributes.FromPackage(
tabTitleData = InfoPanelContent.TabTitleData(tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms")),
attributes = buildAttributesFromRawStrings(attributesNames)
attributes = attributesNames.parseAttributesFromRawStrings()
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ sealed interface PackageListItemEvent {
val variantName: String,
) : OnHeaderAttributesClick
@Serializable
data class SearchHeaderAttributesClick(
override val eventId: PackageListItem.Header.Id.Remote,
val attributesNames: List<String>
data class SearchHeaderWithVariantsAttributesClick(
override val eventId: PackageListItem.Header.Id.Remote.WithVariant,
val attributesNames: List<String>,
) : OnHeaderAttributesClick

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,19 +626,23 @@ class PackageListViewModel(
infoPanelViewModel.setDeclaredHeaderAttributes(event.variantName, attributes = attributes)
}

is PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.SearchHeaderAttributesClick -> {
val attributes = module
.variants
.map { it.value.attributes }
.flatten()
.filter { it.value in event.attributesNames }
.distinct()
is PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.SearchHeaderWithVariantsAttributesClick -> {

val variants = module.variants.values.map { it.name } - module.mainVariantName
val variants = event.eventId
.compatibleVariantNames
.mapNotNull { module.variants[it] }

val defaultVariant = variants.firstOrNull { it.isPrimary }?.name
?: variants.firstOrNull()?.name
?: return

val attributes = variants.firstOrNull()
?.attributes
?: return

infoPanelViewModel.setSearchHeaderAttributes(
defaultVariant = module.mainVariantName,
additionalVariants = variants,
defaultVariant = defaultVariant,
additionalVariants = variants.map { it.name } - defaultVariant,
attributes = attributes
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ fun PackageListHeader(
.onClick {
val event =
when (content.id) {
is PackageListItem.Header.Id.Declared.Base -> return@onClick
is PackageListItem.Header.Id.Remote -> PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.SearchHeaderAttributesClick(
is PackageListItem.Header.Id.Declared.Base, is PackageListItem.Header.Id.Remote.Base -> return@onClick
is PackageListItem.Header.Id.Remote.WithVariant -> PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.SearchHeaderWithVariantsAttributesClick(
eventId = content.id,
attributesNames = content.attributes
)

is PackageListItem.Header.Id.Declared.WithVariant -> PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.DeclaredHeaderAttributesClick(
eventId = content.id,
variantName = content.title,
Expand Down
Loading