mirror of
https://github.com/JetBrains/intellij-platform-plugin-template.git
synced 2025-12-05 06:11:52 +00:00
Refactor: Replace id with label for improved naming clarity
This commit is contained in:
parent
324fea18bf
commit
376292e5f8
@ -7,15 +7,27 @@ import androidx.compose.runtime.Immutable
|
|||||||
*
|
*
|
||||||
* @property name The name of the location.
|
* @property name The name of the location.
|
||||||
* @property country The associated country of the location.
|
* @property country The associated country of the location.
|
||||||
* @property id A derived unique identifier for the location in the format `name, country`.
|
* @property label A textual representation of the location.
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
data class Location(val name: String, val country: String) : PreviewableItem, Searchable {
|
data class Location(val name: String, val country: String) : PreviewableItem, Searchable {
|
||||||
val id: String = "$name, $country"
|
|
||||||
|
override val label: String
|
||||||
|
get() {
|
||||||
|
if (country.isBlank()) {
|
||||||
|
return name.takeIf { it.isNotBlank() } ?: "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.isBlank()) {
|
||||||
|
return country.takeIf { it.isNotBlank() } ?: "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "$name, $country"
|
||||||
|
}
|
||||||
|
|
||||||
override fun matches(query: String): Boolean {
|
override fun matches(query: String): Boolean {
|
||||||
val applicableCandidates = listOf(
|
val applicableCandidates = listOf(
|
||||||
id,
|
label,
|
||||||
name,
|
name,
|
||||||
country,
|
country,
|
||||||
name.split(" ").map { it.first() }.joinToString(""),
|
name.split(" ").map { it.first() }.joinToString(""),
|
||||||
@ -25,9 +37,6 @@ data class Location(val name: String, val country: String) : PreviewableItem, Se
|
|||||||
|
|
||||||
return applicableCandidates.any { it.contains(query, ignoreCase = true) }
|
return applicableCandidates.any { it.contains(query, ignoreCase = true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override val label: String
|
|
||||||
get() = id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
|
|||||||
@ -190,7 +190,7 @@ private fun ContentItemRow(item: Location, isSelected: Boolean, isActive: Boolea
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
) {
|
) {
|
||||||
Text(text = item.id, modifier = Modifier.weight(1f), overflow = TextOverflow.Ellipsis, maxLines = 1)
|
Text(text = item.label, modifier = Modifier.weight(1f), overflow = TextOverflow.Ellipsis, maxLines = 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user