feat(app): complete runs UI candidate

This commit is contained in:
2026-10-21 13:51:07 +01:00
parent 0a0d287e49
commit 6b8d5ea32e
5 changed files with 285 additions and 22 deletions
@@ -8,7 +8,7 @@ class RunDetailView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final run = controller.detail;
if (controller.loading && run == null) {
if (controller.detailLoading && run == null) {
return const Center(child: CircularProgressIndicator());
}
if (run == null) {
@@ -84,7 +84,7 @@ class RunDetailView extends StatelessWidget {
),
),
),
const ListTile(title: Text('Metrics'), subtitle: Text('Unavailable')),
_section(context, 'Metrics', run['usage'] is Map ? run['usage'] as Map : const {}),
],
);
}
+136 -20
View File
@@ -10,12 +10,19 @@ class RunsController extends ChangeNotifier {
final RunsRepository repository;
StreamSubscription<JsonMap>? _subscription;
List<JsonMap> runs = [];
JsonMap? detail;
JsonMap? detail, usage;
String? error;
bool loading = false;
String query = '', sort = 'newest_first';
bool loading = false, detailLoading = false;
String query = '',
sort = 'newest_first',
scheduled = 'any',
timeRange = 'any_time';
final Set<String> statuses = {};
int? pipelineId;
int _selection = 0;
num? _selectedId;
Timer? _refresh;
bool _refreshInFlight = false, _refreshAgain = false, _disposed = false;
void listen(Stream<JsonMap> frames) {
_subscription?.cancel();
@@ -31,13 +38,18 @@ class RunsController extends ChangeNotifier {
notifyListeners();
try {
final result = await repository.listRuns();
if (token != _selection) return;
if (_disposed || token != _selection) return;
runs = result.runs;
if (initialId != null) await select(initialId);
usage = result.usage;
if (initialId != null) {
// Keep list and detail request generations independent: selecting the
// initial row must not make this list request's completion stale.
await select(initialId);
}
} catch (e) {
if (token == _selection) error = '$e';
if (!_disposed && token == _selection) error = '$e';
}
if (token == _selection) {
if (!_disposed && token == _selection) {
loading = false;
notifyListeners();
}
@@ -45,25 +57,33 @@ class RunsController extends ChangeNotifier {
Future<void> select(num id) async {
final token = ++_selection;
detail = null;
_refresh?.cancel();
_refresh = null;
_refreshAgain = false;
_selectedId = id;
detailLoading = true;
error = null;
loading = true;
notifyListeners();
try {
final value = await repository.getRun(id);
if (token == _selection) detail = value;
if (!_disposed && token == _selection) detail = value;
} catch (e) {
if (token == _selection) error = '$e';
if (!_disposed && token == _selection) error = '$e';
}
if (token == _selection) {
loading = false;
if (!_disposed && token == _selection) {
detailLoading = false;
notifyListeners();
}
}
void back() {
++_selection;
_selectedId = null;
_refresh?.cancel();
_refresh = null;
_refreshAgain = false;
detail = null;
detailLoading = false;
error = null;
notifyListeners();
}
@@ -73,24 +93,118 @@ class RunsController extends ChangeNotifier {
notifyListeners();
}
void setStatus(String? value) {
if (value == null) {
statuses.clear();
} else if (!statuses.add(value)) {
statuses.remove(value);
}
notifyListeners();
}
void setPipeline(int? value) {
pipelineId = value;
notifyListeners();
}
void setScheduled(String value) {
scheduled = value;
notifyListeners();
}
void setSort(String value) {
sort = value;
notifyListeners();
}
void _event(JsonMap frame) {
final folded = foldRunEvent(runs, frame);
runs = folded.runs;
if (detail?['id'] == frame['run_id']) {
detail = foldRunEventDetail(detail, frame);
}
if (detail != null && runDetailNeedsFullSync(frame)) {
_refresh?.cancel();
_refresh = Timer(
const Duration(milliseconds: 150),
() => select(detail!['id'] as num),
);
if (frame['run_id'] == null || folded.needsResync) {
_scheduleListRefresh();
}
if (_selectedId != null &&
frame['run_id'] == _selectedId &&
(folded.needsResync || runDetailNeedsFullSync(frame))) {
if (_refreshInFlight) {
_refreshAgain = true;
} else {
_refresh?.cancel();
final id = _selectedId!;
final generation = _selection;
_refresh = Timer(
const Duration(milliseconds: 150),
() => _refreshDetail(id, generation),
);
}
}
notifyListeners();
}
void _scheduleListRefresh() {
if (_disposed || loading) return;
loading = true;
notifyListeners();
unawaited(_reloadList());
}
Future<void> _reloadList() async {
try {
final result = await repository.listRuns();
if (_disposed) return;
runs = result.runs;
usage = result.usage;
error = null;
} catch (e) {
if (!_disposed) error = '$e';
} finally {
if (!_disposed) {
loading = false;
notifyListeners();
}
}
}
Future<void> _refreshDetail(num id, int generation) async {
if (_disposed || generation != _selection || _selectedId != id) return;
_refreshInFlight = true;
try {
final value = await repository.getRun(id);
if (!_disposed && generation == _selection && _selectedId == id) {
detail = value;
notifyListeners();
}
} catch (e) {
if (!_disposed && generation == _selection && _selectedId == id) {
error = '$e';
notifyListeners();
}
} finally {
_refreshInFlight = false;
if (!_disposed &&
_refreshAgain &&
generation == _selection &&
_selectedId == id) {
_refreshAgain = false;
_refresh = Timer(
const Duration(milliseconds: 150),
() => _refreshDetail(id, generation),
);
}
}
}
List<JsonMap> get visibleRuns => sortRuns(
runs
filterRuns(
runs,
statuses: statuses,
pipelineId: pipelineId,
scheduled: scheduled,
timeRange: timeRange,
)
.where(
(r) => '${r['title'] ?? r['name'] ?? ''}'.toLowerCase().contains(
query.toLowerCase(),
@@ -99,8 +213,10 @@ class RunsController extends ChangeNotifier {
.toList(),
sort: sort,
);
@override
void dispose() {
_disposed = true;
_subscription?.cancel();
_refresh?.cancel();
super.dispose();
+8
View File
@@ -27,6 +27,8 @@ class RunsList extends StatelessWidget {
}
return Column(
children: [
if (controller.usage != null)
Padding(padding: const EdgeInsets.symmetric(horizontal: 16), child: Text('Usage: ${controller.usage}')),
if (controller.error != null)
MaterialBanner(
content: Text(controller.error!),
@@ -44,6 +46,12 @@ class RunsList extends StatelessWidget {
onChanged: controller.setQuery,
),
),
Wrap(spacing: 8, children: [
DropdownButton<String>(value: controller.sort, onChanged: (v) { if (v != null) controller.setSort(v); }, items: const [DropdownMenuItem(value: 'newest_first', child: Text('Newest')), DropdownMenuItem(value: 'oldest_first', child: Text('Oldest')), DropdownMenuItem(value: 'pipeline_name', child: Text('Pipeline')), DropdownMenuItem(value: 'status', child: Text('Status'))]),
DropdownButton<String>(value: controller.scheduled, onChanged: (v) { if (v != null) controller.setScheduled(v); }, items: const [DropdownMenuItem(value: 'any', child: Text('Any schedule')), DropdownMenuItem(value: 'scheduled', child: Text('Scheduled')), DropdownMenuItem(value: 'unscheduled', child: Text('Unscheduled'))]),
for (final status in ['queued', 'running', 'waiting', 'succeeded', 'failed'])
FilterChip(label: Text(status), selected: controller.statuses.contains(status), onSelected: (_) => controller.setStatus(status)),
]),
Expanded(
child: controller.visibleRuns.isEmpty
? const Center(child: Text('No runs found.'))