Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize url path building #410

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun TagConsumer<*>.BackfillsTable(running: Boolean, backfills: List<UiBackfillRu
"whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-0",
) {
a(classes = "text-green-500 hover:underline") {
href = BackfillShowAction.PATH.replace("{id}", it.id)
href = BackfillShowAction.path(it.id)
+it.name
}
}
Expand Down
52 changes: 0 additions & 52 deletions service/src/main/kotlin/app/cash/backfila/ui/components/NavBar.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BackfillCreateIndexAction @Inject constructor(
// If service + variant is blank, show service selection
val services: Map<String, GetServicesAction.UiService> = servicesGetter.getFlattenedServices()
ServiceSelect(services) { service, variant ->
BackfillCreateServiceIndexAction.PATH.replace("{service}", service).replace("{variantOrBlank}", variant ?: "")
BackfillCreateServiceIndexAction.path(service, variant)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class BackfillCreateServiceIndexAction @Inject constructor(
): Response<ResponseBody> {
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,
Expand All @@ -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",
Expand Down Expand Up @@ -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
)

[email protected]("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") {
Expand Down Expand Up @@ -124,22 +124,10 @@ class BackfillCreateServiceIndexAction @Inject constructor(
return Response(htmlResponseBody)
}

enum class BackfillCreateField(val fieldId: String) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah unused

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 ?: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())

[email protected]("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") {
Expand All @@ -92,53 +93,9 @@ class BackfillIndexAction @Inject constructor(
+backfill.state.name
}
}
// p("mt-1 truncate text-sm text-gray-500") { +"""Regional Paradigm Technician""" }
}
}
}
// Buttons
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was code copied in from Tailwind but didn't end up using.

// 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:[email protected]"
// // 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"""
// }
// }
// }
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ServiceIndexAction @Inject constructor(
// Search and select from Services
val services: Map<String, GetServicesAction.UiService> = serviceDataHelper.getFlattenedServices()
ServiceSelect(services) { service, variant ->
ServiceShowAction.PATH.replace("{service}", service).replace("{variantOrBlank}", variant ?: "")
ServiceShowAction.path(service, variant)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ?: "")
}
}
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
}
Expand Down
Loading