f57d8eeb76
`/runs/:id/stage/:key?visit=N` now selects that stage's N-th recorded visit in the run detail Timeline, matching the web client's stage-local visit ordering. A stage key without a visit opens the latest recorded visit, an out-of-range index clamps to the last one, and a stage with no recorded visit selects only its Graph node instead of inventing a visit. Route plumbing carries the query end to end: boot seeds the router from path and query, the parser reads path plus query, and restore keeps `?` a query separator instead of percent-encoding it. That also repairs the existing `?action=decide` and `/runs?pipeline=` URLs. The Graph node click and the stage route share one sequence-ordered resolver, so both open the same latest visit.
160 lines
4.9 KiB
Dart
160 lines
4.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../core/api_gateway.dart';
|
|
import '../attention/notify/notification_controller.dart';
|
|
import '../attention/runtime/attention_store.dart';
|
|
import 'data/runs_repository.dart';
|
|
import 'ui/run_detail_view.dart';
|
|
import 'ui/runs_controller.dart';
|
|
import 'ui/runs_list.dart';
|
|
|
|
/// The runs destination's list/detail switch.
|
|
///
|
|
/// The controller's `selectedRunId` is the only selection source, so an
|
|
/// initial run, a pending detail, a failed detail, Back and a route change all
|
|
/// navigate the same way. The shell owns the app bar; this screen adds no
|
|
/// second one.
|
|
class RunsScreen extends StatefulWidget {
|
|
const RunsScreen({
|
|
super.key,
|
|
required this.gateway,
|
|
this.initialRunId,
|
|
this.initialStageKey,
|
|
this.initialVisit,
|
|
this.syncToken = 0,
|
|
this.listRefreshToken = 0,
|
|
this.onRunSelected,
|
|
this.onBack,
|
|
this.attentionStore = const SharedPreferencesAttentionStore(),
|
|
this.attentionNow,
|
|
this.notifications,
|
|
});
|
|
|
|
final ApiGateway gateway;
|
|
|
|
/// The run the current route names, or null for the list.
|
|
final int? initialRunId;
|
|
|
|
/// The recorded stage visit the route names inside [initialRunId]. The detail
|
|
/// applies it once per route target; the feature never invents a visit.
|
|
final String? initialStageKey;
|
|
final int? initialVisit;
|
|
|
|
/// Advances when the shared socket is replaced. The loaded screen refreshes
|
|
/// in place instead of being remounted, so its selection survives.
|
|
final int syncToken;
|
|
|
|
/// Advances when a launch accepted outside this screen must be reflected by a
|
|
/// fresh `list_runs` read. It never inserts a row of its own.
|
|
final int listRefreshToken;
|
|
|
|
final ValueChanged<int>? onRunSelected;
|
|
final VoidCallback? onBack;
|
|
|
|
/// Persisted attention dismissals and the clock for its local-day window.
|
|
/// The app uses SharedPreferences; tests and fixtures inject a memory store.
|
|
final AttentionStore attentionStore;
|
|
final DateTime Function()? attentionNow;
|
|
|
|
/// App-level notification delivery for live attention transitions.
|
|
final NotificationController? notifications;
|
|
|
|
@override
|
|
State<RunsScreen> createState() => _RunsScreenState();
|
|
}
|
|
|
|
class _RunsScreenState extends State<RunsScreen> {
|
|
late final RunsController controller;
|
|
num? _shownRunId;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller = RunsController(RunsRepository(widget.gateway));
|
|
controller.listen(widget.gateway.frames);
|
|
controller.addListener(_selectionChanged);
|
|
controller.load(widget.initialRunId);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant RunsScreen oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.syncToken != oldWidget.syncToken) {
|
|
controller.resync();
|
|
}
|
|
// A launch accepted on another destination invalidates the list only. The
|
|
// route change below selects the returned run separately, so this is the
|
|
// one fresh server read that makes the new row appear.
|
|
if (widget.listRefreshToken != oldWidget.listRefreshToken) {
|
|
controller.load();
|
|
}
|
|
if (widget.initialRunId != oldWidget.initialRunId) {
|
|
final id = widget.initialRunId;
|
|
if (id == null) {
|
|
if (controller.selectedRunId != null) controller.back();
|
|
} else if (controller.selectedRunId != id) {
|
|
controller.select(id);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Rebuild the switch only when the selection changes. Detail progress and
|
|
/// live updates are already watched by [RunDetailView] and [RunsList], so
|
|
/// this avoids a second whole-detail rebuild per notification.
|
|
void _selectionChanged() {
|
|
final selected = controller.selectedRunId;
|
|
if (selected == _shownRunId) return;
|
|
_shownRunId = selected;
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
void _select(num id) {
|
|
controller.select(id);
|
|
widget.onRunSelected?.call(id.toInt());
|
|
}
|
|
|
|
void _back() {
|
|
controller.back();
|
|
widget.onBack?.call();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.removeListener(_selectionChanged);
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final selected = controller.selectedRunId != null;
|
|
return Stack(
|
|
children: [
|
|
AnimatedBuilder(
|
|
animation: controller,
|
|
builder: (context, _) => Offstage(
|
|
offstage: selected,
|
|
child: RunsList(
|
|
controller: controller,
|
|
onSelected: _select,
|
|
syncToken: widget.syncToken,
|
|
attentionStore: widget.attentionStore,
|
|
attentionNow: widget.attentionNow,
|
|
notifications: widget.notifications,
|
|
),
|
|
),
|
|
),
|
|
if (selected)
|
|
RunDetailView(
|
|
controller: controller,
|
|
gateway: widget.gateway,
|
|
onBack: _back,
|
|
onRunOpened: _select,
|
|
initialStageKey: widget.initialStageKey,
|
|
initialVisit: widget.initialVisit,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|