wip(app): runs-filter-menu (retained from the cancelled overrun lane)

This commit is contained in:
2026-10-22 21:59:06 +01:00
parent 1bcc26a4fd
commit dc56795cfd
3 changed files with 195 additions and 15 deletions
@@ -177,6 +177,11 @@ class RunsController extends ChangeNotifier {
notifyListeners();
}
void setTimeRange(String value) {
timeRange = value;
notifyListeners();
}
void setSort(String value) {
sort = value;
notifyListeners();
+134 -9
View File
@@ -7,8 +7,8 @@ import 'runs_controller.dart';
/// The runs list's compact native filter/sort toolbar and applied-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.
/// Mirrors the browser's run toolbar: one `Filter` menu carrying its 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 {
@@ -58,6 +58,8 @@ class RunsFilters extends StatelessWidget {
checked: controller.sort == sort.$1,
child: Text(sort.$2),
),
const PopupMenuDivider(),
const PopupMenuItem(value: 'newest_first', child: Text('Reset')),
],
child: _materialButton(
Icons.sort,
@@ -79,6 +81,7 @@ class RunsFilters extends StatelessWidget {
);
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
const PopupMenuItem(enabled: false, child: Text('Status')),
for (final status in runStates)
CheckedPopupMenuItem(
value: (kind: 'status', value: status),
@@ -86,6 +89,28 @@ class RunsFilters extends StatelessWidget {
child: Text(status),
),
const PopupMenuDivider(),
const PopupMenuItem(enabled: false, child: Text('Pipeline')),
CheckedPopupMenuItem(
value: (kind: 'pipeline', value: ''),
checked: controller.pipelineId == null,
child: const Text('Any pipeline'),
),
for (final pipeline in _pipelines(controller))
CheckedPopupMenuItem(
value: (kind: 'pipeline', value: '${pipeline.id}'),
checked: controller.pipelineId == pipeline.id,
child: Text(pipeline.name),
),
const PopupMenuDivider(),
const PopupMenuItem(enabled: false, child: Text('Time range')),
for (final range in _timeRanges)
CheckedPopupMenuItem(
value: (kind: 'time', value: range.$1),
checked: controller.timeRange == range.$1,
child: Text(range.$2),
),
const PopupMenuDivider(),
const PopupMenuItem(enabled: false, child: Text('Trigger')),
for (final schedule in _schedules)
CheckedPopupMenuItem(
value: (kind: 'schedule', value: schedule.$1),
@@ -99,6 +124,15 @@ class RunsFilters extends StatelessWidget {
child: Text('Clear filters'),
),
],
if (_hasUnclassifiedRuns(controller)) ...[
const PopupMenuDivider(),
const PopupMenuItem(
enabled: false,
child: Text(
'Some records have no scheduling provenance; they stay unclassified.',
),
),
],
];
void _apply(_FilterChoice choice) {
@@ -106,6 +140,12 @@ class RunsFilters extends StatelessWidget {
controller.setStatus(choice.value);
} else if (choice.kind == 'schedule') {
controller.setScheduled(choice.value);
} else if (choice.kind == 'pipeline') {
controller.setPipeline(
choice.value.isEmpty ? null : int.tryParse(choice.value),
);
} else if (choice.kind == 'time') {
controller.setTimeRange(choice.value);
} else {
controller.clearFilters();
}
@@ -127,7 +167,7 @@ class RunsFilters extends StatelessWidget {
onPressed: () => _choose(
context,
'Sort runs',
_sorts,
_sortChoices,
controller.sort,
controller.setSort,
),
@@ -148,6 +188,7 @@ class RunsFilters extends StatelessWidget {
builder: (context, _) => CupertinoActionSheet(
title: const Text('Filter runs'),
actions: [
_cupertinoSection('Status'),
for (final status in runStates)
CupertinoActionSheetAction(
onPressed: () => controller.setStatus(status),
@@ -155,6 +196,29 @@ class RunsFilters extends StatelessWidget {
'${controller.statuses.contains(status) ? '✓ ' : ''}$status',
),
),
_cupertinoSection('Pipeline'),
CupertinoActionSheetAction(
onPressed: () => controller.setPipeline(null),
child: Text(
'${controller.pipelineId == null ? '✓ ' : ''}Any pipeline',
),
),
for (final pipeline in _pipelines(controller))
CupertinoActionSheetAction(
onPressed: () => controller.setPipeline(pipeline.id),
child: Text(
'${controller.pipelineId == pipeline.id ? '✓ ' : ''}${pipeline.name}',
),
),
_cupertinoSection('Time range'),
for (final range in _timeRanges)
CupertinoActionSheetAction(
onPressed: () => controller.setTimeRange(range.$1),
child: Text(
'${controller.timeRange == range.$1 ? '✓ ' : ''}${range.$2}',
),
),
_cupertinoSection('Trigger'),
for (final schedule in _schedules)
CupertinoActionSheetAction(
onPressed: () => controller.setScheduled(schedule.$1),
@@ -163,6 +227,13 @@ class RunsFilters extends StatelessWidget {
'${schedule.$2}',
),
),
if (_hasUnclassifiedRuns(controller))
CupertinoActionSheetAction(
onPressed: () {},
child: const Text(
'Some records have no scheduling provenance; they stay unclassified.',
),
),
if (controller.activeFilterCount > 0)
CupertinoActionSheetAction(
onPressed: controller.clearFilters,
@@ -206,12 +277,16 @@ class RunsFilters extends StatelessWidget {
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)],
return Semantics(
container: true,
label: 'Applied run filters',
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
child: Wrap(
spacing: 8,
runSpacing: 4,
children: [for (final entry in applied) _appliedChip(context, entry)],
),
),
);
}
@@ -225,6 +300,12 @@ class RunsFilters extends StatelessWidget {
for (final status in controller.statuses) {
applied.add((label: status, clear: () => controller.setStatus(status)));
}
if (controller.timeRange != 'any_time') {
applied.add((
label: _timeRangeLabel(controller.timeRange),
clear: () => controller.setTimeRange('any_time'),
));
}
if (controller.scheduled != 'any') {
applied.add((
label: _scheduleLabel(controller.scheduled),
@@ -288,14 +369,58 @@ typedef _FilterChoice = ({String kind, String value});
const _sorts = [
('newest_first', 'Newest first'),
('oldest_first', 'Oldest first'),
('longest_duration', 'Longest duration'),
('shortest_duration', 'Shortest duration'),
('pipeline_name', 'Pipeline name'),
('status', 'Status'),
];
const _sortChoices = [..._sorts, ('newest_first', 'Reset')];
const _schedules = [
('any', 'Any trigger'),
('scheduled', 'Scheduled runs'),
('unscheduled', 'Not scheduled'),
];
const _timeRanges = [
('any_time', 'Any time'),
('today', 'Today'),
('last_7_days', 'Last 7 days'),
('last_30_days', 'Last 30 days'),
];
List<({int id, String name})> _pipelines(RunsController controller) {
final names = <int, String>{};
final ids = <int>{};
for (final run in controller.runs) {
final id = run['pipeline_id'];
if (id is! int) continue;
ids.add(id);
final name = '${run['name'] ?? ''}'.trim();
if (name.isNotEmpty && !names.containsKey(id)) names[id] = name;
}
final options = ids
.map((id) => (id: id, name: names[id] ?? 'Pipeline $id'))
.toList();
options.sort((a, b) {
final nameOrder = a.name.toLowerCase().compareTo(b.name.toLowerCase());
return nameOrder != 0 ? nameOrder : a.id.compareTo(b.id);
});
return options;
}
bool _hasUnclassifiedRuns(RunsController controller) =>
controller.runs.any((run) {
final id = run['schedule_id'];
return run['scheduled'] is! bool && !(id is num && id > 0);
});
Widget _cupertinoSection(String title) => Padding(
padding: const EdgeInsetsDirectional.only(top: 8),
child: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
);
String _timeRangeLabel(String value) => _timeRanges
.firstWhere((entry) => entry.$1 == value, orElse: () => _timeRanges.first)
.$2;
String _sortLabel(String value) =>
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
String _scheduleLabel(String value) => _schedules
@@ -38,8 +38,21 @@ void main() {
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},
{
'id': 1,
'pipeline_id': 9,
'name': 'Alpha',
'status': 'running',
'created_at': DateTime.now().toIso8601String(),
'scheduled': true,
},
{
'id': 2,
'pipeline_id': 10,
'name': 'Beta',
'status': 'failed',
'created_at': DateTime.now().toIso8601String(),
},
],
};
await controller.load();
@@ -68,8 +81,42 @@ void main() {
await tester.tap(find.text('Filter'));
await tester.pumpAndSettle();
expect(find.text('queued'), findsOneWidget);
expect(find.text('Pipeline'), findsOneWidget);
expect(find.text('Any pipeline'), findsOneWidget);
expect(find.text('Time range'), findsOneWidget);
expect(find.text('Last 7 days'), findsOneWidget);
expect(find.text('Any trigger'), findsOneWidget);
expect(
find.text(
'Some records have no scheduling provenance; they stay unclassified.',
),
findsOneWidget,
);
final pipelineItem = find.ancestor(
of: find.text('Alpha'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.ensureVisible(pipelineItem);
await tester.tap(pipelineItem);
await tester.pumpAndSettle();
expect(controller.pipelineId, 9);
await tester.tap(find.text('Filter (1)'));
await tester.pumpAndSettle();
final timeItem = find.ancestor(
of: find.text('Last 7 days'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
);
await tester.ensureVisible(timeItem);
await tester.tap(timeItem);
await tester.pumpAndSettle();
expect(controller.timeRange, 'last_7_days');
expect(find.text('Filter (2)'), findsOneWidget);
expect(find.byTooltip('Clear filter: Last 7 days'), findsOneWidget);
await tester.tap(find.text('Filter (2)'));
await tester.pumpAndSettle();
final failedItem = find.ancestor(
of: find.text('failed'),
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
@@ -77,11 +124,10 @@ void main() {
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('Filter (3)'), findsOneWidget);
expect(find.byType(InputChip), findsNWidgets(3));
expect(find.text('failed'), findsWidgets);
expect(find.text('Alpha'), findsNothing);
expect(find.text('Beta'), findsOneWidget);
expect(controller.visibleRuns, isEmpty);
await tester.tap(find.textContaining('Sort:'));
await tester.pumpAndSettle();
@@ -97,6 +143,8 @@ void main() {
await tester.tap(find.byTooltip('Clear filter: failed'));
await tester.pumpAndSettle();
expect(controller.statuses, isEmpty);
controller.clearFilters();
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNothing);
expect(find.text('Filter'), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
@@ -122,6 +170,8 @@ void main() {
await tester.pumpAndSettle();
expect(controller.statuses, {'failed'});
expect(find.text('✓ failed'), findsOneWidget);
expect(find.text('Pipeline'), findsOneWidget);
expect(find.text('Last 7 days'), findsOneWidget);
expect(find.text('Filter (1)'), findsOneWidget);
await tester.tap(find.text('Done'));