feat(app): turn documents in the artifact gallery
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'artifact_capture.dart';
|
||||
import 'artifact_kind.dart';
|
||||
import 'artifact_record.dart';
|
||||
import 'artifact_selection.dart';
|
||||
|
||||
/// The exact server-recorded name of a visit's session export. It is the one
|
||||
/// turn document that only ever opens externally.
|
||||
const String sessionExportDocumentName = 'session.html';
|
||||
|
||||
/// The turn-protocol documents a visit records, in the order the audit surface
|
||||
/// presents them. These are the same files the stage-artifact filter treats as
|
||||
/// turn-owned ([systemArtifactNames]), aliased so a rename cannot make the
|
||||
/// gallery and the filter disagree.
|
||||
const List<String> turnDocumentNames = systemArtifactNames;
|
||||
|
||||
/// The exact absence wording for a missing turn document. Session absence is
|
||||
/// contextual and comes from [sessionDocumentAbsence].
|
||||
const String noInputDocument = 'No input recorded.';
|
||||
const String noOutputDocument = 'No output recorded.';
|
||||
const String noMemoryDocument = 'No memory recorded for this visit.';
|
||||
|
||||
/// One presented turn document of a visit.
|
||||
///
|
||||
/// [record] is the server's exact recorded artifact, or null when the visit did
|
||||
/// not record that document. A null record is never completed from a step field
|
||||
/// or another document: the entry carries [absence] instead, so the gallery can
|
||||
/// show why the document is missing.
|
||||
class ArtifactDocument {
|
||||
const ArtifactDocument({
|
||||
required this.name,
|
||||
required this.record,
|
||||
required this.absence,
|
||||
});
|
||||
|
||||
final String name;
|
||||
final ArtifactRecord? record;
|
||||
|
||||
/// The exact wording shown when [record] is null; empty when recorded.
|
||||
final String absence;
|
||||
|
||||
/// The session export is read-only evidence: it only ever opens externally.
|
||||
bool get externalOnly => name == sessionExportDocumentName;
|
||||
|
||||
/// Whether selecting this document opens the existing in-app renderer. A
|
||||
/// session export is excluded even if the server sniffed it as text.
|
||||
bool get opensInViewer {
|
||||
final recorded = record;
|
||||
if (recorded == null || externalOnly) return false;
|
||||
return isViewerArtifact(recorded.contentType, recorded.name);
|
||||
}
|
||||
}
|
||||
|
||||
String? _text(dynamic value) {
|
||||
if (value == null) return null;
|
||||
final text = '$value';
|
||||
return text.isEmpty ? null : text;
|
||||
}
|
||||
|
||||
/// The web client's contextual session wording, used only when no exact
|
||||
/// `session.html` artifact was recorded. A recorded session id and a missing
|
||||
/// export are different facts and are never collapsed into "not recorded".
|
||||
String sessionDocumentAbsence(JsonMap step) {
|
||||
final export = step['session_export'];
|
||||
final evidence = export is Map ? Map<String, dynamic>.from(export) : null;
|
||||
final evidenceSessionId = _text(evidence?['session_id']);
|
||||
final sessionId = _text(step['session_id']) ?? evidenceSessionId ?? '';
|
||||
if (sessionId.isNotEmpty) {
|
||||
final recoveryValue = step['session_export_recovery'];
|
||||
final recovery = recoveryValue is Map
|
||||
? Map<String, dynamic>.from(recoveryValue)
|
||||
: null;
|
||||
final recoveryStatus = _text(recovery?['status']);
|
||||
final evidenceStatus = _text(evidence?['status']);
|
||||
final status = recoveryStatus == 'pending' || recoveryStatus == 'running'
|
||||
? 'pending recovery'
|
||||
: evidenceStatus == 'complete'
|
||||
? 'not available in the artifact inventory'
|
||||
: evidenceStatus ?? 'not yet available';
|
||||
final diagnostic = _text(evidence?['diagnostic']);
|
||||
return 'Session $sessionId is recorded. Its export is $status.'
|
||||
'${diagnostic == null ? '' : ' $diagnostic'}';
|
||||
}
|
||||
final model = _text(step['model']) != null || _text(step['provider']) != null;
|
||||
final status = _text(step['status']);
|
||||
final outcome = _text(step['outcome']);
|
||||
if (status == 'skipped' || outcome == 'skipped') {
|
||||
return 'This visit was skipped; no harness session was started.';
|
||||
}
|
||||
if (status == 'canceled' || status == 'interrupted') {
|
||||
return 'The stage stopped before a harness session was recorded.';
|
||||
}
|
||||
if (model) {
|
||||
if (status == 'running') return 'The stage session is being created.';
|
||||
if (status == 'failed') {
|
||||
final diagnostic = _text(step['diagnostic']);
|
||||
return diagnostic == null
|
||||
? 'The stage did not create a harness session.'
|
||||
: 'The stage did not create a harness session. $diagnostic';
|
||||
}
|
||||
return 'Runtime error: this model stage has no recorded session identity.';
|
||||
}
|
||||
return 'This visit has no harness session.';
|
||||
}
|
||||
|
||||
String _absenceFor(String name, JsonMap step) => switch (name) {
|
||||
'input.md' => noInputDocument,
|
||||
'output.md' => noOutputDocument,
|
||||
'memory.md' => noMemoryDocument,
|
||||
_ => sessionDocumentAbsence(step),
|
||||
};
|
||||
|
||||
/// Every turn document slot of one visit, recorded or absent.
|
||||
///
|
||||
/// A capture whose `artifacts` field is absent yields no slots at all: a missing
|
||||
/// capture is not evidence that the visit recorded no document. A visit that
|
||||
/// recorded none of the four turn documents yields no slots either, so a stage
|
||||
/// outside the turn protocol is never presented as four missing documents. Only
|
||||
/// exact recorded names are presented; nothing is synthesized from other step
|
||||
/// fields.
|
||||
List<ArtifactDocument> visitDocuments(JsonMap step) {
|
||||
final capture = ArtifactCapture.fromStep(step);
|
||||
if (!capture.isAvailable) return const <ArtifactDocument>[];
|
||||
final recorded = presentedArtifacts(capture.artifacts);
|
||||
ArtifactRecord? firstNamed(String name) {
|
||||
for (final artifact in recorded) {
|
||||
if (artifact.name == name) return artifact;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final records = <String, ArtifactRecord>{};
|
||||
for (final name in turnDocumentNames) {
|
||||
final record = firstNamed(name);
|
||||
if (record != null) records[name] = record;
|
||||
}
|
||||
if (records.isEmpty) return const <ArtifactDocument>[];
|
||||
|
||||
final documents = <ArtifactDocument>[];
|
||||
for (final name in turnDocumentNames) {
|
||||
final record = records[name];
|
||||
documents.add(
|
||||
record == null
|
||||
? ArtifactDocument(
|
||||
name: name,
|
||||
record: null,
|
||||
absence: _absenceFor(name, step),
|
||||
)
|
||||
: ArtifactDocument(name: name, record: record, absence: ''),
|
||||
);
|
||||
}
|
||||
return List<ArtifactDocument>.unmodifiable(documents);
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../graph/domain/stage_visits.dart';
|
||||
import 'artifact_document.dart';
|
||||
import 'artifact_record.dart';
|
||||
import 'artifact_selection.dart';
|
||||
|
||||
/// One gallery group: the stage-produced artifacts of a recorded stage visit.
|
||||
/// One gallery group: the stage-produced artifacts of a recorded stage visit
|
||||
/// plus that visit's turn documents, recorded or explicitly absent.
|
||||
class ArtifactGroup {
|
||||
const ArtifactGroup({
|
||||
required this.stageKey,
|
||||
required this.visit,
|
||||
required this.artifacts,
|
||||
this.documents = const <ArtifactDocument>[],
|
||||
});
|
||||
|
||||
final String stageKey;
|
||||
@@ -18,6 +21,15 @@ class ArtifactGroup {
|
||||
final int visit;
|
||||
|
||||
final List<ArtifactRecord> artifacts;
|
||||
|
||||
/// The visit's turn-document slots. Empty when the capture was unavailable,
|
||||
/// so an unknown capture is never presented as four missing documents.
|
||||
final List<ArtifactDocument> documents;
|
||||
|
||||
/// The count the gallery header reports: stage artifacts plus the turn
|
||||
/// documents the server actually recorded, never an absent slot.
|
||||
int get recordedCount =>
|
||||
artifacts.length + documents.where((doc) => doc.record != null).length;
|
||||
}
|
||||
|
||||
int _sequenceOf(JsonMap step) {
|
||||
@@ -86,6 +98,45 @@ List<ArtifactGroup> artifactGroups(List<JsonMap> steps) {
|
||||
return List<ArtifactGroup>.unmodifiable(groups);
|
||||
}
|
||||
|
||||
String _galleryKey(String stageKey, int visit) => '$stageKey\u0000$visit';
|
||||
|
||||
/// The gallery's per-visit groups: stage artifacts and turn documents in one
|
||||
/// section per recorded visit.
|
||||
///
|
||||
/// Stage-only grouping is unchanged ([artifactGroups]); this function adds the
|
||||
/// turn-document slots a visit recorded and keeps a visit whose only recorded
|
||||
/// files are turn documents. A visit with neither stage artifacts nor a
|
||||
/// recorded document, or whose capture is unavailable, produces no group.
|
||||
List<ArtifactGroup> galleryGroups(List<JsonMap> steps) {
|
||||
if (steps.isEmpty) return const <ArtifactGroup>[];
|
||||
final stageGroups = <String, ArtifactGroup>{
|
||||
for (final group in artifactGroups(steps))
|
||||
_galleryKey(group.stageKey, group.visit): group,
|
||||
};
|
||||
final groups = <ArtifactGroup>[];
|
||||
for (final entry in visitsByStage(steps).entries) {
|
||||
for (var index = 0; index < entry.value.length; index += 1) {
|
||||
final step = entry.value[index];
|
||||
final visit = displayVisit(step, index);
|
||||
final base = stageGroups[_galleryKey(entry.key, visit)];
|
||||
final documents = visitDocuments(step);
|
||||
final recordedDocuments = documents.where((doc) => doc.record != null);
|
||||
if ((base?.artifacts.isEmpty ?? true) && recordedDocuments.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
groups.add(
|
||||
ArtifactGroup(
|
||||
stageKey: entry.key,
|
||||
visit: visit,
|
||||
artifacts: base?.artifacts ?? const <ArtifactRecord>[],
|
||||
documents: documents,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return List<ArtifactGroup>.unmodifiable(groups);
|
||||
}
|
||||
|
||||
/// One visit's stage artifacts, excluding shared public files that an earlier
|
||||
/// visit already recorded. A repeated non-public name in a later visit stays
|
||||
/// because it is a different recorded artifact, not the same shared file.
|
||||
|
||||
@@ -6,8 +6,8 @@ import '../../../core/api_gateway.dart';
|
||||
const String legacySessionMarkdownArtifact = 'session.md';
|
||||
|
||||
/// The files the turn protocol itself writes for every visit. They are audit
|
||||
/// evidence, not stage output, so the artifact gallery lists stage files first
|
||||
/// and keeps these for an audit/debug surface.
|
||||
/// evidence, not stage output: the artifact gallery presents them as the visit's
|
||||
/// turn documents, and the stage-file list still excludes them.
|
||||
const List<String> systemArtifactNames = <String>[
|
||||
'input.md',
|
||||
'memory.md',
|
||||
|
||||
@@ -16,14 +16,15 @@ String artifactsEmptyMessage(bool executing) => executing
|
||||
|
||||
/// The run summary's Artifacts section header.
|
||||
///
|
||||
/// The recorded count is exactly the number of tiles [artifactGroups] yields;
|
||||
/// the title takes its singular form for one. A run whose capture is unavailable
|
||||
/// says so instead of claiming that nothing was recorded. Partial capture is
|
||||
/// flagged when any visit excluded or omitted files.
|
||||
/// The recorded count is the number of recorded entries [galleryGroups] yields:
|
||||
/// stage files plus the turn documents the server actually recorded, never an
|
||||
/// absent slot. The title takes its singular form for one. A run whose capture is
|
||||
/// unavailable says so instead of claiming that nothing was recorded. Partial
|
||||
/// capture is flagged when any visit excluded or omitted files.
|
||||
String artifactsHeader(List<JsonMap> steps, {required bool executing}) {
|
||||
final recorded = artifactGroups(
|
||||
final recorded = galleryGroups(
|
||||
steps,
|
||||
).fold<int>(0, (sum, group) => sum + group.artifacts.length);
|
||||
).fold<int>(0, (sum, group) => sum + group.recordedCount);
|
||||
if (recorded == 0) {
|
||||
if (executing) return artifactsEmptyMessage(true);
|
||||
final unavailable = steps.any(
|
||||
@@ -44,8 +45,10 @@ String artifactsHeader(List<JsonMap> steps, {required bool executing}) {
|
||||
///
|
||||
/// A running visit says capture pending. A finished visit whose capture field was
|
||||
/// absent says capture unavailable rather than "not recorded"; only an explicitly
|
||||
/// empty capture says "not recorded for this visit". Recorded counts exclude the
|
||||
/// turn-owned files and the retired session markdown, so the words match tiles.
|
||||
/// empty capture says "not recorded for this visit". Without [count] the recorded
|
||||
/// number excludes the turn-owned files and the retired session markdown, so the
|
||||
/// stage-artifact words match the stage tiles; a caller that presents the turn
|
||||
/// documents too passes its own recorded entry count.
|
||||
String artifactsSummary(JsonMap step, {int? count}) {
|
||||
final capture = ArtifactCapture.fromStep(step);
|
||||
final recorded = count ?? stageArtifacts(step).length;
|
||||
|
||||
@@ -36,21 +36,27 @@ String artifactVisitIdentityOf(ArtifactGroup group, ArtifactRecord artifact) {
|
||||
}
|
||||
|
||||
/// The artifacts the viewer can page through, in gallery order: group by group,
|
||||
/// each group's images, videos and markdown/text documents in recorded order.
|
||||
/// Other artifacts open externally and are not part of this list. Pure: it only
|
||||
/// filters and orders records the gallery already holds.
|
||||
/// each group's images, videos and markdown/text documents in recorded order,
|
||||
/// then the visit's recorded turn documents that open in the renderer. A session
|
||||
/// export is external-only and never enters the page list. Pure: it only filters
|
||||
/// and orders records the gallery already holds.
|
||||
List<PagedArtifact> pagedArtifacts(List<ArtifactGroup> groups) {
|
||||
final pages = <PagedArtifact>[];
|
||||
void add(ArtifactGroup group, ArtifactRecord artifact) {
|
||||
pages.add(
|
||||
PagedArtifact(group: group, artifact: artifact, pageIndex: pages.length),
|
||||
);
|
||||
}
|
||||
|
||||
for (final group in groups) {
|
||||
for (final artifact in group.artifacts) {
|
||||
if (!isViewerArtifact(artifact.contentType, artifact.name)) continue;
|
||||
pages.add(
|
||||
PagedArtifact(
|
||||
group: group,
|
||||
artifact: artifact,
|
||||
pageIndex: pages.length,
|
||||
),
|
||||
);
|
||||
add(group, artifact);
|
||||
}
|
||||
for (final document in group.documents) {
|
||||
final artifact = document.record;
|
||||
if (artifact == null || !document.opensInViewer) continue;
|
||||
add(group, artifact);
|
||||
}
|
||||
}
|
||||
return List<PagedArtifact>.unmodifiable(pages);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user