merge(app): land recorded artifact visit list

This commit is contained in:
2026-10-21 18:56:54 +01:00
6 changed files with 1062 additions and 0 deletions
@@ -0,0 +1,231 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/artifact_groups.dart';
import '../domain/artifact_kind.dart';
import '../domain/artifact_record.dart';
/// A selection callback carrying the recorded group and the exact record the
/// operator chose, so the visit is never lost when two groups share a name.
typedef ArtifactSelected =
void Function(ArtifactGroup group, ArtifactRecord artifact);
/// The identity of [artifact] inside [group], for
/// [ArtifactVisitList.selectedIdentity].
///
/// The recorded stage visit is part of the key, so two visits that both
/// recorded `result.csv` stay distinct even when their urls are identical.
/// A filename alone is never an identity.
String artifactVisitIdentity(ArtifactGroup group, ArtifactRecord artifact) {
final recorded = artifact.hasUrl ? artifact.url : artifact.name;
return '${group.stageKey}\u0000${group.visit}\u0000$recorded';
}
/// A read-only, selectable list of recorded artifact groups.
///
/// Each group shows its recorded stage and visit, and each row its recorded
/// filename, content type and size. Rendering uses the host's own controls:
/// Material list tiles under [MaterialApp] and grouped Cupertino list sections
/// under [CupertinoApp]. It never resolves a url, opens a preview, downloads,
/// shares or filters; the only action is [onSelected].
class ArtifactVisitList extends StatelessWidget {
const ArtifactVisitList({
super.key,
required this.groups,
this.selectedIdentity,
this.onSelected,
});
final List<ArtifactGroup> groups;
/// [artifactVisitIdentity] of the selected artifact, or null for none.
final String? selectedIdentity;
final ArtifactSelected? onSelected;
@override
Widget build(BuildContext context) {
if (groups.isEmpty) {
return const _NoArtifacts();
}
if (usesCupertinoHost(context)) {
return ListView(
children: [
for (final group in groups)
CupertinoListSection.insetGrouped(
// `container` keeps the heading a separate semantics node. Without
// it the heading merges into the neighbouring row button, so it is
// not navigable as a heading and activating it selects the row.
header: Semantics(
container: true,
header: true,
child: Text(_groupLabel(group)),
),
hasLeading: false,
children: [
for (var index = 0; index < group.artifacts.length; index += 1)
_CupertinoRow(
key: _rowKey(group, group.artifacts[index], index),
group: group,
artifact: group.artifacts[index],
selected: _isSelected(group, group.artifacts[index]),
onSelected: onSelected,
),
],
),
],
);
}
return ListView(
children: [
for (final group in groups) ...<Widget>[
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 4),
child: Semantics(
container: true,
header: true,
child: Text(_groupLabel(group)),
),
),
for (var index = 0; index < group.artifacts.length; index += 1)
_MaterialRow(
key: _rowKey(group, group.artifacts[index], index),
group: group,
artifact: group.artifacts[index],
selected: _isSelected(group, group.artifacts[index]),
onSelected: onSelected,
),
],
],
);
}
bool _isSelected(ArtifactGroup group, ArtifactRecord artifact) =>
selectedIdentity == artifactVisitIdentity(group, artifact);
static Key _rowKey(ArtifactGroup group, ArtifactRecord artifact, int index) =>
ValueKey<String>('${artifactVisitIdentity(group, artifact)}\u0000$index');
}
/// The recorded group heading, matching the web client's group vocabulary.
String _groupLabel(ArtifactGroup group) =>
'${group.stageKey} · visit ${group.visit}';
/// The displayed artifact name: a missing server name stays explicit.
String _displayName(ArtifactRecord artifact) =>
artifact.name.isEmpty ? '(unnamed artifact)' : artifact.name;
/// The recorded MIME and byte size, never inferred from the name.
///
/// The value and its unit are joined by a non-breaking space so a narrow row
/// never wraps `120.6` away from `KiB`.
String _facts(ArtifactRecord artifact) {
final type = artifact.contentType.split(';').first.trim();
final mime = type.isEmpty ? 'type not recorded' : type;
final size = humanBytes(artifact.sizeBytes).replaceFirst(' ', '\u00a0');
return '$mime · $size';
}
class _MaterialRow extends StatelessWidget {
const _MaterialRow({
super.key,
required this.group,
required this.artifact,
required this.selected,
required this.onSelected,
});
final ArtifactGroup group;
final ArtifactRecord artifact;
final bool selected;
final ArtifactSelected? onSelected;
@override
Widget build(BuildContext context) {
return ListTile(
selected: selected,
title: Text(_displayName(artifact)),
subtitle: Text(_facts(artifact)),
trailing: selected ? const Icon(Icons.check) : null,
onTap: onSelected == null ? null : () => onSelected!(group, artifact),
);
}
}
class _CupertinoRow extends StatelessWidget {
const _CupertinoRow({
super.key,
required this.group,
required this.artifact,
required this.selected,
required this.onSelected,
});
final ArtifactGroup group;
final ArtifactRecord artifact;
final bool selected;
final ArtifactSelected? onSelected;
@override
Widget build(BuildContext context) {
final textTheme = CupertinoTheme.of(context).textTheme;
final factsStyle = textTheme.textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
final content = DefaultTextStyle.merge(
style: textTheme.textStyle,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(_displayName(artifact)),
Text(_facts(artifact), style: factsStyle),
],
),
),
if (selected) const Icon(CupertinoIcons.check_mark),
],
),
);
// `container` makes this row its own semantics node, so the section
// heading stays a separate header node and never covers the row.
return Semantics(
container: true,
selected: selected,
child: SizedBox(
width: double.infinity,
// A read-only row is not a button: a disabled CupertinoButton would
// still expose a button role to assistive technology.
child: onSelected == null
? Padding(
padding: kCupertinoButtonPadding[CupertinoButtonSize.large]!,
child: content,
)
: CupertinoButton(
alignment: AlignmentDirectional.centerStart,
onPressed: () => onSelected!(group, artifact),
child: content,
),
),
);
}
}
class _NoArtifacts extends StatelessWidget {
const _NoArtifacts();
@override
Widget build(BuildContext context) {
return ListView(
children: const [
Padding(
padding: EdgeInsets.all(16),
child: Text('No stage artifacts recorded.'),
),
],
);
}
}