Skip to content

Commit

Permalink
Introduce InfoPanelContent attributes and update UI in HeaderAttribut…
Browse files Browse the repository at this point in the history
…esTab (#9)

Refactor platformListMock to getter in HeaderAttributesTab
scrollToAttribute has CoroutineScope as receiver
rename InfoPanelContentEvent Attributes Declared into FromVariant and Search into FromSearch
rename Attributes Declared into FromVariant and Search into FromSearch

This commit adds InfoPanelContent Attributes for "Declared" type to the asPanelContent function, including the tab's title, variant's title, and attributes. A click event handler for the selected packages is also added to refresh the side panel content. A new event for package selection has been placed in 'PackageListItemEvent'. Furthermore, the attribute type name description and content title in the package search UI have been updated for clarity. The style of the 'Search' content in HeaderAttributesTab has also been modified to reduce redundancy and clarify display conditions. Now, by clicking on an attribute badge, it's possible to scroll to individual attributes with a smooth animation.
fscarponi authored Jan 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 461e2d7 commit 259a0d2
Showing 19 changed files with 565 additions and 34 deletions.
1 change: 1 addition & 0 deletions packagesearch.versions.toml
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ ij-platform-ide-core = { module = "com.jetbrains.intellij.platform:ide-core", ve
ij-platform-ide-impl = { module = "com.jetbrains.intellij.platform:ide-impl", version.ref = "idea" }
jewel-ui = { module = "org.jetbrains.jewel:jewel-ui", version.ref = "jewel" }
jewel-foundation = { module = "org.jetbrains.jewel:jewel-foundation", version.ref = "jewel" }
jewel-standalone = { module= "org.jetbrains.jewel:jewel-int-ui-standalone", version.ref = "jewel" }
jewel-bridge-ij232 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-232" }
jewel-bridge-ij233 = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge", version.ref = "jewel-bridge-233" }
compose-desktop-components-splitpane = { module = "org.jetbrains.compose.components:components-splitpane", version.ref = "composeDesktop" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jetbrains.packagesearch.plugin.ui

import androidx.compose.ui.graphics.Color
import com.jetbrains.packagesearch.plugin.ui.bridge.pickComposeColorFromLaf

object PackageSearchColors {
object Backgrounds {
fun packageItemHeader(): Color =
pickComposeColorFromLaf("ToolWindow.HeaderTab.selectedInactiveBackground")


fun attributeBadge() = packageItemHeader()

}


}
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.intellij.ui.JBColor
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.ui.bridge.packageSearchSplitter
Original file line number Diff line number Diff line change
@@ -4,7 +4,10 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.onClick
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
@@ -23,9 +26,9 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import com.intellij.icons.AllIcons
import com.jetbrains.packagesearch.plugin.ui.PackageSearchColors
import com.jetbrains.packagesearch.plugin.ui.PackageSearchMetrics
import java.awt.Cursor
import org.jetbrains.compose.splitpane.SplitPaneScope
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.LocalTextStyle
import org.jetbrains.jewel.ui.component.DropdownLink
@@ -34,6 +37,7 @@ import org.jetbrains.jewel.ui.component.IconButton
import org.jetbrains.jewel.ui.component.MenuScope
import org.jetbrains.jewel.ui.component.PopupMenu
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.compose.splitpane.SplitPaneScope

@Composable
fun LabelInfo(
@@ -141,7 +145,6 @@ internal fun PackageActionPopup(
}



internal fun SplitPaneScope.packageSearchSplitter(
splitterColor: Color,
cursor: PointerIcon = PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)),
@@ -171,3 +174,43 @@ internal fun SplitPaneScope.packageSearchSplitter(
}
}
}


@Composable
internal fun AttributeBadge(text: String, onClick: () -> Unit) {
val isDark = JewelTheme.isDark
val background = remember(isDark) {
PackageSearchColors.Backgrounds.attributeBadge()
}

Box(
modifier = Modifier
.background(color = background, shape = RoundedCornerShape(12.dp))
.pointerHoverIcon(PointerIcon(Cursor(Cursor.HAND_CURSOR)))
.onClick { onClick() },
) {
Text(
modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp), text = text,
)
}

}

