Files
pipelines/app/lib/features/changes/widgets/capture_section.dart
T
alan f02ff56dfe App: dark-aware HTML views, run cards, changed/missing file notes, one card width, dense diff rows
show_html documents that declare dark support follow the app theme; others
stay light. Tool description and skill docs say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 19:54:58 +00:00

215 lines
6.8 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/change_capture.dart';
import '../domain/change_kind.dart';
import '../domain/change_wording.dart';
import '../domain/file_change.dart';
import 'change_style.dart';
/// One stage/visit capture: its honest status, scope, counters and diagnostic,
/// followed by the recorded file rows. Missing and unavailable captures are
/// shown as evidence gaps, never as an observed no-change.
class StageCaptureSection extends StatelessWidget {
const StageCaptureSection({
super.key,
required this.stage,
required this.query,
required this.onOpen,
});
final StageCapture stage;
final String query;
final ValueChanged<FileChange> onOpen;
@override
Widget build(BuildContext context) {
final capture = stage.capture;
final filtered = capture == null
? const <FileChange>[]
: filterFileChanges(capture.files, query);
// The aggregate trims and lowercases the status before testing it; do the
// same here so the section and the run header always agree.
final status = stage.stepStatus.trim().toLowerCase();
final pending =
capture == null && (status == 'running' || status == 'waiting');
final meta = [
'Visit ${stage.visit}',
if (stage.stepStatus.isNotEmpty) stage.stepStatus,
].join(' · ');
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(meta, style: Theme.of(context).textTheme.bodySmall),
if (capture != null) ...[
Text(
fileChangesSummary(capture),
style: Theme.of(context).textTheme.bodySmall,
),
if (capture.scope.isNotEmpty)
Text(
'Scope: ${capture.scope}',
style: Theme.of(context).textTheme.bodySmall,
),
],
],
),
),
const Divider(height: 1),
if (capture == null)
_CaptureNote(
icon: _noteIcon(pending ? _NoteKind.pending : _NoteKind.missing),
title: pending ? 'Capture pending' : 'Capture unavailable',
detail: pending ? pendingCaptureDetail : missingCaptureDetail,
)
else if (capture.unavailable)
_CaptureNote(
icon: _noteIcon(_NoteKind.unavailable),
title: 'Capture unavailable',
detail: capture.diagnostic.isEmpty
? unavailableCaptureDetail
: capture.diagnostic,
)
else if (capture.files.isEmpty)
_CaptureNote(
icon: _noteIcon(
capture.partial ? _NoteKind.partial : _NoteKind.empty,
),
title: capture.partial ? 'Partial capture' : 'No changes observed',
detail: capture.partial ? partialCaptureDetail : emptyCaptureDetail,
)
else if (filtered.isEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 16),
child: Text('No changed filenames match "$query".'),
)
else
for (final file in filtered)
ChangeFileRow(
key: ValueKey('change-${stage.sequence}-${file.path}'),
file: file,
onOpen: onOpen,
),
],
);
}
}
/// One changed file: its kind, path and line counts; tapping opens its diff.
/// [dense] draws it on one compact line (the path, then the counts), for a
/// card that lists many files in little space.
class ChangeFileRow extends StatelessWidget {
const ChangeFileRow({
super.key,
required this.file,
required this.onOpen,
this.dense = false,
});
final FileChange file;
final ValueChanged<FileChange> onOpen;
final bool dense;
@override
Widget build(BuildContext context) {
final mono = nativeDiffText(DefaultTextStyle.of(context).style);
final leading = Icon(changeKindIcon(file.kind), size: dense ? 20 : null);
final Widget title = dense
? Row(
children: [
Expanded(
child: Text(
file.path,
style: mono,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 12),
ChangeStatText(changeFileMeta(file)),
],
)
: Text(file.path, style: mono);
final subtitle = dense ? null : ChangeStatText(changeFileMeta(file));
final trailing = dense ? null : const Icon(Icons.chevron_right);
return Semantics(
container: true,
button: true,
// Announce the visible kind and meta too; the row's icon and subtitle are
// excluded from the semantic tree by [excludeSemantics].
label:
'Open diff for ${file.path}. '
'${changeKindTitle(file.kind)} · ${changeFileMeta(file)}',
excludeSemantics: true,
onTap: () => onOpen(file),
child: ListTile(
dense: dense,
visualDensity: dense ? VisualDensity.compact : null,
minLeadingWidth: dense ? 20 : null,
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
onTap: () => onOpen(file),
),
);
}
}
class _CaptureNote extends StatelessWidget {
const _CaptureNote({
required this.icon,
required this.title,
required this.detail,
});
final IconData icon;
final String title;
final String detail;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: Theme.of(context).textTheme.titleSmall),
const SizedBox(height: 4),
Text(detail),
],
),
),
],
),
);
}
}
enum _NoteKind { missing, unavailable, empty, partial, pending }
IconData _noteIcon(_NoteKind kind) => switch (kind) {
_NoteKind.missing || _NoteKind.unavailable => Icons.warning_amber,
_NoteKind.empty => Icons.check_circle_outline,
_NoteKind.partial => Icons.info_outline,
_NoteKind.pending => Icons.schedule,
};
/// The glyph a changed file's kind is drawn with.
IconData changeKindIcon(ChangeKind kind) => switch (kind) {
ChangeKind.added => Icons.add_circle_outline,
ChangeKind.deleted => Icons.delete_outline,
ChangeKind.modified => Icons.edit_outlined,
ChangeKind.other => Icons.description_outlined,
};