-
Notifications
You must be signed in to change notification settings - Fork 62
Add service info modal to display service metadata #514
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
service/src/main/kotlin/app/cash/backfila/dashboard/GetServiceDetailsAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package app.cash.backfila.dashboard | ||
|
||
import app.cash.backfila.service.persistence.BackfilaDb | ||
import app.cash.backfila.service.persistence.ServiceQuery | ||
import java.time.Instant | ||
import javax.inject.Inject | ||
import misk.exceptions.BadRequestException | ||
import misk.hibernate.Query | ||
import misk.hibernate.Transacter | ||
import misk.hibernate.newQuery | ||
import misk.security.authz.Authenticated | ||
import misk.web.Get | ||
import misk.web.PathParam | ||
import misk.web.ResponseContentType | ||
import misk.web.actions.WebAction | ||
import misk.web.mediatype.MediaTypes | ||
|
||
data class GetServiceDetailsResponse( | ||
val service_name: String, | ||
val variant: String, | ||
val connector: String, | ||
val connector_extra_data: String?, | ||
val slack_channel: String?, | ||
val created_at: Instant, | ||
val updated_at: Instant, | ||
val last_registered_at: Instant?, | ||
) | ||
|
||
class GetServiceDetailsAction @Inject constructor( | ||
@BackfilaDb private val transacter: Transacter, | ||
private val queryFactory: Query.Factory, | ||
) : WebAction { | ||
@Get("/services/{service}/variants/{variant}/details") | ||
@ResponseContentType(MediaTypes.APPLICATION_JSON) | ||
@Authenticated(allowAnyUser = true) | ||
fun getServiceDetails( | ||
@PathParam service: String, | ||
@PathParam variant: String, | ||
): GetServiceDetailsResponse { | ||
return transacter.transaction { session -> | ||
val dbService = queryFactory.newQuery<ServiceQuery>() | ||
.registryName(service) | ||
.variant(variant) | ||
.uniqueResult(session) ?: throw BadRequestException("`$service`-`$variant` doesn't exist") | ||
|
||
GetServiceDetailsResponse( | ||
service_name = dbService.registry_name, | ||
variant = dbService.variant, | ||
connector = dbService.connector, | ||
connector_extra_data = dbService.connector_extra_data, | ||
slack_channel = dbService.slack_channel, | ||
created_at = dbService.created_at, | ||
updated_at = dbService.updated_at, | ||
last_registered_at = dbService.last_registered_at, | ||
) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceInfoAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package app.cash.backfila.ui.pages | ||
|
||
import app.cash.backfila.dashboard.GetServiceDetailsAction | ||
import app.cash.backfila.ui.components.DashboardPageLayout | ||
import app.cash.backfila.ui.components.PageTitle | ||
import java.net.HttpURLConnection | ||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlinx.html.div | ||
import kotlinx.html.pre | ||
import kotlinx.html.span | ||
import misk.security.authz.Authenticated | ||
import misk.tailwind.Link | ||
import misk.web.Get | ||
import misk.web.PathParam | ||
import misk.web.Response | ||
import misk.web.ResponseBody | ||
import misk.web.ResponseContentType | ||
import misk.web.actions.WebAction | ||
import misk.web.mediatype.MediaTypes | ||
import misk.web.toResponseBody | ||
|
||
@Singleton | ||
class ServiceInfoAction @Inject constructor( | ||
private val dashboardPageLayout: DashboardPageLayout, | ||
private val getServiceDetailsAction: GetServiceDetailsAction, | ||
) : WebAction { | ||
|
||
@Get(PATH) | ||
@ResponseContentType(MediaTypes.TEXT_HTML) | ||
@Authenticated(capabilities = ["users"]) | ||
fun get( | ||
@PathParam service: String?, | ||
@PathParam variantOrBlank: String? = "", | ||
): Response<ResponseBody> { | ||
if (service.isNullOrBlank()) { | ||
return Response( | ||
body = "Service name is required".toResponseBody(), | ||
statusCode = HttpURLConnection.HTTP_BAD_REQUEST, | ||
) | ||
} | ||
|
||
val variant = variantOrBlank.orEmpty().ifBlank { "default" } | ||
|
||
try { | ||
val serviceDetails = getServiceDetailsAction.getServiceDetails(service, variant) | ||
val label = if (variant == "default") service else "$service ($variant)" | ||
|
||
val htmlResponseBody = dashboardPageLayout.newBuilder() | ||
.title("$label Info | Backfila") | ||
.breadcrumbLinks( | ||
Link("Services", ServiceIndexAction.PATH), | ||
Link(label, ServiceShowAction.path(service, variantOrBlank)), | ||
Link("Info", path(service, variantOrBlank)), | ||
) | ||
.buildHtmlResponseBody { | ||
PageTitle("Service Information", label) | ||
|
||
div("bg-white shadow rounded-lg") { | ||
div("px-4 py-5 sm:p-6") { | ||
div("space-y-6") { | ||
div { | ||
span("text-sm font-medium text-gray-500") { +"Service Name" } | ||
div("mt-1 text-sm text-gray-900 font-semibold") { | ||
+serviceDetails.service_name | ||
} | ||
} | ||
|
||
div { | ||
span("text-sm font-medium text-gray-500") { +"Variant" } | ||
div("mt-1 text-sm text-gray-900") { | ||
+serviceDetails.variant | ||
} | ||
} | ||
|
||
div { | ||
span("text-sm font-medium text-gray-500") { +"Connector" } | ||
div("mt-1 text-sm text-gray-900 font-mono bg-gray-100 px-2 py-1 rounded") { | ||
+serviceDetails.connector | ||
} | ||
} | ||
|
||
div { | ||
span("text-sm font-medium text-gray-500") { +"Connector Extra Data" } | ||
div("mt-1") { | ||
if (serviceDetails.connector_extra_data.isNullOrBlank()) { | ||
div("text-sm text-gray-500 italic") { +"None" } | ||
} else { | ||
pre("text-sm text-gray-900 bg-gray-50 p-3 rounded border overflow-x-auto whitespace-pre-wrap") { | ||
+serviceDetails.connector_extra_data | ||
} | ||
} | ||
} | ||
} | ||
|
||
div { | ||
span("text-sm font-medium text-gray-500") { +"Slack Channel" } | ||
div("mt-1 text-sm text-gray-900") { | ||
if (serviceDetails.slack_channel.isNullOrBlank()) { | ||
span("text-gray-500 italic") { +"None configured" } | ||
} else { | ||
span("font-mono bg-blue-100 text-blue-800 px-2 py-1 rounded") { | ||
+serviceDetails.slack_channel | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Timestamps section | ||
div("border-t border-gray-200 pt-6") { | ||
span("text-sm font-medium text-gray-500 block mb-4") { +"Timestamps" } | ||
|
||
div("grid grid-cols-1 md:grid-cols-3 gap-4") { | ||
div { | ||
span("text-xs font-medium text-gray-500") { +"Created At" } | ||
div("mt-1 text-sm text-gray-900") { | ||
+serviceDetails.created_at.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | ||
} | ||
} | ||
|
||
div { | ||
span("text-xs font-medium text-gray-500") { +"Updated At" } | ||
div("mt-1 text-sm text-gray-900") { | ||
+serviceDetails.updated_at.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | ||
} | ||
} | ||
|
||
div { | ||
span("text-xs font-medium text-gray-500") { +"Last Registered At" } | ||
div("mt-1 text-sm text-gray-900") { | ||
if (serviceDetails.last_registered_at != null) { | ||
+serviceDetails.last_registered_at.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | ||
} else { | ||
span("text-red-600 font-medium") { +"Never registered" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Response(htmlResponseBody) | ||
} catch (e: Exception) { | ||
val htmlResponseBody = dashboardPageLayout.newBuilder() | ||
.title("Service Info Error | Backfila") | ||
.breadcrumbLinks( | ||
Link("Services", ServiceIndexAction.PATH), | ||
) | ||
.buildHtmlResponseBody { | ||
PageTitle("Service Information", "Error") | ||
|
||
div("bg-red-50 border border-red-200 rounded-md p-4") { | ||
div("flex") { | ||
div("ml-3") { | ||
span("text-sm font-medium text-red-800") { +"Error loading service information" } | ||
div("mt-2 text-sm text-red-700") { | ||
+e.message.orEmpty() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Response(htmlResponseBody) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val PATH = "/services/{service}/{variantOrBlank}/info" | ||
fun path(service: String, variantOrBlank: String?) = PATH | ||
.replace("{service}", service) | ||
.replace("{variantOrBlank}", variantOrBlank ?: "") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.