merge(app): land changes-paging
This commit is contained in:
@@ -180,5 +180,6 @@ List<FileChange> filterFileChanges(Iterable<FileChange> files, String query) {
|
||||
.toList(growable: false);
|
||||
}
|
||||
|
||||
/// The `N of M` position label a viewer can show for its open file.
|
||||
/// The `N of M` position label a viewer can show for its open file or for the
|
||||
/// Changes visit on screen.
|
||||
String changePositionLabel(int index, int count) => '${index + 1} of $count';
|
||||
|
||||
@@ -8,11 +8,17 @@ import '../domain/run_changes.dart';
|
||||
import 'capture_section.dart';
|
||||
import 'change_style.dart';
|
||||
import 'file_diff_viewer.dart';
|
||||
import 'visit_pager.dart';
|
||||
|
||||
/// The run's Changes surface: an honest final-state summary followed by one
|
||||
/// section per stage/visit capture, with changed-filename filtering and the
|
||||
/// The run's Changes surface: an honest final-state summary followed by the
|
||||
/// recorded stage/visit captures, with changed-filename filtering and the
|
||||
/// reusable single-file diff viewer.
|
||||
///
|
||||
/// The run-wide header and filter always describe the whole run. Below them the
|
||||
/// viewer shows one recorded visit at a time and offers Previous/Next paging
|
||||
/// through the rest in run order, so a long run stays readable without changing
|
||||
/// the aggregate. The shown visit keeps its own stage/visit heading.
|
||||
///
|
||||
/// The viewer fills the available height, so give it a bounded parent (a
|
||||
/// Scaffold body, tab body or Expanded child). It never opens its own socket or
|
||||
/// requests data; the caller passes the run detail's `steps`.
|
||||
@@ -45,6 +51,10 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
late List<StageCapture> _captures;
|
||||
late RunChanges _run;
|
||||
|
||||
/// The zero-based position of the shown visit in [_captures] (run order).
|
||||
/// The page opens at the first recorded visit; Previous/Next never wrap.
|
||||
int _visitIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -62,6 +72,19 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
void _derive() {
|
||||
_captures = stageCaptures(widget.steps);
|
||||
_run = runChangesFor(_captures);
|
||||
// A fresh reply may have fewer recorded visits; never point past the end.
|
||||
_visitIndex = _clampVisit(_visitIndex, _captures.length);
|
||||
}
|
||||
|
||||
static int _clampVisit(int index, int count) {
|
||||
if (count <= 0 || index < 0) return 0;
|
||||
return index >= count ? count - 1 : index;
|
||||
}
|
||||
|
||||
void _stepVisit(int delta) {
|
||||
final next = _clampVisit(_visitIndex + delta, _captures.length);
|
||||
if (next == _visitIndex) return;
|
||||
setState(() => _visitIndex = next);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -81,6 +104,7 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
(visit) => visit.capture?.files.isNotEmpty ?? false,
|
||||
);
|
||||
final note = showSummary ? runChangesNote(run) : '';
|
||||
final visit = captures.isEmpty ? null : captures[_visitIndex];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
@@ -107,8 +131,8 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'The summary counts each path once, as the last recorded '
|
||||
'visit left it. Each stage/visit below lists what its own '
|
||||
'capture recorded.',
|
||||
'visit left it. Each stage/visit page below lists what '
|
||||
'its own capture recorded.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
@@ -122,27 +146,33 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
),
|
||||
if (showSummary) const Divider(height: 1),
|
||||
Expanded(
|
||||
child: captures.isEmpty
|
||||
child: visit == null
|
||||
? SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(noChangeDetail(run)),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: captures.length,
|
||||
itemBuilder: (context, index) {
|
||||
final visit = captures[index];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
StageCaptureSection(
|
||||
stage: visit,
|
||||
query: _query,
|
||||
onOpen: (file) => showFileDiffViewer(context, file),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
],
|
||||
);
|
||||
},
|
||||
: SingleChildScrollView(
|
||||
// Keying the body by visit keeps each page's pager and heading
|
||||
// at the top instead of inheriting the previous scroll offset.
|
||||
key: ValueKey<String>(
|
||||
'changes-visit-${visit.stage}-${visit.sequence}',
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ChangesVisitPager(
|
||||
index: _visitIndex,
|
||||
count: captures.length,
|
||||
onPrevious: () => _stepVisit(-1),
|
||||
onNext: () => _stepVisit(1),
|
||||
),
|
||||
StageCaptureSection(
|
||||
stage: visit,
|
||||
query: _query,
|
||||
onOpen: (file) => showFileDiffViewer(context, file),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/change_wording.dart';
|
||||
import 'change_style.dart';
|
||||
|
||||
/// The Changes page's Previous/Next pager over the run's recorded stage visits.
|
||||
///
|
||||
/// It only moves between the captures the viewer already holds and never wraps:
|
||||
/// the first recorded visit has no previous page and the last none after it.
|
||||
/// The shown visit's own heading (its stage and visit number) stays with the
|
||||
/// capture section below, so paging never loses which visit is on screen.
|
||||
class ChangesVisitPager extends StatelessWidget {
|
||||
const ChangesVisitPager({
|
||||
super.key,
|
||||
required this.index,
|
||||
required this.count,
|
||||
required this.onPrevious,
|
||||
required this.onNext,
|
||||
});
|
||||
|
||||
static const previousKey = ValueKey<String>('changes-previous-visit');
|
||||
static const nextKey = ValueKey<String>('changes-next-visit');
|
||||
|
||||
/// The shown visit's zero-based position in the run's recorded visits.
|
||||
final int index;
|
||||
final int count;
|
||||
final VoidCallback onPrevious;
|
||||
final VoidCallback onNext;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (count <= 1) return const SizedBox.shrink();
|
||||
final hasPrevious = index > 0;
|
||||
final hasNext = index < count - 1;
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'${changePositionLabel(index, count)} recorded visits',
|
||||
key: const ValueKey<String>('changes-visit-position'),
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// A `Wrap` keeps both controls whole and lets them take separate
|
||||
// lines at large text sizes or on a narrow page.
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
_button(
|
||||
context,
|
||||
key: previousKey,
|
||||
label: 'Previous visit',
|
||||
enabled: hasPrevious,
|
||||
onPressed: onPrevious,
|
||||
previous: true,
|
||||
),
|
||||
_button(
|
||||
context,
|
||||
key: nextKey,
|
||||
label: 'Next visit',
|
||||
enabled: hasNext,
|
||||
onPressed: onNext,
|
||||
previous: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _button(
|
||||
BuildContext context, {
|
||||
required Key key,
|
||||
required String label,
|
||||
required bool enabled,
|
||||
required VoidCallback onPressed,
|
||||
required bool previous,
|
||||
}) {
|
||||
if (usesCupertino(context)) {
|
||||
return CupertinoButton(
|
||||
key: key,
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: enabled ? onPressed : null,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
previous ? CupertinoIcons.back : CupertinoIcons.forward,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(label),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return TextButton.icon(
|
||||
key: key,
|
||||
onPressed: enabled ? onPressed : null,
|
||||
icon: Icon(previous ? Icons.arrow_back : Icons.arrow_forward),
|
||||
label: Text(label),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user