feat(app): turn documents in the artifact gallery

This commit is contained in:
2026-10-22 03:24:40 +01:00
parent 4f684ba467
commit 3fa4657be7
18 changed files with 1365 additions and 168 deletions
@@ -0,0 +1,124 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/artifact_document.dart';
import '../domain/artifact_groups.dart';
import 'artifact_record_row.dart';
import 'artifact_row_labels.dart';
/// One visit's turn documents, shown below its stage artifacts.
///
/// A recorded document is a normal gallery row with its recorded name, MIME and
/// size. A document the visit did not record is a non-actionable row carrying
/// the exact absence wording. The section never synthesizes a missing document
/// from another field and never offers an action for it.
class ArtifactDocumentSection extends StatelessWidget {
const ArtifactDocumentSection({
super.key,
required this.group,
this.selectedIdentity,
this.onSelected,
});
final ArtifactGroup group;
final String? selectedIdentity;
final ArtifactSelected? onSelected;
@override
Widget build(BuildContext context) {
final rows = <Widget>[
for (final document in group.documents) _row(document),
];
if (usesCupertinoHost(context)) {
return CupertinoListSection.insetGrouped(
header: Semantics(
container: true,
header: true,
child: const Text('Turn documents'),
),
hasLeading: false,
children: rows,
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
child: Semantics(
container: true,
header: true,
child: const Text('Turn documents'),
),
),
...rows,
],
);
}
Widget _row(ArtifactDocument document) {
final record = document.record;
if (record == null) return _AbsentDocumentRow(document: document);
final key = ValueKey<String>(
'${artifactVisitIdentity(group, record)}\u0000document',
);
return ArtifactRecordRow(
key: key,
group: group,
artifact: record,
selected: selectedIdentity == artifactVisitIdentity(group, record),
onSelected: onSelected,
);
}
}
/// A document the visit did not record: the recorded name and its exact absence
/// wording, with no tap target.
class _AbsentDocumentRow extends StatelessWidget {
const _AbsentDocumentRow({required this.document});
final ArtifactDocument document;
@override
Widget build(BuildContext context) {
if (!usesCupertinoHost(context)) {
// The absence line is informational product content, so it keeps the
// theme's normal secondary label colour. A disabled tile would paint both
// lines at the disabled colour (about 2.7:1 in light mode); no `onTap`
// keeps the row non-actionable without dimming it.
return ListTile(
title: Text(document.name),
subtitle: Text(
document.absence,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
);
}
final textTheme = CupertinoTheme.of(context).textTheme;
final absenceStyle = textTheme.textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
return Semantics(
container: true,
child: SizedBox(
width: double.infinity,
child: Padding(
padding: kCupertinoButtonPadding[CupertinoButtonSize.large]!,
child: DefaultTextStyle.merge(
style: textTheme.textStyle,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(document.name),
Text(document.absence, style: absenceStyle),
],
),
),
),
),
);
}
}
@@ -7,6 +7,7 @@ import '../../../ui/adaptive/host.dart';
import '../../chat/ui/transcript/chat_markdown_view.dart';
import '../actions/artifact_file_actions.dart';
import '../actions/artifact_file_bridge.dart';
import '../domain/artifact_document.dart';
import '../domain/artifact_groups.dart';
import '../domain/artifact_kind.dart';
import '../domain/artifact_record.dart';
@@ -76,9 +77,17 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
String? _status;
List<ArtifactGroup> _groupsOf(int? focusIndex) {
if (focusIndex == null) return artifactGroups(widget.steps);
if (focusIndex == null) return galleryGroups(widget.steps);
final group = visitArtifactGroup(widget.steps, focusIndex);
return group == null ? const <ArtifactGroup>[] : <ArtifactGroup>[group];
if (group == null) return const <ArtifactGroup>[];
// The visit pane sees the same document-enriched group the gallery shows for
// that visit, not only its recorded files.
for (final enriched in galleryGroups(widget.steps)) {
if (enriched.stageKey == group.stageKey && enriched.visit == group.visit) {
return <ArtifactGroup>[enriched];
}
}
return <ArtifactGroup>[group];
}
Future<void> _select(ArtifactGroup group, ArtifactRecord artifact) async {
@@ -86,11 +95,13 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
final resolved = artifact.hasUrl
? resolveArtifactUrl(widget.configuredEndpoint, artifact.url)
: null;
final externalOnly = artifact.name == sessionExportDocumentName;
setState(() {
_selectedIdentity = identity;
_status = null;
});
if (resolved != null &&
if (!externalOnly &&
resolved != null &&
isViewerArtifact(artifact.contentType, artifact.name)) {
await _openViewer(identity);
return;
@@ -0,0 +1,82 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/artifact_groups.dart';
import '../domain/artifact_record.dart';
import 'artifact_row_labels.dart';
/// One recorded artifact row in a gallery section.
///
/// Material draws a standard [ListTile]; Cupertino draws the same content in a
/// grouped-row button. The row only reports the selection; it never resolves a
/// url, opens a preview, downloads, shares or filters.
class ArtifactRecordRow extends StatelessWidget {
const ArtifactRecordRow({
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) {
if (!usesCupertinoHost(context)) {
return ListTile(
selected: selected,
title: Text(artifactDisplayName(artifact)),
subtitle: Text(artifactFactsLabel(artifact)),
trailing: selected ? const Icon(Icons.check) : null,
onTap: onSelected == null ? null : () => onSelected!(group, artifact),
);
}
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(artifactDisplayName(artifact)),
Text(artifactFactsLabel(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,
),
),
);
}
}
@@ -0,0 +1,32 @@
import '../domain/artifact_groups.dart';
import '../domain/artifact_kind.dart';
import '../domain/artifact_record.dart';
import '../domain/gallery_navigation.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], shared by rows and the viewer.
String artifactVisitIdentity(ArtifactGroup group, ArtifactRecord artifact) =>
artifactVisitIdentityOf(group, artifact);
/// The recorded group heading, matching the web client's group vocabulary.
String artifactGroupLabel(ArtifactGroup group) =>
'${group.stageKey} · visit ${group.visit}';
/// The displayed artifact name: a missing server name stays explicit.
String artifactDisplayName(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 artifactFactsLabel(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';
}
@@ -54,7 +54,7 @@ class ArtifactSelectionFacts extends StatelessWidget {
Text(artifactGroupLabel(group)),
if (recordedStep != null) ...[
const SizedBox(height: 8),
Text(artifactsSummary(recordedStep, count: group.artifacts.length)),
Text(artifactsSummary(recordedStep, count: group.recordedCount)),
for (final note in artifactCaptureNotes(recordedStep))
Padding(padding: const EdgeInsets.only(top: 4), child: Text(note)),
],
@@ -222,8 +222,13 @@ class _Pager extends StatelessWidget {
top: false,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(8, 0, 8, 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// A `Row` clips the second labelled button once 2x text is wider than
// the viewport; a `Wrap` keeps both controls whole and lets them take
// separate lines, like the Cupertino pager.
child: Wrap(
alignment: WrapAlignment.spaceBetween,
spacing: 8,
runSpacing: 4,
children: [
TextButton.icon(
onPressed: hasPrevious ? onPrevious : null,
@@ -3,50 +3,28 @@ 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';
import '../domain/gallery_navigation.dart';
import 'artifact_document_section.dart';
import 'artifact_record_row.dart';
import 'artifact_row_labels.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) =>
artifactVisitIdentityOf(group, artifact);
/// The recorded group heading, matching the web client's group vocabulary.
String artifactGroupLabel(ArtifactGroup group) =>
'${group.stageKey} · visit ${group.visit}';
/// The displayed artifact name: a missing server name stays explicit.
String artifactDisplayName(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 artifactFactsLabel(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';
}
export 'artifact_row_labels.dart'
show
ArtifactSelected,
artifactDisplayName,
artifactFactsLabel,
artifactGroupLabel,
artifactVisitIdentity;
/// 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].
/// Each group shows its recorded stage and visit, its stage-produced artifacts,
/// then its turn documents. Every recorded row shows its recorded filename,
/// content type and size; a turn document the visit did not record stays a
/// non-actionable row with the exact absence wording. 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.
class ArtifactVisitList extends StatelessWidget {
const ArtifactVisitList({
super.key,
@@ -70,7 +48,7 @@ class ArtifactVisitList extends StatelessWidget {
if (usesCupertinoHost(context)) {
return ListView(
children: [
for (final group in groups)
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
@@ -83,15 +61,16 @@ class ArtifactVisitList extends StatelessWidget {
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,
),
_row(group, group.artifacts[index], index),
],
),
if (group.documents.isNotEmpty)
ArtifactDocumentSection(
group: group,
selectedIdentity: selectedIdentity,
onSelected: onSelected,
),
],
],
);
}
@@ -107,11 +86,11 @@ class ArtifactVisitList extends StatelessWidget {
),
),
for (var index = 0; index < group.artifacts.length; index += 1)
_MaterialRow(
key: _rowKey(group, group.artifacts[index], index),
_row(group, group.artifacts[index], index),
if (group.documents.isNotEmpty)
ArtifactDocumentSection(
group: group,
artifact: group.artifacts[index],
selected: _isSelected(group, group.artifacts[index]),
selectedIdentity: selectedIdentity,
onSelected: onSelected,
),
],
@@ -119,96 +98,15 @@ class ArtifactVisitList extends StatelessWidget {
);
}
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');
}
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(artifactDisplayName(artifact)),
subtitle: Text(artifactFactsLabel(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(artifactDisplayName(artifact)),
Text(artifactFactsLabel(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,
),
Widget _row(ArtifactGroup group, ArtifactRecord artifact, int index) {
return ArtifactRecordRow(
key: ValueKey<String>(
'${artifactVisitIdentity(group, artifact)}\u0000$index',
),
group: group,
artifact: artifact,
selected: selectedIdentity == artifactVisitIdentity(group, artifact),
onSelected: onSelected,
);
}
}