264 lines
9.8 KiB
Dart
264 lines
9.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../domain/change_capture.dart';
|
|
import '../domain/change_wording.dart';
|
|
import '../domain/file_change.dart';
|
|
import '../domain/run_changes.dart';
|
|
import 'capture_section.dart';
|
|
import 'change_style.dart';
|
|
import 'file_diff_viewer.dart';
|
|
import 'visit_pager.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
import '../../../ui/adaptive/glass_pill.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
|
|
/// 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`.
|
|
class ChangesViewer extends StatefulWidget {
|
|
const ChangesViewer({
|
|
super.key,
|
|
required this.steps,
|
|
this.showSummary = true,
|
|
this.finalOnly = false,
|
|
});
|
|
|
|
/// The run detail's steps exactly as the server returned them. Each step's
|
|
/// `file_changes` may be null (no capture), a complete/partial/unavailable
|
|
/// capture, or a capture with zero files (a recorded no-change).
|
|
///
|
|
/// Pass a stable list: the same instance until the server reply changes. The
|
|
/// captures and the summary are derived from it rather than on every rebuild.
|
|
final List<JsonMap> steps;
|
|
|
|
/// Whether the run-wide final-state header and filter are shown. The web
|
|
/// client gates its aggregate on [showRunChangesSummary]; the per-stage
|
|
/// sections stay the evidence for a run without a settled final state.
|
|
final bool showSummary;
|
|
|
|
/// The run's final changes only: the summary and every changed path once,
|
|
/// as the last recorded visit left it, with no visit pages.
|
|
final bool finalOnly;
|
|
|
|
@override
|
|
State<ChangesViewer> createState() => _ChangesViewerState();
|
|
}
|
|
|
|
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();
|
|
_derive();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(ChangesViewer oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
// Filter keystrokes rebuild this widget with the same steps list; only a
|
|
// new server reply re-derives the captures and the aggregate.
|
|
if (!identical(oldWidget.steps, widget.steps)) _derive();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
/// No filter field: the visit lists every file its capture recorded.
|
|
static const _query = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final run = _run;
|
|
final captures = _captures;
|
|
final showSummary = widget.showSummary;
|
|
final hasFiles = captures.any(
|
|
(visit) => visit.capture?.files.isNotEmpty ?? false,
|
|
);
|
|
final note = showSummary ? runChangesNote(run) : '';
|
|
final visit = captures.isEmpty ? null : captures[_visitIndex];
|
|
final hasVisitPager = !widget.finalOnly && captures.length > 1;
|
|
final pager = hasVisitPager
|
|
? ChangesVisitPager(
|
|
index: _visitIndex,
|
|
count: captures.length,
|
|
onPrevious: () => _stepVisit(-1),
|
|
onNext: () => _stepVisit(1),
|
|
)
|
|
: null;
|
|
final content = Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (showSummary)
|
|
Padding(
|
|
padding: withTopBarClearance(
|
|
context,
|
|
const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ChangeStatText(
|
|
runChangesHeader(run),
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
if (note.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(
|
|
note,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
if (hasFiles)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Text(
|
|
widget.finalOnly
|
|
? 'Each path once, as the last recorded visit left '
|
|
'it. A stage\'s own changes are in its timeline '
|
|
'detail.'
|
|
: 'The summary counts each path once, as the last '
|
|
'recorded visit left it. Each stage/visit page '
|
|
'below lists what its own capture recorded.',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (showSummary) const Divider(height: 1),
|
|
// The run's final changes: every changed path once, as it ended.
|
|
if (widget.finalOnly)
|
|
Expanded(
|
|
child: run.files.isEmpty
|
|
? SingleChildScrollView(
|
|
padding: withTopBarClearance(
|
|
context,
|
|
const EdgeInsets.all(16),
|
|
),
|
|
child: Text(noChangeDetail(run)),
|
|
)
|
|
: ListView(
|
|
key: const ValueKey<String>('changes-final'),
|
|
children: [
|
|
for (final file in run.files)
|
|
ChangeFileRow(
|
|
key: ValueKey<String>('change-final-${file.path}'),
|
|
file: file,
|
|
onOpen: (file) => showFileDiffViewer(
|
|
context,
|
|
file,
|
|
files: run.files,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (!widget.finalOnly)
|
|
Expanded(
|
|
child: visit == null
|
|
? SingleChildScrollView(
|
|
padding: pager == null
|
|
? withTopBarClearance(context, const EdgeInsets.all(16))
|
|
: withBarClearance(context, const EdgeInsets.all(16)),
|
|
child: Text(noChangeDetail(run)),
|
|
)
|
|
: 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}',
|
|
),
|
|
padding: hasVisitPager
|
|
? withBarClearance(context, EdgeInsets.zero)
|
|
: withTopBarClearance(context, EdgeInsets.zero),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
StageCaptureSection(
|
|
stage: visit,
|
|
query: _query,
|
|
// The page steps through the files this visit shows.
|
|
onOpen: (file) => showFileDiffViewer(
|
|
context,
|
|
file,
|
|
files: filterFileChanges(
|
|
visit.capture?.files ?? const <FileChange>[],
|
|
_query,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
if (pager == null) return content;
|
|
return FloatingBarOverlay(
|
|
bar: Align(
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
heightFactor: 1,
|
|
widthFactor: 1,
|
|
child: MediaQuery.removePadding(
|
|
context: context,
|
|
removeBottom: true,
|
|
child: SafeArea(
|
|
top: false,
|
|
minimum: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Padding(
|
|
// The inherited bottom inset belongs to the shell bar. Include it
|
|
// in this overlay's measured bar height so the pager is stacked
|
|
// above it rather than translating into a constrained layout.
|
|
padding: EdgeInsets.only(
|
|
bottom: MediaQuery.paddingOf(context).bottom,
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: IntrinsicWidth(
|
|
child: GlassPill(
|
|
cupertino: usesCupertinoHost(context),
|
|
child: pager,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
child: content,
|
|
);
|
|
}
|
|
}
|