fix(app): keep a search selection one-shot and always reach Summary
A retired or unknown field hit now selects the plain Summary instead of leaving an open visit pane in place, matching the browser's searchFieldTab and Android. The resolved target is a sealed Summary/visit value, so the field mapping lives in one place. An unapplied request is dropped when the shell leaves the run it names, so Backing out of a loading detail no longer replays the selection on a later, unrelated visit. Search/Templates/Schedules pages above the run keep it.
This commit is contained in:
@@ -173,12 +173,12 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selects the recorded visit a search result names, without presenting any
|
||||
/// visit the run did not record.
|
||||
/// Selects the Summary section or recorded visit a search result names.
|
||||
///
|
||||
/// 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.
|
||||
/// The request is applied once per loaded run and is consumed afterwards. A
|
||||
/// retired or unknown field still selects the plain Summary, exactly as the
|
||||
/// browser's `searchFieldTab` does, and a visit the run did not record falls
|
||||
/// back to the plain Summary, so no stale hit leaves an unrelated pane open.
|
||||
void _applySearchSelection() {
|
||||
final scope = RunSearchSelectionScope.maybeOf(context);
|
||||
final selection = scope?.selection;
|
||||
@@ -190,8 +190,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
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);
|
||||
_selectSearchTarget(resolveRunSearchSelection(selection, widget.run));
|
||||
final consumed = scope.onConsumed;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) consumed();
|
||||
@@ -199,25 +198,25 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
}
|
||||
|
||||
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;
|
||||
switch (target) {
|
||||
case RunSummaryTarget(:final section):
|
||||
_tab = RunDetailTab.summary;
|
||||
_selectedStage = null;
|
||||
_selectedVisit = null;
|
||||
switch (section) {
|
||||
case RunSummarySection.input:
|
||||
_inputSection.expand();
|
||||
case RunSummarySection.output:
|
||||
_outputSection.expand();
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
case RunVisitTarget(:final stageKey, :final timelineIndex):
|
||||
if (detailVisitStepAt(widget.run, timelineIndex) == null) return;
|
||||
_selectedStage = stageKey;
|
||||
_selectedVisit = timelineIndex;
|
||||
_tab = RunDetailTab.timeline;
|
||||
}
|
||||
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,
|
||||
|
||||
@@ -32,61 +32,66 @@ class RunSearchSelection {
|
||||
int get hashCode => Object.hash(runId, sequence, field);
|
||||
}
|
||||
|
||||
/// The collapsible Summary section a text hit names.
|
||||
enum RunSummarySection { input, output }
|
||||
|
||||
/// 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;
|
||||
sealed class RunSearchTarget {
|
||||
const RunSearchTarget();
|
||||
}
|
||||
|
||||
/// Resolves [selection] against the loaded [run], or null when the run recorded
|
||||
/// nothing the request names.
|
||||
/// The run Summary, optionally with the matched field's section expanded.
|
||||
final class RunSummaryTarget extends RunSearchTarget {
|
||||
const RunSummaryTarget({this.section});
|
||||
|
||||
/// The section a text hit matched, or null for the plain Summary.
|
||||
final RunSummarySection? section;
|
||||
}
|
||||
|
||||
/// One recorded visit: [stageKey] plus the detail row index the Timeline and
|
||||
/// the Graph selection also use.
|
||||
final class RunVisitTarget extends RunSearchTarget {
|
||||
const RunVisitTarget({required this.stageKey, required this.timelineIndex});
|
||||
|
||||
final String stageKey;
|
||||
final int timelineIndex;
|
||||
}
|
||||
|
||||
/// Resolves [selection] against the loaded [run] into the detail state to show.
|
||||
///
|
||||
/// 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(
|
||||
/// A text hit always selects the Summary, using the browser's `searchFieldTab`
|
||||
/// mapping: `input` and `output` expand that section, while a retired or
|
||||
/// unknown field leaves the plain Summary instead of guessing a section. A
|
||||
/// visit hit selects the step with the recorded sequence; a sequence the run did
|
||||
/// not record falls back to the plain Summary, as the browser does, so a stale
|
||||
/// hit never leaves an unrelated visit pane open.
|
||||
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,
|
||||
};
|
||||
return RunSummaryTarget(
|
||||
section: switch (field) {
|
||||
'input' => RunSummarySection.input,
|
||||
'output' => RunSummarySection.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);
|
||||
if (sequence != null && sequence > 0) {
|
||||
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) break;
|
||||
// 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 RunVisitTarget(stageKey: stage, timelineIndex: index);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return const RunSummaryTarget();
|
||||
}
|
||||
|
||||
int? _sequence(JsonMap step) {
|
||||
|
||||
Reference in New Issue
Block a user