//@Preview
//@Composable
//internal fun AttributeBadgePreview() {
// Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
// IntUiTheme {
// Box(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// AttributeBadge(text = "Android") {}
// }
// }
// IntUiTheme(true) {
// Box(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// AttributeBadge(text = "Android") {}
// }
// }
// }
//
//
//}
Original file line number Diff line number Diff line change
@@ -41,4 +41,3 @@ fun isLightTheme(): Boolean {

private fun Color.getBrightness() = (red * 299 + green * 587 + blue * 114) / 1000

fun Modifier.pointerChangeToHandModifier() = this.pointerHoverIcon(PointerIcon(Cursor(Cursor.HAND_CURSOR)))
Original file line number Diff line number Diff line change
@@ -32,4 +32,4 @@ internal val Project.isProjectImportingFlow
trySend(false)
}
}
}.withInitialValue(false)
}.withInitialValue(false)
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package com.jetbrains.packagesearch.plugin.ui.model.infopanel

import com.jetbrains.packagesearch.plugin.core.data.IconProvider
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModuleVariant
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem

sealed interface InfoPanelContent {
@@ -140,4 +141,21 @@ sealed interface InfoPanelContent {
}
}

sealed interface Attributes : InfoPanelContent{
val attributes: List<PackageSearchModuleVariant.Attribute>

data class FromVariant(
override val tabTitle: String,
val variantName: String,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
) : Attributes

data class FromSearch(
override val tabTitle: String,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
val defaultSourceSet: String,
val additionalSourceSets: List<String>,
) : Attributes
}

}
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ package com.jetbrains.packagesearch.plugin.ui.model.infopanel

import com.jetbrains.packagesearch.plugin.core.data.PackageSearchDeclaredPackage
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModuleVariant
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem
import org.jetbrains.packagesearch.api.v3.ApiPackage

sealed interface InfoPanelContentEvent {

val module: PackageSearchModule

sealed interface Package : InfoPanelContentEvent {
val module: PackageSearchModule

val packageListId: PackageListItem.Package.Id

@@ -51,5 +51,20 @@ sealed interface InfoPanelContentEvent {
}
}

sealed interface Attributes : InfoPanelContentEvent {
val attributes: List<PackageSearchModuleVariant.Attribute>

data class FromVariant(
val variantName: String,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
) : Attributes

data class FromSearch(
val defaultVariant: String,
val additionalVariants: List<String>,
override val attributes: List<PackageSearchModuleVariant.Attribute>,
) : Attributes

}

}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchDeclaredPackage
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModule
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModuleVariant
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListViewModel
import com.jetbrains.packagesearch.plugin.utils.PackageSearchProjectService
@@ -62,6 +63,14 @@ class InfoPanelViewModel(
}
}
}

is InfoPanelContentEvent.Attributes.FromVariant -> {
event.asPanelContent()
}

is InfoPanelContentEvent.Attributes.FromSearch -> {
event.asPanelContent()
}
}
}
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
@@ -134,6 +143,32 @@ class InfoPanelViewModel(
)
}

fun setDeclaredHeaderAttributes(
variantName: String,
attributes: List<PackageSearchModuleVariant.Attribute>,
) {
setDataEventChannel.trySend(
InfoPanelContentEvent.Attributes.FromVariant(
variantName = variantName,
attributes = attributes
)
)
}

fun setSearchHeaderAttributes(
defaultVariant: String,
additionalVariants: List<String>,
attributes: List<PackageSearchModuleVariant.Attribute>,
) {
setDataEventChannel.trySend(
InfoPanelContentEvent.Attributes.FromSearch(
defaultVariant = defaultVariant,
additionalVariants = additionalVariants,
attributes = attributes
)
)
}

}


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetbrains.packagesearch.plugin.ui.model.infopanel

