Expand run detail output by default

Make run and visit output sections open when details are viewed while preserving user collapse behavior. Add coverage and implementation notes for the updated interaction.
This commit is contained in:
2026-11-12 01:56:41 +00:00
parent 2330f50268
commit 22af093eda
9 changed files with 323 additions and 86 deletions
@@ -107,7 +107,12 @@ Widget runDetailSummaryTab({
title: 'Output',
controller: outputController,
copyText: runFieldCopyText(run['output']),
body: RunFieldBody(value: run['output'], empty: visitEmptyOutput),
// Output starts open, so it is a sliver: a long one builds only the
// fields on screen.
sliverBody: RunFieldSliver(
value: run['output'],
empty: visitEmptyOutput,
),
),
const SliverToBoxAdapter(child: SizedBox(height: 16)),
const SliverFloatingBarClearance(),
@@ -115,19 +120,25 @@ Widget runDetailSummaryTab({
);
}
/// A summary section that starts closed, follows its [controller] (so a
/// search hit can open it), and offers a copy of its recorded text.
/// A summary section that follows its [controller] (its open state starts from
/// the controller's; a search hit can open it), and offers a copy of its
/// recorded text.
class _StickyField extends StatefulWidget {
const _StickyField({
super.key,
required this.title,
required this.body,
this.body,
this.sliverBody,
this.controller,
this.copyText,
});
}) : assert((body == null) != (sliverBody == null));
final String title;
final Widget body;
/// The content as a box, or as [sliverBody] for a long one (see
/// [StickySection.sliverBody]); exactly one is given.
final Widget? body;
final Widget? sliverBody;
final ExpansibleController? controller;
final String? copyText;
@@ -158,25 +169,31 @@ class _StickyFieldState extends State<_StickyField> {
final copyText = widget.copyText;
return ListenableBuilder(
listenable: _controller,
builder: (context, _) => StickySection(
title: widget.title,
open: _controller.isExpanded,
onToggle: () => _controller.isExpanded
? _controller.collapse()
: _controller.expand(),
trailing: [
if (copyText != null && copyText.isNotEmpty)
IconButton(
tooltip: 'Copy ${widget.title}',
onPressed: _copy,
icon: Icon(_copied ? Icons.check : Icons.copy),
),
],
body: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: widget.body,
),
),
builder: (context, _) {
// The body's own padding, the same for the box and the sliver form.
const padding = EdgeInsets.fromLTRB(16, 0, 16, 16);
final box = widget.body;
final sliver = widget.sliverBody;
return StickySection(
title: widget.title,
open: _controller.isExpanded,
onToggle: () => _controller.isExpanded
? _controller.collapse()
: _controller.expand(),
trailing: [
if (copyText != null && copyText.isNotEmpty)
IconButton(
tooltip: 'Copy ${widget.title}',
onPressed: _copy,
icon: Icon(_copied ? Icons.check : Icons.copy),
),
],
body: box == null ? null : Padding(padding: padding, child: box),
sliverBody: sliver == null
? null
: SliverPadding(padding: padding, sliver: sliver),
);
},
);
}
}
+17 -11
View File
@@ -98,12 +98,13 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
Route<void>? _visitRoute;
late final ValueNotifier<JsonMap> _liveRun = ValueNotifier(widget.run);
/// 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.
/// The Summary's collapsible Input and Output sections. Output starts open
/// and Input starts closed; the operator may close either for this view. 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();
final _outputSection = ExpansibleController()..expand();
/// 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.
@@ -124,6 +125,12 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
_applySearchSelection();
}
/// The Summary's default sections: Input closed, Output open.
void _resetSummarySections() {
_inputSection.collapse();
_outputSection.expand();
}
@override
void dispose() {
_inputSection.dispose();
@@ -146,8 +153,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
_tab = RunDetailTab.summary;
_selectedStage = null;
_selectedVisit = null;
_inputSection.collapse();
_outputSection.collapse();
_resetSummarySections();
_applyInitialVisit();
} else if (!sameTarget) {
// A route that names another stage or visit is applied to the same run.
@@ -231,10 +237,10 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
case RunSummarySection.output:
_outputSection.expand();
case null:
// A hit that names no section must not leave a previously expanded
// one open; the Summary panel starts collapsed.
_inputSection.collapse();
_outputSection.collapse();
// A hit that names no section must not leave a previously toggled
// one in a state the operator did not open; the Summary returns to
// its default sections.
_resetSummarySections();
}
case RunVisitTarget(:final stageKey, :final timelineIndex):
if (detailVisitStepAt(widget.run, timelineIndex) == null) return;
@@ -111,7 +111,8 @@ Widget runVisitSectionBody({
);
switch (section) {
case RunVisitSection.summary:
// Input then Output, each a sticky collapsible with a copy button.
// Input then Output, each a sticky collapsible with a copy button; Output
// starts open.
return _VisitSummary(
key: ValueKey('run-visit-summary-$visitIndex'),
input: step['input'],
@@ -181,7 +182,9 @@ class _VisitSummary extends StatefulWidget {
}
class _VisitSummaryState extends State<_VisitSummary> {
final Set<String> _closed = {'Input', 'Output'};
/// The sections the operator has closed. Input starts closed; Output starts
/// open, and this set is per visit view.
final Set<String> _closed = {'Input'};
String? _copied;
Future<void> _copy(String name, dynamic value) async {
@@ -189,7 +192,14 @@ class _VisitSummaryState extends State<_VisitSummary> {
if (mounted) setState(() => _copied = name);
}
Widget _section(String name, dynamic value, String empty) {
/// [lazy] builds the field as a sliver, for a section open by default (the
/// Output): a long one then lays out only the fields on screen.
Widget _section(
String name,
dynamic value,
String empty, {
bool lazy = false,
}) {
final copy = IconButton(
key: ValueKey('run-visit-copy-$name'),
tooltip: 'Copy $name',
@@ -197,6 +207,7 @@ class _VisitSummaryState extends State<_VisitSummary> {
icon: Icon(_copied == name ? Icons.check : Icons.copy),
);
final open = !_closed.contains(name);
const padding = EdgeInsets.fromLTRB(16, 0, 16, 16);
return StickySection(
key: ValueKey('run-visit-section-$name'),
title: name,
@@ -205,10 +216,18 @@ class _VisitSummaryState extends State<_VisitSummary> {
if (!_closed.remove(name)) _closed.add(name);
}),
trailing: [copy],
body: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: RunFieldBody(value: value, empty: empty),
),
body: lazy
? null
: Padding(
padding: padding,
child: RunFieldBody(value: value, empty: empty),
),
sliverBody: lazy
? SliverPadding(
padding: padding,
sliver: RunFieldSliver(value: value, empty: empty),
)
: null,
);
}
@@ -221,7 +240,7 @@ class _VisitSummaryState extends State<_VisitSummary> {
const SliverTopBarClearance(),
if (widget.facts case final facts?) SliverToBoxAdapter(child: facts),
_section('Input', widget.input, visitEmptyInput),
_section('Output', widget.output, visitEmptyOutput),
_section('Output', widget.output, visitEmptyOutput, lazy: true),
const SliverFloatingBarClearance(),
],
);
+87 -28
View File
@@ -55,40 +55,99 @@ class RunFieldBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final map = value is Map ? Map<String, dynamic>.from(value as Map) : null;
if (map == null || map.isEmpty) return _plain(empty);
if (map.length == 1 && map.keys.single.toLowerCase() == 'markdown') {
return _value(runFieldText(map.values.single));
final map = _runFieldMap(value);
if (map == null || map.isEmpty) {
return _runFieldPlain(empty, textBuilder);
}
if (_isMarkdownDocument(map)) {
return _runFieldValue(runFieldText(map.values.single), textBuilder);
}
final caption = Theme.of(context).textTheme.labelMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final (index, entry) in map.entries.indexed)
Padding(
padding: EdgeInsets.only(top: index == 0 ? 0 : 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
entry.key.trim().isEmpty ? 'value' : entry.key,
style: caption,
),
const SizedBox(height: 2),
_value(runFieldText(entry.value)),
],
),
),
_runFieldRow(context, index, entry, textBuilder),
],
);
}
Widget _value(String text) => runFieldLooksLikeMarkdown(text)
? ChatMarkdownView(text: text)
: _plain(text);
Widget _plain(String text) => textBuilder?.call(text) ?? SelectableText(text);
}
/// [RunFieldBody] as a sliver, for a section of a [CustomScrollView] that is
/// open by default. A field map builds and lays out only the fields on screen,
/// however many there are, so a long Output does not cost a full layout when
/// its section opens. Its rows take the full width the sliver gives them; the
/// host pads it.
class RunFieldSliver extends StatelessWidget {
const RunFieldSliver({
super.key,
required this.value,
required this.empty,
this.textBuilder,
});
final dynamic value;
final String empty;
/// Draws a plain value; the host's selectable text by default.
final Widget Function(String text)? textBuilder;
@override
Widget build(BuildContext context) {
final map = _runFieldMap(value);
if (map == null || map.isEmpty || _isMarkdownDocument(map)) {
return SliverToBoxAdapter(
child: RunFieldBody(
value: value,
empty: empty,
textBuilder: textBuilder,
),
);
}
final entries = map.entries.toList(growable: false);
return SliverList.builder(
itemCount: entries.length,
itemBuilder: (context, index) =>
_runFieldRow(context, index, entries[index], textBuilder),
);
}
}
Map<String, dynamic>? _runFieldMap(dynamic value) =>
value is Map ? Map<String, dynamic>.from(value) : null;
/// A lone `markdown` field, shown as the document itself.
bool _isMarkdownDocument(Map<String, dynamic> map) =>
map.length == 1 && map.keys.single.toLowerCase() == 'markdown';
/// One recorded field: its name, then its value.
Widget _runFieldRow(
BuildContext context,
int index,
MapEntry<String, dynamic> entry,
Widget Function(String text)? textBuilder,
) {
final theme = Theme.of(context);
final caption = theme.textTheme.labelMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurfaceVariant,
);
return Padding(
padding: EdgeInsets.only(top: index == 0 ? 0 : 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(entry.key.trim().isEmpty ? 'value' : entry.key, style: caption),
const SizedBox(height: 2),
_runFieldValue(runFieldText(entry.value), textBuilder),
],
),
);
}
Widget _runFieldValue(String text, Widget Function(String text)? textBuilder) =>
runFieldLooksLikeMarkdown(text)
? ChatMarkdownView(text: text)
: _runFieldPlain(text, textBuilder);
Widget _runFieldPlain(String text, Widget Function(String text)? textBuilder) =>
textBuilder?.call(text) ?? SelectableText(text);