Give the detail screens tabs, styled code blocks and a foldable layout

- Pipeline detail and run detail are now tabbed: run detail has Summary, Graph,
  Input, Output, Evidence and Steps, pipeline detail has Summary, Graph and Source,
  with the version list in Summary. The graph gets a tab of its own, so it uses the
  whole content area with its Fit and expand controls. Selection is remembered and
  the tabs carry real tab semantics.
- The code-like blocks (Input, Output, Source, prompt, transcripts) are styled
  content cards with a label header, monospace body, a copy action and a bounded
  height that scrolls internally, instead of a raw bordered div.
- Content inside a tab breaks down into collapsible inner sections (DetailTabs.kt,
  CodeBlock.kt), reusing the existing section component with remembered state.
- Foldable layout is driven by window width (WindowSize.kt): narrow windows keep
  the single-pane tabs, wide windows use list-and-detail side by side with the
  detail capped to a readable width.

Verified: :app:assembleDebug and :app:testDebugUnitTest succeed offline with 60
tests and 0 failures (new WindowSizeTest and DetailTabsTest), and the reviewer
drove every tab plus both a narrow and a wide window on the emulator (captures in
android/captures/tabs_pass/view/). The implementer's own capture set in that
directory is unusable: it wrote screencap's multi-display warning into the files
(they begin with ASCII '[Warning', not the PNG magic), so only the reviewer's
captures were reviewed.
This commit is contained in:
2026-10-15 14:34:49 +01:00
parent e843aa08a8
commit 1828171a9c
9 changed files with 902 additions and 247 deletions
+68 -3
View File
@@ -111,9 +111,43 @@ stops it.
is retained for when it is explicitly requested.
- Consistent Material 3 top app bars on Pipelines, Runs and Settings (and the
existing back/refresh/start/cancel/retry bars on the detail screens).
- Both detail screens render a single `LazyColumn` whose sections ("Versions",
"Workflow graph", "Source" on a pipeline; "Run graph", "Input", "Output",
"Session evidence", "Steps" on a run) are collapsible via a shared
- Both detail screens are tabbed via one shared `ui/components/DetailTabs.kt`:
run detail exposes Summary, Graph, Input, Output, Evidence and Steps, pipeline
detail Summary, Graph and Source, with Summary first and the default. The run's
six tabs scroll horizontally on a narrow window; on a wide window the same tabs
render as a vertical selectable rail. Selection is `rememberSaveable` (survives
recomposition and configuration changes) and the tabs carry real tab semantics
(`Role.Tab` + selected state), so selection is never conveyed by colour alone.
Only the selected tab's body composes (`when`), each tab is a single
`LazyColumn`, and the Graph tab keeps the full-height `WorkflowGraph` panel
with its Fit and expand controls.
- The Summary tab carries what each page header carried: for a run the
status/outcome/executing chip row, recorded + completed visits, pipeline
id/version, stage, workspace, content hash, start/finish/duration and the
failure diagnostic; for a pipeline the name, id/version, stages, content hash,
created/updated, latest version/version-created and the version list.
- Code-like content (Input, Output, Source, session transcripts, per-field and
evidence data, diagnostics) renders through one themed `ui/components/
CodeBlock.kt` card: `surfaceContainer` role, default rounded shape, a small
label header, a whole-block copy action (`LocalClipboardManager`) and monospace
at the shared size/line height, with a bounded height that scrolls internally
instead of pushing the page. Blank content renders nothing, and no raw bordered
monospace box remains.
- Inside each tab the existing `LazyListScope.collapsibleSection` (`SectionHeader`)
provides inner sections where content naturally breaks down: Output per result
field, Input per labelled part, Steps per stage group and Evidence per entry.
Each defaults to expanded and its collapsed set is `rememberSaveable`, so it
survives configuration changes; the sections are items of the tab's single
`LazyColumn`, so no scrollable nests inside a same-direction scrollable.
- Foldable-responsive layout driven by window size (`ui/WindowSize.kt`,
`isWideLayout(widthDp)` at a 600dp breakpoint, read from
`LocalConfiguration.current.screenWidthDp`): a narrow window keeps the
single-pane lists, top tabs and bottom navigation, while a wide window shows
the pipeline list beside the selected pipeline's tabs and the run list beside
the selected run's tabs (master pane ~360dp), with the detail tabs as a side
rail, the text column capped at a comfortable width and the graph using the
extra width. No material3-adaptive dependency is added.
- Both detail screens' sections are still collapsible via the shared
`SectionHeader`: tapping a header toggles it, an animated chevron rotates with
the state, the header sticks to the top of the list while its content scrolls
under an opaque background, and the state is exposed to accessibility
@@ -232,3 +266,34 @@ package contained no `FATAL EXCEPTION` or Compose/other runtime exception during
the sweep. As before, `adb` cannot synthesise a two-finger pinch, so the
centroid-anchored zoom is verified primarily by the `zoomAbout` unit tests and
the on-device graph was exercised with pan + "Fit graph to view" only.
The tabs / code-block / foldable pass was verified on the same
`Pixel_Fold_API_36` emulator (dark mode, `adb shell cmd uimode night yes`) against
the live server: `:app:testDebugUnitTest` reported **60 tests, 0 failures**
(including new `WindowSizeTest` for `isWideLayout` at 400/600/800 and
`DetailTabsTest` for the tab lists and `clampTabIndex`) and `:app:assembleDebug`
succeeded. The debug APK was installed and driven; captures were written to
`captures/tabs_pass/` (git-ignored): every run-detail tab (`05_run_summary`,
`06_run_graph`, `07_run_input`, `08_run_output`, `10_run_evidence`,
`11_run_steps`), every pipeline-detail tab (`01_pipeline_summary`,
`02_pipeline_graph`, `03_pipeline_source`), a long Input/Output block showing the
themed card scrolling internally (`07_run_input`/`08_run_output`, whose block
`ScrollView` measures the 320dp cap), a collapsed inner section
(`09_run_output_collapsed`, `"input, collapsed"`), a step's expanded evidence code
blocks (`12_run_step_expanded`) and the wide two-pane layouts with the vertical
tab rail (`13_wide_runs_split`, `14_wide_run_summary`, `15_wide_pipelines_split`,
`16_wide_pipeline_summary`, `17_wide_pipeline_graph`). Tab-selection persistence
across a configuration change was exercised by switching `wm density` 390→401
with the run detail open; the selected tab stayed selected
(`18_before_config`, `18_after_config`). `adb logcat` for the app package
contained no `FATAL EXCEPTION` and no Compose/other runtime exception.
Because `adb` cannot physically fold the phone, the wide two-pane/rail layout was
exercised on the emulator by resizing the emulated display (`adb shell wm size
2000x3400`, ≈820dp at density 390) and the narrow single-pane layout at the
default width (1080px ≈ 443dp); the attached Pixel 10 Pro Fold was not used to
drive the app. Note that `:app:installDebug` installs to *every* connected
device: that Gradle task therefore also (re)installed the debug APK on the
attached Pixel 10 Pro Fold; all device-driving commands targeted the emulator
serial (`adb -s emulator-5554`) explicitly. The emulator was stopped with
`adb emu kill` plus `kill -9` of the surviving `qemu-system-aarch64-headless`.
@@ -1,7 +1,12 @@
package net.awan.pipelines.ui
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.History
@@ -11,10 +16,18 @@ import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
@@ -23,6 +36,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import net.awan.pipelines.ui.components.ConnectionBanner
import net.awan.pipelines.ui.components.EmptyState
import net.awan.pipelines.ui.screens.PipelineDetailScreen
import net.awan.pipelines.ui.screens.PipelineListScreen
import net.awan.pipelines.ui.screens.RunDetailScreen
@@ -44,6 +58,9 @@ fun PipelinesApp(vm: AppViewModel) {
val currentRoute = backStackEntry?.destination?.route
val connectionState by vm.connectionState.collectAsStateWithLifecycle()
val configuredUrl by vm.configuredServerUrl.collectAsStateWithLifecycle()
// Window-size driven (never a hardcoded device): a foldable's narrow cover
// display stays single-pane, its wide inner display shows list + detail.
val wide = isWideLayout(LocalConfiguration.current.screenWidthDp)
Scaffold(
bottomBar = {
@@ -81,9 +98,16 @@ fun PipelinesApp(vm: AppViewModel) {
modifier = Modifier.weight(1f),
) {
composable("pipelines") {
PipelineListScreen(vm, onOpen = { id, version ->
navController.navigate("pipeline/$id/$version")
})
if (wide) {
WidePipelinePane(
vm = vm,
onOpenRun = { runId -> navController.navigate("run/$runId") },
)
} else {
PipelineListScreen(vm, onOpen = { id, version ->
navController.navigate("pipeline/$id/$version")
})
}
}
composable(
route = "pipeline/{id}/{version}",
@@ -101,7 +125,11 @@ fun PipelinesApp(vm: AppViewModel) {
)
}
composable("runs") {
RunHistoryScreen(vm, onOpenRun = { runId -> navController.navigate("run/$runId") })
if (wide) {
WideRunPane(vm)
} else {
RunHistoryScreen(vm, onOpenRun = { runId -> navController.navigate("run/$runId") })
}
}
composable(
route = "run/{id}",
@@ -120,3 +148,72 @@ fun PipelinesApp(vm: AppViewModel) {
}
}
}
/**
* Wide Pipelines destination: the pipeline list beside the selected pipeline's
* tabs. The selection is remembered across config changes and Back inside the
* detail clears it (rather than popping a route that is not on the stack).
*/
@Composable
private fun WidePipelinePane(vm: AppViewModel, onOpenRun: (Long) -> Unit) {
var selectedId by rememberSaveable { mutableStateOf<Long?>(null) }
var selectedVersion by rememberSaveable { mutableIntStateOf(0) }
Row(Modifier.fillMaxSize()) {
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
PipelineListScreen(
vm,
onOpen = { id, version ->
selectedId = id
selectedVersion = version
},
)
}
VerticalDivider()
Box(Modifier.weight(1f).fillMaxHeight()) {
val id = selectedId
if (id == null) {
EmptyState("Select a pipeline to see its Summary, Graph and Source.")
} else {
PipelineDetailScreen(
vm = vm,
pipelineId = id,
version = selectedVersion,
onBack = { selectedId = null },
onOpenRun = onOpenRun,
wide = true,
)
}
}
}
}
/**
* Wide Runs destination: the run list beside the selected run's tabs. The
* selection is remembered across config changes and Back inside the detail clears
* it instead of popping.
*/
@Composable
private fun WideRunPane(vm: AppViewModel) {
var selectedRunId by rememberSaveable { mutableLongStateOf(0L) }
Row(Modifier.fillMaxSize()) {
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
RunHistoryScreen(vm, onOpenRun = { selectedRunId = it })
}
VerticalDivider()
Box(Modifier.weight(1f).fillMaxHeight()) {
if (selectedRunId == 0L) {
EmptyState("Select a run to see its Summary, Graph, Input, Output, Evidence and Steps.")
} else {
RunDetailScreen(
vm = vm,
runId = selectedRunId,
onBack = { selectedRunId = 0L },
wide = true,
)
}
}
}
}
/** Width of the master list pane in the wide two-pane layout. */
private val LIST_PANE_WIDTH = 360.dp
@@ -0,0 +1,16 @@
package net.awan.pipelines.ui
/**
* Window-width breakpoint (dp) between the narrow single-pane and the wide
* list-and-detail layout. A foldable's cover display (~400dp) stays narrow while
* the inner display (~700-800dp and up) is wide.
*
* Kept as a pure predicate so the decision is unit-testable and no screen has to
* hardcode device numbers; composables read the live width from
* `LocalConfiguration.current.screenWidthDp` so it follows window-size changes
* without any new listener or dependency.
*/
const val WIDE_LAYOUT_MIN_WIDTH_DP = 600
/** True when [widthDp] is wide enough for the two-pane / side-rail layout. */
fun isWideLayout(widthDp: Int): Boolean = widthDp >= WIDE_LAYOUT_MIN_WIDTH_DP
@@ -0,0 +1,95 @@
package net.awan.pipelines.ui.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.theme.pipelinesText
/**
* The one themed card for code-like content (Input, Output, Source, transcripts,
* per-field/evidence data, diagnostics). It matches the rest of the app's cards
* (surfaceContainer role, default rounded shape, no elevation) rather than
* reading as a foreign bordered monospace box, and adds:
*
* - a small label header naming the block plus a whole-block copy action;
* - monospace body at the shared [pipelinesText] `mono` size/line height;
* - 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
* inside the tab's single LazyColumn (never an unbounded same-direction nest).
*
* Blank content renders nothing, so callers never leave an empty block.
*/
@Composable
fun CodeBlock(
label: String,
text: String,
modifier: Modifier = Modifier,
maxHeight: Dp = CODE_BLOCK_MAX_HEIGHT,
) {
if (text.isBlank()) return
val styles = pipelinesText()
val clipboard = LocalClipboardManager.current
Card(
modifier = modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
) {
Column {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 4.dp, top = 4.dp, bottom = 4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = label,
style = styles.label,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.weight(1f),
)
IconButton(onClick = { clipboard.setText(AnnotatedString(text)) }) {
Icon(
imageVector = Icons.Default.ContentCopy,
contentDescription = "Copy $label",
modifier = Modifier.size(18.dp),
)
}
}
Text(
text = text,
style = styles.mono,
modifier = Modifier
.fillMaxWidth()
.heightIn(max = maxHeight)
.verticalScroll(rememberScrollState())
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
)
}
}
}
/** Bounded code-block height: beyond this the block scrolls internally. */
val CODE_BLOCK_MAX_HEIGHT = 320.dp
@@ -0,0 +1,206 @@
package net.awan.pipelines.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.theme.pipelinesText
/** A named detail page tab: [key] is stable for `when` dispatch, [title] is shown. */
data class DetailTab(val key: String, val title: String)
/** Run-detail tabs, Summary first so it is the default selection. */
val runDetailTabs: List<DetailTab> = listOf(
DetailTab("summary", "Summary"),
DetailTab("graph", "Graph"),
DetailTab("input", "Input"),
DetailTab("output", "Output"),
DetailTab("evidence", "Evidence"),
DetailTab("steps", "Steps"),
)
/** Pipeline-detail tabs, Summary first (the version list lives inside it). */
val pipelineDetailTabs: List<DetailTab> = listOf(
DetailTab("summary", "Summary"),
DetailTab("graph", "Graph"),
DetailTab("source", "Source"),
)
/**
* Clamps a restored/persisted selected index into `[0, tabCount)`. A stale saved
* index (or a tab list that shrank) can therefore never index out of bounds.
*/
fun clampTabIndex(index: Int, tabCount: Int): Int =
if (tabCount <= 0) 0 else index.coerceIn(0, tabCount - 1)
/**
* A tab host that renders the tab strip and *only* the selected tab's content
* (the caller's `when`), so switching tabs never composes every tab at once.
*
* Narrow windows get a horizontally scrolling Material 3 [PrimaryScrollableTabRow]
* (the run detail's six tabs scroll on a cover display); wide windows get a
* vertical selectable rail. Both carry real tab semantics (`Role.Tab` + selected
* state), so selection is never conveyed by colour alone.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DetailTabs(
tabs: List<DetailTab>,
selectedIndex: Int,
onSelect: (Int) -> Unit,
wide: Boolean,
modifier: Modifier = Modifier,
content: @Composable (DetailTab, Modifier) -> Unit,
) {
val selected = clampTabIndex(selectedIndex, tabs.size)
if (tabs.isEmpty()) return
if (wide) {
Row(modifier.fillMaxSize()) {
Column(
modifier = Modifier
.width(WIDE_RAIL_WIDTH)
.fillMaxHeight()
.selectableGroup()
.padding(vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
tabs.forEachIndexed { index, tab ->
RailTab(tab = tab, selected = index == selected) { onSelect(index) }
}
}
VerticalDivider()
Box(Modifier.weight(1f).fillMaxHeight()) {
content(tabs[selected], Modifier.fillMaxSize())
}
}
} else {
Column(modifier.fillMaxSize()) {
PrimaryScrollableTabRow(selectedTabIndex = selected, edgePadding = 0.dp) {
tabs.forEachIndexed { index, tab ->
Tab(
selected = index == selected,
onClick = { onSelect(index) },
text = { Text(tab.title, maxLines = 1) },
)
}
}
Box(Modifier.weight(1f).fillMaxWidth()) {
content(tabs[selected], Modifier.fillMaxSize())
}
}
}
}
@Composable
private fun RailTab(tab: DetailTab, selected: Boolean, onClick: () -> Unit) {
val text = pipelinesText()
Row(
modifier = Modifier
.fillMaxWidth()
.selectable(selected = selected, role = Role.Tab, onClick = onClick)
.background(
if (selected) MaterialTheme.colorScheme.secondaryContainer else Color.Transparent,
)
.padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = tab.title,
style = text.cardTitle,
color = if (selected) {
MaterialTheme.colorScheme.onSecondaryContainer
} else {
MaterialTheme.colorScheme.onSurfaceVariant
},
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
/**
* Constrains a text tab's single scroll container to a comfortable reading width
* on a wide window (centred) instead of letting lines run edge to edge; on a
* narrow window the content simply fills the tab.
*/
@Composable
fun DetailTabBody(
wide: Boolean,
modifier: Modifier = Modifier,
content: @Composable (Modifier) -> Unit,
) {
if (wide) {
Box(modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
content(
Modifier
.fillMaxHeight()
.widthIn(max = DETAIL_MAX_WIDTH_DP.dp)
.fillMaxWidth(),
)
}
} else {
content(modifier.fillMaxSize())
}
}
/**
* Remembers which inner sections are collapsed, keyed by their stable section
* key and saved across configuration changes, defaulting every section to
* expanded. A collapsed set is persisted (as an [ArrayList] the Bundle can hold).
*/
@Stable
class SectionExpansionState internal constructor(
private val collapsed: androidx.compose.runtime.MutableState<Set<String>>,
) {
fun isExpanded(key: String): Boolean = key !in collapsed.value
fun toggle(key: String) {
collapsed.value = if (key in collapsed.value) collapsed.value - key else collapsed.value + key
}
}
private val collapsedKeysSaver: Saver<Set<String>, ArrayList<String>> = Saver(
save = { ArrayList(it) },
restore = { it.toSet() },
)
@Composable
fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState {
val collapsed = rememberSaveable(*inputs, stateSaver = collapsedKeysSaver) {
mutableStateOf(emptySet())
}
return remember(collapsed) { SectionExpansionState(collapsed) }
}
private val WIDE_RAIL_WIDTH = 200.dp
/** Comfortable max text width for a tab body on a wide window. */
const val DETAIL_MAX_WIDTH_DP = 840
@@ -1,11 +1,9 @@
package net.awan.pipelines.ui.screens
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
@@ -29,22 +27,26 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import net.awan.pipelines.data.ErrorMessages
import net.awan.pipelines.data.protocol.PipelineDetail
import net.awan.pipelines.data.protocol.VersionSummary
import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.DetailTabs
import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.KeyValueRow
import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.pipelineDetailTabs
import net.awan.pipelines.ui.graph.WorkflowGraph
import net.awan.pipelines.ui.theme.pipelinesText
@@ -57,9 +59,12 @@ fun PipelineDetailScreen(
onBack: () -> Unit,
onOpenRun: (Long) -> Unit,
modifier: Modifier = Modifier,
wide: Boolean = false,
) {
val state by vm.pipelineDetail.collectAsStateWithLifecycle()
var showStart by remember { mutableStateOf(false) }
// Summary is the first/default tab; selection survives config changes.
var selectedTab by rememberSaveable { mutableIntStateOf(0) }
LaunchedEffect(pipelineId, version) { vm.loadPipeline(pipelineId, version) }
@@ -93,7 +98,20 @@ fun PipelineDetailScreen(
modifier = Modifier.padding(padding),
)
detail == null -> LoadingState("Loading pipeline…", Modifier.padding(padding))
else -> PipelineDetailContent(detail, Modifier.padding(padding))
else -> DetailTabs(
tabs = pipelineDetailTabs,
selectedIndex = selectedTab,
onSelect = { selectedTab = it },
wide = wide,
modifier = Modifier.padding(padding),
) { tab, contentModifier ->
// Only the selected tab's content composes (one scroll container each).
when (tab.key) {
"summary" -> PipelineSummaryTab(detail, wide, contentModifier)
"graph" -> PipelineGraphTab(detail, contentModifier)
else -> PipelineSourceTab(detail.source, wide, contentModifier)
}
}
}
}
@@ -110,96 +128,95 @@ fun PipelineDetailScreen(
}
}
@OptIn(ExperimentalFoundationApi::class)
/**
* Summary carries the pipeline identity (name, id, version, stages), content
* hash, created/updated and latest-version fields, plus the version list (moved
* here out of its own tab as an inner collapsible section).
*/
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
@Composable
private fun PipelineDetailContent(detail: PipelineDetail, modifier: Modifier = Modifier) {
private fun PipelineSummaryTab(detail: PipelineDetail, wide: Boolean, modifier: Modifier) {
val text = pipelinesText()
// Per-section expanded state, defaulting to expanded and surviving
// recomposition and configuration changes (each call site is stable).
var versionsExpanded by rememberSaveable { mutableStateOf(true) }
var graphExpanded by rememberSaveable { mutableStateOf(true) }
var sourceExpanded by rememberSaveable { mutableStateOf(true) }
LazyColumn(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "summary") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(detail.name, style = text.screenTitle)
Text(
"id ${detail.id} · v${detail.version} · ${detail.graph.stages.size} stages",
style = text.meta,
)
KeyValueRow("Content hash", detail.contentHash, monospace = true)
KeyValueRow("Latest version", if (detail.latestVersion > 0) "v${detail.latestVersion}" else "")
KeyValueRow("Version created", detail.versionCreatedAt)
KeyValueRow("Pipeline created", detail.createdAt)
KeyValueRow("Pipeline updated", detail.updatedAt)
}
}
collapsibleSection(
title = "Versions",
key = "versions",
expanded = versionsExpanded,
onToggle = { versionsExpanded = !versionsExpanded },
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
if (detail.versions.isEmpty()) {
item(key = "versions-empty") {
Text(
"No versions recorded.",
style = text.meta,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
} else {
items(detail.versions, key = { "version-${it.version}" }) { v ->
VersionRow(v, Modifier.padding(horizontal = 16.dp, vertical = 4.dp).animateItem())
}
}
}
collapsibleSection(
title = "Workflow graph",
key = "graph",
expanded = graphExpanded,
onToggle = { graphExpanded = !graphExpanded },
) {
item(key = "graph") {
item(key = "pipeline-summary") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(detail.name, style = text.screenTitle)
Text(
"Pinch to zoom, drag to pan. Edges are labelled with their outcome; error* is the implicit fallback.",
"id ${detail.id} · v${detail.version} · ${detail.graph.stages.size} stages",
style = text.meta,
)
WorkflowGraph(graph = detail.graph, modifier = Modifier.fillMaxWidth())
KeyValueRow("Content hash", detail.contentHash, monospace = true)
KeyValueRow("Latest version", if (detail.latestVersion > 0) "v${detail.latestVersion}" else "")
KeyValueRow("Version created", detail.versionCreatedAt)
KeyValueRow("Pipeline created", detail.createdAt)
KeyValueRow("Pipeline updated", detail.updatedAt)
}
}
collapsibleSection(
title = "Versions",
key = "versions",
expanded = versionsExpanded,
onToggle = { versionsExpanded = !versionsExpanded },
) {
if (detail.versions.isEmpty()) {
item(key = "versions-empty") {
Text(
"No versions recorded.",
style = text.meta,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
} else {
items(detail.versions, key = { "version-${it.version}" }) { v ->
VersionRow(v, Modifier.padding(horizontal = 16.dp, vertical = 4.dp).animateItem())
}
}
}
}
}
}
if (detail.source.isNotBlank()) {
collapsibleSection(
title = "Source",
key = "source",
expanded = sourceExpanded,
onToggle = { sourceExpanded = !sourceExpanded },
/** The graph tab on its own: the full-height panel with its Fit/expand controls. */
@Composable
private fun PipelineGraphTab(detail: PipelineDetail, modifier: Modifier) {
val text = pipelinesText()
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "pipeline-graph") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
item(key = "source") {
Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp).animateItem()) {
Text(
text = detail.source,
fontFamily = FontFamily.Monospace,
style = text.mono,
modifier = Modifier.padding(12.dp),
)
}
}
Text(
"Pinch to zoom, drag to pan. Edges are labelled with their outcome; error* is the implicit fallback.",
style = text.meta,
)
WorkflowGraph(graph = detail.graph, modifier = Modifier.fillMaxWidth())
}
}
}
}
@Composable
private fun PipelineSourceTab(source: String, wide: Boolean, modifier: Modifier) {
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "pipeline-source") {
CodeBlock("Source", source, Modifier.padding(horizontal = 16.dp))
}
}
}
@@ -11,14 +11,12 @@ import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -28,9 +26,7 @@ import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Replay
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -42,6 +38,7 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
@@ -53,6 +50,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.delay
import kotlinx.serialization.json.JsonElement
import net.awan.pipelines.data.ErrorMessages
import net.awan.pipelines.data.protocol.FileChange
import net.awan.pipelines.data.protocol.NotificationReceipt
@@ -62,15 +60,21 @@ import net.awan.pipelines.data.protocol.RunStep
import net.awan.pipelines.data.protocol.SessionEvidence
import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.LoadState
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.DetailTabs
import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.KeyValueRow
import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.RunStatusIcon
import net.awan.pipelines.ui.components.StatusChip
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.components.runDetailTabs
import net.awan.pipelines.ui.components.runStateColor
import net.awan.pipelines.ui.components.runStateOf
import net.awan.pipelines.ui.displayMap
import net.awan.pipelines.ui.displayText
import net.awan.pipelines.ui.formatDuration
import net.awan.pipelines.ui.graph.WorkflowGraph
import net.awan.pipelines.ui.theme.pipelinesText
@@ -83,12 +87,16 @@ fun RunDetailScreen(
runId: Long,
onBack: () -> Unit,
modifier: Modifier = Modifier,
wide: Boolean = false,
) {
val state by vm.runDetail.collectAsStateWithLifecycle()
val evidenceState by vm.evidence.collectAsStateWithLifecycle()
var confirmCancel by remember { mutableStateOf(false) }
var confirmRetry by remember { mutableStateOf(false) }
var actionError by remember { mutableStateOf<String?>(null) }
// Selected tab survives recomposition and configuration changes; the first
// tab (Summary) is the default.
var selectedTab by rememberSaveable { mutableIntStateOf(0) }
LaunchedEffect(runId) {
// Scope evidence to this run: drop the previous run's records, then fetch
@@ -146,12 +154,40 @@ fun RunDetailScreen(
modifier = Modifier.padding(padding),
)
run == null -> LoadingState("Loading run…", Modifier.padding(padding))
else -> RunDetailContent(
run = run,
onLoadEvidence = { vm.loadEvidence(runId) },
evidenceState = evidenceState,
else -> DetailTabs(
tabs = runDetailTabs,
selectedIndex = selectedTab,
onSelect = { selectedTab = it },
wide = wide,
modifier = Modifier.padding(padding),
)
) { tab, contentModifier ->
// Only the selected tab's content composes (one scroll container each).
when (tab.key) {
"summary" -> RunSummaryTab(run, wide, contentModifier)
"graph" -> RunGraphTab(run, contentModifier)
"input" -> RunFieldSectionsTab(
emptyMessage = "No input recorded.",
keyPrefix = "input",
entries = run.input.orEmpty().toList(),
wide = wide,
modifier = contentModifier,
)
"output" -> RunFieldSectionsTab(
emptyMessage = "No output recorded.",
keyPrefix = "output",
entries = run.output.orEmpty().toList(),
wide = wide,
modifier = contentModifier,
)
"evidence" -> RunEvidenceTab(
evidenceState = evidenceState,
onLoadEvidence = { vm.loadEvidence(runId) },
wide = wide,
modifier = contentModifier,
)
else -> RunStepsTab(run, wide, contentModifier)
}
}
}
}
@@ -214,126 +250,165 @@ private fun ConfirmDialog(
)
}
@OptIn(ExperimentalFoundationApi::class)
/**
* Summary carries everything the old page header carried: the run name, a
* status/outcome/executing chip row, recorded + completed visits, the pipeline
* id/version, current stage, workspace, content hash, start/finish/duration and
* the failure diagnostic.
*/
@Composable
private fun RunDetailContent(
run: RunDetail,
onLoadEvidence: () -> Unit,
evidenceState: LoadState<List<SessionEvidence>>,
modifier: Modifier = Modifier,
) {
private fun RunSummaryTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
val text = pipelinesText()
val runState = remember(run.id, run.steps) { RunGraphState.from(run) }
// Per-section expanded state; defaults to expanded and remembered across
// recomposition and configuration changes.
var graphExpanded by rememberSaveable { mutableStateOf(true) }
var inputExpanded by rememberSaveable { mutableStateOf(true) }
var outputExpanded by rememberSaveable { mutableStateOf(true) }
var evidenceExpanded by rememberSaveable { mutableStateOf(true) }
var stepsExpanded by rememberSaveable { mutableStateOf(true) }
val input = run.input.displayMap()
val output = run.output.displayMap()
val evidence = evidenceState.data.orEmpty()
LazyColumn(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "summary") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(run.name, style = text.screenTitle)
Text(
buildString {
append("run ${run.id} · ${run.status.ifBlank { "unknown" }}")
if (run.outcome.isNotBlank()) append(" · outcome ${run.outcome}")
if (run.executing) append(" · executing")
// Same vocabulary as the runs list and the server's own
// tui/results.go / run_graph.go: completed vs recorded visits.
append(" · ${visitCount(run.steps.size, "recorded")}")
append(" · ${visitCount(run.completedSteps, "completed")}")
},
style = text.meta,
)
KeyValueRow("Pipeline", "id ${run.pipelineId} · v${run.version}")
KeyValueRow("Workspace", run.workspace)
KeyValueRow("Content hash", run.contentHash, monospace = true)
KeyValueRow("Started", run.createdAt)
KeyValueRow("Finished", run.finishedAt)
KeyValueRow("Duration", formatDuration(run.createdAt, run.finishedAt) ?: "")
if (run.diagnostic.isNotBlank()) {
Text(run.diagnostic, color = MaterialTheme.colorScheme.error, style = text.body)
}
}
}
collapsibleSection(
title = "Run graph",
key = "graph",
expanded = graphExpanded,
onToggle = { graphExpanded = !graphExpanded },
val state = runStateOf(run.status)
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "graph") {
item(key = "run-summary") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
if (run.graph.stages.isEmpty()) {
Text("This server did not include the run graph.", style = text.meta)
} else {
Text(
"Executed stages and routes are highlighted; the rest are dimmed. Pinch to zoom, drag to pan.",
style = text.meta,
)
WorkflowGraph(
graph = run.graph,
modifier = Modifier.fillMaxWidth(),
runState = runState,
selectedStage = runState.currentStage,
)
Text(run.name, style = text.screenTitle)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
StatusChip(label = run.status.ifBlank { state.label }, state = state)
if (run.outcome.isNotBlank()) Text("outcome ${run.outcome}", style = text.meta)
if (run.executing) Text("executing", style = text.meta)
}
Text(
buildString {
append("run ${run.id}")
// Same vocabulary as the runs list and the server's own
// tui/results.go / run_graph.go: completed vs recorded visits.
append(" · ${visitCount(run.steps.size, "recorded")}")
append(" · ${visitCount(run.completedSteps, "completed")}")
},
style = text.meta,
)
KeyValueRow("Pipeline", "id ${run.pipelineId} · v${run.version}")
KeyValueRow("Stage", run.currentStage)
KeyValueRow("Workspace", run.workspace)
KeyValueRow("Content hash", run.contentHash, monospace = true)
KeyValueRow("Started", run.createdAt)
KeyValueRow("Finished", run.finishedAt)
KeyValueRow("Duration", formatDuration(run.createdAt, run.finishedAt) ?: "")
KeyValueRow("Retry of", if (run.retryOf > 0) "run ${run.retryOf}" else "")
CodeBlock("Diagnostic", run.diagnostic, Modifier.padding(top = 8.dp))
}
}
}
}
}
if (input.isNotBlank()) {
collapsibleSection(
title = "Input",
key = "input",
expanded = inputExpanded,
onToggle = { inputExpanded = !inputExpanded },
/**
* The graph tab on its own: the full-height [WorkflowGraph] panel with its Fit
* and expand controls, given the whole content area. The tab's single LazyColumn
* is the scroll container, so an expanded panel scrolls instead of clipping.
*/
@Composable
private fun RunGraphTab(run: RunDetail, modifier: Modifier) {
val text = pipelinesText()
val runState = remember(run.id, run.steps) { RunGraphState.from(run) }
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "run-graph") {
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
item(key = "input") {
Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp).animateItem()) {
Text(input, style = text.mono, modifier = Modifier.padding(12.dp))
if (run.graph.stages.isEmpty()) {
Text("This server did not include the run graph.", style = text.meta)
} else {
Text(
"Executed stages and routes are highlighted; the rest are dimmed. Pinch to zoom, drag to pan.",
style = text.meta,
)
WorkflowGraph(
graph = run.graph,
modifier = Modifier.fillMaxWidth(),
runState = runState,
selectedStage = runState.currentStage,
)
}
}
}
}
}
/**
* One inner collapsible section per input/output result field, each holding the
* field's value as a themed [CodeBlock]. Grouping is derived once per data
* change with `remember`, and the expansion state is remembered/saved.
*/
@Composable
private fun RunFieldSectionsTab(
emptyMessage: String,
keyPrefix: String,
entries: List<Pair<String, JsonElement>>,
wide: Boolean,
modifier: Modifier,
) {
val text = pipelinesText()
val expansion = rememberSectionExpansion(entries)
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
if (entries.isEmpty()) {
item(key = "$keyPrefix-empty") {
Text(
emptyMessage,
style = text.meta,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
} else {
entries.forEach { (key, value) ->
val label = key.ifBlank { keyPrefix }
val sectionKey = "$keyPrefix-$key"
collapsibleSection(
title = label,
key = sectionKey,
expanded = expansion.isExpanded(sectionKey),
onToggle = { expansion.toggle(sectionKey) },
) {
item(key = "$sectionKey-body") {
CodeBlock(
label = label,
text = value.displayText(),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
)
}
}
}
}
}
}
}
if (output.isNotBlank()) {
collapsibleSection(
title = "Output",
key = "output",
expanded = outputExpanded,
onToggle = { outputExpanded = !outputExpanded },
) {
item(key = "output") {
Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp).animateItem()) {
Text(output, style = text.mono, modifier = Modifier.padding(12.dp))
}
}
}
}
collapsibleSection(
title = "Session evidence",
key = "evidence",
expanded = evidenceExpanded,
onToggle = { evidenceExpanded = !evidenceExpanded },
/** One inner collapsible section per session-evidence entry (data block inside). */
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun RunEvidenceTab(
evidenceState: LoadState<List<SessionEvidence>>,
onLoadEvidence: () -> Unit,
wide: Boolean,
modifier: Modifier,
) {
val text = pipelinesText()
val evidence = evidenceState.data.orEmpty()
val expansion = rememberSectionExpansion(evidence)
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
item(key = "evidence-reload") {
Row(
@@ -368,17 +443,39 @@ private fun RunDetailContent(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
else -> items(evidence, key = { "evidence-${it.sequence}-${it.sessionId}" }) { record ->
EvidenceCard(record, Modifier.padding(horizontal = 16.dp, vertical = 4.dp).animateItem())
else -> evidence.forEach { record ->
val sectionKey = "evidence-${record.sequence}-${record.sessionId}"
collapsibleSection(
title = "Evidence ${record.sequence}",
key = sectionKey,
expanded = expansion.isExpanded(sectionKey),
onToggle = { expansion.toggle(sectionKey) },
) {
item(key = "$sectionKey-body") {
EvidenceDetails(
record,
Modifier.padding(horizontal = 16.dp, vertical = 4.dp).animateItem(),
)
}
}
}
}
}
}
}
collapsibleSection(
title = "Steps",
key = "steps",
expanded = stepsExpanded,
onToggle = { stepsExpanded = !stepsExpanded },
/** One inner collapsible section per stage group, each listing that stage's steps. */
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun RunStepsTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
val text = pipelinesText()
// Grouped once per step-list change, not per recomposition.
val groups = remember(run.steps) { run.steps.groupBy { it.stage } }
val expansion = rememberSectionExpansion(run.steps)
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = 16.dp),
) {
if (run.steps.isEmpty()) {
item(key = "steps-empty") {
@@ -389,15 +486,25 @@ private fun RunDetailContent(
)
}
} else {
itemsIndexed(
run.steps,
key = { _, step -> "step-${step.sequence}-${step.stage}" },
) { index, step ->
StepCard(
step = step,
isLast = index == run.steps.lastIndex,
modifier = Modifier.padding(horizontal = 16.dp).animateItem(),
)
groups.forEach { (stage, steps) ->
val sectionKey = "steps-$stage"
collapsibleSection(
title = stage.ifBlank { "Unnamed stage" },
key = sectionKey,
expanded = expansion.isExpanded(sectionKey),
onToggle = { expansion.toggle(sectionKey) },
) {
itemsIndexed(
steps,
key = { _, step -> "step-${step.sequence}-${step.stage}" },
) { index, step ->
StepCard(
step = step,
isLast = index == steps.lastIndex,
modifier = Modifier.padding(horizontal = 16.dp).animateItem(),
)
}
}
}
}
}
@@ -480,9 +587,7 @@ private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifi
}
if (step.target.isNotBlank()) Text("target ${step.target}", style = text.meta)
if (step.sessionId.isNotBlank()) Text("session ${step.sessionId}", style = text.mono)
if (step.diagnostic.isNotBlank()) {
Text(step.diagnostic, color = MaterialTheme.colorScheme.error, style = text.meta)
}
CodeBlock("Diagnostic", step.diagnostic, Modifier.padding(top = 4.dp))
// Evidence is collapsed by default so the timeline stays scannable.
Row(
@@ -501,18 +606,17 @@ private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifi
}
if (detailsExpanded) {
StepEvidence(step, text)
StepEvidence(step)
}
}
}
}
@Composable
private fun StepEvidence(step: RunStep, text: net.awan.pipelines.ui.theme.PipelinesTextStyles) {
val input = step.input.displayMap()
if (input.isNotBlank()) EvidenceBlock("input", input, text)
val output = step.output.displayMap()
if (output.isNotBlank()) EvidenceBlock("output", output, text)
private fun StepEvidence(step: RunStep) {
val text = pipelinesText()
CodeBlock("Input", step.input.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
CodeBlock("Output", step.output.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
step.fileChanges?.let { changes ->
Text(
"file changes: ${changes.status}" +
@@ -523,15 +627,7 @@ private fun StepEvidence(step: RunStep, text: net.awan.pipelines.ui.theme.Pipeli
changes.files.take(MAX_LISTED_FILES).forEach { file -> FileChangeRow(file, text) }
}
step.notifications.orEmpty().forEach { notification -> NotificationRow(notification, text) }
if (step.transcript.isNotBlank()) EvidenceBlock("transcript", step.transcript, text)
}
@Composable
private fun EvidenceBlock(label: String, value: String, text: net.awan.pipelines.ui.theme.PipelinesTextStyles) {
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(label, style = text.label)
Text(value, style = text.mono)
}
CodeBlock("Transcript", step.transcript, maxHeight = STEP_CODE_MAX_HEIGHT)
}
@Composable
@@ -553,25 +649,21 @@ private fun NotificationRow(receipt: NotificationReceipt, text: net.awan.pipelin
)
}
/** A session-evidence entry's fields plus its data/diagnostic code blocks. */
@Composable
private fun EvidenceCard(evidence: SessionEvidence, modifier: Modifier = Modifier) {
private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modifier) {
val text = pipelinesText()
Card(modifier.fillMaxWidth()) {
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text("Evidence ${evidence.sequence}", style = text.cardTitle)
if (evidence.sessionId.isNotBlank()) Text("session ${evidence.sessionId}", style = text.mono)
if (evidence.backend.isNotBlank()) Text("backend ${evidence.backend}", style = text.meta)
if (evidence.directory.isNotBlank()) Text("directory ${evidence.directory}", style = text.meta)
if (!evidence.diagnostic.isNullOrBlank()) {
Text(evidence.diagnostic, color = MaterialTheme.colorScheme.error, style = text.meta)
}
if (!evidence.data.isNullOrBlank()) {
HorizontalDivider()
Text(evidence.data, style = text.mono)
}
}
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(4.dp)) {
if (evidence.sessionId.isNotBlank()) Text("session ${evidence.sessionId}", style = text.mono)
if (evidence.backend.isNotBlank()) Text("backend ${evidence.backend}", style = text.meta)
if (evidence.directory.isNotBlank()) Text("directory ${evidence.directory}", style = text.meta)
CodeBlock("Diagnostic", evidence.diagnostic.orEmpty())
CodeBlock("Data", evidence.data.orEmpty())
}
}
private const val POLL_INTERVAL_MILLIS = 1_000L
private const val MAX_LISTED_FILES = 20
/** Step evidence blocks are shorter than a full-page block (they sit in a timeline). */
private val STEP_CODE_MAX_HEIGHT = 240.dp
@@ -0,0 +1,27 @@
package net.awan.pipelines.ui
import org.junit.Assert.assertEquals
import org.junit.Test
class WindowSizeTest {
@Test
fun narrowCoverDisplayIsSinglePane() {
// A foldable cover display / ordinary phone portrait.
assertEquals(false, isWideLayout(400))
assertEquals(false, isWideLayout(0))
assertEquals(false, isWideLayout(WIDE_LAYOUT_MIN_WIDTH_DP - 1))
}
@Test
fun breakpointExactlyIsWide() {
assertEquals(true, isWideLayout(WIDE_LAYOUT_MIN_WIDTH_DP))
assertEquals(true, isWideLayout(600))
}
@Test
fun wideInnerDisplayIsTwoPane() {
assertEquals(true, isWideLayout(800))
assertEquals(true, isWideLayout(1200))
}
}
@@ -0,0 +1,40 @@
package net.awan.pipelines.ui.components
import org.junit.Assert.assertEquals
import org.junit.Test
class DetailTabsTest {
@Test
fun runDetailTabsStartWithSummaryAndCoverEverySection() {
assertEquals("summary", runDetailTabs.first().key)
assertEquals(
listOf("summary", "graph", "input", "output", "evidence", "steps"),
runDetailTabs.map { it.key },
)
assertEquals(listOf("Summary", "Graph", "Input", "Output", "Evidence", "Steps"), runDetailTabs.map { it.title })
}
@Test
fun pipelineDetailTabsStartWithSummaryAndKeepVersionsInSummary() {
assertEquals("summary", pipelineDetailTabs.first().key)
assertEquals(listOf("summary", "graph", "source"), pipelineDetailTabs.map { it.key })
// The version list is not a tab of its own any more.
assertEquals(false, pipelineDetailTabs.any { it.key == "versions" })
}
@Test
fun clampTabIndexKeepsAValidSelection() {
assertEquals(0, clampTabIndex(0, 6))
assertEquals(5, clampTabIndex(5, 6))
assertEquals(3, clampTabIndex(3, 6))
}
@Test
fun clampTabIndexClampsNegativeAndOutOfRangeSelections() {
// A stale saved index or a shrunken tab list must never index out of bounds.
assertEquals(0, clampTabIndex(-4, 3))
assertEquals(2, clampTabIndex(99, 3))
assertEquals(0, clampTabIndex(1, 0))
}
}