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:
@@ -19,6 +19,8 @@ class RunsScreen extends StatefulWidget {
|
||||
super.key,
|
||||
required this.gateway,
|
||||
this.initialRunId,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
this.syncToken = 0,
|
||||
this.listRefreshToken = 0,
|
||||
this.onRunSelected,
|
||||
@@ -33,6 +35,11 @@ class RunsScreen extends StatefulWidget {
|
||||
/// 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;
|
||||
@@ -143,6 +150,8 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
gateway: widget.gateway,
|
||||
onBack: _back,
|
||||
onRunOpened: _select,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -21,6 +21,8 @@ Widget buildCupertinoRunDetail({
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
required String configuredEndpoint,
|
||||
String? initialStageKey,
|
||||
int? initialVisit,
|
||||
}) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
return RunDetailTabs(
|
||||
@@ -30,6 +32,8 @@ Widget buildCupertinoRunDetail({
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
initialStageKey: initialStageKey,
|
||||
initialVisit: initialVisit,
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
|
||||
@@ -21,6 +21,8 @@ Widget buildMaterialRunDetail({
|
||||
required VoidCallback onBack,
|
||||
required VoidCallback onCopy,
|
||||
required String configuredEndpoint,
|
||||
String? initialStageKey,
|
||||
int? initialVisit,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return RunDetailTabs(
|
||||
@@ -30,6 +32,8 @@ Widget buildMaterialRunDetail({
|
||||
copyStatus: copyStatus,
|
||||
onCopy: onCopy,
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
initialStageKey: initialStageKey,
|
||||
initialVisit: initialVisit,
|
||||
header: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
|
||||
@@ -37,6 +37,8 @@ class RunDetailTabs extends StatefulWidget {
|
||||
required this.copyStatus,
|
||||
required this.onCopy,
|
||||
required this.configuredEndpoint,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
@@ -54,6 +56,15 @@ class RunDetailTabs extends StatefulWidget {
|
||||
/// through the landed safe-link helper. Blank leaves relative urls unresolved.
|
||||
final String configuredEndpoint;
|
||||
|
||||
/// The stage a `/runs/:id/stage/:key` route names, or null for the plain
|
||||
/// detail. It selects a recorded visit; a declared but unvisited stage only
|
||||
/// selects its graph node, so no visit is ever invented.
|
||||
final String? initialStageKey;
|
||||
|
||||
/// The zero-based index among [initialStageKey]'s recorded visits. Null opens
|
||||
/// the stage's latest visit, exactly as a Graph node click does.
|
||||
final int? initialVisit;
|
||||
|
||||
@override
|
||||
State<RunDetailTabs> createState() => _RunDetailTabsState();
|
||||
}
|
||||
@@ -63,15 +74,68 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
String? _selectedStage;
|
||||
int? _selectedVisit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_applyInitialVisit();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant RunDetailTabs oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
final sameRun = '${widget.run['id']}' == '${oldWidget.run['id']}';
|
||||
final sameTarget =
|
||||
widget.initialStageKey == oldWidget.initialStageKey &&
|
||||
widget.initialVisit == oldWidget.initialVisit;
|
||||
// A different run is a different detail: its visits and graph do not carry
|
||||
// the previous run's selection.
|
||||
if ('${widget.run['id']}' != '${oldWidget.run['id']}') {
|
||||
if (!sameRun) {
|
||||
_tab = RunDetailTab.summary;
|
||||
_selectedStage = null;
|
||||
_selectedVisit = null;
|
||||
_applyInitialVisit();
|
||||
} else if (!sameTarget) {
|
||||
// A route that names another stage or visit is applied to the same run.
|
||||
// Rebuilds from a live refresh keep the operator's own selection.
|
||||
_applyInitialVisit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the visit a route names, without presenting any visit the run did
|
||||
/// not record.
|
||||
///
|
||||
/// A route with a stage key and no visit opens that stage's latest recorded
|
||||
/// visit, the same visit a Graph node click opens. A valid index selects that
|
||||
/// visit among the stage's own visits; an out-of-range index is clamped to the
|
||||
/// stage's last recorded visit, as the web client does, so the address bar and
|
||||
/// the pane never disagree about which visit is real. A declared but
|
||||
/// unvisited stage selects its Graph node only.
|
||||
void _applyInitialVisit() {
|
||||
final stageKey = widget.initialStageKey;
|
||||
if (stageKey == null || stageKey.isEmpty) {
|
||||
_selectedStage = null;
|
||||
_selectedVisit = null;
|
||||
return;
|
||||
}
|
||||
final index = routeDetailVisitIndex(
|
||||
widget.run['steps'],
|
||||
stageKey,
|
||||
widget.initialVisit,
|
||||
);
|
||||
if (index != null) {
|
||||
_selectedStage = stageKey;
|
||||
_selectedVisit = index;
|
||||
_tab = RunDetailTab.timeline;
|
||||
return;
|
||||
}
|
||||
_selectedVisit = null;
|
||||
// The key is not a recorded visit. Only a stage the pinned graph actually
|
||||
// declares can be selected; anything else leaves the plain detail intact.
|
||||
if (detailVisitHasDefinition(detailGraph(widget.run), stageKey)) {
|
||||
_selectedStage = stageKey;
|
||||
_tab = RunDetailTab.graph;
|
||||
} else {
|
||||
_selectedStage = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ class RunDetailView extends StatefulWidget {
|
||||
required this.gateway,
|
||||
required this.onBack,
|
||||
this.onRunOpened,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
});
|
||||
|
||||
final RunsController controller;
|
||||
@@ -30,6 +32,12 @@ class RunDetailView extends StatefulWidget {
|
||||
/// the server-identified new run. Null keeps the detail on the retried run.
|
||||
final ValueChanged<num>? onRunOpened;
|
||||
|
||||
/// The route's stage and visit, forwarded to the tab body so a `/runs/:id/
|
||||
/// stage/:key[?visit=N]` deep link opens that recorded visit. Null is the
|
||||
/// plain detail.
|
||||
final String? initialStageKey;
|
||||
final int? initialVisit;
|
||||
|
||||
@override
|
||||
State<RunDetailView> createState() => _RunDetailViewState();
|
||||
}
|
||||
@@ -65,6 +73,8 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
|
||||
configuredEndpoint: endpoint,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
)
|
||||
: buildMaterialRunDetail(
|
||||
context: context,
|
||||
@@ -77,6 +87,8 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
onBack: widget.onBack,
|
||||
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
|
||||
configuredEndpoint: endpoint,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -31,15 +31,41 @@ JsonMap? detailVisitStepAt(JsonMap run, int index) {
|
||||
}
|
||||
|
||||
/// The row index of [stageKey]'s latest recorded visit, or null when the run
|
||||
/// never recorded that stage. It reads the same ordered timeline the rows do,
|
||||
/// so a Graph click opens exactly the row the operator would have selected.
|
||||
int? latestDetailVisitIndex(dynamic steps, String stageKey) {
|
||||
/// never recorded that stage.
|
||||
///
|
||||
/// The order matches [routeDetailVisitIndex] and the web client's
|
||||
/// `visitsByStage`: a stage's visits follow their recorded sequence, not their
|
||||
/// position in the reply's step list. So a Graph click and `/runs/:id/stage/:key`
|
||||
/// open the same visit even when the steps are not in sequence order.
|
||||
int? latestDetailVisitIndex(dynamic steps, String stageKey) =>
|
||||
routeDetailVisitIndex(steps, stageKey, null);
|
||||
|
||||
/// The timeline row index a route's [stageKey] and [visit] name, or null when
|
||||
/// the run recorded no visit of that stage.
|
||||
///
|
||||
/// A stage's visits follow their recorded sequence, as the web client's
|
||||
/// `visitsByStage` does, so the same `?visit=N` selects the same visit in both
|
||||
/// clients while equal sequences keep the timeline's own order. A null [visit]
|
||||
/// is the stage's last recorded visit, the one a Graph node click opens; an
|
||||
/// out-of-range index is clamped to that last visit, exactly as the web client
|
||||
/// clamps it. Nothing is invented for a stage with no recorded visit.
|
||||
int? routeDetailVisitIndex(dynamic steps, String stageKey, int? visit) {
|
||||
final visits = detailTimeline(steps);
|
||||
int? latest;
|
||||
for (var index = 0; index < visits.length; index += 1) {
|
||||
if (visits[index].stage == stageKey) latest = index;
|
||||
}
|
||||
return latest;
|
||||
final indices = <int>[
|
||||
for (var index = 0; index < visits.length; index += 1)
|
||||
if (visits[index].stage == stageKey) index,
|
||||
];
|
||||
if (indices.isEmpty) return null;
|
||||
indices.sort((a, b) {
|
||||
final bySequence = (visits[a].sequence ?? 0).compareTo(
|
||||
visits[b].sequence ?? 0,
|
||||
);
|
||||
return bySequence != 0 ? bySequence : a.compareTo(b);
|
||||
});
|
||||
final wanted = visit == null
|
||||
? indices.length - 1
|
||||
: visit.clamp(0, indices.length - 1);
|
||||
return indices[wanted];
|
||||
}
|
||||
|
||||
/// The visit's recorded facts, in the pane's order. A field the server did not
|
||||
|
||||
Reference in New Issue
Block a user