From 322f0a066fda2e9518232208036e6a37c9798e0d Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 02:50:20 +0100 Subject: [PATCH] feat(app): open Changes for the selected visit from its pane The opened recorded-visit pane gains one native Changes action next to Back to timeline. It reuses showRunChanges with only that visit's step, so the pushed page shows that visit's own capture and no run-wide summary, and a visit without a capture reaches the honest missing-capture state. The run-level Changes action and its title are unchanged. --- .../features/runs/ui/run_changes_action.dart | 106 +++++++++++++-- .../features/runs/ui/run_detail_visit.dart | 17 ++- .../ui/run_visit_changes_action_test.dart | 128 ++++++++++++++++++ 3 files changed, 242 insertions(+), 9 deletions(-) create mode 100644 app/test/features/runs/ui/run_visit_changes_action_test.dart diff --git a/app/lib/features/runs/ui/run_changes_action.dart b/app/lib/features/runs/ui/run_changes_action.dart index 5f3bfbfa..981b02ba 100644 --- a/app/lib/features/runs/ui/run_changes_action.dart +++ b/app/lib/features/runs/ui/run_changes_action.dart @@ -9,6 +9,7 @@ import '../../changes/changes.dart'; /// recorded summary and capture wording, so this bar stays neutral. const runChangesLabel = 'Changes'; const runChangesButtonKey = ValueKey('run-detail-changes'); +const runVisitChangesButtonKey = ValueKey('run-visit-changes'); /// The detail's `steps` exactly as returned by the server. The pushed page /// snapshots the returned list once, so it never re-derives on each rebuild. @@ -73,34 +74,118 @@ class RunChangesButton extends StatelessWidget { /// Opens the already-landed [ChangesViewer] for [steps] on a native page. /// The bar is the one title bar; the viewer's own summary and capture facts /// are passed through untouched, except for the caller's [showSummary] gate. +/// +/// [title] names the evidence the page shows. The run-level action keeps the +/// neutral [runChangesLabel]; a visit passes [visitChangesTitle] so the pushed +/// page cannot be mistaken for the run-wide aggregate. Future showRunChanges( BuildContext context, { required List steps, required bool showSummary, + String title = runChangesLabel, }) { final cupertino = usesCupertinoHost(context); return Navigator.of(context).push( cupertino ? CupertinoPageRoute( - builder: (_) => - _CupertinoChangesPage(steps: steps, showSummary: showSummary), + builder: (_) => _CupertinoChangesPage( + steps: steps, + showSummary: showSummary, + title: title, + ), ) : MaterialPageRoute( - builder: (_) => - _MaterialChangesPage(steps: steps, showSummary: showSummary), + builder: (_) => _MaterialChangesPage( + steps: steps, + showSummary: showSummary, + title: title, + ), ), ); } +/// The page identity for exactly one recorded visit: the stage and visit the +/// timeline row shows, so the page names its evidence rather than the run. +String visitChangesTitle(String stage, int? sequence) { + final name = stage.trim(); + final visit = sequence == null ? 'visit unavailable' : 'visit $sequence'; + return name.isEmpty + ? '$runChangesLabel · $visit' + : '$runChangesLabel · $name · $visit'; +} + +/// Opens the Changes viewer for exactly one visit's recorded [step]. +/// +/// The page shows that step's own capture only - never the run's other visits - +/// and no run-wide final-state header, which belongs to the run-level action. +Future showVisitChanges( + BuildContext context, { + required String stage, + required int? sequence, + required JsonMap step, +}) => showRunChanges( + context, + steps: [step], + showSummary: false, + title: visitChangesTitle(stage, sequence), +); + +/// The opened visit pane's own native action. It passes only the visit's step, +/// so the viewer's per-stage section is its single evidence entry. +class RunVisitChangesButton extends StatelessWidget { + const RunVisitChangesButton({ + super.key, + required this.stage, + required this.sequence, + required this.step, + }); + + final String stage; + final int? sequence; + final JsonMap step; + + @override + Widget build(BuildContext context) { + void open() => + showVisitChanges(context, stage: stage, sequence: sequence, step: step); + if (usesCupertinoHost(context)) { + return CupertinoButton( + key: runVisitChangesButtonKey, + padding: EdgeInsets.zero, + onPressed: open, + child: const Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(CupertinoIcons.doc_text), + SizedBox(width: 6), + Flexible(child: Text(runChangesLabel)), + ], + ), + ); + } + return TextButton.icon( + key: runVisitChangesButtonKey, + onPressed: open, + icon: const Icon(Icons.difference_outlined), + label: const Text(runChangesLabel), + ); + } +} + class _MaterialChangesPage extends StatelessWidget { - const _MaterialChangesPage({required this.steps, required this.showSummary}); + const _MaterialChangesPage({ + required this.steps, + required this.showSummary, + required this.title, + }); final List steps; final bool showSummary; + final String title; @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar(title: const Text(runChangesLabel)), + appBar: AppBar(title: Text(title)), body: SafeArea( top: false, child: ChangesViewer(steps: steps, showSummary: showSummary), @@ -109,14 +194,19 @@ class _MaterialChangesPage extends StatelessWidget { } class _CupertinoChangesPage extends StatelessWidget { - const _CupertinoChangesPage({required this.steps, required this.showSummary}); + const _CupertinoChangesPage({ + required this.steps, + required this.showSummary, + required this.title, + }); final List steps; final bool showSummary; + final String title; @override Widget build(BuildContext context) => CupertinoPageScaffold( - navigationBar: const CupertinoNavigationBar(middle: Text(runChangesLabel)), + navigationBar: CupertinoNavigationBar(middle: Text(title)), child: SafeArea( // A CupertinoApp supplies no Material theme; follow the host brightness // so the viewer's Material-derived section text stays readable. diff --git a/app/lib/features/runs/ui/run_detail_visit.dart b/app/lib/features/runs/ui/run_detail_visit.dart index 93c9f818..70602816 100644 --- a/app/lib/features/runs/ui/run_detail_visit.dart +++ b/app/lib/features/runs/ui/run_detail_visit.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/host.dart'; +import 'run_changes_action.dart'; import 'run_detail_content.dart'; import 'run_detail_visit_facts.dart'; import 'run_detail_visit_sections.dart'; @@ -139,7 +140,21 @@ class _RunVisitPaneState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Align(alignment: AlignmentDirectional.centerStart, child: close), + // The close and change actions wrap instead of overflowing when the + // pane is narrow or the text is scaled. + Wrap( + spacing: 8, + runSpacing: 4, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + close, + RunVisitChangesButton( + stage: widget.visit.stage, + sequence: widget.visit.sequence, + step: widget.step, + ), + ], + ), Padding( padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 0, 0), child: Column( diff --git a/app/test/features/runs/ui/run_visit_changes_action_test.dart b/app/test/features/runs/ui/run_visit_changes_action_test.dart new file mode 100644 index 00000000..b6f331dd --- /dev/null +++ b/app/test/features/runs/ui/run_visit_changes_action_test.dart @@ -0,0 +1,128 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/changes/changes.dart'; +import 'package:pipelines_app/features/runs/ui/run_changes_action.dart'; + +import '../../changes/fixtures.dart'; +import 'run_detail_graph_support.dart'; +import 'run_detail_visit_support.dart'; + +/// plan and build each recorded a capture with a different file, so a page that +/// showed the run's steps would leak the other visit's path. +JsonMap _run({JsonMap? planChanges, JsonMap? buildChanges}) => + { + 'id': 77, + 'title': 'Visit changes', + 'name': 'release', + 'status': 'succeeded', + 'steps': [ + stepFixture(stage: 'plan', sequence: 1, fileChanges: planChanges), + stepFixture(stage: 'build', sequence: 2, fileChanges: buildChanges), + ], + }; + +JsonMap _capture(String path) => captureFixture( + files: [fileChangeFixture(path: path, patch: multiHunkPatch)], +); + +Future _openVisitChanges(WidgetTester tester) async { + await tester.tap(find.byKey(runVisitChangesButtonKey)); + await tester.pumpAndSettle(); +} + +void main() { + group('visitChangesTitle', () { + test('names the stage and visit the timeline row shows', () { + expect(visitChangesTitle('plan', 1), 'Changes · plan · visit 1'); + }); + + test('omits a stage the server did not record', () { + expect(visitChangesTitle(' ', 3), 'Changes · visit 3'); + }); + + test('does not invent a visit number when none was recorded', () { + expect( + visitChangesTitle('plan', null), + 'Changes · plan · visit unavailable', + ); + }); + }); + + for (final platform in RunDetailTestPlatform.values) { + testWidgets('${platform.name}: visit Changes opens that visit only', ( + tester, + ) async { + await openVisit( + tester, + platform, + run: _run( + planChanges: _capture('lib/plan.dart'), + buildChanges: _capture('lib/build.dart'), + ), + ); + + await _openVisitChanges(tester); + + expect(find.text('Changes · plan · visit 1'), findsOneWidget); + // The body keeps the landed viewer's own identity for that visit. + expect(find.text('plan'), findsOneWidget); + expect(find.text('Visit 1 · completed'), findsOneWidget); + expect(find.text('lib/plan.dart'), findsOneWidget); + expect(find.text('lib/build.dart'), findsNothing); + }); + + testWidgets('${platform.name}: visit without a capture is honest', ( + tester, + ) async { + await openVisit( + tester, + platform, + run: _run(buildChanges: _capture('lib/build.dart')), + ); + + await _openVisitChanges(tester); + + expect(find.text('Changes · plan · visit 1'), findsOneWidget); + expect(find.text(missingCaptureDetail), findsOneWidget); + // A missing capture is evidence, never an observed no-change. + expect(find.text('No changes observed'), findsNothing); + expect(find.text(emptyCaptureDetail), findsNothing); + expect(find.text('lib/build.dart'), findsNothing); + }); + } + + testWidgets('material: visit Changes returns to the opened pane', ( + tester, + ) async { + await openVisit( + tester, + RunDetailTestPlatform.material, + run: _run(planChanges: _capture('lib/plan.dart')), + ); + + await _openVisitChanges(tester); + await tester.tap(find.byTooltip('Back')); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); + expect(find.byKey(runVisitChangesButtonKey), findsOneWidget); + }); + + testWidgets('cupertino: visit Changes returns to the opened pane', ( + tester, + ) async { + await openVisit( + tester, + RunDetailTestPlatform.cupertino, + run: _run(planChanges: _capture('lib/plan.dart')), + ); + + await _openVisitChanges(tester); + await tester.tap(find.byType(CupertinoNavigationBarBackButton)); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('run-visit-pane')), findsOneWidget); + expect(find.byKey(runVisitChangesButtonKey), findsOneWidget); + }); +}