Skip to content

Commit

Permalink
update core and fix fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed Nov 9, 2024
1 parent 3fc27e8 commit b6eef98
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/jsMain/kotlin/examples/quotesearch/quotesearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ val movieQuotesSearchPluginConfig = SearchPluginConfiguration(
pluginType = "movies",
fieldConfig = listOf(
SearchContextField.StringField("q"),
SearchContextField.IntField("size", 5)
SearchContextField.IntField("size", defaultValue = 5)
),
pluginSettings = null,
metrics = Metric.entries.map { MetricConfiguration(it.name, it, it.supportedParams) }
Expand All @@ -66,7 +66,7 @@ val movieQuotesNgramsSearchPluginConfig = SearchPluginConfiguration(
pluginType = "movies",
fieldConfig = listOf(
SearchContextField.StringField("q"),
SearchContextField.IntField("size", 5)
SearchContextField.IntField("size", defaultValue = 5)
),
pluginSettings = null,
metrics = Metric.entries.map { MetricConfiguration(it.name, it, it.supportedParams) }
Expand Down
7 changes: 4 additions & 3 deletions src/jsMain/kotlin/search/search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ fun RenderContext.searchScreen() {
})
val stores = config.fieldConfig.associate {
it.name to when (it) {
is SearchContextField.BoolField -> storeOf("${it.defaultValue}")
is SearchContextField.IntField -> storeOf("${it.defaultValue}")
is SearchContextField.StringField -> storeOf(it.defaultValue)
is SearchContextField.BoolField -> storeOf("${it.defaultValue?:""}")
is SearchContextField.IntField -> storeOf("${it.defaultValue?:""}")
is SearchContextField.StringField -> storeOf(it.defaultValue?:"")
}
}
div {
for (field in config.fieldConfig) {
val fieldStore = stores[field.name]!!
when (field) {
is SearchContextField.BoolField -> {

textField(
placeHolder = "true", label = field.name
) {
Expand Down
21 changes: 14 additions & 7 deletions src/jsMain/kotlin/searchpluginconfig/shared.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ fun RenderContext.templateVarEditor(

fields.forEach { field ->
val nameStore = storeOf(field.name)
val helpStore = storeOf(field.help)
val typeStore = storeOf(field::class.simpleName!!)
val defaultValueStore = when (field) {
is SearchContextField.BoolField -> storeOf(field.defaultValue.toString())
is SearchContextField.IntField -> storeOf(field.defaultValue.toString())
is SearchContextField.StringField -> storeOf(field.defaultValue)
is SearchContextField.BoolField -> storeOf(field.defaultValue?.toString()?:"")
is SearchContextField.IntField -> storeOf(field.defaultValue?.toString()?:"")
is SearchContextField.StringField -> storeOf(field.defaultValue?:"")
}
val placeHolderStore = when (field) {
is SearchContextField.BoolField -> storeOf("")
Expand All @@ -129,6 +130,9 @@ fun RenderContext.templateVarEditor(
textField("", "name") {
value(nameStore)
}
textAreaField {
value(helpStore)
}
defaultValueStore.data.render { defaultValue ->
when (field) {
is SearchContextField.BoolField -> {
Expand Down Expand Up @@ -158,23 +162,26 @@ fun RenderContext.templateVarEditor(
when (typeStore.current) {
SearchContextField.BoolField::class.simpleName!! -> {
SearchContextField.BoolField(
name = nameStore.current, defaultValue = defaultValueStore.current.toBoolean()
name = nameStore.current,
help = helpStore.current,
defaultValue = defaultValueStore.current.takeIf { it.isNotBlank() }?.toBoolean()
)
}

SearchContextField.IntField::class.simpleName!! -> {
SearchContextField.IntField(
name = nameStore.current,
defaultValue = defaultValueStore.current.toIntOrNull() ?: 0,
help = helpStore.current,
defaultValue = defaultValueStore.current.takeIf { it.isNotBlank() }?.toIntOrNull(),
placeHolder = placeHolderStore.current,
)

}

else -> {
SearchContextField.StringField(
name = nameStore.current,
defaultValue = defaultValueStore.current,
help = helpStore.current,
defaultValue = defaultValueStore.current.takeIf { it.isNotBlank() },
placeHolder = placeHolderStore.current,
)
}
Expand Down
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version.com.github.jillesvangurp..querylight=1.0.5

version.com.jillesvangurp..kotlinx-serialization-extensions=1.0.4

version.com.jillesvangurp..rankquest-core=1.1.1
version.com.jillesvangurp..rankquest-core=1.1.2

version.com.soywiz.korlibs.krypto..krypto=4.0.10

Expand Down

0 comments on commit b6eef98

Please sign in to comment.