Skip to content

Commit

Permalink
Add metadata to the ShowkaseBrowserComponent
Browse files Browse the repository at this point in the history
Improve kdoc
  • Loading branch information
pmecho committed Mar 31, 2023
1 parent 447f2d8 commit c596824
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ package com.airbnb.android.showkase.annotation
* https://github.com/airbnb/Showkase#representing-component-styles-in-showkase
* @param tags Various string values that will be propagated to the Showkase browser to allow additional
* filtering or categorization.
* @param extraMetadata Various string values that are **not** propagated through the Showkase browser
* but are still available in the generated [ShowkaseCodegenMetadata] object.
* @param extraMetadata Various string values that are **not** used by the standard Showkase browser
* but are still available in the generated `ShowkaseBrowserComponent` object. This may be useful when
* extra data is needed for attributing components during other processes (e.g. static analysis,
* displaying attributions in a custom component browser).
*/
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public val comairbnbandroidshowkaseprocessortestinggroupname: ShowkaseBrowserCom
componentKey = """com.airbnb.android.showkase_processor_testing_null_group_name_0_null""",
isDefaultStyle = false,
tags = listOf("tag A", "tag B"),
extraMetadata = listOf("meta A"),
component = @Composable { TestComposable() }
)
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,8 @@ internal fun CodeBlock.Builder.addShowkaseBrowserComponent(
showkaseHeightDp?.let { add("\nheightDp = %L,", it) }
showkaseStyleName?.let { add("\nstyleName = %S,", it) }
}
showkaseMetadata.tags.takeIf { it.isNotEmpty() }?.let {
val tags = it.joinToString(", ", prefix = "listOf(", postfix = ")") { tag ->
"\"$tag\""
}
add("\ntags = $tags,")
}

addStringList("tags", showkaseMetadata.tags)
addStringList("extraMetadata", showkaseMetadata.extraMetadata)
add(
composePreviewFunctionLambdaCodeBlock(
showkaseMetadata.packageName,
Expand All @@ -157,6 +152,18 @@ internal fun CodeBlock.Builder.addShowkaseBrowserComponent(
doubleUnindent()
}

/**
* Adds a list of strings to the [name] parameter if the [values] list is not empty.
*/
private fun CodeBlock.Builder.addStringList(name: String, values: List<String>) {
values.takeIf { it.isNotEmpty() }?.let {
val valuesString = it.joinToString(", ", prefix = "listOf(", postfix = ")") { value ->
"\"$value\""
}
add("\n$name = $valuesString,")
}
}

@Suppress("LongParameterList")
internal fun composePreviewFunctionLambdaCodeBlock(
functionPackageName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ data class ShowkaseBrowserComponent(
val isDefaultStyle: Boolean = false,
val widthDp: Int? = null,
val heightDp: Int? = null,
val tags: List<String> = emptyList()
val tags: List<String> = emptyList(),
val extraMetadata: List<String> = emptyList()
)

0 comments on commit c596824

Please sign in to comment.