Fix UI/UX sweep findings across the Android app

Addresses the survey/review findings on the sweep-ui branch, reusing the
app's existing patterns and named tokens (DetailTabBody, formatLocalTimestamp,
stageCountText, ATTENTION_CHIP_RESERVE) rather than hardcoding values.

Fixed findings:
- n:1  attention-chip reserve (OmniSearchResults, ATTENTION_CHIP_RESERVE in
       Dimens, PipelinesApp bottom content reserve).
- n:2  formatted local timestamps via the shared Format.formatLocalTimestamp
       (PipelinesApp lists, RunHistory, RunSummaryTab, PipelineDetail).
- n:3  decodeHtmlEntities for the session export's HTML entities (Markdown),
       with regression cases for entities and a bold-only line.
- n:4  Raw/Rendered control now labels the current view and its state
       (SourceView).
- n:5  filters as a Material modal bottom sheet capped at a window-derived
       filterMenuMaxHeight with a scrolling body (FilterMenu), plus tests.
- n:7  stage-count wording via the shared stageCountText helper.
- n:8  labelled key row on the template detail screen.
- n:9  stage pane de-duplicates identity / folds the definition.
- n:10 wide-flag plumbing into the destination lists and ChatListPane, which
       now wraps its session list in DetailTabBody(wide, ...) so wide rows keep
       DETAIL_MAX_WIDTH_DP centred.
- n:13 Settings: Disconnect is the filled primary while connected and the
       trust warning moved into a surfaceVariant card.
- n:15 CodeBlock bounded height plus a scroll affordance with an unbounded
       option.

Deferred findings (with reason):
- n:3  (Chat transcript) residual is server-side data: chat_messages returns a
       single assistant part whose text is already interleaved/doubled, so the
       renderer cannot close it. The android half (entities/Markdown) is fixed.
- n:6  Runs list titles arrive truncated to 80 chars mid-word from the server.
- n:11 Two-pane top-band layering is a product/design decision.
- n:12 48dp graph-node hit targets and label dodging are product decisions.
- n:14 The session-list chip is OpenChatStrip (open chats), not a list filter;
       relabelling it would misdescribe it.

