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 10, 2024
1 parent a2eb53a commit 7f0a23d
Show file tree
Hide file tree
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
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" }
compose-desktop-components-splitpane = { module = "org.jetbrains.compose.components:components-splitpane", version.ref = "composeDesktop" }
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
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -141,7 +145,6 @@ internal fun PackageActionPopup(
}



internal fun SplitPaneScope.packageSearchSplitter(
splitterColor: Color,
cursor: PointerIcon = PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)),
Expand Down Expand Up @@ -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
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.isProjectImportingFlow
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 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
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 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
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +65,14 @@ class InfoPanelViewModel(private val project: Project) : Disposable {
}
}
}

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

is InfoPanelContentEvent.Attributes.FromSearch -> {
event.asPanelContent()
}
}
}
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
Expand Down Expand Up @@ -136,6 +145,32 @@ class InfoPanelViewModel(private val project: Project) : Disposable {
)
}

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
)
)
}

override fun dispose() {
viewModelScope.cancel()
}
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.FromVariant(
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.FromVariant(
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.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
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 7f0a23d

Please sign in to comment.