import com.jetbrains.packagesearch.plugin.PackageSearchBundle.message
import org.jetbrains.jewel.foundation.lazy.tree.buildTree
import org.jetbrains.packagesearch.api.v3.ApiGitHub
import org.jetbrains.packagesearch.api.v3.ApiScm
import org.jetbrains.packagesearch.api.v3.LicenseFile
@@ -24,4 +25,5 @@ internal fun Licenses<*>.asInfoPanelLicenseList() = buildList {
internal fun LicenseFile.toInfoPanelLicense(): InfoPanelContent.PackageInfo.License? {
val name = name ?: url ?: return null
return InfoPanelContent.PackageInfo.License(name, url)
}
}

Original file line number Diff line number Diff line change
@@ -126,6 +126,11 @@ internal fun InfoPanelContentEvent.Package.Declared.WithVariant.asPanelContent(
declaredVariant = variantName,
allowMissingScope = !module.dependencyMustHaveAScope,
variantTerminology = module.variantTerminology
),
InfoPanelContent.Attributes.FromVariant(
variantName = variantName,
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
attributes = module.variants.getValue(variantName).attributes
)
)

@@ -152,6 +157,11 @@ internal fun InfoPanelContentEvent.Package.Remote.WithVariants.asPanelContent(
isLoading = isLoading,
isInstalledInPrimaryVariant = module.variants.getValue(primaryVariantName).declaredDependencies
.any { it.id == apiPackage.id }
),
InfoPanelContent.Attributes.FromVariant(
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
variantName = primaryVariantName,
attributes = module.variants.getValue(primaryVariantName).attributes
)
)

@@ -175,4 +185,20 @@ internal fun InfoPanelContentEvent.Package.Remote.Base.asPanelContent(
repositories = apiPackage.repositories(),
isLoading = isLoading
)
)

