From e1c472089e800a196b71f27a580397a1ce594808 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 17:19:04 +0100 Subject: [PATCH 1/2] feat(app): run rows place the run, number, pipeline, duration, time and steps in their corners --- app/lib/features/runs/domain/run_models.dart | 45 ++++++ app/lib/features/runs/ui/runs_list.dart | 137 ++++++++++++++---- .../features/runs/ui/run_list_row_test.dart | 62 ++++++++ .../runs/ui/runs_list_widget_test.dart | 2 +- 4 files changed, 217 insertions(+), 29 deletions(-) create mode 100644 app/test/features/runs/ui/run_list_row_test.dart diff --git a/app/lib/features/runs/domain/run_models.dart b/app/lib/features/runs/domain/run_models.dart index 21906e85..b869a6b8 100644 --- a/app/lib/features/runs/domain/run_models.dart +++ b/app/lib/features/runs/domain/run_models.dart @@ -155,6 +155,51 @@ String runRowMetaText(JsonMap run, DateTime now) { return parts.join(' · '); } +/// The facts a run row lays out in its corners: when it ran, for how long and +/// how far it got. Absent facts are null, never invented. +typedef RunRowFacts = ({String? when, String? duration, String? progress}); + +RunRowFacts runRowFacts(JsonMap run, DateTime now) { + final created = '${run['created_at'] ?? ''}'; + final finished = '${run['finished_at'] ?? ''}'; + final start = formatLocalTimestamp(created); + final executing = run['executing'] == true; + String? when = start; + int? seconds; + if (executing) { + final instant = parseInstant(created); + if (instant != null) seconds = now.difference(instant).inSeconds; + } else { + seconds = durationSeconds(created, finished); + final end = parseInstant(finished)?.toLocal(); + final begin = parseInstant(created)?.toLocal(); + if (start != null && end != null && begin != null) { + // Same day: the end is just its time. + final sameDay = + end.year == begin.year && + end.month == begin.month && + end.day == begin.day; + final endText = sameDay + ? '${end.hour.toString().padLeft(2, '0')}:' + '${end.minute.toString().padLeft(2, '0')}' + : formatLocalTimestamp(finished); + when = '$start → $endText'; + } + } + final steps = run['completed_steps']; + final stage = '${run['current_stage'] ?? ''}'.trim(); + final progress = [ + if (steps is num && steps > 0) + steps == 1 ? '1 step' : '${steps.toInt()} steps', + if (executing && stage.isNotEmpty) 'at $stage', + ].join(' · '); + return ( + when: when, + duration: seconds == null ? null : formatDuration(seconds), + progress: progress.isEmpty ? null : progress, + ); +} + String runStatusLabel(JsonMap run) { final status = '${run['status'] ?? ''}'; if (!{'queued', 'running', 'waiting'}.contains(status)) { diff --git a/app/lib/features/runs/ui/runs_list.dart b/app/lib/features/runs/ui/runs_list.dart index 892b3bcf..e237d118 100644 --- a/app/lib/features/runs/ui/runs_list.dart +++ b/app/lib/features/runs/ui/runs_list.dart @@ -172,36 +172,117 @@ class RunsList extends StatelessWidget { ); Widget _runTile(BuildContext context, JsonMap run) { - final identity = runIdentity(run['title'], run['name']); final id = run['id']; - final title = identity.label.isEmpty ? 'Run $id' : identity.label; - // As the web's run row: the coloured status glyph leads (its tooltip and - // accessible name are the state word), then the run, then - // `pipeline · run N · local time · duration`. - final meta = [ - '${run['name'] ?? 'Pipeline unavailable'}', - runRowMetaText(run, DateTime.now()), - if (run['scheduled'] == true) 'Scheduled', - ].join(' · '); - final status = RunStatusIcon( - state: runStateOf(run['status']), - label: runStatusLabel(run), - ); - if (usesCupertinoHost(context)) { - return CupertinoListTile( - leading: status, - title: Text(title), - subtitle: Text(meta), - trailing: const CupertinoListTileChevron(), - onTap: id is num ? () => onSelected(id) : null, - ); - } - return ListTile( - leading: status, - title: Text(title), - subtitle: Text(meta), - trailing: const Icon(Icons.chevron_right), + return RunListRow( + run: run, + now: DateTime.now(), onTap: id is num ? () => onSelected(id) : null, ); } } + +/// One run in the list with its facts in the row's corners: the run and its +/// number on top, the pipeline and duration below, then when it ran and how +/// far it got. +class RunListRow extends StatelessWidget { + const RunListRow({ + super.key, + required this.run, + required this.now, + this.onTap, + }); + + final JsonMap run; + final DateTime now; + final VoidCallback? onTap; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final identity = runIdentity(run['title'], run['name']); + final id = run['id']; + final title = identity.label.isEmpty ? 'Run $id' : identity.label; + final facts = runRowFacts(run, now); + // A run without its own title is named by its pipeline, so the pipeline + // line does not repeat it. + final pipeline = identity.pipeline?.trim(); + final secondary = cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant; + final base = cupertino + ? CupertinoTheme.of(context).textTheme.textStyle + : Theme.of(context).textTheme.bodyMedium ?? const TextStyle(); + final titleStyle = base.copyWith(fontWeight: FontWeight.w600); + final small = base.copyWith( + color: secondary, + fontSize: (base.fontSize ?? 14) - 1, + ); + Widget line(String? start, String? end, TextStyle style, {Key? key}) => Row( + key: key, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Text( + start ?? '', + style: style, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + if (end != null) ...[ + const SizedBox(width: 12), + Text(end, style: style), + ], + ], + ); + final scheduled = run['scheduled'] == true; + final body = Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(top: 2, right: 12), + child: RunStatusIcon( + state: runStateOf(run['status']), + label: runStatusLabel(run), + ), + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + line(title, id == null ? null : '#$id', titleStyle), + const SizedBox(height: 2), + line( + [ + if (pipeline != null) + pipeline.isEmpty ? 'Pipeline unavailable' : pipeline, + if (scheduled) 'Scheduled', + ].join(' · '), + facts.duration, + small, + ), + line(facts.when, facts.progress, small), + ], + ), + ), + ], + ); + final padded = Padding( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + child: body, + ); + return Semantics( + button: onTap != null, + child: cupertino + ? CupertinoButton( + key: ValueKey('run-row-$id'), + padding: EdgeInsets.zero, + minimumSize: Size.zero, + pressedOpacity: 0.6, + onPressed: onTap, + child: DefaultTextStyle(style: base, child: padded), + ) + : InkWell(key: ValueKey('run-row-$id'), onTap: onTap, child: padded), + ); + } +} diff --git a/app/test/features/runs/ui/run_list_row_test.dart b/app/test/features/runs/ui/run_list_row_test.dart new file mode 100644 index 00000000..c30a8f89 --- /dev/null +++ b/app/test/features/runs/ui/run_list_row_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/runs/domain/run_models.dart'; +import 'package:pipelines_app/features/runs/ui/runs_list.dart'; + +final _finished = { + 'id': 42, + 'title': 'Ship the release notes', + 'name': 'release', + 'status': 'succeeded', + 'executing': false, + 'created_at': '2026-10-21T12:00:00Z', + 'finished_at': '2026-10-21T12:02:05Z', + 'completed_steps': 3, +}; + +void main() { + test('row facts: when, how long and how far', () { + final facts = runRowFacts(_finished, DateTime.utc(2026, 10, 22)); + expect(facts.when, contains('→')); + expect(facts.duration, '2m 5s'); + expect(facts.progress, '3 steps'); + + final running = runRowFacts({ + ..._finished, + 'executing': true, + 'finished_at': '', + 'completed_steps': 1, + 'current_stage': 'review', + }, DateTime.utc(2026, 10, 21, 12, 0, 45)); + expect(running.when, isNot(contains('→'))); + expect(running.duration, '45s'); + expect(running.progress, '1 step · at review'); + }); + + testWidgets('a run row places its facts in the corners', (tester) async { + tester.view.physicalSize = const Size(800, 400); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: RunListRow(run: _finished, now: DateTime.utc(2026, 10, 22)), + ), + ), + ); + Rect at(String text) => tester.getRect(find.text(text)); + final title = at('Ship the release notes'); + final number = at('#42'); + final pipeline = at('release'); + final duration = at('2m 5s'); + final steps = at('3 steps'); + // Left column: run, pipeline, time; right column: number, duration, steps. + expect(number.center.dy, moreOrLessEquals(title.center.dy)); + expect(duration.center.dy, moreOrLessEquals(pipeline.center.dy)); + expect(pipeline.top, greaterThan(title.bottom)); + expect(steps.top, greaterThan(duration.bottom)); + for (final right in [number, duration, steps]) { + expect(right.right, greaterThan(800 - 32)); + } + }); +} diff --git a/app/test/features/runs/ui/runs_list_widget_test.dart b/app/test/features/runs/ui/runs_list_widget_test.dart index 03f13eb5..d2c5b9cc 100644 --- a/app/test/features/runs/ui/runs_list_widget_test.dart +++ b/app/test/features/runs/ui/runs_list_widget_test.dart @@ -83,7 +83,7 @@ void main() { await tester.pumpAndSettle(); expect(find.text('Beta'), findsNWidgets(2)); expect(find.text('Alpha'), findsNothing); - await tester.tap(find.byType(CupertinoListTile)); + await tester.tap(find.byKey(const ValueKey('run-row-2'))); expect(selectedRun, 2); await tester.enterText(find.byType(CupertinoSearchTextField), 'missing'); await tester.pumpAndSettle(); From bb01527f8c8fb157ed1a0f1416f479b375a35560 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 17:20:16 +0100 Subject: [PATCH 2/2] test(app): run row corners allow touching lines --- app/test/features/runs/ui/run_list_row_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/test/features/runs/ui/run_list_row_test.dart b/app/test/features/runs/ui/run_list_row_test.dart index c30a8f89..a1b3ef67 100644 --- a/app/test/features/runs/ui/run_list_row_test.dart +++ b/app/test/features/runs/ui/run_list_row_test.dart @@ -53,8 +53,8 @@ void main() { // Left column: run, pipeline, time; right column: number, duration, steps. expect(number.center.dy, moreOrLessEquals(title.center.dy)); expect(duration.center.dy, moreOrLessEquals(pipeline.center.dy)); - expect(pipeline.top, greaterThan(title.bottom)); - expect(steps.top, greaterThan(duration.bottom)); + expect(pipeline.top, greaterThanOrEqualTo(title.bottom)); + expect(steps.top, greaterThanOrEqualTo(duration.bottom)); for (final right in [number, duration, steps]) { expect(right.right, greaterThan(800 - 32)); }