Cross-fade loading, empty and error states in data-backed panes
A data-backed pane swapped its loading spinner, empty message, error message and content with a plain `when`, so content flashed from empty to full and empty/error states popped. Introduce a shared presentation model in ui/components/States.kt: - `LoadPhase` (Loading, Error(message), Empty(message), Content), with message-carrying phases capturing their text at classification so a fading-out branch never recomposes against cleared error/filter state. - `listLoadPhase(loading, error, hasData, emptyMessage)` and `detailLoadPhase(error, hasData)` pure classifiers preserving the existing precedence (failed load with no data, then loading, then empty, else content; stale data keeps the pane on content). - `StateCrossfade(phase)` wraps the branch in a `Crossfade` using the existing `MotionStandard` token; both branches share one box so the resting layout is unchanged and the outgoing phase fades under the incoming one. Apply to PipelineListScreen, RunHistoryScreen, PipelineDetailScreen and RunDetailScreen. Detail panes render the fading-out branch from the last non-null item. The Runs pane keeps its inline empty/error line inside the list, now fading through animateListItem(). Add LoadPhaseTest covering the classifiers and captured messages, and document the change and evidence in android/README.md.
This commit is contained in:
@@ -2086,3 +2086,86 @@ Not verified in this pass: a narrow-window frame of the item animation; an item
|
||||
leaving a list (a run being deleted is not a client action), only the
|
||||
appear/move halves driven above.
|
||||
|
||||
|
||||
## Loading, empty and error states cross-fade (16 Oct 2026)
|
||||
|
||||
A data-backed pane used to swap its loading spinner, empty message, error message
|
||||
and content with a plain `when`, so content flashed from empty to full and an
|
||||
empty or error state popped. Every pane now swaps through one shared
|
||||
`StateCrossfade` (`ui/components/States.kt`) — a `Crossfade` on the pane's
|
||||
classified state using the already-named `MotionStandard` token. No dependency,
|
||||
geometry token or literal was added.
|
||||
|
||||
- **`LoadPhase`** is the mutually exclusive presentation state: `Loading`,
|
||||
`Error(message)`, `Empty(message)`, `Content`. The message-carrying phases keep
|
||||
the text they were classified with, so the branch that is fading out is never
|
||||
recomposed against a since-cleared error or a since-changed filter.
|
||||
- **`listLoadPhase(loading, error, hasData, emptyMessage)`** and
|
||||
**`detailLoadPhase(error, hasData)`** are the pure classifiers. A list pane
|
||||
reports a failed load with no data, then a load with no data, then empty, else
|
||||
content; a detail pane has no empty state, so data present is content, then a
|
||||
reported error, then loading. Stale data keeps a pane on `Content` (the screen
|
||||
shows the error inline), exactly as before — only the presentation changed.
|
||||
- **`StateCrossfade(phase)`** wraps the branch in a `Crossfade` with
|
||||
`MotionStandard.spec()`; both branches are laid out in one box, so the resting
|
||||
layout is exactly the branch's own layout and the outgoing phase fades under
|
||||
the incoming one. Applied to `PipelineListScreen`, `RunHistoryScreen`,
|
||||
`PipelineDetailScreen` and `RunDetailScreen`. `LoadingState`, `ErrorState` and
|
||||
`EmptyState` themselves are unchanged.
|
||||
- The detail panes render the fading-out branch from the last non-null item
|
||||
(`rememberPaneContent`, the same helper the closing pane uses), so selecting
|
||||
another pipeline/run fades the old content out instead of blanking it.
|
||||
- The Runs pane has no pane-level empty state — an empty list keeps its usage
|
||||
block and sticky headers and shows its `No runs have been recorded yet.` line
|
||||
inside the list, where it now fades in/out through the existing
|
||||
`animateListItem()`, as does its inline error line.
|
||||
|
||||
Evidence (macOS, JDK 17 from Homebrew `openjdk@17`, Gradle 9.7.1,
|
||||
`ANDROID_HOME=~/Library/Android/sdk`, `--offline`):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --console=plain` →
|
||||
`BUILD SUCCESSFUL`; `--rerun-tasks` re-ran all 23 result XMLs to **184 tests, 0
|
||||
failures, 0 errors, 0 skipped** (up from 174; the new `LoadPhaseTest` adds 10
|
||||
pure cases for the classifiers and the message-carrying phases).
|
||||
`app/build/outputs/apk/debug/app-debug.apk` is 17,913,089 bytes, sha256
|
||||
`e99bb970…`.
|
||||
- On `emulator-5554` only (fold AVD, 2076x2152 / 390dpi; **never** the attached
|
||||
Pixel, never `emulator-5556`), against the live server, each frame captured and
|
||||
validated with `scripts/capture_png.sh -s emulator-5554`, `animator_duration_scale`
|
||||
used only to slow the capture:
|
||||
- **Loading → content** at `animator_duration_scale 10`
|
||||
(`load-to-content-10x.mp4`, `load-to-content-10x-sheet.png`): selecting a
|
||||
pipeline shows `Loading pipeline…` and the summary then fades in;
|
||||
`load-to-content-10x-overlap.png` freezes the cross-fade with the loading text
|
||||
(`…ding pip…`) and the dimmed summary visible together, instead of a flash.
|
||||
- **Empty appearing and going away** at scale 10
|
||||
(`empty-appear-disappear-10x-sheet.png`): typing `zzz` into the pipelines
|
||||
search makes `No pipelines match "zzz".` fade in, and clearing it fades the
|
||||
list back.
|
||||
- **Error → content** at scale 10 (`error-to-content-recovery-10x-sheet.png`):
|
||||
with the connection down the Runs pane showed the error state; after the
|
||||
connection returned, pressing Retry fades the error out and the loaded runs
|
||||
(usage block, day groups) in.
|
||||
- **Animations disabled** (`animator_duration_scale 0`): `disabled-empty-sheet.png`
|
||||
(same type/clear) and `disabled-content-sheet.png` (open a pipeline) are each
|
||||
fully settled on every frame — no ghosted or half-placed state, i.e. the swap
|
||||
is instant with no special case.
|
||||
- **Resting layout**: a settled Pipelines list captured at scale 1 and at scale
|
||||
0 is pixel-identical (`captures/imgdiff.py` → `([0.0, 0.0, 0.0], 0.0)`), so the
|
||||
cross-fade never alters the settled layout.
|
||||
- `adb -s emulator-5554 logcat -d` held 0 `FATAL EXCEPTION` / 0
|
||||
`E AndroidRuntime` lines; `animator_duration_scale` was left at 1; no run was
|
||||
started from the app.
|
||||
- **APK publish.** `app-debug.apk` copied to
|
||||
`~/.local/share/pipelines/data/artifacts/106/1/pipelines-debug-wip-934994d.apk`
|
||||
(`934994d` = `git rev-parse --short HEAD`; the working tree is uncommitted WIP on
|
||||
top of it), sha256 `e99bb970…`. `curl
|
||||
http://10.0.0.75:8080/artifacts/106/1/pipelines-debug-wip-934994d.apk` returned
|
||||
`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 17913089`, and a streamed `GET | shasum -a 256` returned the
|
||||
same `e99bb970…` (`10.0.0.249` served it too; at 17.1 MiB it exceeds the 8 MiB
|
||||
per-file inventory cap, so it is served by direct URL only).
|
||||
|
||||
Not verified in this pass: a narrow-window frame (the fold inner display is
|
||||
851dp wide); the error state's fade-in from loading (the disconnected load failed
|
||||
before a loading frame could be drawn, only its fade-out was captured).
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -65,6 +66,88 @@ fun EmptyState(message: String, modifier: Modifier = Modifier) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The mutually exclusive presentation states of a data-backed pane: a load with
|
||||
* no data yet ([Loading]), a failed load with no data ([Error]), loaded-but-
|
||||
* nothing-to-show ([Empty]) and loaded content ([Content]).
|
||||
*
|
||||
* Both message-carrying states and [Empty] capture the text they are rendered
|
||||
* with when the state is classified and never read a live value, so the branch
|
||||
* that is fading out cannot be recomposed against a since-cleared error or a
|
||||
* since-changed filter. [StateCrossfade] animates between these and a pane is in
|
||||
* exactly one at a time.
|
||||
*/
|
||||
sealed interface LoadPhase {
|
||||
/** A load is in flight and there is nothing to show yet. */
|
||||
data object Loading : LoadPhase
|
||||
|
||||
/** The load failed and there is no data to fall back to. */
|
||||
data class Error(val message: String) : LoadPhase
|
||||
|
||||
/** The load succeeded but there is nothing to show; [message] explains it. */
|
||||
data class Empty(val message: String) : LoadPhase
|
||||
|
||||
/** The loaded content. */
|
||||
data object Content : LoadPhase
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies a list pane's [LoadPhase] from its load signals. A failed load with
|
||||
* no data wins, then a load with no data, then an empty result; anything else is
|
||||
* [LoadPhase.Content]. [emptyMessage] is non-null exactly when the pane is empty
|
||||
* and is the text to show, captured so a fading-out empty branch never reads a
|
||||
* changed query.
|
||||
*
|
||||
* When stale data is present neither loading nor an error replaces it: the
|
||||
* screen keeps showing the data and surfaces the error inline, so [hasData]
|
||||
* suppresses both.
|
||||
*/
|
||||
fun listLoadPhase(
|
||||
loading: Boolean,
|
||||
error: String?,
|
||||
hasData: Boolean,
|
||||
emptyMessage: String?,
|
||||
): LoadPhase = when {
|
||||
error != null && !hasData -> LoadPhase.Error(error)
|
||||
loading && !hasData -> LoadPhase.Loading
|
||||
emptyMessage != null -> LoadPhase.Empty(emptyMessage)
|
||||
else -> LoadPhase.Content
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies a detail pane's [LoadPhase]. There is no empty state — a detail with
|
||||
* no data is either an error or still loading — so data present means [Content],
|
||||
* then a reported error, then [LoadPhase.Loading].
|
||||
*/
|
||||
fun detailLoadPhase(error: String?, hasData: Boolean): LoadPhase = when {
|
||||
hasData -> LoadPhase.Content
|
||||
error != null -> LoadPhase.Error(error)
|
||||
else -> LoadPhase.Loading
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross-fades a pane between its [LoadPhase] branches with the shared
|
||||
* [MotionStandard] token. Both branches are laid out in the same box, so the
|
||||
* resting layout is exactly the branch's own layout while the outgoing phase
|
||||
* fades out under the incoming one: loading never flashes into content and an
|
||||
* empty or error state fades in and out rather than popping. With system
|
||||
* animations disabled Compose maps the platform animator duration scale onto the
|
||||
* spec, so the swap is instant.
|
||||
*/
|
||||
@Composable
|
||||
fun StateCrossfade(
|
||||
phase: LoadPhase,
|
||||
modifier: Modifier = Modifier,
|
||||
content: @Composable (LoadPhase) -> Unit,
|
||||
) {
|
||||
Crossfade(
|
||||
targetState = phase,
|
||||
animationSpec = MotionStandard.spec(),
|
||||
modifier = modifier,
|
||||
label = "load-phase",
|
||||
) { content(it) }
|
||||
}
|
||||
|
||||
/** Renders a labelled key/value row used across detail screens. */
|
||||
@Composable
|
||||
fun KeyValueRow(
|
||||
|
||||
@@ -53,13 +53,17 @@ 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.LoadPhase
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.StateCrossfade
|
||||
import net.awan.pipelines.ui.components.animateListItem
|
||||
import net.awan.pipelines.ui.components.paneSafeArea
|
||||
import net.awan.pipelines.ui.components.collapsibleSection
|
||||
import net.awan.pipelines.ui.components.copyText
|
||||
import net.awan.pipelines.ui.components.detailLoadPhase
|
||||
import net.awan.pipelines.ui.components.pipelineDetailTabs
|
||||
import net.awan.pipelines.ui.components.rememberPaneContent
|
||||
import net.awan.pipelines.ui.components.rememberSectionExpansion
|
||||
import net.awan.pipelines.ui.graph.StageFieldRow
|
||||
import net.awan.pipelines.ui.graph.WorkflowGraph
|
||||
@@ -89,6 +93,11 @@ fun PipelineDetailScreen(
|
||||
|
||||
val detail = state.data?.takeIf { it.id == pipelineId }
|
||||
|
||||
// The cross-fading content branch renders the last non-null detail, so
|
||||
// switching to another pipeline (which nulls the id-filtered detail) fades
|
||||
// the old content out instead of blanking it.
|
||||
val shownDetail = rememberPaneContent(detail)
|
||||
|
||||
// A covered pane shows its compact identity only; the tab rail and section
|
||||
// body must never be drawn squeezed into the peek strip.
|
||||
if (covered) {
|
||||
@@ -123,29 +132,36 @@ fun PipelineDetailScreen(
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
when {
|
||||
detail == null && state.error != null -> ErrorState(
|
||||
state.error!!,
|
||||
onRetry = { vm.loadPipeline(pipelineId, version) },
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
detail == null -> LoadingState("Loading pipeline…", Modifier.padding(padding))
|
||||
else -> DetailTabs(
|
||||
tabs = pipelineDetailTabs,
|
||||
selectedIndex = selectedSection,
|
||||
onSelect = onSelectSection,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> PipelineSummaryTab(detail, wide, contentModifier)
|
||||
"graph" -> PipelineGraphTab(
|
||||
detail = detail,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
else -> PipelineSourceTab(detail, contentModifier)
|
||||
StateCrossfade(
|
||||
phase = detailLoadPhase(state.error, hasData = detail != null),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) { phase ->
|
||||
when (phase) {
|
||||
is LoadPhase.Error -> ErrorState(
|
||||
phase.message,
|
||||
onRetry = { vm.loadPipeline(pipelineId, version) },
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
LoadPhase.Loading -> LoadingState("Loading pipeline…", Modifier.padding(padding))
|
||||
else -> if (shownDetail != null) {
|
||||
DetailTabs(
|
||||
tabs = pipelineDetailTabs,
|
||||
selectedIndex = selectedSection,
|
||||
onSelect = onSelectSection,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> PipelineSummaryTab(shownDetail, wide, contentModifier)
|
||||
"graph" -> PipelineGraphTab(
|
||||
detail = shownDetail,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
else -> PipelineSourceTab(shownDetail, contentModifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,12 @@ import net.awan.pipelines.ui.AppViewModel
|
||||
import net.awan.pipelines.ui.components.EmptyState
|
||||
import net.awan.pipelines.ui.components.ErrorState
|
||||
import net.awan.pipelines.ui.components.ListRow
|
||||
import net.awan.pipelines.ui.components.LoadPhase
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.StateCrossfade
|
||||
import net.awan.pipelines.ui.components.animateListItem
|
||||
import net.awan.pipelines.ui.components.listLoadPhase
|
||||
import net.awan.pipelines.ui.components.paneSafeArea
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
@@ -92,30 +95,36 @@ fun PipelineListScreen(
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
when {
|
||||
state.loading && state.data == null -> LoadingState("Loading pipelines…")
|
||||
state.error != null && state.data == null -> ErrorState(state.error!!, onRetry = vm::refreshPipelines)
|
||||
else -> {
|
||||
val items = (state.data ?: emptyList())
|
||||
.filter { it.name.contains(query, ignoreCase = true) }
|
||||
if (items.isEmpty()) {
|
||||
EmptyState(
|
||||
if (query.isBlank()) "No pipelines are defined on this server."
|
||||
else "No pipelines match \"$query\".",
|
||||
)
|
||||
val pipelines = (state.data ?: emptyList())
|
||||
.filter { it.name.contains(query, ignoreCase = true) }
|
||||
StateCrossfade(
|
||||
phase = listLoadPhase(
|
||||
loading = state.loading,
|
||||
error = state.error,
|
||||
hasData = state.data != null,
|
||||
emptyMessage = if (pipelines.isEmpty()) {
|
||||
if (query.isBlank()) "No pipelines are defined on this server."
|
||||
else "No pipelines match \"$query\"."
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(vertical = 8.dp),
|
||||
) {
|
||||
items(items, key = { it.id }) { pipeline ->
|
||||
PipelineRow(
|
||||
pipeline = pipeline,
|
||||
selected = pipeline.id == selectedId,
|
||||
onClick = { onOpen(pipeline.id, pipeline.version) },
|
||||
modifier = animateListItem(),
|
||||
)
|
||||
}
|
||||
null
|
||||
},
|
||||
),
|
||||
) { phase ->
|
||||
when (phase) {
|
||||
LoadPhase.Loading -> LoadingState("Loading pipelines…")
|
||||
is LoadPhase.Error -> ErrorState(phase.message, onRetry = vm::refreshPipelines)
|
||||
is LoadPhase.Empty -> EmptyState(phase.message)
|
||||
LoadPhase.Content -> LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(vertical = 8.dp),
|
||||
) {
|
||||
items(pipelines, key = { it.id }) { pipeline ->
|
||||
PipelineRow(
|
||||
pipeline = pipeline,
|
||||
selected = pipeline.id == selectedId,
|
||||
onClick = { onOpen(pipeline.id, pipeline.version) },
|
||||
modifier = animateListItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,14 +57,18 @@ 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.LoadPhase
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.StateCrossfade
|
||||
import net.awan.pipelines.ui.components.animateListItem
|
||||
import net.awan.pipelines.ui.components.paneSafeArea
|
||||
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.clampTabIndex
|
||||
import net.awan.pipelines.ui.components.detailLoadPhase
|
||||
import net.awan.pipelines.ui.components.rememberPaneContent
|
||||
import net.awan.pipelines.ui.components.rememberSectionExpansion
|
||||
import net.awan.pipelines.ui.components.runDetailTabs
|
||||
import net.awan.pipelines.ui.components.runStateOf
|
||||
@@ -116,6 +120,13 @@ fun RunDetailScreen(
|
||||
val run = state.data?.takeIf { it.id == runId }
|
||||
val executing = run?.executing == true
|
||||
|
||||
// The cross-fading content branch renders the last non-null run, so
|
||||
// switching to another run (which nulls the id-filtered run) fades the old
|
||||
// content out instead of blanking it. The artifact groups are derived from
|
||||
// the same snapshot, so the outgoing grid keeps its cells; the selection is
|
||||
// reseeded per run id, so a stale candidate set is never selectable.
|
||||
val shownRun = rememberPaneContent(run)
|
||||
|
||||
// Bounded polling: only while the run is executing, stopped on terminal status.
|
||||
LaunchedEffect(runId, executing) {
|
||||
if (executing) {
|
||||
@@ -128,7 +139,7 @@ fun RunDetailScreen(
|
||||
|
||||
// Aggregated once per step-list change; it drives the grid and the
|
||||
// selection's copy/share actions, never recomputed per recomposition.
|
||||
val artifactGroups = remember(run?.steps) { runArtifactGroups(run?.steps.orEmpty()) }
|
||||
val artifactGroups = remember(shownRun?.steps) { runArtifactGroups(shownRun?.steps.orEmpty()) }
|
||||
val candidateArtifacts = remember(artifactGroups) {
|
||||
artifactGroups.flatMap { it.artifacts }.distinctBy { it.url }
|
||||
}
|
||||
@@ -182,65 +193,70 @@ fun RunDetailScreen(
|
||||
)
|
||||
},
|
||||
) { selection, onSelectionChange, padding ->
|
||||
when {
|
||||
run == null && state.error != null -> ErrorState(
|
||||
state.error!!,
|
||||
onRetry = { vm.loadRun(runId) },
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
run == null -> LoadingState("Loading run…", Modifier.padding(padding))
|
||||
else -> {
|
||||
DetailTabs(
|
||||
tabs = runDetailTabs,
|
||||
selectedIndex = selectedSection,
|
||||
onSelect = onSelectSection,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> RunSummaryTab(
|
||||
run = run,
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = vm::fetchArtifactBytes,
|
||||
artifactGroups = artifactGroups,
|
||||
selection = selection,
|
||||
onSelectionChange = onSelectionChange,
|
||||
)
|
||||
"graph" -> RunGraphTab(
|
||||
run = run,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
"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,
|
||||
steps = run.steps,
|
||||
onLoadEvidence = { vm.loadEvidence(runId) },
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
)
|
||||
else -> RunTimelineTab(
|
||||
run = run,
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
StateCrossfade(
|
||||
phase = detailLoadPhase(state.error, hasData = run != null),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) { phase ->
|
||||
when (phase) {
|
||||
is LoadPhase.Error -> ErrorState(
|
||||
phase.message,
|
||||
onRetry = { vm.loadRun(runId) },
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
LoadPhase.Loading -> LoadingState("Loading run…", Modifier.padding(padding))
|
||||
else -> if (shownRun != null) {
|
||||
DetailTabs(
|
||||
tabs = runDetailTabs,
|
||||
selectedIndex = selectedSection,
|
||||
onSelect = onSelectSection,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(padding).fillMaxSize(),
|
||||
) { tab, contentModifier ->
|
||||
// Only the selected section's content is composed at rest.
|
||||
when (tab.key) {
|
||||
"summary" -> RunSummaryTab(
|
||||
run = shownRun,
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = vm::fetchArtifactBytes,
|
||||
artifactGroups = artifactGroups,
|
||||
selection = selection,
|
||||
onSelectionChange = onSelectionChange,
|
||||
)
|
||||
"graph" -> RunGraphTab(
|
||||
run = shownRun,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
"input" -> RunFieldSectionsTab(
|
||||
emptyMessage = "No input recorded.",
|
||||
keyPrefix = "input",
|
||||
entries = shownRun.input.orEmpty().toList(),
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
)
|
||||
"output" -> RunFieldSectionsTab(
|
||||
emptyMessage = "No output recorded.",
|
||||
keyPrefix = "output",
|
||||
entries = shownRun.output.orEmpty().toList(),
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
)
|
||||
"evidence" -> RunEvidenceTab(
|
||||
evidenceState = evidenceState,
|
||||
steps = shownRun.steps,
|
||||
onLoadEvidence = { vm.loadEvidence(runId) },
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
)
|
||||
else -> RunTimelineTab(
|
||||
run = shownRun,
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
onStageTap = onOpenStage,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,12 @@ import net.awan.pipelines.ui.components.RunStatusChip
|
||||
import net.awan.pipelines.ui.components.RunStatusIcon
|
||||
import net.awan.pipelines.ui.components.ErrorState
|
||||
import net.awan.pipelines.ui.components.ListRow
|
||||
import net.awan.pipelines.ui.components.LoadPhase
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.StateCrossfade
|
||||
import net.awan.pipelines.ui.components.animateListItem
|
||||
import net.awan.pipelines.ui.components.listLoadPhase
|
||||
import net.awan.pipelines.ui.components.paneSafeArea
|
||||
import net.awan.pipelines.ui.components.runStateColor
|
||||
import net.awan.pipelines.ui.components.runStateOf
|
||||
@@ -102,22 +105,35 @@ fun RunHistoryScreen(
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
when {
|
||||
state.loading && state.data == null -> LoadingState("Loading runs…", Modifier.padding(padding))
|
||||
state.error != null && state.data == null -> ErrorState(
|
||||
state.error!!,
|
||||
onRetry = vm::refreshRuns,
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
else -> RunHistoryContent(
|
||||
usage = state.data?.usage,
|
||||
runs = state.data?.runs.orEmpty(),
|
||||
filterPipelineId = filterPipelineId,
|
||||
selectedRunId = selectedRunId,
|
||||
StateCrossfade(
|
||||
phase = listLoadPhase(
|
||||
loading = state.loading,
|
||||
error = state.error,
|
||||
onOpenRun = onOpenRun,
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
hasData = state.data != null,
|
||||
// Runs has no pane-level empty state: an empty list keeps its
|
||||
// usage block and shows the "no runs" line inside the list, where
|
||||
// the item animation fades it in and out.
|
||||
emptyMessage = null,
|
||||
),
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) { phase ->
|
||||
when (phase) {
|
||||
LoadPhase.Loading -> LoadingState("Loading runs…", Modifier.padding(padding))
|
||||
is LoadPhase.Error -> ErrorState(
|
||||
phase.message,
|
||||
onRetry = vm::refreshRuns,
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
else -> RunHistoryContent(
|
||||
usage = state.data?.usage,
|
||||
runs = state.data?.runs.orEmpty(),
|
||||
filterPipelineId = filterPipelineId,
|
||||
selectedRunId = selectedRunId,
|
||||
error = state.error,
|
||||
onOpenRun = onOpenRun,
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +176,7 @@ private fun RunHistoryContent(
|
||||
"No runs have been recorded yet.",
|
||||
style = pipelinesText().body,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(24.dp),
|
||||
modifier = animateListItem(Modifier.padding(24.dp)),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -182,7 +198,7 @@ private fun RunHistoryContent(
|
||||
error,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = pipelinesText().body,
|
||||
modifier = Modifier.padding(16.dp),
|
||||
modifier = animateListItem(Modifier.padding(16.dp)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* The load-phase classification is pure, so the rules the cross-fading screens
|
||||
* rely on are checked here without a device: a failed load with no data wins over
|
||||
* loading, a load with no data is loading, an empty result is empty, and stale
|
||||
* data always keeps the pane on content (the screen shows the error inline
|
||||
* instead). Detail panes have no empty state, so absent data is an error or a
|
||||
* load. The message-carrying phases keep the text captured at classification.
|
||||
*/
|
||||
class LoadPhaseTest {
|
||||
|
||||
// ---- list panes ---------------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun listReportsAnErrorBeforeLoadingWhenThereIsNoData() {
|
||||
assertEquals(
|
||||
LoadPhase.Error("boom"),
|
||||
listLoadPhase(loading = true, error = "boom", hasData = false, emptyMessage = null),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listReportsLoadingWhenEmptyAndFailedAreBothAbsent() {
|
||||
assertEquals(
|
||||
LoadPhase.Loading,
|
||||
listLoadPhase(loading = true, error = null, hasData = false, emptyMessage = null),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listReportsEmptyWithItsCapturedMessage() {
|
||||
assertEquals(
|
||||
LoadPhase.Empty("No pipelines match \"x\"."),
|
||||
listLoadPhase(loading = false, error = null, hasData = true, emptyMessage = "No pipelines match \"x\"."),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listReportsContentWhenThereAreRows() {
|
||||
assertEquals(
|
||||
LoadPhase.Content,
|
||||
listLoadPhase(loading = false, error = null, hasData = true, emptyMessage = null),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listKeepsStaleDataOnContentDespiteLoadingOrError() {
|
||||
// A refresh keeps the data on screen and surfaces the error inline.
|
||||
assertEquals(
|
||||
LoadPhase.Content,
|
||||
listLoadPhase(loading = true, error = null, hasData = true, emptyMessage = null),
|
||||
)
|
||||
assertEquals(
|
||||
LoadPhase.Content,
|
||||
listLoadPhase(loading = false, error = "offline", hasData = true, emptyMessage = null),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithoutAnySignalStaysOnContent() {
|
||||
// A runs pane deliberately has no pane-level empty state, so its initial
|
||||
// no-data/no-error frame is content (the empty line lives in the list).
|
||||
assertEquals(
|
||||
LoadPhase.Content,
|
||||
listLoadPhase(loading = false, error = null, hasData = false, emptyMessage = null),
|
||||
)
|
||||
}
|
||||
|
||||
// ---- detail panes -------------------------------------------------------
|
||||
|
||||
@Test
|
||||
fun detailReportsContentWheneverDataIsPresent() {
|
||||
assertEquals(
|
||||
LoadPhase.Content,
|
||||
detailLoadPhase(error = "offline", hasData = true),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun detailReportsAnErrorWhenThereIsNoData() {
|
||||
assertEquals(
|
||||
LoadPhase.Error("boom"),
|
||||
detailLoadPhase(error = "boom", hasData = false),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun detailReportsLoadingWhenThereIsNoDataAndNoError() {
|
||||
assertEquals(
|
||||
LoadPhase.Loading,
|
||||
detailLoadPhase(error = null, hasData = false),
|
||||
)
|
||||
}
|
||||
|
||||
// ---- the phases themselves ---------------------------------------------
|
||||
|
||||
@Test
|
||||
fun messagePhasesCompareByTheirCapturedText() {
|
||||
assertEquals(LoadPhase.Error("a"), LoadPhase.Error("a"))
|
||||
assertEquals(LoadPhase.Empty("b"), LoadPhase.Empty("b"))
|
||||
assertEquals(LoadPhase.Loading, LoadPhase.Loading)
|
||||
assertEquals(LoadPhase.Content, LoadPhase.Content)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user