feat(app): compact runs filter and sort toolbar

Replace the full-width runs dropdowns and status chips with web-shaped
controls: a Material filter popup with checked statuses and triggers, a
sort menu, and removable applied-filter chips; Cupertino gets a compact
Filter/Sort row plus one action sheet with live check marks. Add
RunsController.activeFilterCount and clearFilters(), and use the shared
seven-state run vocabulary. Clarify the singular active-filter tooltip.
This commit is contained in:
2026-10-22 14:20:05 +01:00
parent dc0a52380b
commit 535dee0805
6 changed files with 440 additions and 82 deletions
@@ -30,6 +30,14 @@ class RunsController extends ChangeNotifier {
num? get selectedRunId => _selectedId;
/// The number of narrowing facets, one per status set, pipeline, time range
/// and trigger choice. Mirrors the browser's `runFiltersActiveCount`.
int get activeFilterCount =>
(statuses.isNotEmpty ? 1 : 0) +
(pipelineId != null ? 1 : 0) +
(timeRange != 'any_time' && timeRange.isNotEmpty ? 1 : 0) +
(scheduled == 'scheduled' || scheduled == 'unscheduled' ? 1 : 0);
void listen(Stream<JsonMap> frames) {
_subscription?.cancel();
_subscription = frames
@@ -174,6 +182,15 @@ class RunsController extends ChangeNotifier {
notifyListeners();
}
/// Returns every filter to its default, like the browser's `Clear filters`.
void clearFilters() {
statuses.clear();
pipelineId = null;
timeRange = 'any_time';
scheduled = 'any';
notifyListeners();
}
void _event(JsonMap frame) {
final folded = foldRunEvent(runs, frame);
runs = folded.runs;
+241 -76
View File
@@ -2,92 +2,179 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/run_models.dart';
import 'runs_controller.dart';
/// The runs list's native sort/schedule/status controls.
/// The runs list's compact native filter/sort toolbar and applied-filter chips.
///
/// On Cupertino the controls stay in one horizontally scrollable strip: a phone
/// at a doubled text scale cannot stack seven buttons above the list without
/// crushing it, and the browser's narrow toolbar is likewise one row. Material
/// keeps its native dropdowns and filter chips.
/// Mirrors the browser's run toolbar: one `Filter` menu carrying the status and
/// trigger facets, one `Sort:` menu, and a removable chip per applied facet.
/// The buttons sit in a single horizontally scrollable row so a phone at a
/// doubled text scale can still reach them without crushing the list.
class RunsFilters extends StatelessWidget {
const RunsFilters({super.key, required this.controller});
final RunsController controller;
@override
Widget build(BuildContext context) =>
usesCupertinoHost(context) ? _cupertino(context) : _material(context);
Widget _cupertino(BuildContext context) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
Widget build(BuildContext context) {
final count = controller.activeFilterCount;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
CupertinoButton(
onPressed: () => _choose(
context,
'Sort runs',
_sorts,
controller.sort,
controller.setSort,
),
child: Text('Sort: ${_sortLabel(controller.sort)}'),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
child: usesCupertinoHost(context)
? _cupertinoToolbar(context, count)
: _materialToolbar(count),
),
const SizedBox(width: 8),
CupertinoButton(
onPressed: () => _choose(
context,
'Schedule',
_schedules,
controller.scheduled,
controller.setScheduled,
),
child: Text('Schedule: ${_scheduleLabel(controller.scheduled)}'),
),
for (final status in _statuses) ...[
const SizedBox(width: 8),
CupertinoButton(
onPressed: () => controller.setStatus(status),
child: Text(
'${controller.statuses.contains(status) ? '✓ ' : ''}${_title(status)}',
),
),
],
if (count > 0) _appliedFilters(context),
],
);
}
Widget _materialToolbar(int count) => Row(
mainAxisSize: MainAxisSize.min,
children: [
PopupMenuButton<_FilterChoice>(
tooltip: count > 0
? '$count active ${count == 1 ? 'filter' : 'filters'}'
: 'Filter runs',
onSelected: _apply,
itemBuilder: (context) => _materialMenuItems(),
child: _materialButton(
count > 0 ? Icons.filter_alt : Icons.filter_alt_outlined,
count > 0 ? 'Filter ($count)' : 'Filter',
),
),
PopupMenuButton<String>(
tooltip: 'Sort runs',
onSelected: controller.setSort,
itemBuilder: (context) => [
for (final sort in _sorts)
CheckedPopupMenuItem(
value: sort.$1,
checked: controller.sort == sort.$1,
child: Text(sort.$2),
),
],
child: _materialButton(
Icons.sort,
'Sort: ${_sortLabel(controller.sort)}',
),
),
],
);
Widget _materialButton(IconData icon, String label) => Semantics(
button: true,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(12, 8, 12, 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [Icon(icon), const SizedBox(width: 6), Text(label)],
),
),
);
Widget _material(BuildContext context) => Wrap(
spacing: 8,
children: [
DropdownButton<String>(
value: controller.sort,
isExpanded: true,
onChanged: (v) {
if (v != null) controller.setSort(v);
},
items: _sorts
.map((e) => DropdownMenuItem(value: e.$1, child: Text(e.$2)))
.toList(),
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
for (final status in runStates)
CheckedPopupMenuItem(
value: (kind: 'status', value: status),
checked: controller.statuses.contains(status),
child: Text(status),
),
DropdownButton<String>(
value: controller.scheduled,
isExpanded: true,
onChanged: (v) {
if (v != null) controller.setScheduled(v);
},
items: _schedules
.map((e) => DropdownMenuItem(value: e.$1, child: Text(e.$2)))
.toList(),
const PopupMenuDivider(),
for (final schedule in _schedules)
CheckedPopupMenuItem(
value: (kind: 'schedule', value: schedule.$1),
checked: controller.scheduled == schedule.$1,
child: Text(schedule.$2),
),
if (controller.activeFilterCount > 0) ...[
const PopupMenuDivider(),
const PopupMenuItem(
value: (kind: 'clear', value: ''),
child: Text('Clear filters'),
),
for (final status in _statuses)
FilterChip(
label: Text(_title(status)),
selected: controller.statuses.contains(status),
onSelected: (_) => controller.setStatus(status),
),
],
];
void _apply(_FilterChoice choice) {
if (choice.kind == 'status') {
controller.setStatus(choice.value);
} else if (choice.kind == 'schedule') {
controller.setScheduled(choice.value);
} else {
controller.clearFilters();
}
}
Widget _cupertinoToolbar(BuildContext context, int count) => Row(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
minimumSize: Size.zero,
onPressed: () => _showCupertinoFilter(context),
child: Text(count > 0 ? 'Filter ($count)' : 'Filter'),
),
const SizedBox(width: 4),
CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
minimumSize: Size.zero,
onPressed: () => _choose(
context,
'Sort runs',
_sorts,
controller.sort,
controller.setSort,
),
child: Text('Sort: ${_sortLabel(controller.sort)}'),
),
],
);
/// One sheet for both facets, mirroring the browser's filter menu. Tapping an
/// option keeps the sheet open so several statuses can be toggled; the check
/// marks redraw from the controller and `Done` dismisses it.
Future<void> _showCupertinoFilter(
BuildContext context,
) => showCupertinoModalPopup<void>(
context: context,
builder: (sheetContext) => ListenableBuilder(
listenable: controller,
builder: (context, _) => CupertinoActionSheet(
title: const Text('Filter runs'),
actions: [
for (final status in runStates)
CupertinoActionSheetAction(
onPressed: () => controller.setStatus(status),
child: Text(
'${controller.statuses.contains(status) ? '✓ ' : ''}$status',
),
),
for (final schedule in _schedules)
CupertinoActionSheetAction(
onPressed: () => controller.setScheduled(schedule.$1),
child: Text(
'${controller.scheduled == schedule.$1 ? '✓ ' : ''}'
'${schedule.$2}',
),
),
if (controller.activeFilterCount > 0)
CupertinoActionSheetAction(
onPressed: controller.clearFilters,
child: const Text('Clear filters'),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Done'),
),
),
),
);
Future<void> _choose(
@@ -116,23 +203,101 @@ class RunsFilters extends StatelessWidget {
);
if (value != null && value != selected) onSelected(value);
}
Widget _appliedFilters(BuildContext context) {
final applied = _applied();
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
child: Wrap(
spacing: 8,
runSpacing: 4,
children: [for (final entry in applied) _appliedChip(context, entry)],
),
);
}
List<({String label, VoidCallback clear})> _applied() {
final applied = <({String label, VoidCallback clear})>[];
final pipeline = _pipelineLabel;
if (pipeline != null) {
applied.add((label: pipeline, clear: () => controller.setPipeline(null)));
}
for (final status in controller.statuses) {
applied.add((label: status, clear: () => controller.setStatus(status)));
}
if (controller.scheduled != 'any') {
applied.add((
label: _scheduleLabel(controller.scheduled),
clear: () => controller.setScheduled('any'),
));
}
return applied;
}
String? get _pipelineLabel {
final id = controller.pipelineId;
if (id == null) return null;
for (final run in controller.runs) {
if (run['pipeline_id'] == id) {
final name = '${run['name'] ?? ''}'.trim();
if (name.isNotEmpty) return name;
}
}
return 'Pipeline $id';
}
Widget _appliedChip(
BuildContext context,
({String label, VoidCallback clear}) entry,
) {
final clearLabel = 'Clear filter: ${entry.label}';
if (usesCupertinoHost(context)) {
return Semantics(
button: true,
label: clearLabel,
excludeSemantics: true,
onTap: entry.clear,
child: CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
minimumSize: Size.zero,
onPressed: entry.clear,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(entry.label, overflow: TextOverflow.ellipsis),
),
const SizedBox(width: 4),
const Icon(CupertinoIcons.xmark_circle_fill, size: 16),
],
),
),
);
}
return InputChip(
label: Text(entry.label),
onDeleted: entry.clear,
deleteButtonTooltipMessage: clearLabel,
visualDensity: VisualDensity.compact,
);
}
}
typedef _FilterChoice = ({String kind, String value});
const _sorts = [
('newest_first', 'Newest'),
('oldest_first', 'Oldest'),
('pipeline_name', 'Pipeline'),
('newest_first', 'Newest first'),
('oldest_first', 'Oldest first'),
('pipeline_name', 'Pipeline name'),
('status', 'Status'),
];
const _schedules = [
('any', 'Any schedule'),
('scheduled', 'Scheduled'),
('unscheduled', 'Unscheduled'),
('any', 'Any trigger'),
('scheduled', 'Scheduled runs'),
('unscheduled', 'Not scheduled'),
];
const _statuses = ['queued', 'running', 'waiting', 'succeeded', 'failed'];
String _sortLabel(String value) =>
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
String _scheduleLabel(String value) => _schedules
.firstWhere((e) => e.$1 == value, orElse: () => _schedules.first)
.$2;
String _title(String value) => '${value[0].toUpperCase()}${value.substring(1)}';
+8 -3
View File
@@ -55,7 +55,7 @@ class RunsList extends StatelessWidget {
_heading(context),
if (controller.error != null) _inlineError(context),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: usesCupertinoHost(context)
? CupertinoSearchTextField(
placeholder: 'Filter runs',
@@ -63,7 +63,8 @@ class RunsList extends StatelessWidget {
)
: TextField(
decoration: const InputDecoration(
labelText: 'Filter runs',
hintText: 'Filter runs',
isDense: true,
prefixIcon: Icon(Icons.search),
),
onChanged: controller.setQuery,
@@ -93,7 +94,11 @@ class RunsList extends StatelessWidget {
Expanded(
child: controller.usage == null
? const SizedBox.shrink()
: Text('Usage: ${controller.usage}'),
: Text(
'Usage: ${controller.usage}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
NeedsYouRunsHeading(
rows: controller.runs,
@@ -380,4 +380,23 @@ void main() {
expect(controller.runs.first['title'], 'Late rename');
},
);
test('active filter count treats each facet once and clears all', () {
expect(controller.activeFilterCount, 0);
controller.setStatus('failed');
controller.setStatus('running');
expect(controller.activeFilterCount, 1);
controller.setScheduled('scheduled');
controller.setPipeline(4);
expect(controller.activeFilterCount, 3);
controller.clearFilters();
expect(controller.activeFilterCount, 0);
expect(controller.statuses, isEmpty);
expect(controller.pipelineId, isNull);
expect(controller.scheduled, 'any');
expect(controller.timeRange, 'any_time');
});
}
@@ -87,12 +87,23 @@ void main() {
expect(find.text('No runs found.'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), '');
await tester.pumpAndSettle();
await tester.tap(find.textContaining('Schedule:'));
await tester.tap(find.text('Filter'));
await tester.pumpAndSettle();
expect(find.text('Scheduled'), findsWidgets);
await tester.tap(find.text('Scheduled').last);
final scheduled = find.widgetWithText(
CupertinoActionSheetAction,
'Scheduled runs',
);
await tester.ensureVisible(scheduled);
await tester.tap(scheduled);
await tester.pumpAndSettle();
expect(controller.scheduled, 'scheduled');
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('Scheduled runs'), findsOneWidget);
await tester.tap(find.text('Scheduled runs'));
await tester.pumpAndSettle();
expect(controller.scheduled, 'any');
expect(find.text('Scheduled runs'), findsNothing);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
@@ -0,0 +1,141 @@
import 'dart:async';
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/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
JsonMap? reply;
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async =>
reply ?? {'runs': []};
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late _Gateway gateway;
late RunsController controller;
setUp(() {
gateway = _Gateway();
controller = RunsController(RunsRepository(gateway));
});
tearDown(() async {
controller.dispose();
await gateway.framesController.close();
});
Future<void> mount(WidgetTester tester, {required bool cupertino}) async {
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
],
};
await controller.load();
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) =>
RunsList(controller: controller, onSelected: (_) {}),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
await tester.pumpAndSettle();
}
testWidgets(
'material toolbar is a compact menu row with removable applied chips',
(tester) async {
await mount(tester, cupertino: false);
expect(find.byType(DropdownButton<String>), findsNothing);
expect(find.byType(FilterChip), findsNothing);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Sort: Newest first'), findsOneWidget);
await tester.tap(find.text('Filter'));
await tester.pumpAndSettle();
expect(find.text('queued'), findsOneWidget);
expect(find.text('Any trigger'), findsOneWidget);
final failedItem = find.ancestor(
of: find.text('failed'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.tap(failedItem);
await tester.pumpAndSettle();
expect(controller.statuses, {'failed'});
expect(find.text('Filter (1)'), findsOneWidget);
expect(find.byType(InputChip), findsOneWidget);
expect(find.text('failed'), findsWidgets);
expect(find.text('Alpha'), findsNothing);
expect(find.text('Beta'), findsOneWidget);
await tester.tap(find.textContaining('Sort:'));
await tester.pumpAndSettle();
final statusItem = find.ancestor(
of: find.text('Status'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.tap(statusItem);
await tester.pumpAndSettle();
expect(controller.sort, 'status');
expect(find.text('Sort: Status'), findsOneWidget);
await tester.tap(find.byTooltip('Clear filter: failed'));
await tester.pumpAndSettle();
expect(controller.statuses, isEmpty);
expect(find.byType(InputChip), findsNothing);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets(
'cupertino toolbar filters from one sheet and its chip clears the facet',
(tester) async {
await mount(tester, cupertino: true);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Sort: Newest first'), findsOneWidget);
await tester.tap(find.text('Filter'));
await tester.pumpAndSettle();
final failedAction = find.widgetWithText(
CupertinoActionSheetAction,
'failed',
);
await tester.ensureVisible(failedAction);
await tester.tap(failedAction);
await tester.pumpAndSettle();
expect(controller.statuses, {'failed'});
expect(find.text('✓ failed'), findsOneWidget);
expect(find.text('Filter (1)'), findsOneWidget);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
final failedChip = find.widgetWithText(CupertinoButton, 'failed');
expect(failedChip, findsOneWidget);
expect(find.text('Alpha'), findsNothing);
await tester.tap(failedChip);
await tester.pumpAndSettle();
expect(controller.statuses, isEmpty);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
}