internal fun InfoPanelContentEvent.Attributes.FromVariant.asPanelContent() = listOf(
InfoPanelContent.Attributes.FromVariant(
variantName = variantName,
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
attributes = attributes,
)
)
internal fun InfoPanelContentEvent.Attributes.FromSearch.asPanelContent() = listOf(
InfoPanelContent.Attributes.FromSearch(
tabTitle = message("packagesearch.ui.toolwindow.packages.details.info.attributes"),
defaultSourceSet = defaultVariant,
additionalSourceSets = additionalVariants,
attributes = attributes,
)
)
Original file line number Diff line number Diff line change
@@ -21,7 +21,19 @@ sealed interface PackageListItemEvent {
sealed interface InfoPanelEvent : PackageListItemEvent {

@Serializable
data class OnHeaderAttributesClick(override val eventId: PackageListItem.Header.Id) : InfoPanelEvent
sealed interface OnHeaderAttributesClick : InfoPanelEvent {
@Serializable
data class DeclaredHeaderAttributesClick(
override val eventId: PackageListItem.Header.Id.Declared,
val variantName: String,
) : OnHeaderAttributesClick
@Serializable
data class SearchHeaderAttributesClick(
override val eventId: PackageListItem.Header.Id.Remote,
val attributesNames: List<String>
) : OnHeaderAttributesClick

}

@Serializable
data class OnHeaderVariantsClick(override val eventId: PackageListItem.Header.Id) : InfoPanelEvent
@@ -31,6 +43,11 @@ sealed interface PackageListItemEvent {

@Serializable
data class OnPackageDoubleClick(override val eventId: PackageListItem.Id) : InfoPanelEvent

@Serializable
data class OnSelectedPackageClick(override val eventId: PackageListItem.Id) : InfoPanelEvent


}

@Serializable
@@ -87,9 +104,6 @@ sealed interface PackageListItemEvent {
}





@Serializable
data class Update(override val eventId: PackageListItem.Package.Declared.Id) : OnPackageAction

Original file line number Diff line number Diff line change
@@ -310,6 +310,7 @@ class PackageListViewModel(
is PackageListItemEvent.InfoPanelEvent.OnHeaderVariantsClick -> handle(event)
is PackageListItemEvent.InfoPanelEvent.OnPackageSelected -> handle(event)
is PackageListItemEvent.InfoPanelEvent.OnPackageDoubleClick -> handle(event)
is PackageListItemEvent.InfoPanelEvent.OnSelectedPackageClick -> handle(event)
is PackageListItemEvent.OnPackageAction.GoToSource -> handle(event)
is PackageListItemEvent.OnPackageAction.Install.Base -> handle(event)
is PackageListItemEvent.OnPackageAction.Install.WithVariant -> handle(event)
@@ -331,6 +332,12 @@ class PackageListViewModel(
logInfoPanelOpened()
}

private fun handle(event: PackageListItemEvent.InfoPanelEvent.OnSelectedPackageClick) {
if (event.eventId is PackageListItem.Package.Id) handle(
PackageListItemEvent.InfoPanelEvent.OnPackageSelected(event.eventId)
)
}

private fun handle(event: PackageListItemEvent.InfoPanelEvent.OnPackageSelected) {
val infoPanelViewModel = project.service<InfoPanelViewModel>()
logPackageSelected(event.eventId is PackageListItem.Package.Declared.Id)
@@ -591,13 +598,46 @@ class PackageListViewModel(
}
}

private fun handle(event: PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick) {
logTODO()
logHeaderAttributesClick(
isSearchHeader = event.eventId is PackageListItem.Header.Id.Remote
)
private suspend fun handle(event: PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick) {
logHeaderAttributesClick(isSearchHeader = event.eventId is PackageListItem.Header.Id.Remote)
val infoPanelViewModel = project.service<InfoPanelViewModel>()

val module = event.eventId.getModule() as? PackageSearchModule.WithVariants ?: return

when (event) {
is PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.DeclaredHeaderAttributesClick -> {
val attributes = module.variants[event.variantName]?.attributes ?: return
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()

val variants = module.variants.values.map { it.name } - module.mainVariantName

infoPanelViewModel.setSearchHeaderAttributes(
defaultVariant = module.mainVariantName,
additionalVariants = variants,
attributes = attributes
)
}
}


project.service<ToolWindowViewModel>().isInfoPanelOpen.let { openStateFlow ->
if (!openStateFlow.value) {
openStateFlow.emit(true)
}
}

}


private suspend fun handle(event: PackageListItemEvent.EditPackageEvent.SetVariant) {
val module = event.eventId
.getModule() as? PackageSearchModule.WithVariants
Original file line number Diff line number Diff line change
@@ -131,7 +131,12 @@ internal fun SelectableLazyItemScope.PackageListItem(
.onClick(
interactionSource = remember { MutableInteractionSource() },
onDoubleClick = { onPackageListItemEvent(OnPackageDoubleClick(content.id)) },
onClick = { }
onClick = {
//this event should be handled when you click on a selected package to refresh side panel content
if (isSelected ) onPackageListItemEvent(
PackageListItemEvent.InfoPanelEvent.OnSelectedPackageClick(content.id)
)
}
),
) {
Row(
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jetbrains.packagesearch.plugin.ui.panels.packages.items

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement.SpaceBetween
import androidx.compose.foundation.layout.Box
@@ -11,6 +10,10 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.onClick
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -20,30 +23,30 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.intellij.icons.AllIcons
import com.jetbrains.packagesearch.plugin.PackageSearchBundle.message
import com.jetbrains.packagesearch.plugin.ui.PackageSearchColors
import com.jetbrains.packagesearch.plugin.ui.bridge.LabelInfo
import com.jetbrains.packagesearch.plugin.ui.bridge.pickComposeColorFromLaf
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItem.Header.State
import com.jetbrains.packagesearch.plugin.ui.model.packageslist.PackageListItemEvent
import java.awt.Cursor
import org.jetbrains.jewel.foundation.modifier.onHover
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.ui.component.CircularProgressIndicator
import org.jetbrains.jewel.ui.component.Icon
import org.jetbrains.jewel.ui.component.Link
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.jewel.ui.theme.linkStyle

@Composable
fun PackageListHeader(
additionalContentModifier: Modifier = Modifier,
content: PackageListItem.Header,
onEvent: (PackageListItemEvent) -> Unit,
) {
val backgroundColor =
if (JewelTheme.isDark) {
pickComposeColorFromLaf("ToolWindow.HeaderTab.selectedInactiveBackground")
} else {
pickComposeColorFromLaf("Tree.selectionInactiveBackground")
}
val isDarkTheme = JewelTheme.isDark
val backgroundColor = remember(isDarkTheme) {
PackageSearchColors.Backgrounds.packageItemHeader()
}

Row(
modifier = Modifier
@@ -88,22 +91,40 @@ fun PackageListHeader(
}

Text(
fontWeight = FontWeight(600),
fontWeight = FontWeight.ExtraBold,
text = content.title,
maxLines = 1
)
}
if (content.attributes.isNotEmpty()) {
var attributeTextColor by remember { mutableStateOf(Color.Unspecified) }
val linkTextColor = JewelTheme.linkStyle.colors.content
Box(
modifier = Modifier
.onClick {
onEvent(PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick(content.id))
val event =
when (content.id) {
is PackageListItem.Header.Id.Declared.Base -> return@onClick
is PackageListItem.Header.Id.Remote -> PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.SearchHeaderAttributesClick(
eventId = content.id,
attributesNames = content.attributes
)
is PackageListItem.Header.Id.Declared.WithVariant -> PackageListItemEvent.InfoPanelEvent.OnHeaderAttributesClick.DeclaredHeaderAttributesClick(
eventId = content.id,
variantName = content.title,
)
}
onEvent(event)
}
.onHover {
attributeTextColor = if (it) linkTextColor else Color.Unspecified
}
.pointerHoverIcon(PointerIcon(Cursor(Cursor.HAND_CURSOR))),
contentAlignment = Alignment.Center,
) {
LabelInfo(
Text(
text = content.attributes.joinToString(" "),
color = attributeTextColor,
maxLines = 1
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
package com.jetbrains.packagesearch.plugin.ui.panels.side

import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jetbrains.packagesearch.plugin.PackageSearchBundle
import com.jetbrains.packagesearch.plugin.core.data.PackageSearchModuleVariant
import com.jetbrains.packagesearch.plugin.ui.bridge.AttributeBadge
import com.jetbrains.packagesearch.plugin.ui.bridge.LabelInfo
import com.jetbrains.packagesearch.plugin.ui.model.infopanel.InfoPanelContent
import kotlin.math.roundToInt
import kotlin.random.Random
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.jetbrains.jewel.ui.component.Text

@Composable
fun HeaderAttributesTab(
content: InfoPanelContent.Attributes,
scrollState: ScrollState,
) {
HeaderAttributesTabImpl(
content = content,
scrollState = scrollState,
contentTitle = PackageSearchBundle.message("packagesearch.ui.toolwindow.sidepanel.searchResultSupport"),
attributeTypeName = PackageSearchBundle.message("packagesearch.ui.toolwindow.sidepanel.platformsList"),
sourceSetString = PackageSearchBundle.message("packagesearch.ui.toolwindow.sidepanel.searchResultSupport.sourceSets"),
)
}

@Composable
private fun HeaderAttributesTabImpl(
content: InfoPanelContent.Attributes,
contentTitle: String,
scrollState: ScrollState,
attributeTypeName: String,
sourceSetString: String,
) {
val scope = rememberCoroutineScope()
val attributes = content.attributes
// Global positions of attributes will be used to store the y offset used on scrollToItem
val attributeGlobalPositionMap = remember { mutableMapOf<Int, Int>() }

Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(12.dp)) {
if (content is InfoPanelContent.Attributes.FromSearch) {
Text(
text = contentTitle,
fontSize = 14.sp,
fontWeight = FontWeight.ExtraBold,
modifier = Modifier.padding(top = 4.dp)
)
}


Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
attributes.forEachIndexed { index, attribute ->
AttributeBadge(text = attribute.value) {
scope.scrollToAttribute(scrollState, attributeGlobalPositionMap, index)
}
}
}

if (content is InfoPanelContent.Attributes.FromSearch) {
SourceSetsList(content, sourceSetString)
}

AttributeItems(attributeTypeName = attributeTypeName, attributes, attributeGlobalPositionMap)
}
}


@Composable
private fun ColumnScope.SourceSetsList(
content: InfoPanelContent.Attributes.FromSearch,
title: String,
) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(
text = title,
fontSize = 14.sp,
fontWeight = FontWeight.ExtraBold,
modifier = Modifier.padding(top = 4.dp)
)
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
Text(text = content.defaultSourceSet)
LabelInfo(PackageSearchBundle.message("packagesearch.ui.toolwindow.variant.default.text"))
}
Text(text = content.additionalSourceSets.joinToString(", "))

}
}

@Composable
private fun AttributeItems(
attributeTypeName: String,
attributesName: List<PackageSearchModuleVariant.Attribute>,
attributeGlobalPosition: MutableMap<Int, Int>,
) {
Text(
text = attributeTypeName,
fontSize = 14.sp,
fontWeight = FontWeight.ExtraBold,
modifier = Modifier.padding(top = 4.dp)
)

attributesName.forEachIndexed { index, attribute ->
AttributeItem(
modifier = Modifier.onGloballyPositioned {
attributeGlobalPosition[index] = it.positionInParent().y.roundToInt()
},
attributeName = attribute.value,
nestedAttributesName = attribute.flatten()
)
}
}

private fun PackageSearchModuleVariant.Attribute.flatten(): List<String> =
when (this) {
is PackageSearchModuleVariant.Attribute.NestedAttribute -> children.flatMap { it.flatten() }
is PackageSearchModuleVariant.Attribute.StringAttribute -> listOf(value)
}


private fun CoroutineScope.scrollToAttribute(
scrollState: ScrollState,
attributeGlobalPosition: MutableMap<Int, Int>,
index: Int,
) {
launch {
scrollState.animateScrollTo(
value = attributeGlobalPosition[index] ?: 0,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessVeryLow
)
)
}
}

@Composable
fun AttributeItem(modifier: Modifier = Modifier, attributeName: String, nestedAttributesName: List<String>) {

Row(modifier = modifier, verticalAlignment = Alignment.Top, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Row(
modifier = Modifier.width(160.dp),
verticalAlignment = Alignment.Bottom,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(text = attributeName)
LabelInfo(nestedAttributesName.size.toString())
}

Text(text = nestedAttributesName.joinToString("\n"))
}
}


//@Preview
//@Composable
//private fun HeaderAttributesPreviewTab() {
// val activeTabMock = InfoPanelContent.Attributes.FromVariant(
// tabTitle = "FromVariant",
// variantName = "jvm",
// attributes = generateAttributesMock()
// )
// val scrollStateMock = ScrollState(0)
// Column(Modifier.padding(8.dp)) {
// IntUiTheme(true) {
// Column(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// HeaderAttributesTabImpl(
// content = activeTabMock,
// scrollState = scrollStateMock,
// contentTitle = "FromSearch results that support:",
// attributeTypeName = "Platforms:",
// sourceSetString = "Source Sets:"
// )
//
// }
//
// Divider(orientation = Orientation.Horizontal, modifier = Modifier.padding(vertical = 16.dp))
//
// }
//
//
// IntUiTheme(false) {
// Column(Modifier.background(LocalGlobalColors.current.paneBackground).padding(16.dp)) {
// HeaderAttributesTabImpl(
// content = activeTabMock,
// scrollState = scrollStateMock,
// contentTitle = "FromSearch results that support:",
// attributeTypeName = "Platforms:",
// sourceSetString = "Source Sets:"
// )
//
// }
// }
// }
//}

private fun generateAttributesMock(): List<PackageSearchModuleVariant.Attribute> {
val attributes = mutableListOf<PackageSearchModuleVariant.Attribute>()

platformListMock.take(Random.nextInt(2, 10)).forEach {
attributes.add(
if (Random.nextBoolean()) {
PackageSearchModuleVariant.Attribute.NestedAttribute(
it,
platformListMock.take(Random.nextInt(2, 10)).map {
PackageSearchModuleVariant.Attribute.StringAttribute(it)
}
)


} else {

PackageSearchModuleVariant.Attribute.StringAttribute(it)
}
)
}

return attributes

}

internal val platformListMock get() = buildList {
add("Android")
add("android")
add("Apple")
add("iOS")
add("iosX64")
add("iosArm64")
add("iosSimulatorArm64")
add("macOS")
add("macosArm64")
add("macosX64")

add("watchOS")
add("watchosArm32")
add("watchosArm64")
add("watchosX64")
add("watchosSimulatorArm64")

add("tvOS")
add("tvosX64")
add("tvosArm64")
add("tvosSimulatorArm64")


add("Java")
add("jvm")

add("JavaScript")
add("jsLegacy")
add("jslr")

add("Linux")
add("LinuxMipsel32")
add("LinuxArm64")
add("LinuxArm32Hfp")
add("LinuxX64")

add("Windows")
add("WindowsX64")
add("WindowsX86")

add("WebAssembly")
add("wasm")
add("wasm32")

}
Original file line number Diff line number Diff line change
@@ -65,6 +65,14 @@ fun PackageSearchInfoPanel(
content = activeTab
)
}

is InfoPanelContent.Attributes.FromVariant -> {
HeaderAttributesTab(content = activeTab, scrollState = viewModel.scrollState)

}
is InfoPanelContent.Attributes.FromSearch -> {
HeaderAttributesTab(content = activeTab, scrollState = viewModel.scrollState)
}
}
}
VerticalScrollbar(
Original file line number Diff line number Diff line change
@@ -30,10 +30,7 @@ import com.jetbrains.packagesearch.plugin.ui.model.tree.TreeItemModel
import com.jetbrains.packagesearch.plugin.ui.model.tree.TreeViewModel
import com.jetbrains.packagesearch.plugin.ui.viewModel
import org.jetbrains.jewel.foundation.lazy.tree.Tree
import org.jetbrains.jewel.foundation.lazy.tree.buildTree
import org.jetbrains.jewel.foundation.lazy.tree.rememberTreeState
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.ThemeDefinition
import org.jetbrains.jewel.ui.Orientation
import org.jetbrains.jewel.ui.component.Divider
import org.jetbrains.jewel.ui.component.Icon
@@ -157,7 +154,7 @@ private fun TreeActionToolbar(
modifier = Modifier.padding(5.dp),
resource = "icons/intui/toggleOfflineMode.svg",
iconClass = IconProvider::class.java,
contentDescription = "Package Search is offline."
contentDescription = "Package FromSearch is offline."
)
},
)
Original file line number Diff line number Diff line change
@@ -215,11 +215,16 @@ packagesearch.toolwindow.loading.easterEgg.2=Asking the Mages in Dalaran to Tele
packagesearch.toolwindow.loading.easterEgg.3=Hiring Goblin Engineers for High-Speed Package Data Transfer...
packagesearch.toolwindow.loading.easterEgg.4=Deciphering Runes in Ulduar for Encrypted Package Data...
packagesearch.ui.toolwindow.packages.details.info.overview=Overview
packagesearch.ui.toolwindow.packages.details.info.attributes=Attributes
packagesearch.ui.toolwindow.packages.details.info.unknown=Unknown
packagesearch.ui.tree.tooltips.offline=Package Search is offline
packagesearch.ui.toolwindow.packages.details.info.scm.github=GitHub
packagesearch.ui.toolwindow.packages.actions.remove=Remove
packagesearch.ui.toolwindow.packages.details.info.scope=Scope:
packagesearch.toolwindow.loading.dumbMode=Project is initializing...
packagesearch.ui.tree.tooltips.expand=Expand all
packagesearch.ui.tree.tooltips.collapse=Collapse all
packagesearch.ui.tree.tooltips.collapse=Collapse all
packagesearch.ui.toolwindow.sidepanel.platformsList=Platforms:
packagesearch.ui.toolwindow.sidepanel.platforms=Platforms
packagesearch.ui.toolwindow.sidepanel.searchResultSupport=Search results that support:
packagesearch.ui.toolwindow.sidepanel.searchResultSupport.sourceSets=Source Sets:

0 comments on commit 259a0d2

Please sign in to comment.