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
@@ -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.