feat(app): select a search hit's recorded run section or visit

This commit is contained in:
2026-10-22 15:34:48 +01:00
parent 6b021f1483
commit 133df9301d
7 changed files with 676 additions and 27 deletions
@@ -21,6 +21,8 @@ Widget runDetailSummaryTab({
required bool copying,
required String? copyStatus,
required VoidCallback onCopy,
ExpansibleController? inputController,
ExpansibleController? outputController,
}) {
final rows = detailSummaryRows(run);
final identity = detailSummaryIdentity(run);
@@ -55,6 +57,7 @@ Widget runDetailSummaryTab({
title: 'Input',
value: run['input'],
empty: visitEmptyInput,
controller: inputController,
),
_cupertinoFieldSection(
context,
@@ -62,6 +65,7 @@ Widget runDetailSummaryTab({
title: 'Output',
value: run['output'],
empty: visitEmptyOutput,
controller: outputController,
),
],
);
@@ -96,6 +100,7 @@ Widget runDetailSummaryTab({
title: 'Input',
value: run['input'],
empty: visitEmptyInput,
controller: inputController,
),
_materialFieldSection(
context,
@@ -103,6 +108,7 @@ Widget runDetailSummaryTab({
title: 'Output',
value: run['output'],
empty: visitEmptyOutput,
controller: outputController,
),
],
);
@@ -196,9 +202,11 @@ Widget _materialFieldSection(
required String title,
required dynamic value,
required String empty,
ExpansibleController? controller,
}) {
return ExpansionTile(
key: ValueKey(key),
controller: controller,
title: Text(title),
expandedCrossAxisAlignment: CrossAxisAlignment.start,
childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
@@ -314,12 +322,14 @@ Widget _cupertinoFieldSection(
required String title,
required dynamic value,
required String empty,
ExpansibleController? controller,
}) {
return CupertinoListSection.insetGrouped(
key: ValueKey(key),
children: [
CupertinoExpansionTile(
title: Text(title),
controller: controller,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
child: Align(
@@ -11,6 +11,7 @@ import 'run_detail_tab_strip.dart';
import 'run_detail_timeline.dart';
import 'run_detail_visit.dart';
import 'run_detail_visit_facts.dart';
import 'run_search_selection.dart';
/// The least height the selected tab keeps for its own content.
///
@@ -81,12 +82,36 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
String? _selectedStage;
int? _selectedVisit;
/// The Summary's collapsible Input and Output sections. A search text hit
/// expands the one its recorded field names, exactly as the browser opens the
/// matching Summary section. The detail owns them so the tab body stays a
/// presentation widget.
final _inputSection = ExpansibleController();
final _outputSection = ExpansibleController();
/// The search request last applied by this detail, so a rebuild of the same
/// request never reopens a pane the operator closed in the meantime.
RunSearchSelection? _appliedSearchSelection;
@override
void initState() {
super.initState();
_applyInitialVisit();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_applySearchSelection();
}
@override
void dispose() {
_inputSection.dispose();
_outputSection.dispose();
super.dispose();
}
@override
void didUpdateWidget(covariant RunDetailTabs oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -100,6 +125,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
_tab = RunDetailTab.summary;
_selectedStage = null;
_selectedVisit = null;
_inputSection.collapse();
_outputSection.collapse();
_applyInitialVisit();
} else if (!sameTarget) {
// A route that names another stage or visit is applied to the same run.
@@ -146,6 +173,53 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
}
}
/// Selects the recorded visit a search result names, without presenting any
/// visit the run did not record.
///
/// The request is applied once per loaded run. A visit the run did not record,
/// an unknown field or a bare run hit resolves to nothing, which leaves the
/// plain run detail; either way the request is consumed so it never replays.
void _applySearchSelection() {
final scope = RunSearchSelectionScope.maybeOf(context);
final selection = scope?.selection;
if (scope == null || selection == null) {
_appliedSearchSelection = null;
return;
}
if (selection == _appliedSearchSelection) return;
final id = widget.run['id'];
if (id is! num || id.toInt() != selection.runId) return;
_appliedSearchSelection = selection;
final resolved = resolveRunSearchSelection(selection, widget.run);
if (resolved != null) _selectSearchTarget(resolved);
final consumed = scope.onConsumed;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) consumed();
});
}
void _selectSearchTarget(RunSearchTarget target) {
if (target.section case final section?) {
_tab = RunDetailTab.summary;
_selectedStage = null;
_selectedVisit = null;
switch (section) {
case 'input':
_inputSection.expand();
case 'output':
_outputSection.expand();
}
return;
}
final stageKey = target.stageKey;
final index = target.timelineIndex;
if (stageKey == null || index == null) return;
if (detailVisitStepAt(widget.run, index) == null) return;
_selectedStage = stageKey;
_selectedVisit = index;
_tab = RunDetailTab.timeline;
}
/// Selects the stage's latest recorded visit. An unvisited stage has none,
/// so the detail stays where it is rather than fabricating a visit.
void _openStage(String stageKey) {
@@ -214,6 +288,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
copying: widget.copying,
copyStatus: widget.copyStatus,
onCopy: widget.onCopy,
inputController: _inputSection,
outputController: _outputSection,
);
case RunDetailTab.graph:
return RunGraphView(
@@ -0,0 +1,121 @@
import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import 'run_detail_visit_facts.dart';
/// A search hit's requested selection inside one run's detail.
///
/// A recorded hit names only the run's own recorded [sequence] and, for a text
/// hit, the [field] it matched; the stage and timeline position are resolved
/// against the loaded detail, exactly as the browser client does. A request is
/// consumed once, so reopening the run later never replays it.
@immutable
class RunSearchSelection {
const RunSearchSelection({required this.runId, this.sequence, this.field});
final int runId;
/// The server's recorded visit number, or null when the hit names no visit.
final int? sequence;
/// The matched step field (`input`, `output`, …), or null for a visit hit.
final String? field;
@override
bool operator ==(Object other) =>
other is RunSearchSelection &&
other.runId == runId &&
other.sequence == sequence &&
other.field == field;
@override
int get hashCode => Object.hash(runId, sequence, field);
}
/// What a resolved search request selects in the loaded run detail.
///
/// A [section] names one collapsible Summary section; [stageKey] and
/// [timelineIndex] name one recorded visit, using the same row index the
/// Timeline and the Graph selection use.
@immutable
class RunSearchTarget {
const RunSearchTarget.section(this.section)
: stageKey = null,
timelineIndex = null;
const RunSearchTarget.visit({
required this.stageKey,
required this.timelineIndex,
}) : section = null;
final String? section;
final String? stageKey;
final int? timelineIndex;
}
/// Resolves [selection] against the loaded [run], or null when the run recorded
/// nothing the request names.
///
/// A text hit selects the Summary section holding the matched field, mirroring
/// the browser's `searchFieldTab`: a retired or unknown field resolves to the
/// plain Summary instead of guessing a section. A visit hit selects the step
/// with the recorded sequence and its own row in the Timeline; a sequence the
/// run did not record resolves to nothing. Either null leaves the plain run
/// detail in place.
RunSearchTarget? resolveRunSearchSelection(
RunSearchSelection selection,
JsonMap run,
) {
final field = selection.field?.trim() ?? '';
if (field.isNotEmpty) {
return switch (field) {
'input' => const RunSearchTarget.section('input'),
'output' => const RunSearchTarget.section('output'),
_ => null,
};
}
final sequence = selection.sequence;
if (sequence == null || sequence <= 0) return null;
final steps = detailRunSteps(run);
for (var index = 0; index < steps.length; index++) {
if (_sequence(steps[index]) != sequence) continue;
final stage = '${steps[index]['stage'] ?? ''}'.trim();
if (stage.isEmpty) return null;
// The row index is the Timeline's own index, the identity the visit pane
// reads back through detailVisitStepAt, so no ordinal is guessed here.
return RunSearchTarget.visit(stageKey: stage, timelineIndex: index);
}
return null;
}
int? _sequence(JsonMap step) {
final value = step['sequence'];
final number = value is num ? value.toInt() : int.tryParse('${value ?? ''}');
return number != null && number > 0 ? number : null;
}
/// Carries the shell's one pending search request to the mounted run detail.
///
/// The composition mounts it around the shell; [RunDetailTabs] reads it and
/// reports [onConsumed] once the request has been applied, so a later visit to
/// the same run starts plain. Keeping the request here means a field or artifact
/// hit needs no invented URL: the browser has no route for either selection.
class RunSearchSelectionScope extends InheritedWidget {
const RunSearchSelectionScope({
super.key,
required this.selection,
required this.onConsumed,
required super.child,
});
final RunSearchSelection? selection;
final VoidCallback onConsumed;
static RunSearchSelectionScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<RunSearchSelectionScope>();
@override
bool updateShouldNotify(RunSearchSelectionScope oldWidget) =>
oldWidget.selection != selection || oldWidget.onConsumed != onConsumed;
}