merge(app): land search-pane

This commit is contained in:
2026-10-22 16:15:50 +01:00
8 changed files with 1017 additions and 27 deletions
+9
View File
@@ -97,6 +97,15 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
/// The saved-schedule list page, opened above Settings.
bool get schedulesOpen => _route.kind == AppRouteKind.schedules;
/// The route the shell renders underneath the transient Search, Templates
/// and Schedules pages. Those pages keep the shell mounted, so the route the
/// operator last opened there is still the shell's own destination.
AppRoute get shellRoute => searchOpen
? _searchReturn
: templatesOpen || schedulesOpen
? _templatesReturn
: _route;
@override
AppRoute get currentConfiguration => _route;
+82 -26
View File
@@ -10,6 +10,7 @@ import '../shell/adaptive_shell.dart';
import '../shell/destination.dart';
import '../features/attention/notify/notification_controller.dart';
import '../features/attention/notify/notification_store.dart';
import '../features/runs/ui/run_search_selection.dart';
import '../features/search/domain/search_target.dart';
import '../features/settings/settings_screen.dart';
import 'app.dart';
@@ -75,6 +76,13 @@ class _PipelinesAppState extends State<PipelinesApp>
/// list once; the run itself is then opened from its route.
int _runsRefresh = 0;
/// One run detail request from Search, delivered through the shell so the
/// mounted run detail can resolve it once the named run's steps have loaded.
/// A field or artifact hit names no addressable URL of its own, so the request
/// is not route state; it is cleared after the detail applies it or when the
/// shell leaves that run, so an abandoned hit never replays later.
RunSearchSelection? _pendingRunSearch;
/// One notification capability for the app: the Runs attention surface
/// publishes live transitions and Settings renders the same permission.
late final NotificationController _notifications = NotificationController(
@@ -117,6 +125,7 @@ class _PipelinesAppState extends State<PipelinesApp>
schedulesBuilder: _buildSchedules,
builder: _buildShell,
);
_delegate.addListener(_routeChanged);
_config = RouterConfig<AppRoute>(
routeInformationParser: const AppRouteParser(),
routerDelegate: _delegate,
@@ -129,6 +138,7 @@ class _PipelinesAppState extends State<PipelinesApp>
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_notifications.dispose();
_delegate.removeListener(_routeChanged);
_delegate.dispose();
if (_ownsProvider) {
(_provider as PlatformRouteInformationProvider).dispose();
@@ -171,25 +181,65 @@ class _PipelinesAppState extends State<PipelinesApp>
/// Open a result through the exact identity the hit records. An unresolvable
/// hit navigates nowhere: the screen already presents it read-only rather than
/// guessing a destination.
///
/// A field or artifact hit has no URL of its own: both open the run and leave
/// a resolved-once request for the mounted detail, which selects the recorded
/// Summary section or visit as soon as that run's steps are available. A
/// sequence or field the run did not record leaves the plain detail.
void _openSearchResult(JsonMap hit) {
final resolved = searchTargetFor(hit);
if (resolved is! ResolvedSearchTarget) return;
final route = switch (resolved.target) {
SearchPipelineTarget(:final pipelineId) => AppRoute.pipeline(pipelineId),
SearchVersionTarget(:final pipelineId, :final version) =>
AppRoute.pipeline(pipelineId, version: version),
SearchRunTarget(:final runId) => AppRoute.run(runId),
SearchStepTarget(:final runId, :final stage, :final visit) =>
stage == null
AppRoute? route;
RunSearchSelection? selection;
switch (resolved.target) {
case SearchPipelineTarget(:final pipelineId):
route = AppRoute.pipeline(pipelineId);
case SearchVersionTarget(:final pipelineId, :final version):
route = AppRoute.pipeline(pipelineId, version: version);
case SearchRunTarget(:final runId):
route = AppRoute.run(runId);
case SearchStepTarget(:final runId, :final stage, :final visit):
route = stage == null
? AppRoute.run(runId)
: AppRoute.run.stage(runId, stage, visit: visit),
// A field or artifact names a visit inside the run; the run detail owns
// that pane, so open the run rather than inventing a stage route.
SearchFieldTarget(:final runId) => AppRoute.run(runId),
SearchArtifactTarget(:final runId) =>
runId == null ? null : AppRoute.run(runId),
};
if (route != null) _delegate.goTo(route);
: AppRoute.run.stage(runId, stage, visit: visit);
case SearchFieldTarget(:final runId, :final sequence, :final field):
selection = RunSearchSelection(
runId: runId,
sequence: sequence,
field: field,
);
route = AppRoute.run(runId);
case SearchArtifactTarget(:final runId, :final sequence):
if (runId != null) {
selection = RunSearchSelection(runId: runId, sequence: sequence);
route = AppRoute.run(runId);
}
}
if (route == null) return;
setState(() => _pendingRunSearch = selection);
_delegate.goTo(route);
}
/// The mounted run detail applied the pending request; reopening the same run
/// later starts from its plain detail and never replays the search selection.
void _runSearchConsumed() {
if (!mounted || _pendingRunSearch == null) return;
setState(() => _pendingRunSearch = null);
}
/// Drops a pending request once the shell leaves the run it names.
///
/// The mounted detail is the only consumer, and it exists only after the run's
/// detail has loaded. Backing out while that read is still pending, or leaving
/// a failed detail, would otherwise keep the request for the next unrelated
/// visit to the same run. Search/Templates/Schedules pages above the run keep
/// it, because the shell route underneath them still names that run.
void _routeChanged() {
final pending = _pendingRunSearch;
if (!mounted || pending == null) return;
final route = _delegate.shellRoute;
if (route.kind == AppRouteKind.runs && route.runId == pending.runId) return;
setState(() => _pendingRunSearch = null);
}
/// The Templates page above Settings. Closing it restores the same Settings
@@ -243,17 +293,23 @@ class _PipelinesAppState extends State<PipelinesApp>
initialVersion: route.version,
initialStageKey: route.stageKey,
),
AppDestination.runs: (_) => RunsDestination(
session: _session,
server: widget.server,
initialRunId: route.runId,
initialStageKey: route.stageKey,
initialVisit: route.visit,
initialDecide: route.decide,
listRefreshToken: _runsRefresh,
notifications: _notifications,
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
onBack: () => _delegate.goTo(AppRoute.runs),
// The one place a field or artifact hit's selection can be resolved: the
// run detail owns the recorded visit and Summary section.
AppDestination.runs: (_) => RunSearchSelectionScope(
selection: _pendingRunSearch,
onConsumed: _runSearchConsumed,
child: RunsDestination(
session: _session,
server: widget.server,
initialRunId: route.runId,
initialStageKey: route.stageKey,
initialVisit: route.visit,
initialDecide: route.decide,
listRefreshToken: _runsRefresh,
notifications: _notifications,
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
onBack: () => _delegate.goTo(AppRoute.runs),
),
),
AppDestination.chat: (_) => ChatDestination(
session: _session,
@@ -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,52 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
}
}
/// Selects the Summary section or recorded visit a search result names.
///
/// 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;
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;
_selectSearchTarget(resolveRunSearchSelection(selection, widget.run));
final consumed = scope.onConsumed;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) consumed();
});
}
void _selectSearchTarget(RunSearchTarget target) {
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;
}
}
/// 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 +287,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,126 @@
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);
}
/// The collapsible Summary section a text hit names.
enum RunSummarySection { input, output }
/// What a resolved search request selects in the loaded run detail.
sealed class RunSearchTarget {
const RunSearchTarget();
}
/// 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 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 RunSummaryTarget(
section: switch (field) {
'input' => RunSummarySection.input,
'output' => RunSummarySection.output,
_ => null,
},
);
}
final sequence = selection.sequence;
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 const RunSummaryTarget();
}
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;
}