feat(app): open a recorded run visit from its URL

`/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.
This commit is contained in:
2026-10-22 10:48:36 +01:00
parent 7aa7007aee
commit f57d8eeb76
12 changed files with 623 additions and 18 deletions
+28 -6
View File
@@ -11,13 +11,24 @@ class AppRouteParser extends RouteInformationParser<AppRoute> {
@override
Future<AppRoute> parseRouteInformation(
RouteInformation routeInformation,
) async => AppRoute.parse(routeInformation.uri.path);
) async => AppRoute.parse(routeLocation(routeInformation.uri));
@override
RouteInformation restoreRouteInformation(AppRoute configuration) =>
RouteInformation(uri: Uri(path: configuration.path));
// The route's path already carries its query (`?visit=N`, `?action=…`).
// Parsing it keeps that query a query instead of percent-encoding the
// `?` into the path, which would make a reload read one bogus key.
RouteInformation(uri: Uri.parse(configuration.path));
}
/// The app-relative location of [uri]: its path plus query, without origin.
///
/// [AppRoute.parse] understands this form, so a browser location such as
/// `/runs/7/stage/plan?visit=1` keeps the query instead of losing it to
/// `Uri.path`. A fragment is not part of an app route.
String routeLocation(Uri uri) =>
uri.hasQuery ? '${uri.path}?${uri.query}' : uri.path;
/// Owns the app's current route and builds the shell for it.
///
/// Route changes made by the operator go through [goTo]; the Router reports
@@ -190,10 +201,21 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
/// The location a web launch starts at, or the Pipelines list elsewhere.
///
/// Only the path is meaningful to [AppRouteParser]; the origin stays out of
/// route configuration so a serialised route is always app-relative.
/// The origin stays out of route configuration so a serialised route is always
/// app-relative, but the path and its query are both part of the route: a
/// launch at `/runs/7/stage/plan?visit=1` must open exactly that visit.
RouteInformation initialRouteInformation() {
if (!kIsWeb) return RouteInformation(uri: Uri(path: '/pipelines'));
final path = Uri.base.path;
return RouteInformation(uri: Uri(path: path.isEmpty ? '/' : path));
return routeInformationForLocation(Uri.base);
}
/// The app-relative route information for a browser [base] location.
///
/// Exposed for the boot test: [Uri.base] cannot be changed inside a widget
/// test, so the web launch seam is exercised through this function.
@visibleForTesting
RouteInformation routeInformationForLocation(Uri base) {
final path = base.path.isEmpty ? '/' : base.path;
final query = base.hasQuery ? '?${base.query}' : '';
return RouteInformation(uri: Uri.parse('$path$query'));
}