diff --git a/service/src/main/kotlin/app/cash/backfila/ui/components/BackfillsTable.kt b/service/src/main/kotlin/app/cash/backfila/ui/components/BackfillsTable.kt index 8ac1d722..49ba61dd 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/components/BackfillsTable.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/components/BackfillsTable.kt @@ -45,7 +45,7 @@ fun TagConsumer<*>.BackfillsTable(running: Boolean, backfills: List.NavBar(currentPath: String) { - val links = listOf( - Pair(ServiceIndexAction.PATH, "Overview"), - Pair(ServiceShowAction.PATH.split("{").first(), "Service"), - ) - - nav("bg-white shadow-sm") { - div("mx-auto max-w-7xl px-4 sm:px-6 lg:px-8") { - div("flex h-16 justify-between") { - div("flex") { - div("flex flex-shrink-0 items-center") { - a("/") { - img(classes = "block h-8 w-auto") { - src = "/static/cash-app.png" - alt = "Cash App" - } - } - } - div("sm:-my-px sm:ml-6 sm:flex sm:space-x-8") { - a(classes = "text-gray-900 inline-flex items-center text-sm font-bold") { - href = "/" - +"""Backfila""" - } - } - div("sm:-my-px sm:ml-6 sm:flex sm:space-x-8") { - val bestMatch = links.map { it.first to Pair(currentPath.startsWith(it.first), it.first.length) }.filter { it.second.first }.sortedByDescending { it.second.second }.first() - links.map { (path, label) -> - val selectedStyle = if (path == bestMatch.first) "border-green-500" else "" - a(classes = "$selectedStyle text-gray-900 inline-flex items-center border-b-2 pt-1 text-sm font-medium") { - href = path - if (currentPath.startsWith(path)) { - attributes["aria-current"] = "page" - } - +label - } - } - } - } - } - } - } -} diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateAction.kt index bd14ad7f..dcd73b83 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateAction.kt @@ -8,8 +8,6 @@ import app.cash.backfila.ui.actions.ServiceDataHelper import app.cash.backfila.ui.components.AlertError import app.cash.backfila.ui.components.DashboardPageLayout import app.cash.backfila.ui.components.PageTitle -import javax.inject.Inject -import javax.inject.Singleton import kotlinx.html.ButtonType import kotlinx.html.InputType import kotlinx.html.button @@ -31,6 +29,8 @@ import misk.web.ResponseBody import misk.web.ResponseContentType import misk.web.actions.WebAction import misk.web.mediatype.MediaTypes +import javax.inject.Inject +import javax.inject.Singleton @Singleton class BackfillCreateAction @Inject constructor( @@ -86,22 +86,12 @@ class BackfillCreateAction @Inject constructor( Link("Services", ServiceIndexAction.PATH), Link( label, - ServiceShowAction.PATH - .replace("{service}", service) - .replace("{variantOrBlank}", if (variant != "default") variant else ""), + ServiceShowAction.path(service = service, variantOrBlank = if (variant != "default") variant else ""), ), if (backfillToClone != null) { - Link( - "Backfill #${backfillToClone.id}", - BackfillShowAction.PATH.replace("{id}", backfillToClone.id), - ) + Link("Backfill #${backfillToClone.id}", BackfillShowAction.path(backfillToClone.id)) } else if (registeredBackfill != null) { - Link( - "Create", - BackfillCreateServiceIndexAction.PATH - .replace("{service}", service) - .replace("{variantOrBlank}", variantOrBlank ?: ""), - ) + Link("Create", BackfillCreateServiceIndexAction.path(service = service, variantOrBlank = variantOrBlank)) } else { null }, @@ -129,8 +119,7 @@ class BackfillCreateAction @Inject constructor( AlertError( message = "Invalid backfill name to create or ID to clone provided.", label = "Create a Backfill", - link = BackfillCreateServiceIndexAction.PATH.replace("{service}", service) - .replace("{variantOrBlank}", variantOrBlank ?: ""), + link = BackfillCreateServiceIndexAction.path(service = service, variantOrBlank = variantOrBlank ?: ""), ) } else { div("mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8") { @@ -411,6 +400,10 @@ class BackfillCreateAction @Inject constructor( } companion object { - const val PATH = "/backfills/create/{service}/{variantOrBackfillNameOrId}/{backfillNameOrId}" + private const val PATH = "/backfills/create/{service}/{variantOrBackfillNameOrId}/{backfillNameOrId}" + fun path(service: String, variantOrBackfillNameOrId: String, backfillNameOrId: String) = PATH + .replace("{service}", service) + .replace("{variantOrBackfillNameOrId}", variantOrBackfillNameOrId) + .replace("{backfillNameOrId}", backfillNameOrId) } } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateIndexAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateIndexAction.kt index 5a78d94d..79eaca84 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateIndexAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateIndexAction.kt @@ -32,7 +32,7 @@ class BackfillCreateIndexAction @Inject constructor( // If service + variant is blank, show service selection val services: Map = servicesGetter.getFlattenedServices() ServiceSelect(services) { service, variant -> - BackfillCreateServiceIndexAction.PATH.replace("{service}", service).replace("{variantOrBlank}", variant ?: "") + BackfillCreateServiceIndexAction.path(service, variant) } } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateServiceIndexAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateServiceIndexAction.kt index 178db352..38472d09 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateServiceIndexAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillCreateServiceIndexAction.kt @@ -41,10 +41,11 @@ class BackfillCreateServiceIndexAction @Inject constructor( ): Response { if (variantOrBlank.orEmpty().contains(".") || variantOrBlank.orEmpty().toIntOrNull() != null) { // This means variant is default and the value provided is the backfill name or backfill ID to clone, redirect accordingly - val newPath = BackfillCreateAction.PATH - .replace("{service}", service) - .replace("{variantOrBackfillNameOrId}", variantOrBlank.orEmpty()) - .replace("{backfillNameOrId}", "") + val newPath = BackfillCreateAction.path( + service = service, + variantOrBackfillNameOrId = variantOrBlank.orEmpty(), + backfillNameOrId = "" + ) return Response( body = "go to $newPath".toResponseBody(), statusCode = HttpURLConnection.HTTP_MOVED_TEMP, @@ -60,9 +61,7 @@ class BackfillCreateServiceIndexAction @Inject constructor( Link("Services", ServiceIndexAction.PATH), Link( label, - ServiceShowAction.PATH - .replace("{service}", service) - .replace("{variantOrBlank}", variantOrBlank ?: ""), + ServiceShowAction.path(service, variantOrBlank), ), Link( "Create", @@ -93,10 +92,11 @@ class BackfillCreateServiceIndexAction @Inject constructor( registeredBackfills.backfills.map { a { val variantOrBackfillNameOrId = variantOrBlank.orEmpty().ifBlank { it.name } - href = BackfillCreateAction.PATH - .replace("{service}", service) - .replace("{variantOrBackfillNameOrId}", variantOrBackfillNameOrId) - .replace("{backfillNameOrId}", if (variantOrBackfillNameOrId == it.name) "" else it.name) + href = BackfillCreateAction.path( + service = service, + variantOrBackfillNameOrId = variantOrBackfillNameOrId, + backfillNameOrId = if (variantOrBackfillNameOrId == it.name) "" else it.name + ) this@ul.li("registration col-span-1 divide-y divide-gray-200 rounded-lg bg-white shadow") { div("flex w-full items-center justify-between space-x-6 p-6") { @@ -124,22 +124,10 @@ class BackfillCreateServiceIndexAction @Inject constructor( return Response(htmlResponseBody) } - enum class BackfillCreateField(val fieldId: String) { - SERVICE("service"), - VARIANT("variant"), - BACKFILL_NAME("backfillName"), - DRY_RUN("dryRun"), - RANGE_START("rangeStart"), - RANGE_END("rangeEnd"), - BATCH_SIZE("batchSize"), - SCAN_SIZE("scanSize"), - THREADS_PER_PARTITION("threadsPerPartition"), - EXTRA_SLEEP_MS("extraSleepMs"), - BACKOFF_SCHEDULE("backoffSchedule"), - CUSTOM_PARAMETER_PREFIX("customParameter_"), - } - companion object { - const val PATH = "/backfills/create/{service}/{variantOrBlank}" + private const val PATH = "/backfills/create/{service}/{variantOrBlank}" + fun path(service: String, variantOrBlank: String?) = PATH + .replace("{service}", service) + .replace("{variantOrBlank}", variantOrBlank ?: "") } } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillIndexAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillIndexAction.kt index 3df681b0..6acda828 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillIndexAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillIndexAction.kt @@ -13,6 +13,7 @@ import kotlinx.html.button import kotlinx.html.div import kotlinx.html.h3 import kotlinx.html.li +import kotlinx.html.p import kotlinx.html.role import kotlinx.html.span import kotlinx.html.ul @@ -68,7 +69,7 @@ class BackfillIndexAction @Inject constructor( backfills.map { backfill -> a { - href = BackfillShowAction.PATH.replace("{id}", backfill.id.toString()) + href = BackfillShowAction.path(backfill.id.toString()) this@ul.li("registration col-span-1 divide-y divide-gray-200 rounded-lg bg-white shadow") { div("flex w-full items-center justify-between space-x-6 p-6") { @@ -92,53 +93,9 @@ class BackfillIndexAction @Inject constructor( +backfill.state.name } } - // p("mt-1 truncate text-sm text-gray-500") { +"""Regional Paradigm Technician""" } } } } - // Buttons - // div { - // div("-mt-px flex divide-x divide-gray-200") { - // div("flex w-0 flex-1") { - // a(classes = "relative -mr-px inline-flex w-0 flex-1 items-center justify-center gap-x-3 rounded-bl-lg border border-transparent py-4 text-sm font-semibold text-gray-900") { - // href = "mailto:janecooper@example.com" - // // svg("size-5 text-gray-400") { - // // viewbox = "0 0 20 20" - // // fill = "currentColor" - // // attributes["aria-hidden"] = "true" - // // attributes["data-slot"] = "icon" - // // path { - // // d = - // // "M3 4a2 2 0 0 0-2 2v1.161l8.441 4.221a1.25 1.25 0 0 0 1.118 0L19 7.162V6a2 2 0 0 0-2-2H3Z" - // // } - // // path { - // // d = - // // "m19 8.839-7.77 3.885a2.75 2.75 0 0 1-2.46 0L1 8.839V14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.839Z" - // // } - // // } - // +"""Email""" - // } - // } - // div("-ml-px flex w-0 flex-1") { - // a(classes = "relative inline-flex w-0 flex-1 items-center justify-center gap-x-3 rounded-br-lg border border-transparent py-4 text-sm font-semibold text-gray-900") { - // href = "tel:+1-202-555-0170" - // // svg("size-5 text-gray-400") { - // // viewbox = "0 0 20 20" - // // fill = "currentColor" - // // attributes["aria-hidden"] = "true" - // // attributes["data-slot"] = "icon" - // // path { - // // attributes["fill-rule"] = "evenodd" - // // d = - // // "M2 3.5A1.5 1.5 0 0 1 3.5 2h1.148a1.5 1.5 0 0 1 1.465 1.175l.716 3.223a1.5 1.5 0 0 1-1.052 1.767l-.933.267c-.41.117-.643.555-.48.95a11.542 11.542 0 0 0 6.254 6.254c.395.163.833-.07.95-.48l.267-.933a1.5 1.5 0 0 1 1.767-1.052l3.223.716A1.5 1.5 0 0 1 18 15.352V16.5a1.5 1.5 0 0 1-1.5 1.5H15c-1.149 0-2.263-.15-3.326-.43A13.022 13.022 0 0 1 2.43 8.326 13.019 13.019 0 0 1 2 5V3.5Z" - // // attributes["clip-rule"] = "evenodd" - // // } - // // } - // +"""Call""" - // } - // } - // } - // } } } } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt index a98650ed..99c43514 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt @@ -60,19 +60,22 @@ class BackfillShowAction @Inject constructor( Link("Services", ServiceIndexAction.PATH), Link( label, - ServiceShowAction.PATH.replace("{service}", backfill.service_name) - .replace("{variantOrBlank}", if (backfill.variant != "default") backfill.variant else ""), + ServiceShowAction.path( + service = backfill.service_name, + variantOrBlank = if (backfill.variant != "default") backfill.variant else "" + ) ), - Link("Backfill #$id", PATH.replace("{id}", id)), + Link("Backfill #$id", path(id)), ) .buildHtmlResponseBody { AutoReload { PageTitle("Backfill", id) { a { - href = BackfillCreateAction.PATH - .replace("{service}", backfill.service_name) - .replace("{variantOrBackfillNameOrId}", if (backfill.variant != "default") backfill.variant else id) - .replace("{backfillNameOrId}", if (backfill.variant != "default") id else "") + href = BackfillCreateAction.path( + service = backfill.service_name, + variantOrBackfillNameOrId = if (backfill.variant != "default") backfill.variant else id, + backfillNameOrId = if (backfill.variant != "default") id else "" + ) button(classes = "rounded-full bg-indigo-600 px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600") { type = ButtonType.button @@ -409,7 +412,8 @@ class BackfillShowAction @Inject constructor( ) companion object { - const val PATH = "/backfills/{id}" + private const val PATH = "/backfills/{id}" + fun path(id: String) = PATH.replace("{id}", id) const val UPDATE_BUTTON_LABEL = "Update" } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceIndexAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceIndexAction.kt index 4b445904..c319c833 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceIndexAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceIndexAction.kt @@ -28,7 +28,7 @@ class ServiceIndexAction @Inject constructor( // Search and select from Services val services: Map = serviceDataHelper.getFlattenedServices() ServiceSelect(services) { service, variant -> - ServiceShowAction.PATH.replace("{service}", service).replace("{variantOrBlank}", variant ?: "") + ServiceShowAction.path(service, variant) } } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceShowAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceShowAction.kt index 1f2d46da..effd63d2 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceShowAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceShowAction.kt @@ -67,8 +67,7 @@ class ServiceShowAction @Inject constructor( AutoReload { PageTitle("Service", label) { a { - href = BackfillCreateServiceIndexAction.PATH.replace("{service}", service) - .replace("{variantOrBlank}", variantOrBlank ?: "") + href = BackfillCreateServiceIndexAction.path(service, variantOrBlank) button(classes = "rounded-full bg-indigo-600 px-3 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600") { type = ButtonType.button @@ -86,6 +85,9 @@ class ServiceShowAction @Inject constructor( } companion object { - const val PATH = "/services/{service}/{variantOrBlank}" + private const val PATH = "/services/{service}/{variantOrBlank}" + fun path(service: String, variantOrBlank: String?) = PATH + .replace("{service}", service) + .replace("{variantOrBlank}", variantOrBlank ?: "") } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 2b2a704e..0f6be34b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,6 @@ rootProject.name = "backfila" includeBuild("build-support") { - // dependencySubstitution { substitute(module("app.cash.backfila:client-sqldelight-gradle-plugin")).using(project(":client-sqldelight-gradle-plugin")) }