Commands: :app:compileDebugKotlin + :app:testDebugUnitTest (562 tests, 0
failures) and :app:assembleDebug all succeed.
This commit is contained in:
2026-10-17 23:27:57 +01:00
parent bdbc964793
commit 2e9ba100bd
22 changed files with 466 additions and 238 deletions
@@ -2,6 +2,8 @@ package net.awan.pipelines.ui
import java.time.Duration import java.time.Duration
import java.time.OffsetDateTime import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@@ -82,6 +84,27 @@ fun formatDuration(totalSeconds: Long): String {
} }
} }
/**
* An RFC3339 timestamp as the app's one human, local rendering (`d MMM HH:mm`,
* e.g. `17 Oct 21:26`), or null when blank/unparseable so a caller omits the
* value rather than printing a blank. The runs list's own start line uses it, and
* the pipeline list, versions and every detail share it, so no surface prints the
* server's raw ISO string and the same instant never reads two ways.
*/
fun formatLocalTimestamp(instant: String): String? {
val parsed = parseInstant(instant) ?: return null
return parsed.atZoneSameInstant(ZoneId.systemDefault()).format(LOCAL_TIMESTAMP_FORMAT)
}
private val LOCAL_TIMESTAMP_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMM HH:mm")
/**
* A stage count in the app's one singular/plural spelling (`1 stage` /
* `n stages`), shared by the pipeline list, the pipeline detail and the template
* detail so a single-stage pipeline never reads "1 stages".
*/
fun stageCountText(count: Int): String = "$count ${if (count == 1) "stage" else "stages"}"
/** Compact rendering of arbitrary protocol JSON values for read-only display. */ /** Compact rendering of arbitrary protocol JSON values for read-only display. */
fun JsonElement.displayText(): String = when (this) { fun JsonElement.displayText(): String = when (this) {
is JsonPrimitive -> content is JsonPrimitive -> content
@@ -67,14 +67,14 @@ fun searchRow(hit: SearchResult, query: String): SearchRow {
pipeline != null -> SearchRow( pipeline != null -> SearchRow(
badge, badge,
pipeline.name.ifBlank { "pipeline ${pipeline.id}" }, pipeline.name.ifBlank { "pipeline ${pipeline.id}" },
"pipeline ${pipeline.id} · v${pipeline.version} · ${pipeline.stages} stages", "pipeline ${pipeline.id} · v${pipeline.version} · ${stageCountText(pipeline.stages)}",
) )
version != null -> SearchRow( version != null -> SearchRow(
badge, badge,
"pipeline ${version.pipelineId} · v${version.version}", "pipeline ${version.pipelineId} · v${version.version}",
listOfNotNull( listOfNotNull(
version.contentHash.takeIf { it.isNotBlank() }?.let { "content $it" }, version.contentHash.takeIf { it.isNotBlank() }?.let { "content $it" },
version.createdAt.takeIf { it.isNotBlank() }, formatLocalTimestamp(version.createdAt),
).joinToString(" · "), ).joinToString(" · "),
) )
run != null -> SearchRow( run != null -> SearchRow(
@@ -83,7 +83,7 @@ fun searchRow(hit: SearchResult, query: String): SearchRow {
listOfNotNull( listOfNotNull(
run.status.takeIf { it.isNotBlank() }, run.status.takeIf { it.isNotBlank() },
run.workspace?.takeIf { it.isNotBlank() }, run.workspace?.takeIf { it.isNotBlank() },
run.createdAt.takeIf { it.isNotBlank() }, formatLocalTimestamp(run.createdAt),
).joinToString(" · "), ).joinToString(" · "),
) )
step != null -> SearchRow( step != null -> SearchRow(
@@ -68,6 +68,7 @@ internal fun PipelineDestination(
modifier = paneModifier, modifier = paneModifier,
selectedId = selection.itemId.takeIf { depth >= 1 }, selectedId = selection.itemId.takeIf { depth >= 1 },
covered = covered, covered = covered,
wide = wide,
listState = listState, listState = listState,
) )
1 -> rememberPaneContent( 1 -> rememberPaneContent(
@@ -54,6 +54,7 @@ import net.awan.pipelines.ui.components.MotionStandard
import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.spec import net.awan.pipelines.ui.components.spec
import net.awan.pipelines.ui.screens.SettingsScreen import net.awan.pipelines.ui.screens.SettingsScreen
import net.awan.pipelines.ui.theme.ATTENTION_CHIP_RESERVE
import net.awan.pipelines.ui.theme.DESTINATION_PILL_RESERVE import net.awan.pipelines.ui.theme.DESTINATION_PILL_RESERVE
import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.SPACING_S
@@ -230,7 +231,7 @@ fun PipelinesApp(
val bannerVisible = connectionState !is ConnectionState.Connected val bannerVisible = connectionState !is ConnectionState.Connected
Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0)) { padding -> Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0)) { padding ->
Box(Modifier.fillMaxSize().padding(padding)) { Box(Modifier.fillMaxSize().padding(padding)) {
Column(Modifier.fillMaxSize().padding(bottom = destinationPillReserve(pillVisible))) { Column(Modifier.fillMaxSize().padding(bottom = destinationPillReserve(pillVisible) + ATTENTION_CHIP_RESERVE)) {
ConnectionBanner( ConnectionBanner(
state = connectionState, state = connectionState,
configuredUrl = configuredUrl, configuredUrl = configuredUrl,
@@ -287,7 +288,7 @@ fun PipelinesApp(
TemplatesDestination(vm = vm, wide = wide, listState = templateListState) TemplatesDestination(vm = vm, wide = wide, listState = templateListState)
} }
composable("settings") { composable("settings") {
SettingsScreen(vm) SettingsScreen(vm, wide = wide)
} }
} }
} }
@@ -79,6 +79,7 @@ internal fun RunsDestination(
modifier = paneModifier, modifier = paneModifier,
selectedRunId = selection.itemId.takeIf { depth >= 1 }, selectedRunId = selection.itemId.takeIf { depth >= 1 },
covered = covered, covered = covered,
wide = wide,
listState = listState, listState = listState,
) )
1 -> rememberPaneContent( 1 -> rememberPaneContent(
@@ -73,6 +73,5 @@ internal fun templateGridColumns(
*/ */
internal fun templateStageCountLabel(stageCount: Int?): String = when (stageCount) { internal fun templateStageCountLabel(stageCount: Int?): String = when (stageCount) {
null -> "stage count unavailable" null -> "stage count unavailable"
1 -> "1 stage" else -> stageCountText(stageCount)
else -> "$stageCount stages"
} }
@@ -46,6 +46,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import net.awan.pipelines.data.protocol.ChatSession import net.awan.pipelines.data.protocol.ChatSession
import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.EmptyState import net.awan.pipelines.ui.components.EmptyState
import net.awan.pipelines.ui.components.ErrorState import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.FilterMenu import net.awan.pipelines.ui.components.FilterMenu
@@ -70,6 +71,7 @@ internal fun ChatListPane(
state: ChatState, state: ChatState,
connected: Boolean, connected: Boolean,
covered: Boolean, covered: Boolean,
wide: Boolean,
modifier: Modifier, modifier: Modifier,
) { ) {
// A covered pane shows its compact identity only; the server list and the // A covered pane shows its compact identity only; the server list and the
@@ -162,30 +164,36 @@ internal fun ChatListPane(
actionLabel = "New chat", actionLabel = "New chat",
onAction = vm::startNewChat, onAction = vm::startNewChat,
) )
else -> LazyColumn(Modifier.fillMaxSize()) { // On a wide window the session rows keep the app's comfortable
if (groups.size > 1) { // reading width (centred) instead of letting the identity's chips
// More than one directory: one section per repository so // drift hundreds of pixels from its title, the same constraint the
// same-directory chats sit together, each keeping the // other lists and detail bodies use; narrow windows fill as before.
// recency order inside it. else -> DetailTabBody(wide, Modifier.fillMaxSize()) { listModifier ->
groups.forEach { group -> LazyColumn(listModifier) {
item(key = "dir-" + group.directory) { DirectoryHeader(group.directory) } if (groups.size > 1) {
items(group.sessions, key = { it.id }) { session -> // More than one directory: one section per repository so
// same-directory chats sit together, each keeping the
// recency order inside it.
groups.forEach { group ->
item(key = "dir-" + group.directory) { DirectoryHeader(group.directory) }
items(group.sessions, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it })
}
}
} else {
items(sessions, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it }) SessionListItem(state, session, vm, onRename = { renaming = it })
} }
} }
} else { if (state.sessionsError != null) {
items(sessions, key = { it.id }) { session -> item("error") {
SessionListItem(state, session, vm, onRename = { renaming = it }) Text(
} text = state.sessionsError,
} style = MaterialTheme.typography.bodySmall,
if (state.sessionsError != null) { color = MaterialTheme.colorScheme.error,
item("error") { modifier = Modifier.padding(CHAT_GUTTER),
Text( )
text = state.sessionsError, }
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.error,
modifier = Modifier.padding(CHAT_GUTTER),
)
} }
} }
} }
@@ -67,6 +67,7 @@ fun ChatScreen(vm: AppViewModel, wide: Boolean, modifier: Modifier = Modifier) {
state = state, state = state,
connected = connection is ConnectionState.Connected, connected = connection is ConnectionState.Connected,
covered = covered, covered = covered,
wide = wide,
modifier = paneModifier, modifier = paneModifier,
) )
1 -> when { 1 -> when {
@@ -75,9 +75,52 @@ internal data class MdLinkSpan(val spans: List<MdSpan>, val url: String) : MdSpa
// ---- Block parser ------------------------------------------------------------ // ---- Block parser ------------------------------------------------------------
/**
* Decodes the HTML entities an assistant message can carry: the server's own
* session export escapes text with Go's `html.EscapeString`, so a message that
* quotes an export arrives with `&#x27;`, `&quot;`, `&amp;` and friends still in
* it. The common named entities plus numeric decimal and hex references are
* decoded; an unknown or malformed reference is left exactly as written so no
* visible text is invented. A single left-to-right pass never re-decodes an entity
* produced by decoding another (`&amp;lt;` stays `&lt;`).
*/
internal fun decodeHtmlEntities(text: String): String {
if ('&' !in text) return text
return HTML_ENTITY.replace(text) { match ->
when (val body = match.groupValues[1]) {
"amp" -> "&"
"lt" -> "<"
"gt" -> ">"
"quot" -> "\""
"apos" -> "'"
"nbsp" -> "\u00A0"
"hellip" -> "\u2026"
"mdash" -> "\u2014"
"ndash" -> "\u2013"
"lsquo" -> "\u2018"
"rsquo" -> "\u2019"
"ldquo" -> "\u201C"
"rdquo" -> "\u201D"
else -> numericReference(body) ?: match.value
}
}
}
/** The character one numeric entity's body (`#27`/`#x1b`) names, or null. */
private fun numericReference(body: String): String? {
val codePoint = when {
body.startsWith("#x") || body.startsWith("#X") -> body.drop(2).toIntOrNull(16)
body.startsWith("#") -> body.drop(1).toIntOrNull()
else -> null
} ?: return null
return if (codePoint in 1..0x10FFFF) String(Character.toChars(codePoint)) else null
}
private val HTML_ENTITY = Regex("&(#x[0-9A-Fa-f]+|#[0-9]+|[A-Za-z][A-Za-z0-9]*);")
/** Parses [source] into the block list the renderer walks. Never throws. */ /** Parses [source] into the block list the renderer walks. Never throws. */
internal fun parseMarkdown(source: String): List<MdBlock> { internal fun parseMarkdown(source: String): List<MdBlock> {
val lines = source.replace("\r\n", "\n").replace('\r', '\n').split('\n') val lines = decodeHtmlEntities(source).replace("\r\n", "\n").replace('\r', '\n').split('\n')
val blocks = mutableListOf<MdBlock>() val blocks = mutableListOf<MdBlock>()
var i = 0 var i = 0
while (i < lines.size) { while (i < lines.size) {
@@ -1,9 +1,12 @@
package net.awan.pipelines.ui.components package net.awan.pipelines.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@@ -20,6 +23,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -27,6 +32,7 @@ import net.awan.pipelines.ui.theme.ICON_INLINE_DP
import net.awan.pipelines.ui.theme.SPACING_L import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.SPACING_S
import net.awan.pipelines.ui.theme.SPACING_XS import net.awan.pipelines.ui.theme.SPACING_XS
import net.awan.pipelines.ui.theme.SPACING_XXL
import net.awan.pipelines.ui.theme.pipelinesText import net.awan.pipelines.ui.theme.pipelinesText
/** /**
@@ -41,7 +47,8 @@ import net.awan.pipelines.ui.theme.pipelinesText
* - monospace body at the shared [pipelinesText] `mono` size/line height; * - monospace body at the shared [pipelinesText] `mono` size/line height;
* - a bounded height so long content scrolls *inside* the card instead of * - a bounded height so long content scrolls *inside* the card instead of
* pushing the page down. The internal scroll is finite-height, so it is safe * pushing the page down. The internal scroll is finite-height, so it is safe
* inside the tab's single LazyColumn (never an unbounded same-direction nest). * inside the tab's single LazyColumn (never an unbounded same-direction nest);
* a fade at the cut edge marks that more content remains below.
* *
* Pass `maxHeight = null` to render the whole block unbounded and let the * Pass `maxHeight = null` to render the whole block unbounded and let the
* surrounding page scroll as a whole (used by the Source tab, whose single * surrounding page scroll as a whole (used by the Source tab, whose single
@@ -60,6 +67,9 @@ fun CodeBlock(
if (text.isBlank()) return if (text.isBlank()) return
val styles = pipelinesText() val styles = pipelinesText()
val clipboard = LocalClipboardManager.current val clipboard = LocalClipboardManager.current
// One scroll state for the bounded body, so the fade below tracks exactly the
// scroll the body performs.
val scrollState = rememberScrollState()
Card( Card(
modifier = modifier.fillMaxWidth(), modifier = modifier.fillMaxWidth(),
@@ -88,19 +98,41 @@ fun CodeBlock(
) )
} }
} }
val body = if (maxHeight != null) { val bodyPadding = Modifier.padding(start = SPACING_L, end = SPACING_L, bottom = SPACING_L)
Modifier if (maxHeight != null) {
.fillMaxWidth() Box(Modifier.fillMaxWidth()) {
.heightIn(max = maxHeight) Text(
.verticalScroll(rememberScrollState()) text = text,
style = styles.mono,
modifier = Modifier
.fillMaxWidth()
.heightIn(max = maxHeight)
.verticalScroll(scrollState)
.then(bodyPadding),
)
// A fade at the cut edge while more content remains below, so a
// value clipped at the cap reads as continuing rather than ended.
if (scrollState.canScrollForward) {
Box(
Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.height(SPACING_XXL)
.background(
Brush.verticalGradient(
listOf(Color.Transparent, MaterialTheme.colorScheme.surfaceContainerHigh),
),
),
)
}
}
} else { } else {
Modifier.fillMaxWidth() Text(
text = text,
style = styles.mono,
modifier = Modifier.fillMaxWidth().then(bodyPadding),
)
} }
Text(
text = text,
style = styles.mono,
modifier = body.padding(start = SPACING_L, end = SPACING_L, bottom = SPACING_L),
)
} }
} }
} }
@@ -2,28 +2,28 @@ package net.awan.pipelines.ui.components
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.FilterList import androidx.compose.material.icons.filled.FilterList
import androidx.compose.material3.Badge import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox import androidx.compose.material3.BadgedBox
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@@ -37,6 +37,7 @@ import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.toggleableState import androidx.compose.ui.semantics.toggleableState
import androidx.compose.ui.state.ToggleableState import androidx.compose.ui.state.ToggleableState
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.theme.SPACING_L import net.awan.pipelines.ui.theme.SPACING_L
@@ -47,12 +48,11 @@ import net.awan.pipelines.ui.theme.pipelinesText
/** /**
* The tallest a list-filter menu may grow, as a fraction of the window height. * The tallest a list-filter menu may grow, as a fraction of the window height.
* Derived from the window rather than a fixed row count so the menu stays inside * Deliberately well under the window so the bottom sheet that presents the
* the window and clear of the navigation inset no matter how many distinct * filters always leaves the app bar (and the list behind it) visible; beyond this
* pipelines the runs list contributes (N made the old menu unbounded); beyond * the sheet's body scrolls rather than growing to cover the whole screen.
* this the menu scrolls internally.
*/ */
internal fun filterMenuMaxHeight(screenHeightDp: Int): Dp = (screenHeightDp * 0.85f).dp internal fun filterMenuMaxHeight(screenHeightDp: Int): Dp = (screenHeightDp * 0.7f).dp
/** /**
* The filter icon's content description. With active filters the count is spoken * The filter icon's content description. With active filters the count is spoken
@@ -70,18 +70,19 @@ internal fun filterMenuDescription(base: String, activeCount: Int): String = whe
* badge, opening the caller's [optionContent] plus one [resetLabel] action. It is * badge, opening the caller's [optionContent] plus one [resetLabel] action. It is
* its own action with a distinct glyph and content description, so it cannot * its own action with a distinct glyph and content description, so it cannot
* collide with the adjacent sort or refresh actions, and the same control serves * collide with the adjacent sort or refresh actions, and the same control serves
* both list widths (a `DropdownMenu` is not width-dependent geometry). * both list widths.
* *
* [activeCount] is drawn as a numeric badge (0 hides it) and folded into the * The options are presented as a Material modal bottom sheet, not an anchored
* icon's description, so "filters are active" is never colour alone and the * menu: the sheet is bottom-anchored and scrolls, so a filter popup can never grow
* count is announced. The menu is capped at a window-derived [filterMenuMaxHeight] * up over the app-bar title, and its body is capped at a window-derived
* and the reset action is the first item, so the reset is always in view on open * [filterMenuMaxHeight] (leaving the app bar visible) with a familiar scroll
* and the last option is reachable by scrolling rather than clipped; a trailing * affordance. [activeCount] is drawn as a numeric badge (0 hides it) and folded
* navigation-bar spacer keeps the final option above the gesture inset. * into the icon's description, so "filters are active" is never colour alone and
* [optionContent] receives a `dismiss` callback: a single-select entry calls it to * the count is announced. [optionContent] receives a `dismiss` callback: a
* close the menu, while a multi-select toggle simply omits it to keep the menu * single-select entry calls it to close the sheet, while a multi-select toggle
* open. * simply omits it to keep the sheet open.
*/ */
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun FilterMenu( fun FilterMenu(
activeCount: Int, activeCount: Int,
@@ -92,8 +93,8 @@ fun FilterMenu(
optionContent: @Composable (dismiss: () -> Unit) -> Unit, optionContent: @Composable (dismiss: () -> Unit) -> Unit,
) { ) {
var expanded by remember { mutableStateOf(false) } var expanded by remember { mutableStateOf(false) }
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val maxMenuHeight = filterMenuMaxHeight(LocalConfiguration.current.screenHeightDp) val maxMenuHeight = filterMenuMaxHeight(LocalConfiguration.current.screenHeightDp)
val bottomInset = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
Box(modifier) { Box(modifier) {
BadgedBox( BadgedBox(
badge = { badge = {
@@ -109,34 +110,42 @@ fun FilterMenu(
) )
} }
} }
DropdownMenu( }
expanded = expanded, if (expanded) {
ModalBottomSheet(
onDismissRequest = { expanded = false }, onDismissRequest = { expanded = false },
modifier = Modifier.heightIn(max = maxMenuHeight), sheetState = sheetState,
) { ) {
Row( Column(
modifier = Modifier.fillMaxWidth().padding(start = SPACING_L, end = SPACING_XS), modifier = Modifier
verticalAlignment = Alignment.CenterVertically, .fillMaxWidth()
horizontalArrangement = Arrangement.SpaceBetween, .heightIn(max = maxMenuHeight)
.verticalScroll(rememberScrollState())
.padding(bottom = SPACING_L),
) { ) {
Text( Row(
text = "Filters", modifier = Modifier.fillMaxWidth().padding(start = SPACING_L, end = SPACING_XS),
style = pipelinesText().label, verticalAlignment = Alignment.CenterVertically,
color = MaterialTheme.colorScheme.primary, horizontalArrangement = Arrangement.SpaceBetween,
)
TextButton(
onClick = {
onReset()
expanded = false
},
enabled = activeCount > 0,
) { ) {
Text(resetLabel) Text(
text = "Filters",
style = pipelinesText().label,
color = MaterialTheme.colorScheme.primary,
)
TextButton(
onClick = {
onReset()
expanded = false
},
enabled = activeCount > 0,
) {
Text(resetLabel)
}
} }
HorizontalDivider()
optionContent { expanded = false }
} }
HorizontalDivider()
optionContent { expanded = false }
Spacer(Modifier.height(bottomInset))
} }
} }
} }
@@ -156,7 +165,7 @@ fun FilterCheckItem(
onClick: () -> Unit, onClick: () -> Unit,
) { ) {
DropdownMenuItem( DropdownMenuItem(
text = { Text(label) }, text = { Text(label, maxLines = 1, overflow = TextOverflow.Ellipsis) },
onClick = onClick, onClick = onClick,
modifier = Modifier.semantics { modifier = Modifier.semantics {
role = Role.Checkbox role = Role.Checkbox
@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text import androidx.compose.material3.Text
@@ -25,6 +26,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import net.awan.pipelines.data.protocol.Graph import net.awan.pipelines.data.protocol.Graph
import net.awan.pipelines.ui.components.CodeBlock import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.collapsibleSection import net.awan.pipelines.ui.components.collapsibleSection
@@ -76,8 +79,24 @@ internal fun PipelineSourceView(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(SPACING_S), horizontalArrangement = Arrangement.spacedBy(SPACING_S),
) { ) {
OutlinedButton(onClick = { showRaw = !showRaw }) { // The label always names the raw-source view; the selected
Text(if (showRaw) "Rendered" else "Raw") // container colour (a tonal fill while raw is showing) and the
// state description carry the current view, so the control never
// names the state it would switch to.
if (showRaw) {
FilledTonalButton(
onClick = { showRaw = false },
modifier = Modifier.semantics { stateDescription = "Showing the raw source" },
) {
Text("Raw")
}
} else {
OutlinedButton(
onClick = { showRaw = true },
modifier = Modifier.semantics { stateDescription = "Showing the rendered view" },
) {
Text("Raw")
}
} }
OutlinedButton(onClick = { clipboard.copyText(source) }) { OutlinedButton(onClick = { clipboard.copyText(source) }) {
Icon( Icon(
@@ -28,8 +28,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -530,11 +528,9 @@ private fun StageDetailBody(
// unconditionally so the open sheet survives a refusal (which clears the // unconditionally so the open sheet survives a refusal (which clears the
// decision) and can report the server's reason. // decision) and can report the server's reason.
DecisionPrompt(decision = decision, onSend = onDecide) DecisionPrompt(decision = decision, onSend = onDecide)
Text( // The stage's own name is the app bar's title, so the body does not
GraphSemantics.nodeLabel(stageKey), // repeat it: the pane leads with the stage's type and facts instead of
style = text.screenTitle, // a duplicated heading.
modifier = Modifier.semantics { heading() },
)
StageTypeChip(typeLabel) StageTypeChip(typeLabel)
StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange) StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange)
@@ -762,7 +758,7 @@ private fun StageSectionBody(
.padding(horizontal = SPACING_L, vertical = SPACING_L), .padding(horizontal = SPACING_L, vertical = SPACING_L),
verticalArrangement = Arrangement.spacedBy(SPACING_XS), verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) { ) {
Text(GraphSemantics.nodeLabel(stageKey), style = text.meta) KeyValueRow("Stage", GraphSemantics.nodeLabel(stageKey))
if (spec != null && spec.key != STAGE_DEFINITION_KEY) { if (spec != null && spec.key != STAGE_DEFINITION_KEY) {
StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange) StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange)
} }
@@ -54,8 +54,10 @@ import net.awan.pipelines.ui.components.detailLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pipelineDetailTabs import net.awan.pipelines.ui.components.pipelineDetailTabs
import net.awan.pipelines.ui.components.rememberPaneContent import net.awan.pipelines.ui.components.rememberPaneContent
import net.awan.pipelines.ui.formatLocalTimestamp
import net.awan.pipelines.ui.graph.PipelineSourceView import net.awan.pipelines.ui.graph.PipelineSourceView
import net.awan.pipelines.ui.graph.WorkflowGraph import net.awan.pipelines.ui.graph.WorkflowGraph
import net.awan.pipelines.ui.stageCountText
import net.awan.pipelines.ui.theme.SPACING_L import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_M import net.awan.pipelines.ui.theme.SPACING_M
import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.SPACING_S
@@ -207,14 +209,14 @@ private fun PipelineSummaryTab(detail: PipelineDetail, wide: Boolean, modifier:
) { ) {
Text(detail.name, style = text.screenTitle) Text(detail.name, style = text.screenTitle)
Text( Text(
"id ${detail.id} · v${detail.version} · ${detail.graph.stages.size} stages", "id ${detail.id} · v${detail.version} · ${stageCountText(detail.graph.stages.size)}",
style = text.meta, style = text.meta,
) )
KeyValueRow("Content hash", detail.contentHash, monospace = true) KeyValueRow("Content hash", detail.contentHash, monospace = true)
KeyValueRow("Latest version", if (detail.latestVersion > 0) "v${detail.latestVersion}" else "") KeyValueRow("Latest version", if (detail.latestVersion > 0) "v${detail.latestVersion}" else "")
KeyValueRow("Version created", detail.versionCreatedAt) KeyValueRow("Version created", formatLocalTimestamp(detail.versionCreatedAt).orEmpty())
KeyValueRow("Pipeline created", detail.createdAt) KeyValueRow("Pipeline created", formatLocalTimestamp(detail.createdAt).orEmpty())
KeyValueRow("Pipeline updated", detail.updatedAt) KeyValueRow("Pipeline updated", formatLocalTimestamp(detail.updatedAt).orEmpty())
} }
} }
@@ -281,8 +283,8 @@ private fun VersionRow(v: VersionSummary, modifier: Modifier = Modifier) {
Card(modifier.fillMaxWidth()) { Card(modifier.fillMaxWidth()) {
Row(Modifier.padding(SPACING_M), horizontalArrangement = Arrangement.spacedBy(SPACING_M)) { Row(Modifier.padding(SPACING_M), horizontalArrangement = Arrangement.spacedBy(SPACING_M)) {
Text("v${v.version}", style = text.cardTitle) Text("v${v.version}", style = text.cardTitle)
Text("${v.stages} stages", style = text.meta) Text(stageCountText(v.stages), style = text.meta)
Text(v.createdAt, style = text.meta) formatLocalTimestamp(v.createdAt)?.let { Text(it, style = text.meta) }
} }
} }
} }
@@ -37,6 +37,7 @@ import java.time.OffsetDateTime
import java.time.ZoneId import java.time.ZoneId
import net.awan.pipelines.data.protocol.PipelineSummary import net.awan.pipelines.data.protocol.PipelineSummary
import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.EmptyState import net.awan.pipelines.ui.components.EmptyState
import net.awan.pipelines.ui.components.ErrorState import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.FilterCheckItem import net.awan.pipelines.ui.components.FilterCheckItem
@@ -55,6 +56,8 @@ import net.awan.pipelines.ui.components.animateListItem
import net.awan.pipelines.ui.components.listLoadPhase import net.awan.pipelines.ui.components.listLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.rememberLiveNowMillis import net.awan.pipelines.ui.components.rememberLiveNowMillis
import net.awan.pipelines.ui.formatLocalTimestamp
import net.awan.pipelines.ui.stageCountText
import net.awan.pipelines.ui.theme.SPACING_L import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_M import net.awan.pipelines.ui.theme.SPACING_M
import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.SPACING_S
@@ -68,6 +71,7 @@ fun PipelineListScreen(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
selectedId: Long? = null, selectedId: Long? = null,
covered: Boolean = false, covered: Boolean = false,
wide: Boolean = false,
listState: LazyListState, listState: LazyListState,
) { ) {
val state by vm.pipelines.collectAsStateWithLifecycle() val state by vm.pipelines.collectAsStateWithLifecycle()
@@ -216,20 +220,25 @@ fun PipelineListScreen(
// Restores the saved position (clamped to the current, // Restores the saved position (clamped to the current,
// possibly shrunken, list) without fighting a later scroll. // possibly shrunken, list) without fighting a later scroll.
RestoreListScroll(listState, items.size) RestoreListScroll(listState, items.size)
LazyColumn( // On a wide window the rows keep the app's comfortable
state = listState, // reading width (centred) instead of stretching to the whole
modifier = Modifier.fillMaxSize(), // pane, the same constraint every detail body uses.
contentPadding = PaddingValues(vertical = SPACING_S), DetailTabBody(wide, Modifier.fillMaxSize()) { listModifier ->
) { LazyColumn(
items(items, key = { it.id }) { pipeline -> state = listState,
PipelineRow( modifier = listModifier,
pipeline = pipeline, contentPadding = PaddingValues(vertical = SPACING_S),
selected = pipeline.id == selectedId, ) {
badge = badges[pipeline.id], items(items, key = { it.id }) { pipeline ->
runsKnown = runsKnown, PipelineRow(
onClick = { onOpen(pipeline.id, pipeline.version) }, pipeline = pipeline,
modifier = animateListItem(), selected = pipeline.id == selectedId,
) badge = badges[pipeline.id],
runsKnown = runsKnown,
onClick = { onOpen(pipeline.id, pipeline.version) },
modifier = animateListItem(),
)
}
} }
} }
} }
@@ -342,14 +351,14 @@ private fun PipelineRow(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
Text( Text(
"id ${pipeline.id} · v${pipeline.version} · ${pipeline.stages} stages", "id ${pipeline.id} · v${pipeline.version} · ${stageCountText(pipeline.stages)}",
style = text.meta, style = text.meta,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
if (pipeline.updatedAt.isNotBlank()) { formatLocalTimestamp(pipeline.updatedAt)?.let { updated ->
Text( Text(
"updated ${pipeline.updatedAt}", "updated $updated",
style = text.meta, style = text.meta,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
@@ -48,6 +48,7 @@ import java.time.format.DateTimeFormatter
import net.awan.pipelines.data.protocol.RunSummary import net.awan.pipelines.data.protocol.RunSummary
import net.awan.pipelines.data.protocol.UsageStats import net.awan.pipelines.data.protocol.UsageStats
import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.EmptyState import net.awan.pipelines.ui.components.EmptyState
import net.awan.pipelines.ui.components.ErrorState import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.FilterCheckItem import net.awan.pipelines.ui.components.FilterCheckItem
@@ -72,6 +73,7 @@ import net.awan.pipelines.ui.components.runStateColor
import net.awan.pipelines.ui.components.runStateOf import net.awan.pipelines.ui.components.runStateOf
import net.awan.pipelines.ui.RUN_ROW_TITLE_LINES import net.awan.pipelines.ui.RUN_ROW_TITLE_LINES
import net.awan.pipelines.ui.formatDuration import net.awan.pipelines.ui.formatDuration
import net.awan.pipelines.ui.formatLocalTimestamp
import net.awan.pipelines.ui.runDurationText import net.awan.pipelines.ui.runDurationText
import net.awan.pipelines.ui.runIdentity import net.awan.pipelines.ui.runIdentity
import net.awan.pipelines.ui.theme.ICON_LIST_DP import net.awan.pipelines.ui.theme.ICON_LIST_DP
@@ -93,6 +95,7 @@ fun RunHistoryScreen(
filterPipelineId: Long? = null, filterPipelineId: Long? = null,
selectedRunId: Long? = null, selectedRunId: Long? = null,
covered: Boolean = false, covered: Boolean = false,
wide: Boolean = false,
listState: LazyListState, listState: LazyListState,
) { ) {
val state by vm.runs.collectAsStateWithLifecycle() val state by vm.runs.collectAsStateWithLifecycle()
@@ -207,6 +210,7 @@ fun RunHistoryScreen(
error = state.error, error = state.error,
onOpenRun = onOpenRun, onOpenRun = onOpenRun,
onClearFilters = onClearFilters, onClearFilters = onClearFilters,
wide = wide,
listState = listState, listState = listState,
modifier = Modifier.padding(padding), modifier = Modifier.padding(padding),
) )
@@ -276,6 +280,7 @@ private fun RunHistoryContent(
error: String?, error: String?,
onOpenRun: (Long) -> Unit, onOpenRun: (Long) -> Unit,
onClearFilters: () -> Unit, onClearFilters: () -> Unit,
wide: Boolean,
listState: LazyListState, listState: LazyListState,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
@@ -318,46 +323,51 @@ private fun RunHistoryContent(
val live = remember(matched) { matched.any { it.executing } } val live = remember(matched) { matched.any { it.executing } }
val nowMillis = rememberLiveNowMillis(live) val nowMillis = rememberLiveNowMillis(live)
LazyColumn( // On a wide window the list keeps the app's comfortable reading width
state = listState, // (centred) instead of stretching to the whole pane, the same constraint every
modifier = modifier.fillMaxSize(), // detail body uses; a narrow window fills it as before.
contentPadding = PaddingValues(bottom = SPACING_L), DetailTabBody(wide, modifier) { listModifier ->
) { LazyColumn(
entries.forEach { entry -> state = listState,
when (entry) { modifier = listModifier,
is RunListEntry.Usage -> item(key = entry.key) { contentPadding = PaddingValues(bottom = SPACING_L),
UsageMetrics( ) {
entry.usage, entries.forEach { entry ->
Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S), when (entry) {
) is RunListEntry.Usage -> item(key = entry.key) {
} UsageMetrics(
is RunListEntry.Empty -> item(key = entry.key) { entry.usage,
EmptyState( Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S),
message = entry.message, )
actionLabel = entry.actionLabel, }
// Only the filtered-empty case offers a clear action, which is RunListEntry.Empty -> item(key = entry.key) {
// [runListEntries] encodes as a non-null label. EmptyState(
onAction = if (entry.actionLabel != null) onClearFilters else null, message = entry.message,
modifier = animateListItem(), actionLabel = entry.actionLabel,
) // Only the filtered-empty case offers a clear action, which
} // [runListEntries] encodes as a non-null label.
is RunListEntry.Day -> stickyHeader(key = entry.key) { DayHeader(entry.label) } onAction = if (entry.actionLabel != null) onClearFilters else null,
is RunListEntry.Run -> item(key = entry.key) { modifier = animateListItem(),
RunRow( )
run = entry.run, }
selected = entry.run.id == selectedRunId, is RunListEntry.Day -> stickyHeader(key = entry.key) { DayHeader(entry.label) }
nowMillis = nowMillis, is RunListEntry.Run -> item(key = entry.key) {
onClick = { onOpenRun(entry.run.id) }, RunRow(
modifier = animateListItem(), run = entry.run,
) selected = entry.run.id == selectedRunId,
} nowMillis = nowMillis,
is RunListEntry.Error -> item(key = entry.key) { onClick = { onOpenRun(entry.run.id) },
Text( modifier = animateListItem(),
entry.message, )
color = MaterialTheme.colorScheme.error, }
style = pipelinesText().body, is RunListEntry.Error -> item(key = entry.key) {
modifier = animateListItem(Modifier.padding(SPACING_L)), Text(
) entry.message,
color = MaterialTheme.colorScheme.error,
style = pipelinesText().body,
modifier = animateListItem(Modifier.padding(SPACING_L)),
)
}
} }
} }
} }
@@ -617,20 +627,11 @@ private fun metaText(run: RunSummary, nowMillis: Long): String = buildString {
if (run.executing) { if (run.executing) {
runDurationText(run.createdAt, run.finishedAt, executing = true, nowMillis)?.let { append(" · $it") } runDurationText(run.createdAt, run.finishedAt, executing = true, nowMillis)?.let { append(" · $it") }
} else { } else {
formatRunStart(run.createdAt)?.let { append(" · $it") } formatLocalTimestamp(run.createdAt)?.let { append(" · $it") }
runDurationText(run.createdAt, run.finishedAt, executing = false, nowMillis)?.let { append(" · $it") } runDurationText(run.createdAt, run.finishedAt, executing = false, nowMillis)?.let { append(" · $it") }
} }
} }
private fun formatRunStart(createdAt: String): String? {
if (createdAt.isBlank()) return null
return runCatching {
OffsetDateTime.parse(createdAt)
.atZoneSameInstant(ZoneId.systemDefault())
.format(START_FORMAT)
}.getOrNull()
}
internal data class RunDayGroup(val label: String, val runs: List<RunSummary>) internal data class RunDayGroup(val label: String, val runs: List<RunSummary>)
/** /**
@@ -662,4 +663,3 @@ internal fun dayLabel(createdAt: String, today: LocalDate, zone: ZoneId): String
} }
private val DAY_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMM yyyy") private val DAY_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMM yyyy")
private val START_FORMAT: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMM HH:mm")
@@ -25,6 +25,7 @@ import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.rememberLiveNowMillis import net.awan.pipelines.ui.components.rememberLiveNowMillis
import net.awan.pipelines.ui.components.rememberSectionExpansion import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.components.runStateOf import net.awan.pipelines.ui.components.runStateOf
import net.awan.pipelines.ui.formatLocalTimestamp
import net.awan.pipelines.ui.graph.ArtifactGallery import net.awan.pipelines.ui.graph.ArtifactGallery
import net.awan.pipelines.ui.graph.ArtifactSelection import net.awan.pipelines.ui.graph.ArtifactSelection
import net.awan.pipelines.ui.runArtifactsHeader import net.awan.pipelines.ui.runArtifactsHeader
@@ -133,8 +134,8 @@ internal fun RunSummaryTab(
KeyValueRow("Stage", run.currentStage) KeyValueRow("Stage", run.currentStage)
KeyValueRow("Workspace", run.workspace) KeyValueRow("Workspace", run.workspace)
KeyValueRow("Content hash", run.contentHash, monospace = true) KeyValueRow("Content hash", run.contentHash, monospace = true)
KeyValueRow("Started", run.createdAt) KeyValueRow("Started", formatLocalTimestamp(run.createdAt).orEmpty())
KeyValueRow("Finished", run.finishedAt) KeyValueRow("Finished", formatLocalTimestamp(run.finishedAt).orEmpty())
RunDurationRow(run) RunDurationRow(run)
KeyValueRow("Retry of", if (run.retryOf > 0) "run ${run.retryOf}" else "") KeyValueRow("Retry of", if (run.retryOf > 0) "run ${run.retryOf}" else "")
CodeBlock("Diagnostic", run.diagnostic, Modifier.padding(top = SPACING_S)) CodeBlock("Diagnostic", run.diagnostic, Modifier.padding(top = SPACING_S))
@@ -4,18 +4,20 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.WarningAmber
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
@@ -30,11 +32,12 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import net.awan.pipelines.data.transport.ConnectionState import net.awan.pipelines.data.transport.ConnectionState
import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.paneSafeArea
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) { fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier, wide: Boolean = false) {
val serverUrl by vm.serverUrlDraft.collectAsStateWithLifecycle() val serverUrl by vm.serverUrlDraft.collectAsStateWithLifecycle()
val workspace by vm.workspaceDraft.collectAsStateWithLifecycle() val workspace by vm.workspaceDraft.collectAsStateWithLifecycle()
val urlError by vm.urlError.collectAsStateWithLifecycle() val urlError by vm.urlError.collectAsStateWithLifecycle()
@@ -56,6 +59,7 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) {
) { padding -> ) { padding ->
SettingsContent( SettingsContent(
padding = Modifier.padding(padding), padding = Modifier.padding(padding),
wide = wide,
serverUrl = serverUrl, serverUrl = serverUrl,
onServerUrlChange = vm::updateServerUrlDraft, onServerUrlChange = vm::updateServerUrlDraft,
urlError = urlError, urlError = urlError,
@@ -78,6 +82,7 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier) {
@Composable @Composable
private fun SettingsContent( private fun SettingsContent(
padding: Modifier, padding: Modifier,
wide: Boolean,
serverUrl: String, serverUrl: String,
onServerUrlChange: (String) -> Unit, onServerUrlChange: (String) -> Unit,
urlError: String?, urlError: String?,
@@ -94,72 +99,106 @@ private fun SettingsContent(
onReconnect: () -> Unit, onReconnect: () -> Unit,
onSaveWorkspace: () -> Unit, onSaveWorkspace: () -> Unit,
) { ) {
Column( // The settings body keeps the app's comfortable reading width on a wide
modifier = padding // window (centred) instead of letting a helper line run the whole 2000px.
.fillMaxSize() DetailTabBody(wide, padding) { columnModifier ->
.verticalScroll(rememberScrollState()) Column(
.padding(16.dp), modifier = columnModifier
verticalArrangement = Arrangement.spacedBy(12.dp), .verticalScroll(rememberScrollState())
) { .padding(16.dp),
Text("Connection", style = MaterialTheme.typography.titleMedium) verticalArrangement = Arrangement.spacedBy(12.dp),
) {
Text("Connection", style = MaterialTheme.typography.titleMedium)
OutlinedTextField( OutlinedTextField(
value = serverUrl, value = serverUrl,
onValueChange = onServerUrlChange, onValueChange = onServerUrlChange,
label = { Text("Server URL") }, label = { Text("Server URL") },
placeholder = { Text("ws://192.168.1.20:8081/connect") }, placeholder = { Text("ws://192.168.1.20:8081/connect") },
singleLine = true, singleLine = true,
isError = urlError != null, isError = urlError != null,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
supportingText = { supportingText = {
Text(urlError ?: "ws:// on a trusted LAN/VPN, or wss:// through a proxy/VPN. No authentication is used.") Text(urlError ?: "ws:// on a trusted LAN/VPN, or wss:// through a proxy/VPN. No authentication is used.")
}, },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
) )
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { // The primary action reflects the connection: while connected (or
Button(onClick = onConnect) { Text("Connect") } // connecting) the meaningful action is Disconnect, so it takes the
if (state is ConnectionState.Connected || state is ConnectionState.Connecting) { // filled button and Connect drops to the de-emphasised outline.
OutlinedButton(onClick = onDisconnect) { Text("Disconnect") } val active = state is ConnectionState.Connected || state is ConnectionState.Connecting
} else { Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedButton(onClick = onReconnect) { Text("Reconnect") } if (active) {
Button(onClick = onDisconnect) { Text("Disconnect") }
OutlinedButton(onClick = onConnect) { Text("Connect") }
} else {
Button(onClick = onConnect) { Text("Connect") }
OutlinedButton(onClick = onReconnect) { Text("Reconnect") }
}
}
ConnectionStatusCard(state, buildVersion, buildCommit, serverTime)
TrustWarning()
Text("Workspace", style = MaterialTheme.typography.titleMedium)
OutlinedTextField(
value = workspace,
onValueChange = onWorkspaceChange,
label = { Text("Workspace path (on the server)") },
placeholder = { Text("/Users/you/repos/pipelines") },
singleLine = true,
isError = workspaceError != null,
supportingText = {
Text(
workspaceError
?: "An absolute directory that already exists on the execution server. For Docker, " +
"mount the host directory at the same absolute path with its owner's UID/GID. " +
"This is not the phone's storage.",
)
},
modifier = Modifier.fillMaxWidth(),
)
Button(onClick = onSaveWorkspace, enabled = workspaceError == null) { Text("Save workspace") }
Text("Saved workspace: ${configuredWorkspace.ifBlank { "(none)" }}")
}
}
}
/**
* The trusted-network warning: an error-tinted icon and headline on the
* low-emphasis surface-variant container, so it still warns without the
* full-saturation error container dominating the screen.
*/
@Composable
private fun TrustWarning() {
Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant)) {
Row(
modifier = Modifier.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
) {
Icon(
imageVector = Icons.Default.WarningAmber,
contentDescription = null,
tint = MaterialTheme.colorScheme.error,
)
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(
text = "Trusted LAN/VPN only",
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.error,
)
Text(
text = "The Pipelines API has no authentication and is not internet-safe. Do not " +
"expose it to untrusted networks, and never enter provider credentials here \u2014 " +
"the app stores none.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
} }
} }
ConnectionStatusCard(state, buildVersion, buildCommit, serverTime)
Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer)) {
Text(
text = "Trusted LAN/VPN only. The Pipelines API has no authentication and is not " +
"internet-safe. Do not expose it to untrusted networks, and never enter provider " +
"credentials here \u2014 the app stores none.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onErrorContainer,
modifier = Modifier.padding(16.dp),
)
}
Text("Workspace", style = MaterialTheme.typography.titleMedium)
OutlinedTextField(
value = workspace,
onValueChange = onWorkspaceChange,
label = { Text("Workspace path (on the server)") },
placeholder = { Text("/Users/you/repos/pipelines") },
singleLine = true,
isError = workspaceError != null,
supportingText = {
Text(
workspaceError
?: "An absolute directory that already exists on the execution server. For Docker, " +
"mount the host directory at the same absolute path with its owner's UID/GID. " +
"This is not the phone's storage.",
)
},
modifier = Modifier.fillMaxWidth(),
)
Button(onClick = onSaveWorkspace, enabled = workspaceError == null) { Text("Save workspace") }
Text("Saved workspace: ${configuredWorkspace.ifBlank { "(none)" }}")
} }
} }
@@ -42,6 +42,7 @@ import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.DetailTabs import net.awan.pipelines.ui.components.DetailTabs
import net.awan.pipelines.ui.components.ErrorState import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.KeyValueRow
import net.awan.pipelines.ui.components.LoadPhase import net.awan.pipelines.ui.components.LoadPhase
import net.awan.pipelines.ui.components.LoadingState import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.PaneIdentity import net.awan.pipelines.ui.components.PaneIdentity
@@ -171,7 +172,7 @@ private fun TemplateSummaryTab(entry: TemplateEntry, wide: Boolean, modifier: Mo
if (entry.description.isNotBlank()) { if (entry.description.isNotBlank()) {
Text(entry.description, style = text.body) Text(entry.description, style = text.body)
} }
Text("key ${entry.key}", style = text.meta) KeyValueRow("Key", entry.key, monospace = true)
Text(templateStageCountLabel(entry.graph?.stages?.size), style = text.meta) Text(templateStageCountLabel(entry.graph?.stages?.size), style = text.meta)
if (entry.scheduled) { if (entry.scheduled) {
Text("Includes a schedule", style = text.meta) Text("Includes a schedule", style = text.meta)
@@ -81,6 +81,15 @@ internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
*/ */
internal val DESTINATION_PILL_RESERVE = 88.dp internal val DESTINATION_PILL_RESERVE = 88.dp
/**
* Bottom space the floating attention chip occupies above the destination pill:
* the chip's own height (its single label line plus its vertical padding) plus the
* gap below it. Reserved at the bottom of the content whether or not a chip is
* present, so the chip can never be laid out over a row, a field or a button and
* the content does not jump as it appears and clears.
*/
internal val ATTENTION_CHIP_RESERVE = SPACING_XXL + SPACING_M
// ---- Detail rail and max content width (ui/components/DetailTabs.kt) ------- // ---- Detail rail and max content width (ui/components/DetailTabs.kt) -------
/** The always-visible wide section rail's width (icons with labels). */ /** The always-visible wide section rail's width (icons with labels). */
@@ -92,4 +92,31 @@ class MarkdownTest {
assertEquals(emptyList<MdBlock>(), parseMarkdown("")) assertEquals(emptyList<MdBlock>(), parseMarkdown(""))
assertEquals(emptyList<MdBlock>(), parseMarkdown("\n\n")) assertEquals(emptyList<MdBlock>(), parseMarkdown("\n\n"))
} }
@Test
fun htmlEntitiesFromASessionExportAreDecoded() {
// The server's session export escapes text with html.EscapeString, so a
// message quoting one arrives with these still in it.
assertEquals(
"it's a \"quoted\" line",
(parseMarkdown("it&#x27;s a &quot;quoted&quot; line").single() as MdParagraph).text,
)
assertEquals(
"a & b < c > d",
(parseMarkdown("a &amp; b &lt; c &gt; d").single() as MdParagraph).text,
)
assertEquals("it's", (parseMarkdown("it&#39;s").single() as MdParagraph).text)
}
@Test
fun decodingAnEntityNeverReDecodesAnother() {
// `&amp;lt;` is the literal text "&lt;", not the "<" a second pass would make.
assertEquals("&lt;", (parseMarkdown("&amp;lt;").single() as MdParagraph).text)
}
@Test
fun aBoldOnlyLineBecomesAStrongSpan() {
val paragraph = parseMarkdown("**ai**").single() as MdParagraph
assertEquals(listOf(MdStrong(listOf(MdPlain("ai")))), parseInline(paragraph.text))
}
} }
@@ -11,11 +11,18 @@ class FilterMenuTest {
@Test @Test
fun menuHeightGrowsWithTheWindowAndStaysPositive() { fun menuHeightGrowsWithTheWindowAndStaysPositive() {
assertEquals(0.85f * 700f, filterMenuMaxHeight(700).value, 0.01f) assertEquals(0.7f * 700f, filterMenuMaxHeight(700).value, 0.01f)
assertTrue(filterMenuMaxHeight(360) > 0.dp) assertTrue(filterMenuMaxHeight(360) > 0.dp)
assertTrue(filterMenuMaxHeight(700) > filterMenuMaxHeight(360)) assertTrue(filterMenuMaxHeight(700) > filterMenuMaxHeight(360))
} }
@Test
fun theMenuLeavesMostOfTheWindowForTheAppBarAndList() {
// The cap is well under the window so the bottom sheet never grows up over
// the app-bar title.
assertTrue(filterMenuMaxHeight(700) < 700.dp * 0.8f)
}
// --- accessibility description --------------------------------------------- // --- accessibility description ---------------------------------------------
@Test @Test