From e0e3517d0b934894c49659788deee40a8ea7e096 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 16:05:15 +0100 Subject: [PATCH] feat(app): Retry sits beside a failed run's status --- .../features/runs/ui/run_detail_actions.dart | 6 +- .../runs/ui/run_detail_cupertino.dart | 15 +++- .../features/runs/ui/run_detail_material.dart | 15 +++- app/lib/features/runs/ui/run_detail_view.dart | 14 ++++ .../runs/ui/run_retry_placement_test.dart | 72 +++++++++++++++++++ 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 app/test/features/runs/ui/run_retry_placement_test.dart diff --git a/app/lib/features/runs/ui/run_detail_actions.dart b/app/lib/features/runs/ui/run_detail_actions.dart index 0416d823..e2f1ed16 100644 --- a/app/lib/features/runs/ui/run_detail_actions.dart +++ b/app/lib/features/runs/ui/run_detail_actions.dart @@ -19,6 +19,7 @@ class RunDetailActions extends StatelessWidget { required this.gateway, required this.onRunChanged, this.onRunOpened, + this.retry = true, }); final JsonMap run; @@ -28,6 +29,9 @@ class RunDetailActions extends StatelessWidget { /// Opens the new run named by an accepted retry reply; see [RetryRunAction]. final ValueChanged? onRunOpened; + /// False when the host draws Retry beside the run's failed status instead. + final bool retry; + @override Widget build(BuildContext context) => Column( mainAxisSize: MainAxisSize.min, @@ -51,7 +55,7 @@ class RunDetailActions extends StatelessWidget { ), if (canScheduleRun(run)) ScheduleRunAction(run: run, gateway: gateway), - if (retryRunId(run) != null && canRetryRun(run)) + if (retry && retryRunId(run) != null && canRetryRun(run)) RetryRunAction( run: run, gateway: gateway, diff --git a/app/lib/features/runs/ui/run_detail_cupertino.dart b/app/lib/features/runs/ui/run_detail_cupertino.dart index 7ecb30c8..bccdf089 100644 --- a/app/lib/features/runs/ui/run_detail_cupertino.dart +++ b/app/lib/features/runs/ui/run_detail_cupertino.dart @@ -15,6 +15,7 @@ Widget buildCupertinoRunDetail({ required BuildContext context, required JsonMap run, required Widget headerActions, + Widget? statusAction, required bool detailLoading, required String? error, required bool copying, @@ -72,9 +73,17 @@ Widget buildCupertinoRunDetail({ child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - RunStatusKicker( - state: runStateOf(run['status']), - label: runStatusLabel(run), + Wrap( + spacing: 8, + runSpacing: 4, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + RunStatusKicker( + state: runStateOf(run['status']), + label: runStatusLabel(run), + ), + ?statusAction, + ], ), const SizedBox(height: 4), Text( diff --git a/app/lib/features/runs/ui/run_detail_material.dart b/app/lib/features/runs/ui/run_detail_material.dart index ea8b4ead..3c0e6796 100644 --- a/app/lib/features/runs/ui/run_detail_material.dart +++ b/app/lib/features/runs/ui/run_detail_material.dart @@ -15,6 +15,7 @@ Widget buildMaterialRunDetail({ required BuildContext context, required JsonMap run, required Widget headerActions, + Widget? statusAction, required bool detailLoading, required String? error, required bool copying, @@ -62,9 +63,17 @@ Widget buildMaterialRunDetail({ padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), child: Align( alignment: AlignmentDirectional.centerStart, - child: RunStatusKicker( - state: runStateOf(run['status']), - label: runStatusLabel(run), + child: Wrap( + spacing: 8, + runSpacing: 4, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + RunStatusKicker( + state: runStateOf(run['status']), + label: runStatusLabel(run), + ), + ?statusAction, + ], ), ), ), diff --git a/app/lib/features/runs/ui/run_detail_view.dart b/app/lib/features/runs/ui/run_detail_view.dart index c1bcaea1..09b350eb 100644 --- a/app/lib/features/runs/ui/run_detail_view.dart +++ b/app/lib/features/runs/ui/run_detail_view.dart @@ -5,6 +5,8 @@ import 'package:flutter/services.dart'; import '../../../core/api_gateway.dart'; import '../../../core/transport/pipelines_client.dart'; import '../../../ui/adaptive/host.dart'; +import '../actions/retry_action.dart'; +import '../actions/retry_eligibility.dart'; import 'run_detail_actions.dart'; import 'run_detail_content.dart'; import 'run_detail_cupertino.dart'; @@ -60,12 +62,23 @@ class _RunDetailViewState extends State { gateway: widget.gateway, onRunChanged: widget.controller.acceptRunDetail, onRunOpened: widget.onRunOpened, + retry: false, ); + // Retry sits next to the status it answers, and only for a failed run. + final statusAction = retryRunId(run) != null && canRetryRun(run) + ? RetryRunAction( + run: run, + gateway: widget.gateway, + onRunChanged: widget.controller.acceptRunDetail, + onRunOpened: widget.onRunOpened, + ) + : null; return cupertino ? buildCupertinoRunDetail( context: context, run: run, headerActions: headerActions, + statusAction: statusAction, detailLoading: widget.controller.detailLoading, error: widget.controller.error, copying: _copying, @@ -82,6 +95,7 @@ class _RunDetailViewState extends State { context: context, run: run, headerActions: headerActions, + statusAction: statusAction, detailLoading: widget.controller.detailLoading, error: widget.controller.error, copying: _copying, diff --git a/app/test/features/runs/ui/run_retry_placement_test.dart b/app/test/features/runs/ui/run_retry_placement_test.dart new file mode 100644 index 00000000..49f0ae68 --- /dev/null +++ b/app/test/features/runs/ui/run_retry_placement_test.dart @@ -0,0 +1,72 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/runs/data/runs_repository.dart'; +import 'package:pipelines_app/features/runs/ui/run_detail_view.dart'; +import 'package:pipelines_app/features/runs/ui/runs_controller.dart'; +import 'package:pipelines_app/ui/status/run_status_icon.dart'; + +class _FakeGateway implements ApiGateway { + _FakeGateway(this.detail); + final JsonMap detail; + + @override + Stream get frames => const Stream.empty(); + + @override + Future call(String type, [JsonMap fields = const {}]) { + if (type != 'get_run') throw UnsupportedError(type); + return Future.value({'run_detail': detail}); + } +} + +Future _pump(WidgetTester tester, String status, bool cupertino) async { + tester.view.physicalSize = const Size(390, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final controller = RunsController( + RunsRepository( + _FakeGateway({ + 'id': 21, + 'title': 'Nightly build', + 'name': 'nightly', + 'status': status, + 'executing': false, + }), + ), + ); + await controller.select(21); + final view = RunDetailView( + controller: controller, + gateway: _FakeGateway(const {}), + onBack: () {}, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: view)) + : MaterialApp(home: Scaffold(body: view)), + ); + await tester.pumpAndSettle(); +} + +void main() { + for (final cupertino in [false, true]) { + final host = cupertino ? 'cupertino' : 'material'; + testWidgets('$host: Retry sits beside the failed status', (tester) async { + await _pump(tester, 'failed', cupertino); + + final retry = find.text('Retry'); + expect(retry, findsOneWidget); + final kicker = tester.getRect(find.byType(RunStatusKicker)); + final button = tester.getRect(retry); + expect(button.center.dy, moreOrLessEquals(kicker.center.dy, epsilon: 8)); + expect(button.left, greaterThan(kicker.right)); + }); + + testWidgets('$host: a succeeded run offers no Retry', (tester) async { + await _pump(tester, 'succeeded', cupertino); + expect(find.text('Retry'), findsNothing); + }); + } +}