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

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.
  • Loading branch information
fscarponi committed Dec 19, 2023
1 parent f9e1a87 commit 0b31120
Show file tree
Hide file tree
Showing 20 changed files with 593 additions and 35 deletions.
1 change: 1 addition & 0 deletions packagesearch.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
Expand Down
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation(compose.desktop.windows_x64)
implementation(packageSearchCatalog.kotlinx.serialization.core)
implementation(packageSearchCatalog.jewel.bridge.ij233)
implementation(packageSearchCatalog.jewel.standalone)
implementation(packageSearchCatalog.ktor.client.logging)
implementation(packageSearchCatalog.packagesearch.api.models)
implementation(projects.plugin.gradle.base)
Expand Down
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
@@ -1,11 +1,20 @@
package com.jetbrains.packagesearch.plugin.ui.bridge

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
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
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
Expand All @@ -15,10 +24,15 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
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.jewel.foundation.LocalGlobalColors
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.LocalTextStyle
import org.jetbrains.jewel.intui.standalone.theme.IntUiTheme
import org.jetbrains.jewel.ui.component.DropdownLink
import org.jetbrains.jewel.ui.component.Icon
import org.jetbrains.jewel.ui.component.IconButton
Expand Down Expand Up @@ -130,3 +144,43 @@ internal fun PackageActionPopup(
}
}
}


@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
Expand Up @@ -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
Expand Up @@ -32,4 +32,4 @@ internal val Project.isProjectSyncing
trySend(false)
}
}
}.withInitialValue(false)
}.withInitialValue(false)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -140,4 +141,21 @@ sealed interface InfoPanelContent {
}
}

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

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

data class Search(
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
Expand Up @@ -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

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

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

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

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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ 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.ui.model.packageslist.modifiedBy
import com.jetbrains.packagesearch.plugin.utils.PackageSearchProjectService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -62,6 +64,14 @@ class InfoPanelViewModel(
}
}
}

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

is InfoPanelContentEvent.Attributes.Search -> {
event.asPanelContent()
}
}
}
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
Expand Down Expand Up @@ -134,6 +144,32 @@ class InfoPanelViewModel(
)
}

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

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

}


Expand Down
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
Expand All @@ -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
Expand Up @@ -126,6 +126,11 @@ internal fun InfoPanelContentEvent.Package.Declared.WithVariant.asPanelContent(
declaredVariant = variantName,
allowMissingScope = !module.dependencyMustHaveAScope,
variantTerminology = module.variantTerminology
),
InfoPanelContent.Attributes.Declared(
variantName = variantName,
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
attributes = module.variants.getValue(variantName).attributes
)
)

Expand All @@ -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.Declared(
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
variantName = primaryVariantName,
attributes = module.variants.getValue(primaryVariantName).attributes
)
)

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

internal fun InfoPanelContentEvent.Attributes.Declared.asPanelContent() = listOf(
InfoPanelContent.Attributes.Declared(
variantName = variantName,
tabTitle = message("packagesearch.ui.toolwindow.sidepanel.platforms"),
attributes = attributes,
)
)
internal fun InfoPanelContentEvent.Attributes.Search.asPanelContent() = listOf(
InfoPanelContent.Attributes.Search(
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
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -87,9 +104,6 @@ sealed interface PackageListItemEvent {
}





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

Expand Down
Loading

0 comments on commit 0b31120

Please sign in to comment.