wip(app): runs-filter-menu (retained from the cancelled overrun lane)
This commit is contained in:
@@ -177,6 +177,11 @@ class RunsController extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTimeRange(String value) {
|
||||||
|
timeRange = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
void setSort(String value) {
|
void setSort(String value) {
|
||||||
sort = value;
|
sort = value;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import 'runs_controller.dart';
|
|||||||
|
|
||||||
/// The runs list's compact native filter/sort toolbar and applied-filter chips.
|
/// 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
|
/// Mirrors the browser's run toolbar: one `Filter` menu carrying its facets,
|
||||||
/// trigger facets, one `Sort:` menu, and a removable chip per applied facet.
|
/// one `Sort:` menu, and a removable chip per applied facet.
|
||||||
/// The buttons sit in a single horizontally scrollable row so a phone at a
|
/// 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.
|
/// doubled text scale can still reach them without crushing the list.
|
||||||
class RunsFilters extends StatelessWidget {
|
class RunsFilters extends StatelessWidget {
|
||||||
@@ -58,6 +58,8 @@ class RunsFilters extends StatelessWidget {
|
|||||||
checked: controller.sort == sort.$1,
|
checked: controller.sort == sort.$1,
|
||||||
child: Text(sort.$2),
|
child: Text(sort.$2),
|
||||||
),
|
),
|
||||||
|
const PopupMenuDivider(),
|
||||||
|
const PopupMenuItem(value: 'newest_first', child: Text('Reset')),
|
||||||
],
|
],
|
||||||
child: _materialButton(
|
child: _materialButton(
|
||||||
Icons.sort,
|
Icons.sort,
|
||||||
@@ -79,6 +81,7 @@ class RunsFilters extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
|
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
|
||||||
|
const PopupMenuItem(enabled: false, child: Text('Status')),
|
||||||
for (final status in runStates)
|
for (final status in runStates)
|
||||||
CheckedPopupMenuItem(
|
CheckedPopupMenuItem(
|
||||||
value: (kind: 'status', value: status),
|
value: (kind: 'status', value: status),
|
||||||
@@ -86,6 +89,28 @@ class RunsFilters extends StatelessWidget {
|
|||||||
child: Text(status),
|
child: Text(status),
|
||||||
),
|
),
|
||||||
const PopupMenuDivider(),
|
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)
|
for (final schedule in _schedules)
|
||||||
CheckedPopupMenuItem(
|
CheckedPopupMenuItem(
|
||||||
value: (kind: 'schedule', value: schedule.$1),
|
value: (kind: 'schedule', value: schedule.$1),
|
||||||
@@ -99,6 +124,15 @@ class RunsFilters extends StatelessWidget {
|
|||||||
child: Text('Clear filters'),
|
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) {
|
void _apply(_FilterChoice choice) {
|
||||||
@@ -106,6 +140,12 @@ class RunsFilters extends StatelessWidget {
|
|||||||
controller.setStatus(choice.value);
|
controller.setStatus(choice.value);
|
||||||
} else if (choice.kind == 'schedule') {
|
} else if (choice.kind == 'schedule') {
|
||||||
controller.setScheduled(choice.value);
|
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 {
|
} else {
|
||||||
controller.clearFilters();
|
controller.clearFilters();
|
||||||
}
|
}
|
||||||
@@ -127,7 +167,7 @@ class RunsFilters extends StatelessWidget {
|
|||||||
onPressed: () => _choose(
|
onPressed: () => _choose(
|
||||||
context,
|
context,
|
||||||
'Sort runs',
|
'Sort runs',
|
||||||
_sorts,
|
_sortChoices,
|
||||||
controller.sort,
|
controller.sort,
|
||||||
controller.setSort,
|
controller.setSort,
|
||||||
),
|
),
|
||||||
@@ -148,6 +188,7 @@ class RunsFilters extends StatelessWidget {
|
|||||||
builder: (context, _) => CupertinoActionSheet(
|
builder: (context, _) => CupertinoActionSheet(
|
||||||
title: const Text('Filter runs'),
|
title: const Text('Filter runs'),
|
||||||
actions: [
|
actions: [
|
||||||
|
_cupertinoSection('Status'),
|
||||||
for (final status in runStates)
|
for (final status in runStates)
|
||||||
CupertinoActionSheetAction(
|
CupertinoActionSheetAction(
|
||||||
onPressed: () => controller.setStatus(status),
|
onPressed: () => controller.setStatus(status),
|
||||||
@@ -155,6 +196,29 @@ class RunsFilters extends StatelessWidget {
|
|||||||
'${controller.statuses.contains(status) ? '✓ ' : ''}$status',
|
'${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)
|
for (final schedule in _schedules)
|
||||||
CupertinoActionSheetAction(
|
CupertinoActionSheetAction(
|
||||||
onPressed: () => controller.setScheduled(schedule.$1),
|
onPressed: () => controller.setScheduled(schedule.$1),
|
||||||
@@ -163,6 +227,13 @@ class RunsFilters extends StatelessWidget {
|
|||||||
'${schedule.$2}',
|
'${schedule.$2}',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_hasUnclassifiedRuns(controller))
|
||||||
|
CupertinoActionSheetAction(
|
||||||
|
onPressed: () {},
|
||||||
|
child: const Text(
|
||||||
|
'Some records have no scheduling provenance; they stay unclassified.',
|
||||||
|
),
|
||||||
|
),
|
||||||
if (controller.activeFilterCount > 0)
|
if (controller.activeFilterCount > 0)
|
||||||
CupertinoActionSheetAction(
|
CupertinoActionSheetAction(
|
||||||
onPressed: controller.clearFilters,
|
onPressed: controller.clearFilters,
|
||||||
@@ -206,12 +277,16 @@ class RunsFilters extends StatelessWidget {
|
|||||||
|
|
||||||
Widget _appliedFilters(BuildContext context) {
|
Widget _appliedFilters(BuildContext context) {
|
||||||
final applied = _applied();
|
final applied = _applied();
|
||||||
return Padding(
|
return Semantics(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
container: true,
|
||||||
child: Wrap(
|
label: 'Applied run filters',
|
||||||
spacing: 8,
|
child: Padding(
|
||||||
runSpacing: 4,
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||||
children: [for (final entry in applied) _appliedChip(context, entry)],
|
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) {
|
for (final status in controller.statuses) {
|
||||||
applied.add((label: status, clear: () => controller.setStatus(status)));
|
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') {
|
if (controller.scheduled != 'any') {
|
||||||
applied.add((
|
applied.add((
|
||||||
label: _scheduleLabel(controller.scheduled),
|
label: _scheduleLabel(controller.scheduled),
|
||||||
@@ -288,14 +369,58 @@ typedef _FilterChoice = ({String kind, String value});
|
|||||||
const _sorts = [
|
const _sorts = [
|
||||||
('newest_first', 'Newest first'),
|
('newest_first', 'Newest first'),
|
||||||
('oldest_first', 'Oldest first'),
|
('oldest_first', 'Oldest first'),
|
||||||
|
('longest_duration', 'Longest duration'),
|
||||||
|
('shortest_duration', 'Shortest duration'),
|
||||||
('pipeline_name', 'Pipeline name'),
|
('pipeline_name', 'Pipeline name'),
|
||||||
('status', 'Status'),
|
('status', 'Status'),
|
||||||
];
|
];
|
||||||
|
const _sortChoices = [..._sorts, ('newest_first', 'Reset')];
|
||||||
const _schedules = [
|
const _schedules = [
|
||||||
('any', 'Any trigger'),
|
('any', 'Any trigger'),
|
||||||
('scheduled', 'Scheduled runs'),
|
('scheduled', 'Scheduled runs'),
|
||||||
('unscheduled', 'Not scheduled'),
|
('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) =>
|
String _sortLabel(String value) =>
|
||||||
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
|
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
|
||||||
String _scheduleLabel(String value) => _schedules
|
String _scheduleLabel(String value) => _schedules
|
||||||
|
|||||||
@@ -38,8 +38,21 @@ void main() {
|
|||||||
Future<void> mount(WidgetTester tester, {required bool cupertino}) async {
|
Future<void> mount(WidgetTester tester, {required bool cupertino}) async {
|
||||||
gateway.reply = {
|
gateway.reply = {
|
||||||
'runs': [
|
'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();
|
await controller.load();
|
||||||
@@ -68,8 +81,42 @@ void main() {
|
|||||||
await tester.tap(find.text('Filter'));
|
await tester.tap(find.text('Filter'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('queued'), findsOneWidget);
|
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('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(
|
final failedItem = find.ancestor(
|
||||||
of: find.text('failed'),
|
of: find.text('failed'),
|
||||||
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
|
matching: find.byWidgetPredicate((widget) => widget is PopupMenuItem),
|
||||||
@@ -77,11 +124,10 @@ void main() {
|
|||||||
await tester.tap(failedItem);
|
await tester.tap(failedItem);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(controller.statuses, {'failed'});
|
expect(controller.statuses, {'failed'});
|
||||||
expect(find.text('Filter (1)'), findsOneWidget);
|
expect(find.text('Filter (3)'), findsOneWidget);
|
||||||
expect(find.byType(InputChip), findsOneWidget);
|
expect(find.byType(InputChip), findsNWidgets(3));
|
||||||
expect(find.text('failed'), findsWidgets);
|
expect(find.text('failed'), findsWidgets);
|
||||||
expect(find.text('Alpha'), findsNothing);
|
expect(controller.visibleRuns, isEmpty);
|
||||||
expect(find.text('Beta'), findsOneWidget);
|
|
||||||
|
|
||||||
await tester.tap(find.textContaining('Sort:'));
|
await tester.tap(find.textContaining('Sort:'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -97,6 +143,8 @@ void main() {
|
|||||||
await tester.tap(find.byTooltip('Clear filter: failed'));
|
await tester.tap(find.byTooltip('Clear filter: failed'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(controller.statuses, isEmpty);
|
expect(controller.statuses, isEmpty);
|
||||||
|
controller.clearFilters();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(InputChip), findsNothing);
|
expect(find.byType(InputChip), findsNothing);
|
||||||
expect(find.text('Filter'), findsOneWidget);
|
expect(find.text('Filter'), findsOneWidget);
|
||||||
expect(find.text('Alpha'), findsOneWidget);
|
expect(find.text('Alpha'), findsOneWidget);
|
||||||
@@ -122,6 +170,8 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(controller.statuses, {'failed'});
|
expect(controller.statuses, {'failed'});
|
||||||
expect(find.text('✓ failed'), findsOneWidget);
|
expect(find.text('✓ failed'), findsOneWidget);
|
||||||
|
expect(find.text('Pipeline'), findsOneWidget);
|
||||||
|
expect(find.text('Last 7 days'), findsOneWidget);
|
||||||
expect(find.text('Filter (1)'), findsOneWidget);
|
expect(find.text('Filter (1)'), findsOneWidget);
|
||||||
|
|
||||||
await tester.tap(find.text('Done'));
|
await tester.tap(find.text('Done'));
|
||||||
|
|||||||
Reference in New Issue
Block a user