diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 14ecb4f6..78d29c56 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -289,6 +289,8 @@ class _PipelinesAppState extends State server: widget.server, refreshToken: _pipelinesRefresh, onRunStarted: _runStarted, + onViewPipelineRuns: (id) => + _delegate.goTo(AppRoute.runsForPipeline(id)), initialPipelineId: route.pipelineId, initialVersion: route.version, initialStageKey: route.stageKey, @@ -302,13 +304,19 @@ class _PipelinesAppState extends State session: _session, server: widget.server, initialRunId: route.runId, + initialPipelineId: route.pipelineId, initialStageKey: route.stageKey, initialVisit: route.visit, initialDecide: route.decide, listRefreshToken: _runsRefresh, notifications: _notifications, onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)), - onBack: () => _delegate.goTo(AppRoute.runs), + onBack: (id) => _delegate.goTo( + id == null ? AppRoute.runs : AppRoute.runsForPipeline(id), + ), + onPipelineFilterChanged: (id) => _delegate.goTo( + id == null ? AppRoute.runs : AppRoute.runsForPipeline(id), + ), ), ), AppDestination.chat: (_) => ChatDestination( diff --git a/app/lib/application/pipelines_destination.dart b/app/lib/application/pipelines_destination.dart index e7c492e1..5720c3e6 100644 --- a/app/lib/application/pipelines_destination.dart +++ b/app/lib/application/pipelines_destination.dart @@ -19,6 +19,7 @@ class PipelinesDestination extends StatelessWidget { required this.server, this.refreshToken = 0, this.onRunStarted, + this.onViewPipelineRuns, this.initialPipelineId, this.initialVersion = 0, this.initialStageKey, @@ -34,6 +35,7 @@ class PipelinesDestination extends StatelessWidget { /// Receives the run id an accepted launch named; the shell opens that route. final ValueChanged? onRunStarted; + final ValueChanged? onViewPipelineRuns; /// The pipeline and pinned version a deep link names. final int? initialPipelineId; @@ -77,6 +79,7 @@ class PipelinesDestination extends StatelessWidget { gateway: session.gateway, embedded: true, onRunStarted: onRunStarted, + onViewPipelineRuns: onViewPipelineRuns, initialPipelineId: initialPipelineId, initialVersion: initialVersion, initialStageKey: initialStageKey, diff --git a/app/lib/application/runs_destination.dart b/app/lib/application/runs_destination.dart index 978faad1..5a042766 100644 --- a/app/lib/application/runs_destination.dart +++ b/app/lib/application/runs_destination.dart @@ -19,11 +19,13 @@ class RunsDestination extends StatelessWidget { required this.session, required this.server, this.initialRunId, + this.initialPipelineId, this.initialStageKey, this.initialVisit, this.initialDecide = false, this.onRunSelected, this.onBack, + this.onPipelineFilterChanged, this.listRefreshToken = 0, this.notifications, }); @@ -31,6 +33,7 @@ class RunsDestination extends StatelessWidget { final AppSession session; final ServerEndpoint server; final int? initialRunId; + final int? initialPipelineId; /// The stage key and optional visit a `/runs/:id/stage/:key[?visit=N]` route /// names. They reach the detail only through [RunsScreen]; the destination @@ -43,7 +46,8 @@ class RunsDestination extends StatelessWidget { final bool initialDecide; final ValueChanged? onRunSelected; - final VoidCallback? onBack; + final ValueChanged? onBack; + final ValueChanged? onPipelineFilterChanged; /// Advances when a launch was accepted elsewhere. The mounted Runs screen /// re-reads its list once; no row is inserted locally. @@ -87,6 +91,7 @@ class RunsDestination extends StatelessWidget { Widget _runsScreen() => RunsScreen( gateway: session.gateway, initialRunId: initialRunId, + initialPipelineId: initialPipelineId, initialStageKey: initialStageKey, initialVisit: initialVisit, initialDecide: initialDecide, @@ -95,5 +100,6 @@ class RunsDestination extends StatelessWidget { notifications: notifications, onRunSelected: onRunSelected, onBack: onBack, + onPipelineFilterChanged: onPipelineFilterChanged, ); } diff --git a/app/lib/features/pipelines/screen.dart b/app/lib/features/pipelines/screen.dart index c7de8828..590281c5 100644 --- a/app/lib/features/pipelines/screen.dart +++ b/app/lib/features/pipelines/screen.dart @@ -28,6 +28,7 @@ class PipelinesScreen extends StatefulWidget { this.embedded = false, this.syncToken = 0, this.onRunStarted, + this.onViewPipelineRuns, this.initialPipelineId, this.initialVersion = 0, this.initialStageKey, @@ -45,6 +46,7 @@ class PipelinesScreen extends StatefulWidget { /// Receives the run id an accepted launch names, so the composition can open /// the existing run route. The feature never navigates on its own. final ValueChanged? onRunStarted; + final ValueChanged? onViewPipelineRuns; /// The pipeline a deep link names, opened after the list read starts. final int? initialPipelineId; @@ -170,6 +172,7 @@ class _PipelinesScreenState extends State { gateway: widget.gateway, showBack: true, onRunStarted: widget.onRunStarted, + onViewPipelineRuns: widget.onViewPipelineRuns, stageKey: stageKey, stagePipelineId: widget.initialPipelineId, stageVersion: widget.initialVersion, @@ -192,6 +195,7 @@ class _PipelinesScreenState extends State { gateway: widget.gateway, showBack: false, onRunStarted: widget.onRunStarted, + onViewPipelineRuns: widget.onViewPipelineRuns, stageKey: stageKey, stagePipelineId: widget.initialPipelineId, stageVersion: widget.initialVersion, diff --git a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart index 69014cad..351cea2c 100644 --- a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart @@ -30,6 +30,7 @@ class PipelineDetailPanel extends StatefulWidget { required this.gateway, required this.showBack, this.onRunStarted, + this.onViewPipelineRuns, this.stageKey, this.stagePipelineId, this.stageVersion = 0, @@ -45,6 +46,7 @@ class PipelineDetailPanel extends StatefulWidget { /// A run started from this detail's Run action; receives the server's id. final ValueChanged? onRunStarted; + final ValueChanged? onViewPipelineRuns; /// The stage the route names for this detail, or null when it names none. final String? stageKey; @@ -337,6 +339,25 @@ class _PipelineDetailPanelState extends State { onRunStarted: widget.onRunStarted, ), ), + Align( + alignment: AlignmentDirectional.centerStart, + child: Semantics( + button: true, + label: detail.name.trim().isEmpty + ? 'View runs of this pipeline' + : 'View runs of ${detail.name}', + child: ExcludeSemantics( + child: TextButton.icon( + onPressed: widget.onViewPipelineRuns == null + ? null + : () => widget.onViewPipelineRuns!(detail.id), + icon: const Icon(Icons.list_alt), + label: const Text('Runs'), + key: const Key('pipeline-view-runs'), + ), + ), + ), + ), ], ), ); diff --git a/app/lib/features/runs/screen.dart b/app/lib/features/runs/screen.dart index 3e8403e2..8c0f7369 100644 --- a/app/lib/features/runs/screen.dart +++ b/app/lib/features/runs/screen.dart @@ -24,6 +24,7 @@ class RunsScreen extends StatefulWidget { super.key, required this.gateway, this.initialRunId, + this.initialPipelineId, this.initialStageKey, this.initialVisit, this.initialDecide = false, @@ -31,6 +32,7 @@ class RunsScreen extends StatefulWidget { this.listRefreshToken = 0, this.onRunSelected, this.onBack, + this.onPipelineFilterChanged, this.attentionStore = const SharedPreferencesAttentionStore(), this.attentionNow, this.notifications, @@ -40,6 +42,7 @@ class RunsScreen extends StatefulWidget { /// The run the current route names, or null for the list. final int? initialRunId; + final int? initialPipelineId; /// The recorded stage visit the route names inside [initialRunId]. The detail /// applies it once per route target; the feature never invents a visit. @@ -60,7 +63,8 @@ class RunsScreen extends StatefulWidget { final int listRefreshToken; final ValueChanged? onRunSelected; - final VoidCallback? onBack; + final ValueChanged? onBack; + final ValueChanged? onPipelineFilterChanged; /// Persisted attention dismissals and the clock for its local-day window. /// The app uses SharedPreferences; tests and fixtures inject a memory store. @@ -77,6 +81,8 @@ class RunsScreen extends StatefulWidget { class _RunsScreenState extends State { late final RunsController controller; num? _shownRunId; + int? _reportedPipelineId; + bool _applyingRoutePipeline = false; /// The route's decision request is one-shot: the first loaded detail for the /// named run consumes it, whether or not that run is waiting. @@ -86,8 +92,14 @@ class _RunsScreenState extends State { void initState() { super.initState(); controller = RunsController(RunsRepository(widget.gateway)); + _reportedPipelineId = widget.initialPipelineId; + if (widget.initialPipelineId != null) { + controller.clearFilters(); + controller.setPipeline(widget.initialPipelineId); + } controller.listen(widget.gateway.frames); controller.addListener(_selectionChanged); + controller.addListener(_pipelineFilterChanged); controller.addListener(_detailChanged); controller.load(widget.initialRunId); } @@ -99,6 +111,21 @@ class _RunsScreenState extends State { widget.initialDecide != oldWidget.initialDecide) { _decideConsumed = false; } + if (widget.initialPipelineId != oldWidget.initialPipelineId) { + final id = widget.initialPipelineId; + // A run detail replaces the list URL but retains its active list filter. + // Only a route back to the list can explicitly clear that facet. + if (id != null || widget.initialRunId == null) { + _applyingRoutePipeline = true; + try { + if (id != null) controller.clearFilters(); + controller.setPipeline(id); + _reportedPipelineId = id; + } finally { + _applyingRoutePipeline = false; + } + } + } if (widget.syncToken != oldWidget.syncToken) { controller.resync(); } @@ -132,6 +159,19 @@ class _RunsScreenState extends State { if (mounted) setState(() {}); } + void _pipelineFilterChanged() { + final id = controller.pipelineId; + if (_applyingRoutePipeline) { + _reportedPipelineId = id; + return; + } + if (id == _reportedPipelineId) return; + _reportedPipelineId = id; + if (controller.selectedRunId == null) { + widget.onPipelineFilterChanged?.call(id); + } + } + /// Opens the route's decision prompt after the named detail has arrived. /// A non-waiting run consumes the request without a prompt, and the prompt /// itself only closes; the detail underneath is left as it is. @@ -166,12 +206,13 @@ class _RunsScreenState extends State { void _back() { controller.back(); - widget.onBack?.call(); + widget.onBack?.call(controller.pipelineId); } @override void dispose() { controller.removeListener(_selectionChanged); + controller.removeListener(_pipelineFilterChanged); controller.removeListener(_detailChanged); controller.dispose(); super.dispose(); diff --git a/app/lib/features/runs/ui/runs_filters.dart b/app/lib/features/runs/ui/runs_filters.dart index 7e756402..7148c5b7 100644 --- a/app/lib/features/runs/ui/runs_filters.dart +++ b/app/lib/features/runs/ui/runs_filters.dart @@ -37,6 +37,23 @@ class RunsFilters extends StatelessWidget { Widget _materialToolbar(int count) => Row( mainAxisSize: MainAxisSize.min, children: [ + PopupMenuButton<_FilterChoice>( + tooltip: 'Filter by pipeline', + onSelected: _apply, + itemBuilder: (context) => [ + const PopupMenuItem( + value: (kind: 'pipeline', value: ''), + child: Text('Any pipeline'), + ), + for (final pipeline in _pipelines) + CheckedPopupMenuItem( + value: (kind: 'pipeline', value: '${pipeline.$1}'), + checked: controller.pipelineId == pipeline.$1, + child: Text(pipeline.$2), + ), + ], + child: _materialButton(Icons.account_tree_outlined, 'Pipeline'), + ), PopupMenuButton<_FilterChoice>( tooltip: count > 0 ? '$count active ${count == 1 ? 'filter' : 'filters'}' @@ -102,6 +119,12 @@ class RunsFilters extends StatelessWidget { ]; void _apply(_FilterChoice choice) { + if (choice.kind == 'pipeline') { + controller.setPipeline( + choice.value.isEmpty ? null : int.parse(choice.value), + ); + return; + } if (choice.kind == 'status') { controller.setStatus(choice.value); } else if (choice.kind == 'schedule') { @@ -111,6 +134,19 @@ class RunsFilters extends StatelessWidget { } } + List<(int, String)> get _pipelines { + final names = {}; + for (final run in controller.runs) { + final rawId = run['pipeline_id']; + final id = rawId is num ? rawId.toInt() : int.tryParse('$rawId'); + if (id == null || id <= 0) continue; + final name = '${run['name'] ?? ''}'.trim(); + names.putIfAbsent(id, () => name.isEmpty ? 'Pipeline $id' : name); + } + return names.entries.map((entry) => (entry.key, entry.value)).toList() + ..sort((a, b) => a.$2.toLowerCase().compareTo(b.$2.toLowerCase())); + } + Widget _cupertinoToolbar(BuildContext context, int count) => Row( mainAxisSize: MainAxisSize.min, children: [ @@ -148,6 +184,17 @@ class RunsFilters extends StatelessWidget { builder: (context, _) => CupertinoActionSheet( title: const Text('Filter runs'), actions: [ + CupertinoActionSheetAction( + onPressed: () => controller.setPipeline(null), + child: const Text('Any pipeline'), + ), + for (final pipeline in _pipelines) + CupertinoActionSheetAction( + onPressed: () => controller.setPipeline(pipeline.$1), + child: Text( + '${controller.pipelineId == pipeline.$1 ? '✓ ' : ''}${pipeline.$2}', + ), + ), for (final status in runStates) CupertinoActionSheetAction( onPressed: () => controller.setStatus(status), diff --git a/app/test/application/runs_destination_test.dart b/app/test/application/runs_destination_test.dart index abdd07fd..977a3482 100644 --- a/app/test/application/runs_destination_test.dart +++ b/app/test/application/runs_destination_test.dart @@ -21,7 +21,7 @@ Widget materialApp( ServerEndpoint server, { int? initialRunId, ValueChanged? onRunSelected, - VoidCallback? onBack, + ValueChanged? onBack, }) => MaterialApp( home: Scaffold( body: RunsDestination( diff --git a/app/test/features/pipelines/pipelines_screen_test.dart b/app/test/features/pipelines/pipelines_screen_test.dart index a61f4d36..a4ccc60b 100644 --- a/app/test/features/pipelines/pipelines_screen_test.dart +++ b/app/test/features/pipelines/pipelines_screen_test.dart @@ -86,6 +86,30 @@ void main() { expect(find.text('Viewing v1 (latest v2).'), findsNothing); }); + testWidgets('detail Runs action names and opens that pipeline filter', ( + tester, + ) async { + final fixture = PipelineFixture(); + final gateway = gatewayFor(fixture); + final opened = []; + tester.view.physicalSize = const Size(1100, 900); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + await tester.pumpWidget( + MaterialApp( + home: PipelinesScreen(gateway: gateway, onViewPipelineRuns: opened.add), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const Key('pipeline-row-1'))); + await tester.pumpAndSettle(); + + expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget); + await tester.tap(find.byKey(const Key('pipeline-view-runs'))); + expect(opened, [1]); + }); + testWidgets('refresh keeps the selected row and its detail', (tester) async { final fixture = PipelineFixture(); final gateway = gatewayFor(fixture); diff --git a/app/test/features/runs/ui/runs_screen_test.dart b/app/test/features/runs/ui/runs_screen_test.dart index e66cdfb8..e044e234 100644 --- a/app/test/features/runs/ui/runs_screen_test.dart +++ b/app/test/features/runs/ui/runs_screen_test.dart @@ -46,17 +46,21 @@ const _runs = [ Widget _materialScreen( _Gateway gateway, { int? initialRunId, + int? initialPipelineId, int syncToken = 0, ValueChanged? onRunSelected, - VoidCallback? onBack, + ValueChanged? onBack, + ValueChanged? onPipelineFilterChanged, }) => MaterialApp( home: Scaffold( body: RunsScreen( gateway: gateway, initialRunId: initialRunId, + initialPipelineId: initialPipelineId, syncToken: syncToken, onRunSelected: onRunSelected, onBack: onBack, + onPipelineFilterChanged: onPipelineFilterChanged, ), ), ); @@ -149,12 +153,12 @@ void main() { tester, ) async { int? selected; - var backs = 0; + int? backedPipeline; await tester.pumpWidget( _materialScreen( gateway, onRunSelected: (id) => selected = id, - onBack: () => backs++, + onBack: (id) => backedPipeline = id, ), ); await _mountList(tester, gateway); @@ -167,10 +171,60 @@ void main() { await tester.tap(find.text('Back to list')); await tester.pump(); - expect(backs, 1); + expect(backedPipeline, isNull); expect(find.text('Alpha run'), findsOneWidget); }); + testWidgets( + 'pipeline route shows its chip and clearing reports the URL change', + (tester) async { + int? changedPipeline = 3; + await tester.pumpWidget( + _materialScreen( + gateway, + initialPipelineId: 3, + onPipelineFilterChanged: (id) => changedPipeline = id, + ), + ); + await _mountList(tester, gateway); + + expect(find.text('Pipeline 3'), findsOneWidget); + expect(changedPipeline, 3); + await tester.tap(find.byTooltip('Clear filter: Pipeline 3')); + await tester.pump(); + expect(changedPipeline, isNull); + expect(find.text('Pipeline 3'), findsNothing); + }, + ); + + testWidgets('run detail keeps the pipeline filter for Back routing', ( + tester, + ) async { + int? backPipeline; + await tester.pumpWidget( + _materialScreen( + gateway, + initialPipelineId: 3, + onBack: (id) => backPipeline = id, + ), + ); + await _mountList(tester, gateway); + await tester.pumpWidget( + _materialScreen( + gateway, + initialRunId: 2, + onBack: (id) => backPipeline = id, + ), + ); + await tester.pump(); + gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'}); + await tester.pump(); + + await tester.tap(find.text('Back to list')); + await tester.pump(); + expect(backPipeline, 3); + }); + testWidgets('a route change opens and closes the named run', (tester) async { await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2)); await _mountList(tester, gateway);