diff --git a/app/lib/features/runs/ui/run_detail_tab_bodies.dart b/app/lib/features/runs/ui/run_detail_tab_bodies.dart index 134ba8a1..a6377a0a 100644 --- a/app/lib/features/runs/ui/run_detail_tab_bodies.dart +++ b/app/lib/features/runs/ui/run_detail_tab_bodies.dart @@ -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), + ); + }, ); } } diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index d303ba93..940078a6 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -98,12 +98,13 @@ class _RunDetailTabsState extends State { Route? _visitRoute; late final ValueNotifier _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 { _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 { _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 { 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; diff --git a/app/lib/features/runs/ui/run_detail_visit_sections.dart b/app/lib/features/runs/ui/run_detail_visit_sections.dart index df811ae2..27b364fd 100644 --- a/app/lib/features/runs/ui/run_detail_visit_sections.dart +++ b/app/lib/features/runs/ui/run_detail_visit_sections.dart @@ -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 _closed = {'Input', 'Output'}; + /// The sections the operator has closed. Input starts closed; Output starts + /// open, and this set is per visit view. + final Set _closed = {'Input'}; String? _copied; Future _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(), ], ); diff --git a/app/lib/features/runs/ui/run_field_body.dart b/app/lib/features/runs/ui/run_field_body.dart index d1ce93ad..355539b0 100644 --- a/app/lib/features/runs/ui/run_field_body.dart +++ b/app/lib/features/runs/ui/run_field_body.dart @@ -55,40 +55,99 @@ class RunFieldBody extends StatelessWidget { @override Widget build(BuildContext context) { - final map = value is Map ? Map.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? _runFieldMap(dynamic value) => + value is Map ? Map.from(value) : null; + +/// A lone `markdown` field, shown as the document itself. +bool _isMarkdownDocument(Map map) => + map.length == 1 && map.keys.single.toLowerCase() == 'markdown'; + +/// One recorded field: its name, then its value. +Widget _runFieldRow( + BuildContext context, + int index, + MapEntry 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); diff --git a/app/notes/run-detail-output-expanded.md b/app/notes/run-detail-output-expanded.md new file mode 100644 index 00000000..aa1806ca --- /dev/null +++ b/app/notes/run-detail-output-expanded.md @@ -0,0 +1,39 @@ +# Run detail: Output section starts expanded + +## Change +- The run Summary's Output section (`run-detail-summary-output`) now starts open. + Input still starts closed. The Summary's default is restored on a different run + and when a search hit names no section (`RunDetailTabs._resetSummarySections`). +- A visit's Summary Output (`run-visit-section-Output`) starts open; Input starts + closed (`_VisitSummaryState._closed = {'Input'}`). +- Both stay collapsible by tapping the title. The open/closed state lives in the + controller or State for that view only; it is not persisted. +- Long outputs: Output is a sliver. `RunFieldSliver` (in `run_field_body.dart`) + builds one `SliverList` row per recorded + field, so a map with hundreds of fields lays out only the rows on screen. It + is used for the run Summary Output (`_StickyField.sliverBody`) and the visit + Summary Output (`_section(..., lazy: true)`), both through `StickySection`'s + sliver path. A closed `SliverReveal` builds nothing. +- Input stays on the box path (`RunFieldBody`); it starts closed, so its cost is + paid only when the operator opens it. The box and sliver forms share the row + builder, so they render the same fields. + +## Tests (run through `tool/memwatch/full.sh`, one quoted path list) +- Command: `tool/memwatch/full.sh 'test/features/runs/ui/run_detail_visit_sections_test.dart test/features/runs/ui/run_detail_summary_fields_test.dart test/features/runs/ui/run_detail_widget_test.dart test/features/runs/ui/run_search_selection_test.dart test/features/runs/ui/run_detail_tabs_test.dart test/features/runs/ui/run_detail_visit_test.dart'` +- Verdict (final code): `PASS: 49 passed, 0 failed, 0 skipped; peak 1884 MB; 32s; exit 0` +- New: visit Output starts expanded and collapses/reopens; run Output starts + expanded and collapses for the view; a 500-field visit Output opens with only + its first field built and the page scrolls to the last one (lazy regression). +- Updated (the old expectation was that Output started closed): visit tab/empty-state + tests, run Summary empty-wording and recorded-input tests, search-selection tests + for input, retired field and replacing a visit with the Summary. +- Not changed: Input's closed default and every Input expectation. + +## Analyze +- `tool/analyze.sh`: `analyze: clean; 10s; exit 0` +- `dart format --set-exit-if-changed` on the changed files: formatted one widget + test file (whitespace only). + +## Limitations +- No widget capture or browser/device check was run here; ui-review owns that. +- Very long Output is laid out when the section opens. Not measured for jank. diff --git a/app/test/features/runs/ui/run_detail_summary_fields_test.dart b/app/test/features/runs/ui/run_detail_summary_fields_test.dart index 019607b6..b156bfc6 100644 --- a/app/test/features/runs/ui/run_detail_summary_fields_test.dart +++ b/app/test/features/runs/ui/run_detail_summary_fields_test.dart @@ -244,10 +244,9 @@ void main() { await tester.pumpAndSettle(); expect(find.text('No input recorded.'), findsOneWidget); + // Output starts open, so its empty sentence shows without a tap. await tester.ensureVisible(find.text('Output')); await tester.pumpAndSettle(); - await tester.tap(find.text('Output')); - await tester.pumpAndSettle(); expect(find.text('No output recorded.'), findsOneWidget); }); @@ -266,5 +265,35 @@ void main() { await tester.pumpAndSettle(); expect(find.text('ship it'), findsOneWidget); }); + + testWidgets('${platform.name} summary output starts expanded and ' + 'collapses for this view', (tester) async { + await pumpRunDetail( + tester, + platform, + run: recordedRunFixture(), + size: const Size(900, 1600), + ); + + final output = find.byKey(const ValueKey('run-detail-summary-output')); + final outputTitle = find.descendant( + of: output, + matching: find.text('Output'), + ); + final outputBody = find.descendant(of: output, matching: find.text('ok')); + // Output opens with its recorded value; Input stays closed. + expect(outputBody, findsOneWidget); + expect(find.text('ship it'), findsNothing); + + await tester.ensureVisible(outputTitle.first); + await tester.pumpAndSettle(); + await tester.tap(outputTitle.first); + await tester.pumpAndSettle(); + expect(outputBody, findsNothing); + + await tester.tap(outputTitle.first); + await tester.pumpAndSettle(); + expect(outputBody, findsOneWidget); + }); } } diff --git a/app/test/features/runs/ui/run_detail_visit_sections_test.dart b/app/test/features/runs/ui/run_detail_visit_sections_test.dart index 9baebc24..c7c13adb 100644 --- a/app/test/features/runs/ui/run_detail_visit_sections_test.dart +++ b/app/test/features/runs/ui/run_detail_visit_sections_test.dart @@ -49,21 +49,77 @@ void main() { } }); + testWidgets('${platform.name} visit Output starts expanded and collapses', ( + tester, + ) async { + await openVisit(tester, platform); + final output = find.byKey(const ValueKey('run-visit-section-Output')); + final outputTitle = find.descendant( + of: output, + matching: find.text('Output'), + ); + final outputBody = find.descendant(of: output, matching: find.text('ok')); + final input = find.byKey(const ValueKey('run-visit-section-Input')); + + // Output opens expanded; Input stays closed. + expect(find.text('result'), findsOneWidget); + expect(outputBody, findsOneWidget); + expect(find.text('Ship it.'), findsNothing); + + // The operator can collapse Output, and open it again. + await tester.ensureVisible(outputTitle.first); + await tester.tap(outputTitle.first); + await tester.pumpAndSettle(); + expect(outputBody, findsNothing); + expect(find.text('result'), findsNothing); + await tester.tap(outputTitle.first); + await tester.pumpAndSettle(); + expect(outputBody, findsOneWidget); + expect(input, findsOneWidget); + }); + + testWidgets('${platform.name} long visit Output opens lazily and still ' + 'scrolls to its last field', (tester) async { + final run = visitRunFixture(); + firstVisitStep(run)['output'] = { + for (var i = 0; i < 500; i++) 'field$i': 'value $i', + }; + await openVisit(tester, platform, run: run); + + // Open by default, yet only the fields on screen are built. + expect(find.text('value 0'), findsOneWidget); + expect(find.text('value 499'), findsNothing); + + // Scrolling the page reaches the rest of the Output. + await tester.scrollUntilVisible( + find.text('value 499'), + 500, + // The page's own scroll view is the outermost of its scrollables. + scrollable: find + .descendant( + of: find.byKey(const Key('run-visit-body-summary')), + matching: find.byType(Scrollable), + ) + .first, + ); + expect(find.text('value 499'), findsOneWidget); + }); + testWidgets('${platform.name} tabs show recorded values and exact empty ' 'wording', (tester) async { await openVisit(tester, platform); - // Each field by name with its value, never raw JSON. + // Each field by name with its value, never raw JSON. Output is open at + // once; Input's value shows only after its tap. expect(find.text('Ship it.'), findsNothing); - expect(find.text('ok'), findsNothing); + expect(find.text('ok'), findsOneWidget); await tester.tap(find.text('Input')); await tester.pumpAndSettle(); expect(find.text('prompt'), findsOneWidget); expect(find.text('Ship it.'), findsOneWidget); expect(find.textContaining('"prompt"'), findsNothing); + // Output is open as the visit opens; no tap is needed to read it. await openVisitTab(tester, RunVisitSection.output); - await tester.tap(find.text('Output')); - await tester.pumpAndSettle(); expect(find.text('result'), findsOneWidget); expect(find.text('ok'), findsOneWidget); @@ -127,13 +183,12 @@ void main() { await openVisit(tester, platform, run: run); expect(find.text(visitEmptyInput), findsNothing); - expect(find.text(visitEmptyOutput), findsNothing); + // Output is open, so its empty sentence is already there. + expect(find.text(visitEmptyOutput), findsOneWidget); await tester.tap(find.text('Input')); await tester.pumpAndSettle(); expect(find.text(visitEmptyInput), findsOneWidget); await openVisitTab(tester, RunVisitSection.output); - await tester.tap(find.text('Output')); - await tester.pumpAndSettle(); expect(find.text(visitEmptyOutput), findsOneWidget); await openVisitTab(tester, RunVisitSection.artifacts); expect( diff --git a/app/test/features/runs/ui/run_detail_widget_test.dart b/app/test/features/runs/ui/run_detail_widget_test.dart index 9767fb58..a8a81d03 100644 --- a/app/test/features/runs/ui/run_detail_widget_test.dart +++ b/app/test/features/runs/ui/run_detail_widget_test.dart @@ -172,7 +172,17 @@ void main() { expect(find.text('alpha=1, items=1, 2'), findsOneWidget); expect(find.textContaining('"alpha"'), findsNothing); - await openSummarySection('Output'); + // Output starts open: its value is there to scroll to, without a tap. + await tester.scrollUntilVisible( + find.text('ok=true'), + 200, + scrollable: find + .descendant( + of: find.byKey(const Key('run-detail-tab-body-summary')), + matching: find.byType(Scrollable), + ) + .first, + ); expect(find.text('ok=true'), findsOneWidget); await tapTab('Timeline'); diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart index 88711f80..b2d21c4a 100644 --- a/app/test/features/runs/ui/run_search_selection_test.dart +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -263,7 +263,7 @@ void main() { }); for (final platform in RunDetailTestPlatform.values) { - testWidgets('${platform.name} input field expands only the input section', ( + testWidgets('${platform.name} input field expands the input section', ( tester, ) async { await pumpSelection( @@ -277,7 +277,8 @@ void main() { findsOneWidget, ); expect(find.text('ship it'), findsOneWidget); - expect(find.text('ok'), findsNothing); + // Output keeps its default: open, as every Summary opens. + expect(find.text('ok'), findsOneWidget); }); testWidgets( @@ -310,8 +311,9 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); + // The plain Summary shows its default sections: Output open, Input closed. expect(find.text('ship it'), findsNothing); - expect(find.text('ok'), findsNothing); + expect(find.text('ok'), findsOneWidget); }); for (final platform in RunDetailTestPlatform.values) { @@ -337,8 +339,9 @@ void main() { find.byKey(const Key('run-detail-tab-body-summary')), findsOneWidget, ); + // The Summary's default sections: Output open, Input closed. expect(find.text('ship it'), findsNothing); - expect(find.text('ok'), findsNothing); + expect(find.text('ok'), findsOneWidget); }, ); }