feat(app): show the live Needs-you bell over the Runs list rows

This commit is contained in:
2026-10-22 00:52:06 +01:00
parent 1835bc8832
commit a309d9d571
15 changed files with 1557 additions and 127 deletions
+138
View File
@@ -0,0 +1,138 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import 'runs_controller.dart';
/// The runs list's native sort/schedule/status controls.
///
/// 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.
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(
children: [
CupertinoButton(
onPressed: () => _choose(
context,
'Sort runs',
_sorts,
controller.sort,
controller.setSort,
),
child: Text('Sort: ${_sortLabel(controller.sort)}'),
),
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)}',
),
),
],
],
),
);
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(),
),
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(),
),
for (final status in _statuses)
FilterChip(
label: Text(_title(status)),
selected: controller.statuses.contains(status),
onSelected: (_) => controller.setStatus(status),
),
],
);
Future<void> _choose(
BuildContext context,
String title,
List<(String, String)> values,
String selected,
ValueChanged<String> onSelected,
) async {
final value = await showCupertinoModalPopup<String>(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text(title),
actions: [
for (final option in values)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, option.$1),
child: Text(option.$2),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (value != null && value != selected) onSelected(value);
}
}
const _sorts = [
('newest_first', 'Newest'),
('oldest_first', 'Oldest'),
('pipeline_name', 'Pipeline'),
('status', 'Status'),
];
const _schedules = [
('any', 'Any schedule'),
('scheduled', 'Scheduled'),
('unscheduled', 'Unscheduled'),
];
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)}';
+31 -115
View File
@@ -3,19 +3,35 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../attention/runtime/attention_store.dart';
import '../../attention/ui/needs_you_runs_heading.dart';
import '../domain/run_models.dart';
import 'runs_controller.dart';
import 'runs_filters.dart';
class RunsList extends StatelessWidget {
const RunsList({
super.key,
required this.controller,
required this.onSelected,
this.syncToken = 0,
this.attentionStore = const SharedPreferencesAttentionStore(),
this.attentionNow,
});
final RunsController controller;
final ValueChanged<num> onSelected;
/// Advances when the shared socket is replaced, so the attention detector
/// rebaselines instead of replaying a transition from before the gap.
final int syncToken;
/// Test and fixture seam for the persisted attention dismissals.
final AttentionStore attentionStore;
/// Deterministic local-day clock for the attention window.
final DateTime Function()? attentionNow;
@override
Widget build(BuildContext context) {
if (controller.loading && controller.runs.isEmpty) {
@@ -31,6 +47,20 @@ class RunsList extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: NeedsYouRunsHeading(
rows: controller.runs,
frames: controller.repository.gateway.frames,
onOpen: (entry) => onSelected(entry.runId),
syncToken: syncToken,
store: attentionStore,
now: attentionNow,
),
),
),
if (controller.usage != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
@@ -52,7 +82,7 @@ class RunsList extends StatelessWidget {
onChanged: controller.setQuery,
),
),
_selectors(context),
RunsFilters(controller: controller),
Expanded(
child: controller.visibleRuns.isEmpty
? const Center(child: Text('No runs found.'))
@@ -101,101 +131,6 @@ class RunsList extends StatelessWidget {
),
);
Widget _selectors(BuildContext context) {
if (usesCupertinoHost(context)) {
return Wrap(
spacing: 8,
children: [
CupertinoButton(
onPressed: () => _choose(
context,
'Sort runs',
_sorts,
controller.sort,
controller.setSort,
),
child: Text('Sort: ${_sortLabel(controller.sort)}'),
),
CupertinoButton(
onPressed: () => _choose(
context,
'Schedule',
_schedules,
controller.scheduled,
controller.setScheduled,
),
child: Text('Schedule: ${_scheduleLabel(controller.scheduled)}'),
),
for (final status in _statuses)
CupertinoButton(
onPressed: () => controller.setStatus(status),
child: Text(
'${controller.statuses.contains(status) ? '✓ ' : ''}${_title(status)}',
),
),
],
);
}
return 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(),
),
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(),
),
for (final status in _statuses)
FilterChip(
label: Text(_title(status)),
selected: controller.statuses.contains(status),
onSelected: (_) => controller.setStatus(status),
),
],
);
}
Future<void> _choose(
BuildContext context,
String title,
List<(String, String)> values,
String selected,
ValueChanged<String> onSelected,
) async {
final value = await showCupertinoModalPopup<String>(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text(title),
actions: [
for (final option in values)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, option.$1),
child: Text(option.$2),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (value != null && value != selected) onSelected(value);
}
Widget _runTile(BuildContext context, JsonMap run) {
final identity = runIdentity(run['title'], run['name']);
final id = run['id'];
@@ -222,22 +157,3 @@ class RunsList extends StatelessWidget {
);
}
}
const _sorts = [
('newest_first', 'Newest'),
('oldest_first', 'Oldest'),
('pipeline_name', 'Pipeline'),
('status', 'Status'),
];
const _schedules = [
('any', 'Any schedule'),
('scheduled', 'Scheduled'),
('unscheduled', 'Unscheduled'),
];
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)}';