201 lines
6.7 KiB
Dart
201 lines
6.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../domain/change_capture.dart';
|
|
import '../domain/change_wording.dart';
|
|
import '../domain/run_changes.dart';
|
|
import 'capture_section.dart';
|
|
import 'change_style.dart';
|
|
import 'file_diff_viewer.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
|
|
/// reusable single-file diff viewer.
|
|
///
|
|
/// 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,
|
|
});
|
|
|
|
/// 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;
|
|
|
|
@override
|
|
State<ChangesViewer> createState() => _ChangesViewerState();
|
|
}
|
|
|
|
class _ChangesViewerState extends State<ChangesViewer> {
|
|
final _filter = TextEditingController();
|
|
late List<StageCapture> _captures;
|
|
late RunChanges _run;
|
|
|
|
@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);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_filter.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
String get _query => _filter.text;
|
|
|
|
@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) : '';
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (showSummary)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
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(
|
|
'The summary counts each path once, as the last recorded '
|
|
'visit left it. Each stage/visit below lists what its own '
|
|
'capture recorded.',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (showSummary && hasFiles)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
|
child: _filterField(context, run),
|
|
),
|
|
if (showSummary) const Divider(height: 1),
|
|
Expanded(
|
|
child: captures.isEmpty
|
|
? 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),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _filterField(BuildContext context, RunChanges run) {
|
|
final query = _query;
|
|
final matched = query.trim().isEmpty
|
|
? run.files.length
|
|
: filterFileChanges(run.files, query).length;
|
|
// The summary counts paths while the sections below list one row per stage
|
|
// visit, so the counter names what it actually counts.
|
|
final counter = query.trim().isEmpty
|
|
? ''
|
|
: '$matched of ${run.files.length} changed '
|
|
'${run.files.length == 1 ? 'path' : 'paths'} match';
|
|
final field = usesCupertino(context)
|
|
? CupertinoSearchTextField(
|
|
controller: _filter,
|
|
placeholder: 'Filter changed files',
|
|
onChanged: (_) => setState(() {}),
|
|
)
|
|
: TextField(
|
|
controller: _filter,
|
|
decoration: InputDecoration(
|
|
labelText: 'Filter changed files',
|
|
hintText: 'Filename contains…',
|
|
prefixIcon: const Icon(Icons.search),
|
|
suffixIcon: query.isEmpty
|
|
? null
|
|
: IconButton(
|
|
tooltip: 'Clear filter',
|
|
onPressed: () {
|
|
_filter.clear();
|
|
setState(() {});
|
|
},
|
|
icon: const Icon(Icons.clear),
|
|
),
|
|
),
|
|
onChanged: (_) => setState(() {}),
|
|
);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
field,
|
|
if (counter.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(counter, style: Theme.of(context).textTheme.bodySmall),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|