Files
pipelines/app/lib/features/runs/ui/run_detail_visit_artifacts.dart
T

113 lines
3.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../artifacts/domain/artifact_groups.dart';
import '../../artifacts/domain/artifact_record.dart';
import '../../artifacts/domain/artifact_summary.dart';
import '../../artifacts/ui/artifact_gallery_action.dart';
import '../../artifacts/ui/artifact_visit_list.dart';
/// The visit's recorded stage artifacts, in recorded order.
///
/// Selecting a row opens the existing artifact gallery page for exactly this
/// visit, so the pane never grows a second viewer or a link-only substitute.
/// The page receives the whole run so a shared `public/` file stays with the
/// visit that first recorded it, and it lists exactly the rows shown here.
///
/// An empty list is never described as "nothing recorded" on its own: the
/// existing capture semantics say whether the capture is unavailable, still
/// pending or explicitly empty for this visit.
class RunVisitArtifacts extends StatelessWidget {
const RunVisitArtifacts({
super.key,
required this.step,
required this.visitIndex,
required this.runSteps,
required this.configuredEndpoint,
});
final JsonMap step;
/// The visit's index in [runSteps], so the opened page is the same group.
final int visitIndex;
final List<JsonMap> runSteps;
final String configuredEndpoint;
@override
Widget build(BuildContext context) {
final artifacts = visitArtifacts(step, runSteps);
final notes = artifactCaptureNotes(step);
if (artifacts.isEmpty) {
return ListView(
key: const Key('run-visit-body-artifacts'),
padding: const EdgeInsets.all(16),
children: [
Text(artifactsSummary(step, count: 0)),
for (final note in notes)
Padding(padding: const EdgeInsets.only(top: 4), child: Text(note)),
],
);
}
void open() => showArtifactGallery(
context,
steps: runSteps.isEmpty ? <JsonMap>[step] : runSteps,
focusIndex: runSteps.isEmpty ? 0 : visitIndex,
configuredEndpoint: configuredEndpoint,
);
final noteRows = [
for (final note in notes)
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
child: Text(note),
),
];
if (usesCupertinoHost(context)) {
return ListView(
key: const Key('run-visit-body-artifacts'),
children: [
...noteRows,
CupertinoListSection.insetGrouped(
children: [
for (final artifact in artifacts)
_CupertinoArtifactRow(artifact: artifact, onTap: open),
],
),
],
);
}
return ListView(
key: const Key('run-visit-body-artifacts'),
children: [
...noteRows,
for (final artifact in artifacts)
ListTile(
title: Text(artifactDisplayName(artifact)),
subtitle: Text(artifactFactsLabel(artifact)),
trailing: const Icon(Icons.chevron_right),
onTap: open,
),
],
);
}
}
class _CupertinoArtifactRow extends StatelessWidget {
const _CupertinoArtifactRow({required this.artifact, required this.onTap});
final ArtifactRecord artifact;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return CupertinoListTile(
title: Text(artifactDisplayName(artifact)),
subtitle: Text(artifactFactsLabel(artifact)),
trailing: const Icon(CupertinoIcons.chevron_forward),
onTap: onTap,
);
}
}