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.

(cherry picked from commit 259a0d2)
  • Loading branch information
fscarponi committed Jan 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1c3c760 commit 11812f2
Showing 19 changed files with 568 additions and 37 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,6 +26,7 @@ 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
@@ -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
@@ -1,10 +1,6 @@
package com.jetbrains.packagesearch.plugin.ui.bridge

import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import java.awt.Cursor
import java.awt.Desktop
import java.net.URI
import javax.swing.UIDefaults
@@ -41,4 +37,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
@@ -8,6 +8,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
@@ -65,6 +66,14 @@ class InfoPanelViewModel(private val project: Project) : Disposable {
}
}
}

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

is InfoPanelContentEvent.Attributes.FromSearch -> {
event.asPanelContent()
}
}
}
.retry()
@@ -141,6 +150,32 @@ class InfoPanelViewModel(private val project: Project) : Disposable {
override fun dispose() {
viewModelScope.cancel()
}
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
@@ -24,4 +24,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,21 @@ 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,20 @@ 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 +44,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 +105,6 @@ sealed interface PackageListItemEvent {
}





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

Loading

0 comments on commit 11812f2

Please sign in to comment.