feat(app): add run change captures and native diff viewer
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
import 'package:flutter/cupertino.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(stage.stage, style: Theme.of(context).textTheme.titleMedium),
|
||||
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(
|
||||
context,
|
||||
pending ? _NoteKind.pending : _NoteKind.missing,
|
||||
),
|
||||
title: pending ? 'Capture pending' : 'Capture unavailable',
|
||||
detail: pending ? pendingCaptureDetail : missingCaptureDetail,
|
||||
)
|
||||
else if (capture.unavailable)
|
||||
_CaptureNote(
|
||||
icon: _noteIcon(context, _NoteKind.unavailable),
|
||||
title: 'Capture unavailable',
|
||||
detail: capture.diagnostic.isEmpty
|
||||
? unavailableCaptureDetail
|
||||
: capture.diagnostic,
|
||||
)
|
||||
else if (capture.files.isEmpty)
|
||||
_CaptureNote(
|
||||
icon: _noteIcon(
|
||||
context,
|
||||
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)
|
||||
_FileRow(
|
||||
key: ValueKey('change-${stage.sequence}-${file.path}'),
|
||||
file: file,
|
||||
onOpen: onOpen,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FileRow extends StatelessWidget {
|
||||
const _FileRow({super.key, required this.file, required this.onOpen});
|
||||
|
||||
final FileChange file;
|
||||
final ValueChanged<FileChange> onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mono = monospaceText(DefaultTextStyle.of(context).style);
|
||||
final cupertino = usesCupertino(context);
|
||||
final leading = Icon(_kindIcon(context, file.kind));
|
||||
final title = Text(file.path, style: mono);
|
||||
final subtitle = Text(changeFileMeta(file));
|
||||
final trailing = cupertino
|
||||
? const CupertinoListTileChevron()
|
||||
: 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: cupertino
|
||||
? CupertinoListTile(
|
||||
leading: leading,
|
||||
// A recorded path is the row's identity, so it wraps instead of
|
||||
// being ellipsized to one line.
|
||||
title: _unclampedText(title),
|
||||
subtitle: _unclampedText(subtitle),
|
||||
trailing: trailing,
|
||||
onTap: () => onOpen(file),
|
||||
)
|
||||
: ListTile(
|
||||
leading: leading,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
trailing: trailing,
|
||||
onTap: () => onOpen(file),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// CupertinoListTile caps its title and subtitle at one ellipsized line through
|
||||
/// the inherited [DefaultTextStyle]. Re-establish the ambient style without that
|
||||
/// cap so a long recorded path stays readable; the tile keeps its native
|
||||
/// padding, pressed state and chevron.
|
||||
Widget _unclampedText(Widget child) {
|
||||
return Builder(
|
||||
builder: (context) {
|
||||
final inherited = DefaultTextStyle.of(context);
|
||||
return DefaultTextStyle(
|
||||
style: inherited.style,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.visible,
|
||||
textAlign: inherited.textAlign,
|
||||
textWidthBasis: inherited.textWidthBasis,
|
||||
textHeightBehavior: inherited.textHeightBehavior,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
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(BuildContext context, _NoteKind kind) {
|
||||
final cupertino = usesCupertino(context);
|
||||
return switch (kind) {
|
||||
_NoteKind.missing || _NoteKind.unavailable =>
|
||||
cupertino ? CupertinoIcons.exclamationmark_triangle : Icons.warning_amber,
|
||||
_NoteKind.empty =>
|
||||
cupertino ? CupertinoIcons.checkmark_circle : Icons.check_circle_outline,
|
||||
_NoteKind.partial => cupertino ? CupertinoIcons.info : Icons.info_outline,
|
||||
_NoteKind.pending => cupertino ? CupertinoIcons.clock : Icons.schedule,
|
||||
};
|
||||
}
|
||||
|
||||
IconData _kindIcon(BuildContext context, ChangeKind kind) {
|
||||
final cupertino = usesCupertino(context);
|
||||
return switch (kind) {
|
||||
ChangeKind.added =>
|
||||
cupertino ? CupertinoIcons.add_circled : Icons.add_circle_outline,
|
||||
ChangeKind.deleted =>
|
||||
cupertino ? CupertinoIcons.trash : Icons.delete_outline,
|
||||
ChangeKind.modified =>
|
||||
cupertino ? CupertinoIcons.pencil : Icons.edit_outlined,
|
||||
ChangeKind.other =>
|
||||
cupertino ? CupertinoIcons.doc : Icons.description_outlined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user