feat(app): add the Graph tab and recorded-stage selection to run detail

This commit is contained in:
2026-10-22 00:39:42 +01:00
parent 0e323dde10
commit d74e5c501f
16 changed files with 1702 additions and 306 deletions
@@ -48,12 +48,15 @@ class RunChangesButton extends StatelessWidget {
return CupertinoButton.tinted(
key: runChangesButtonKey,
onPressed: open,
// The label keeps its intrinsic size until scaled text no longer fits
// the detail's narrowest pane; then it wraps inside the native button
// instead of overflowing the header row.
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(CupertinoIcons.doc_text),
SizedBox(width: 6),
Text(runChangesLabel),
Flexible(child: Text(runChangesLabel)),
],
),
);
@@ -7,7 +7,17 @@ import '../domain/run_models.dart';
typedef DetailMetric = ({String label, String value});
/// One recorded visit in the run detail's timeline.
typedef DetailVisit = ({String title, String subtitle});
///
/// [stage] and [sequence] are the visit's exact recorded identity, so the
/// Graph tab can select the row of the stage it was clicked for without
/// guessing from the display title. [sequence] is null only when the server
/// sent no usable sequence.
typedef DetailVisit = ({
String stage,
int? sequence,
String title,
String subtitle,
});
/// The run's primary label: the stored title, else the pipeline name, and only
/// then the numeric identity.
@@ -89,6 +99,10 @@ List<DetailVisit> detailTimeline(dynamic steps) {
return [
for (final step in steps.whereType<Map>())
(
stage: '${step['stage'] ?? ''}'.trim(),
sequence: step['sequence'] is num
? (step['sequence'] as num).toInt()
: null,
title:
'${_text(step['stage'], 'Stage unavailable')} · visit '
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
@@ -97,6 +111,28 @@ List<DetailVisit> detailTimeline(dynamic steps) {
];
}
/// The latest recorded visit of [stageKey], or null when this run never
/// recorded that stage.
///
/// The Graph tab opens the same latest visit the web client opens. An
/// unvisited node has no visit here, so no row is invented for it.
DetailVisit? latestDetailVisit(dynamic steps, String stageKey) {
DetailVisit? latest;
for (final visit in detailTimeline(steps)) {
if (visit.stage == stageKey) latest = visit;
}
return latest;
}
/// The run's own pinned definition graph, or null when the reply omitted it.
///
/// The server sends the graph it pinned for the run's pipeline version; the
/// detail never reconstructs one from the current source.
JsonMap? detailGraph(JsonMap run) {
final graph = run['graph'];
return graph is Map ? JsonMap.from(graph) : null;
}
String _visitSubtitle(Map step) {
final status = _text(step['status'], 'Status unavailable');
final outcome = '${step['outcome'] ?? ''}'.trim();
@@ -4,10 +4,12 @@ import '../../../core/api_gateway.dart';
import '../domain/run_models.dart';
import 'run_changes_action.dart';
import 'run_detail_content.dart';
import 'run_detail_tabs.dart';
/// The runs detail with standard Cupertino controls. It has no Material
/// ancestor: sections use native Cupertino expansion tiles and grouped list
/// sections, and copy feedback is an inline live-region status.
/// ancestor: the host header keeps native navigation, actions and notices, and
/// the shared tab body uses native Cupertino expansion tiles and grouped list
/// sections. Copy feedback is an inline live-region status.
Widget buildCupertinoRunDetail({
required BuildContext context,
required JsonMap run,
@@ -20,148 +22,66 @@ Widget buildCupertinoRunDetail({
required VoidCallback onCopy,
}) {
final theme = CupertinoTheme.of(context);
final prompt = detailPrompt(run);
final visits = detailTimeline(run['steps']);
final metrics = detailUsageMetrics(run['usage']);
return ListView(
key: ValueKey<String>('run-detail-${run['id']}'),
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 4,
children: [
CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onBack,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(CupertinoIcons.back),
const SizedBox(width: 4),
const Text('Back'),
],
),
),
if (showRunChangesAction(run)) RunChangesButton(run: run),
if (copying) const CupertinoActivityIndicator(),
],
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
detailTitle(run),
style: theme.textTheme.navLargeTitleTextStyle,
),
const SizedBox(height: 4),
Text(runStatusLabel(run)),
Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'),
],
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: headerActions,
),
),
if (detailLoading) const _CupertinoNotice('Refreshing run details…'),
if (error != null) _CupertinoNotice(error),
if (prompt != null)
return RunDetailTabs(
run: run,
cupertino: true,
copying: copying,
copyStatus: copyStatus,
onCopy: onCopy,
header: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 4,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 4,
children: [
Text(
'Original prompt',
style: theme.textTheme.navTitleTextStyle,
),
CupertinoButton(
padding: EdgeInsets.zero,
onPressed: copying ? null : onCopy,
child: const Text('Copy prompt'),
),
],
),
_CupertinoSelectableText(prompt),
if (copyStatus != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Semantics(liveRegion: true, child: Text(copyStatus)),
CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onBack,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(CupertinoIcons.back),
const SizedBox(width: 4),
const Text('Back'),
],
),
),
if (showRunChangesAction(run)) RunChangesButton(run: run),
if (copying) const CupertinoActivityIndicator(),
],
),
),
_fieldSection('Input', run['input'], 'No input recorded.'),
_fieldSection('Output', run['output'], 'No output recorded.'),
CupertinoListSection.insetGrouped(
header: const Text('Timeline'),
children: [
if (visits.isEmpty)
const CupertinoListTile(title: Text('No visits recorded.'))
else
for (final visit in visits)
CupertinoListTile(
leading: const Icon(CupertinoIcons.circle),
title: Text(visit.title),
subtitle: Text(visit.subtitle),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
detailTitle(run),
style: theme.textTheme.navLargeTitleTextStyle,
),
],
),
CupertinoListSection.insetGrouped(
children: [
CupertinoExpansionTile(
title: const Text('Metrics'),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (metrics.isEmpty)
const Text('No reported usage.')
else
for (final metric in metrics)
CupertinoListTile(
title: Text(metric.label),
subtitle: Text(metric.value),
),
],
),
),
const SizedBox(height: 4),
Text(runStatusLabel(run)),
Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'),
],
),
],
),
],
);
}
Widget _fieldSection(String title, dynamic value, String empty) {
final text = detailEmpty(value) ? empty : detailJson(value);
return CupertinoListSection.insetGrouped(
children: [
CupertinoExpansionTile(
title: Text(title),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
child: _CupertinoSelectableText(text),
),
),
],
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: headerActions,
),
),
if (detailLoading) const _CupertinoNotice('Refreshing run details…'),
if (error != null) _CupertinoNotice(error),
],
),
);
}
@@ -175,42 +95,3 @@ class _CupertinoNotice extends StatelessWidget {
child: Semantics(liveRegion: true, child: Text(text)),
);
}
/// A read-only Cupertino text control: plain, selectable text without a
/// Material dependency, while keeping native selection and copy affordances.
class _CupertinoSelectableText extends StatefulWidget {
const _CupertinoSelectableText(this.text);
final String text;
@override
State<_CupertinoSelectableText> createState() =>
_CupertinoSelectableTextState();
}
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
late final TextEditingController _controller = TextEditingController(
text: widget.text,
);
@override
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.text != oldWidget.text) _controller.text = widget.text;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => CupertinoTextField(
controller: _controller,
readOnly: true,
maxLines: null,
padding: EdgeInsets.zero,
decoration: const BoxDecoration(),
style: CupertinoTheme.of(context).textTheme.textStyle,
);
}
@@ -4,8 +4,12 @@ import '../../../core/api_gateway.dart';
import '../domain/run_models.dart';
import 'run_changes_action.dart';
import 'run_detail_content.dart';
import 'run_detail_tabs.dart';
/// The runs detail with standard Material controls.
///
/// The host header keeps the run identity, status and every action; the shared
/// tab body supplies Summary, Graph, Input, Output and Timeline.
Widget buildMaterialRunDetail({
required BuildContext context,
required JsonMap run,
@@ -18,107 +22,53 @@ Widget buildMaterialRunDetail({
required VoidCallback onCopy,
}) {
final theme = Theme.of(context);
final prompt = detailPrompt(run);
final visits = detailTimeline(run['steps']);
final metrics = detailUsageMetrics(run['usage']);
return ListView(
key: ValueKey<String>('run-detail-${run['id']}'),
padding: const EdgeInsets.all(16),
children: [
Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
TextButton.icon(
onPressed: onBack,
icon: const Icon(Icons.arrow_back),
label: const Text('Back to list'),
),
if (showRunChangesAction(run)) RunChangesButton(run: run),
],
),
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Chip(label: Text(runStatusLabel(run))),
Text('Run ${run['id']}'),
Text('Pipeline ${detailPipeline(run)}'),
headerActions,
],
),
if (detailLoading) const _Notice('Refreshing run details…'),
if (error != null) _Notice(error),
if (prompt != null) ...[
const SizedBox(height: 12),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
'Original prompt',
style: theme.textTheme.titleMedium,
return RunDetailTabs(
run: run,
cupertino: false,
copying: copying,
copyStatus: copyStatus,
onCopy: onCopy,
header: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
TextButton.icon(
onPressed: onBack,
icon: const Icon(Icons.arrow_back),
label: const Text('Back to list'),
),
),
IconButton(
tooltip: 'Copy prompt',
onPressed: copying ? null : onCopy,
icon: const Icon(Icons.copy),
),
],
),
SelectableText(prompt),
if (copyStatus != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Semantics(liveRegion: true, child: Text(copyStatus)),
if (showRunChangesAction(run)) RunChangesButton(run: run),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Text(detailTitle(run), style: theme.textTheme.headlineSmall),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Wrap(
spacing: 8,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Chip(label: Text(runStatusLabel(run))),
Text('Run ${run['id']}'),
Text('Pipeline ${detailPipeline(run)}'),
headerActions,
],
),
),
if (detailLoading) const _Notice('Refreshing run details…'),
if (error != null) _Notice(error),
],
_fieldSection('Input', run['input'], 'No input recorded.'),
_fieldSection('Output', run['output'], 'No output recorded.'),
Text('Timeline', style: theme.textTheme.titleLarge),
if (visits.isEmpty)
const Text('No visits recorded.')
else
...visits.map(
(visit) => ListTile(
leading: const Icon(Icons.circle_outlined),
title: Text(visit.title),
subtitle: Text(visit.subtitle),
),
),
ExpansionTile(
title: const Text('Metrics'),
children: [
if (metrics.isEmpty)
const Padding(
padding: EdgeInsets.all(16),
child: Text('No reported usage.'),
)
else
...metrics.map(
(metric) => ListTile(
title: Text(metric.label),
subtitle: Text(metric.value),
),
),
],
),
],
);
}
Widget _fieldSection(String title, dynamic value, String empty) {
final text = detailEmpty(value) ? empty : detailJson(value);
return ExpansionTile(
title: Text(title),
children: [
Padding(padding: const EdgeInsets.all(16), child: SelectableText(text)),
],
),
);
}
@@ -128,7 +78,7 @@ class _Notice extends StatelessWidget {
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Semantics(liveRegion: true, child: Text(text)),
);
}
@@ -0,0 +1,16 @@
/// The run-detail sections in the web's order: Summary first, the run Graph
/// second, then the recorded Input, Output and Timeline.
///
/// The stable keys match the web client's `RUN_DETAIL_TABS`; the visible labels
/// are the same words.
enum RunDetailTab {
summary('Summary'),
graph('Graph'),
input('Input'),
output('Output'),
timeline('Timeline');
const RunDetailTab(this.label);
final String label;
}
@@ -0,0 +1,204 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import 'run_detail_content.dart';
/// The Summary tab: the stored original prompt with its copy control and the
/// reported usage metrics. Neither the prompt nor a metric is replaced by a
/// fallback value.
Widget runDetailSummaryTab({
required BuildContext context,
required JsonMap run,
required bool cupertino,
required bool copying,
required String? copyStatus,
required VoidCallback onCopy,
}) {
final prompt = detailPrompt(run);
final metrics = detailUsageMetrics(run['usage']);
if (cupertino) {
final theme = CupertinoTheme.of(context);
return ListView(
key: const Key('run-detail-tab-body-summary'),
children: [
if (prompt != null)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 4,
children: [
Text(
'Original prompt',
style: theme.textTheme.navTitleTextStyle,
),
CupertinoButton(
padding: EdgeInsets.zero,
onPressed: copying ? null : onCopy,
child: const Text('Copy prompt'),
),
],
),
_CupertinoSelectableText(prompt),
if (copyStatus != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Semantics(liveRegion: true, child: Text(copyStatus)),
),
],
),
),
_cupertinoMetrics(metrics),
],
);
}
final theme = Theme.of(context);
return ListView(
key: const Key('run-detail-tab-body-summary'),
padding: const EdgeInsets.all(16),
children: [
if (prompt != null) ...[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
'Original prompt',
style: theme.textTheme.titleMedium,
),
),
IconButton(
tooltip: 'Copy prompt',
onPressed: copying ? null : onCopy,
icon: const Icon(Icons.copy),
),
],
),
SelectableText(prompt),
if (copyStatus != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Semantics(liveRegion: true, child: Text(copyStatus)),
),
const SizedBox(height: 12),
],
_materialMetrics(metrics),
],
);
}
/// One recorded Input or Output field as its own tab.
Widget runDetailFieldTab({
required String tabKey,
required dynamic value,
required String empty,
required bool cupertino,
}) {
final text = detailEmpty(value) ? empty : detailJson(value);
if (cupertino) {
return ListView(
key: Key('run-detail-tab-body-$tabKey'),
children: [
CupertinoListSection.insetGrouped(
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
child: _CupertinoSelectableText(text),
),
],
),
],
);
}
return ListView(
key: Key('run-detail-tab-body-$tabKey'),
padding: const EdgeInsets.all(16),
children: [SelectableText(text)],
);
}
Widget _materialMetrics(List<DetailMetric> metrics) => ExpansionTile(
title: const Text('Metrics'),
children: [
if (metrics.isEmpty)
const Padding(
padding: EdgeInsets.all(16),
child: Text('No reported usage.'),
)
else
...metrics.map(
(metric) =>
ListTile(title: Text(metric.label), subtitle: Text(metric.value)),
),
],
);
Widget _cupertinoMetrics(List<DetailMetric> metrics) =>
CupertinoListSection.insetGrouped(
children: [
CupertinoExpansionTile(
title: const Text('Metrics'),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (metrics.isEmpty)
const Text('No reported usage.')
else
for (final metric in metrics)
CupertinoListTile(
title: Text(metric.label),
subtitle: Text(metric.value),
),
],
),
),
),
],
);
/// A read-only Cupertino text control: plain, selectable text without a
/// Material dependency, while keeping native selection and copy affordances.
class _CupertinoSelectableText extends StatefulWidget {
const _CupertinoSelectableText(this.text);
final String text;
@override
State<_CupertinoSelectableText> createState() =>
_CupertinoSelectableTextState();
}
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
late final TextEditingController _controller = TextEditingController(
text: widget.text,
);
@override
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.text != oldWidget.text) _controller.text = widget.text;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => CupertinoTextField(
controller: _controller,
readOnly: true,
maxLines: null,
padding: EdgeInsets.zero,
decoration: const BoxDecoration(),
style: CupertinoTheme.of(context).textTheme.textStyle,
);
}
@@ -0,0 +1,133 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import 'run_detail_tab.dart';
/// The run detail's platform tab strip: a Material segmented button or a
/// Cupertino segmented control, in the web's Summary/Graph/Input/Output/
/// Timeline order.
///
/// The native control keeps every label at its intrinsic width: a narrow pane
/// or scaled text scrolls the strip horizontally instead of squeezing or
/// wrapping the words. A tab selected by the Graph (not tapped in the strip)
/// is scrolled into view, so the operator can see which section is selected.
class RunDetailTabStrip extends StatefulWidget {
const RunDetailTabStrip({
super.key,
required this.selected,
required this.onSelected,
});
final RunDetailTab selected;
final ValueChanged<RunDetailTab> onSelected;
@override
State<RunDetailTabStrip> createState() => _RunDetailTabStripState();
}
class _RunDetailTabStripState extends State<RunDetailTabStrip> {
final Map<RunDetailTab, GlobalKey> _labels = {
for (final tab in RunDetailTab.values) tab: GlobalKey(),
};
@override
void didUpdateWidget(covariant RunDetailTabStrip oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.selected == widget.selected) return;
// The Graph can select Timeline without a strip tap. Wait for the new
// segment to be laid out, then reveal it inside the strip's own scroll.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final context = _labels[widget.selected]?.currentContext;
if (context == null) return;
Scrollable.ensureVisible(
context,
alignment: 0.5,
duration: const Duration(milliseconds: 200),
);
});
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: _ScrollWhenOverflowing(
child: KeyedSubtree(
key: const Key('run-detail-tabs'),
child: cupertino ? _cupertinoControl() : _materialControl(),
),
),
);
}
Widget _materialControl() => SegmentedButton<RunDetailTab>(
segments: [
for (final tab in RunDetailTab.values)
ButtonSegment(value: tab, label: _label(tab)),
],
selected: {widget.selected},
showSelectedIcon: false,
onSelectionChanged: (selection) => widget.onSelected(selection.single),
);
Widget _cupertinoControl() => CupertinoSegmentedControl<RunDetailTab>(
groupValue: widget.selected,
onValueChanged: widget.onSelected,
children: {
for (final tab in RunDetailTab.values)
tab: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: _label(tab),
),
},
);
Widget _label(RunDetailTab tab) => KeyedSubtree(
key: _labels[tab],
child: KeyedSubtree(
key: ValueKey('run-detail-tab-${tab.name}'),
child: Text(tab.label, maxLines: 1, softWrap: false),
),
);
}
/// Gives [child] at least the pane width, then scrolls instead of squeezing it
/// below its content width.
class _ScrollWhenOverflowing extends StatelessWidget {
const _ScrollWhenOverflowing({required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (!constraints.hasBoundedWidth) return child;
return ScrollConfiguration(
// Desktop pointer scrolling is vertical only, so a mouse can drag
// the tab row as well as touch and trackpad.
behavior: ScrollConfiguration.of(context).copyWith(
dragDevices: const {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
PointerDeviceKind.trackpad,
},
),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth),
child: child,
),
),
);
},
);
}
}
@@ -0,0 +1,174 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../graph/widgets/run_graph_view.dart';
import 'run_detail_content.dart';
import 'run_detail_tab.dart';
import 'run_detail_tab_bodies.dart';
import 'run_detail_tab_strip.dart';
import 'run_detail_timeline.dart';
/// The least height the selected tab keeps for its own content.
///
/// A header and tab strip that would leave the tab less than this may scroll
/// instead, so scaled title text or a short window cannot squeeze the Graph
/// canvas away. The Graph view's own legend is one wrapped row pair; this
/// reserve keeps its bounded canvas positive at 320px with 2x text.
const double kRunDetailMinContentHeight = 240;
/// The run detail's tabbed body: the host-built header and platform tab strip
/// above the bounded selected tab.
///
/// The Graph tab fills its slot with [RunGraphView] from the run's own pinned
/// graph and recorded steps. A visited stage click selects that stage's latest
/// recorded visit and switches to Timeline, where the row is highlighted. A
/// node with no recorded visit reports nothing, so no visit is invented.
class RunDetailTabs extends StatefulWidget {
const RunDetailTabs({
super.key,
required this.run,
required this.header,
required this.cupertino,
required this.copying,
required this.copyStatus,
required this.onCopy,
});
final JsonMap run;
/// The host's own header: identity, status and the run actions. It stays
/// outside the tab body, so switching tabs never drops an action.
final Widget header;
final bool cupertino;
final bool copying;
final String? copyStatus;
final VoidCallback onCopy;
@override
State<RunDetailTabs> createState() => _RunDetailTabsState();
}
class _RunDetailTabsState extends State<RunDetailTabs> {
RunDetailTab _tab = RunDetailTab.summary;
String? _selectedStage;
int? _selectedVisit;
@override
void didUpdateWidget(covariant RunDetailTabs oldWidget) {
super.didUpdateWidget(oldWidget);
// 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']}') {
_tab = RunDetailTab.summary;
_selectedStage = null;
_selectedVisit = null;
}
}
/// 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) {
final visit = latestDetailVisit(widget.run['steps'], stageKey);
if (visit == null) return;
setState(() {
_selectedStage = stageKey;
_selectedVisit = visit.sequence;
_tab = RunDetailTab.timeline;
});
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final headerLimit = _headerLimit(constraints);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxHeight: headerLimit),
child: SingleChildScrollView(
key: ValueKey('run-detail-header-${widget.run['id']}'),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
widget.header,
RunDetailTabStrip(
selected: _tab,
onSelected: (tab) => setState(() => _tab = tab),
),
],
),
),
),
// Every tab gets the bounded remaining height. The scrolling tabs
// own their content; the Graph tab fills the slot so its canvas is
// never asked for an unbounded extent.
Expanded(
key: ValueKey('run-detail-body-${widget.run['id']}'),
child: _body(),
),
],
);
},
);
}
Widget _body() {
switch (_tab) {
case RunDetailTab.summary:
return runDetailSummaryTab(
context: context,
run: widget.run,
cupertino: widget.cupertino,
copying: widget.copying,
copyStatus: widget.copyStatus,
onCopy: widget.onCopy,
);
case RunDetailTab.graph:
return RunGraphView(
key: const Key('run-detail-graph'),
graph: detailGraph(widget.run),
run: widget.run,
selectedStage: _selectedStage,
onStageSelected: _openStage,
);
case RunDetailTab.input:
return runDetailFieldTab(
tabKey: 'input',
value: widget.run['input'],
empty: 'No input recorded.',
cupertino: widget.cupertino,
);
case RunDetailTab.output:
return runDetailFieldTab(
tabKey: 'output',
value: widget.run['output'],
empty: 'No output recorded.',
cupertino: widget.cupertino,
);
case RunDetailTab.timeline:
return RunTimelineList(
visits: detailTimeline(widget.run['steps']),
selectedSequence: _selectedVisit,
cupertino: widget.cupertino,
);
}
}
/// The header keeps its natural height while at least
/// [kRunDetailMinContentHeight] remains for the tab, and never more than the
/// detail itself; past that it scrolls.
double _headerLimit(BoxConstraints constraints) {
if (!constraints.hasBoundedHeight) return double.infinity;
final height = constraints.maxHeight;
// Below twice the reserve the two shares meet at 40%, so the header stays
// reachable even when the detail is shorter than the reserve itself.
final floorShare = height * 0.4;
final reserve = height - kRunDetailMinContentHeight;
return math.max(floorShare, reserve).clamp(0.0, height);
}
}
@@ -0,0 +1,106 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'run_detail_content.dart';
/// The Timeline tab's recorded visits, one native row per visit.
///
/// [selectedSequence] is the server sequence of the visit selected from the
/// Graph tab. Only an actual recorded visit can match, so an unvisited stage
/// leaves every row unselected.
class RunTimelineList extends StatelessWidget {
const RunTimelineList({
super.key,
required this.visits,
required this.cupertino,
this.selectedSequence,
});
final List<DetailVisit> visits;
final bool cupertino;
final int? selectedSequence;
@override
Widget build(BuildContext context) {
if (visits.isEmpty) {
return ListView(
key: const Key('run-detail-tab-body-timeline'),
padding: const EdgeInsets.all(16),
children: const [Text('No visits recorded.')],
);
}
final rows = [
for (var index = 0; index < visits.length; index += 1)
RunTimelineRow(
key: ValueKey(
'run-timeline-visit-${visits[index].sequence ?? index}',
),
visit: visits[index],
selected: visits[index].sequence == selectedSequence,
cupertino: cupertino,
),
];
if (cupertino) {
return ListView(
key: const Key('run-detail-tab-body-timeline'),
children: [
CupertinoListSection.insetGrouped(
header: const Text('Timeline'),
children: rows,
),
],
);
}
return ListView(
key: const Key('run-detail-tab-body-timeline'),
padding: const EdgeInsets.symmetric(vertical: 8),
children: rows,
);
}
}
/// One recorded visit. [selected] highlights the row the Graph tab selected;
/// it is never true for a stage with no recorded visit.
class RunTimelineRow extends StatelessWidget {
const RunTimelineRow({
super.key,
required this.visit,
required this.selected,
required this.cupertino,
});
final DetailVisit visit;
final bool selected;
final bool cupertino;
@override
Widget build(BuildContext context) {
if (cupertino) {
return Semantics(
selected: selected,
child: CupertinoListTile(
leading: Icon(
selected
? CupertinoIcons.check_mark_circled_solid
: CupertinoIcons.circle,
),
title: Text(visit.title),
subtitle: Text(visit.subtitle),
trailing: selected ? const Icon(CupertinoIcons.check_mark) : null,
backgroundColor: selected
? CupertinoDynamicColor.resolve(
CupertinoColors.secondarySystemFill,
context,
)
: null,
),
);
}
return ListTile(
selected: selected,
leading: Icon(selected ? Icons.check_circle : Icons.circle_outlined),
title: Text(visit.title),
subtitle: Text(visit.subtitle),
);
}
}