feat(app): run and stage artifacts share one gallery grid with image thumbnails and file-type icons
This commit is contained in:
@@ -382,6 +382,8 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
groups: groups,
|
||||
selectedIdentity: _selectedIdentity,
|
||||
onSelected: _select,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
fetch: widget.fetch,
|
||||
);
|
||||
if (widget.embedded) return body;
|
||||
if (usesCupertinoHost(context)) {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
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';
|
||||
import '../domain/artifact_url.dart';
|
||||
import 'artifact_row_labels.dart';
|
||||
import 'artifact_viewer_fetch.dart';
|
||||
|
||||
/// One artifact in the gallery grid: a thumbnail for an image, otherwise an
|
||||
/// icon for its kind of file, with its name and facts underneath.
|
||||
class ArtifactTile extends StatefulWidget {
|
||||
const ArtifactTile({
|
||||
super.key,
|
||||
required this.group,
|
||||
required this.artifact,
|
||||
required this.selected,
|
||||
required this.configuredEndpoint,
|
||||
required this.fetch,
|
||||
this.onSelected,
|
||||
});
|
||||
|
||||
final ArtifactGroup group;
|
||||
final ArtifactRecord artifact;
|
||||
final bool selected;
|
||||
final String configuredEndpoint;
|
||||
final ArtifactFetch fetch;
|
||||
final ArtifactSelected? onSelected;
|
||||
|
||||
@override
|
||||
State<ArtifactTile> createState() => _ArtifactTileState();
|
||||
}
|
||||
|
||||
class _ArtifactTileState extends State<ArtifactTile> {
|
||||
Future<ArtifactFetchResult>? _thumbnail;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final artifact = widget.artifact;
|
||||
final format = artifactPreviewFormat(artifact.contentType, artifact.name);
|
||||
final resolved = artifact.hasUrl
|
||||
? resolveArtifactUrl(widget.configuredEndpoint, artifact.url)
|
||||
: null;
|
||||
// Only same-origin images load a thumbnail, through the app's own fetch.
|
||||
if (format == ArtifactPreviewFormat.image &&
|
||||
resolved != null &&
|
||||
!resolved.external) {
|
||||
_thumbnail = widget.fetch(resolved.uri);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
final artifact = widget.artifact;
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final surface = cupertino
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final border = widget.selected
|
||||
? (cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary)
|
||||
: (cupertino
|
||||
? CupertinoColors.separator.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.outlineVariant);
|
||||
final icon = Icon(
|
||||
artifactKindIcon(artifact, cupertino: cupertino),
|
||||
size: 40,
|
||||
color: secondary,
|
||||
);
|
||||
final preview = _thumbnail == null
|
||||
? Center(child: icon)
|
||||
: FutureBuilder<ArtifactFetchResult>(
|
||||
future: _thumbnail,
|
||||
builder: (context, snapshot) {
|
||||
final result = snapshot.data;
|
||||
if (result == null || !result.ok || result.bytes.isEmpty) {
|
||||
return Center(child: icon);
|
||||
}
|
||||
return Image.memory(
|
||||
result.bytes,
|
||||
fit: BoxFit.cover,
|
||||
gaplessPlayback: true,
|
||||
errorBuilder: (_, _, _) => Center(child: icon),
|
||||
);
|
||||
},
|
||||
);
|
||||
final name = artifactDisplayName(artifact);
|
||||
final facts = artifactFactsLabel(artifact);
|
||||
final body = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 4 / 3,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(11)),
|
||||
child: ColoredBox(color: surface, child: preview),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
Text(
|
||||
facts,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: secondary, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
final onSelected = widget.onSelected;
|
||||
void tap() => onSelected?.call(widget.group, artifact);
|
||||
final decorated = DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: border, width: widget.selected ? 2 : 1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: body,
|
||||
);
|
||||
return Semantics(
|
||||
button: onSelected != null,
|
||||
selected: widget.selected,
|
||||
label: '$name, $facts',
|
||||
excludeSemantics: true,
|
||||
onTap: onSelected == null ? null : tap,
|
||||
child: cupertino
|
||||
? GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: onSelected == null ? null : tap,
|
||||
child: decorated,
|
||||
)
|
||||
: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: onSelected == null ? null : tap,
|
||||
child: decorated,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The icon for an artifact's kind of file, when it has no thumbnail.
|
||||
IconData artifactKindIcon(ArtifactRecord artifact, {required bool cupertino}) {
|
||||
final name = artifact.name.toLowerCase();
|
||||
final format = artifactPreviewFormat(artifact.contentType, artifact.name);
|
||||
if (name.endsWith('.zip') || name.endsWith('.tar') || name.endsWith('.gz')) {
|
||||
return cupertino ? CupertinoIcons.archivebox : Icons.folder_zip_outlined;
|
||||
}
|
||||
if (name.endsWith('.pdf')) {
|
||||
return cupertino ? CupertinoIcons.doc_richtext : Icons.picture_as_pdf;
|
||||
}
|
||||
return switch (format) {
|
||||
ArtifactPreviewFormat.image =>
|
||||
cupertino ? CupertinoIcons.photo : Icons.image_outlined,
|
||||
ArtifactPreviewFormat.video =>
|
||||
cupertino ? CupertinoIcons.film : Icons.movie_outlined,
|
||||
ArtifactPreviewFormat.markdown =>
|
||||
cupertino ? CupertinoIcons.doc_text : Icons.article_outlined,
|
||||
ArtifactPreviewFormat.text =>
|
||||
cupertino ? CupertinoIcons.doc_plaintext : Icons.description_outlined,
|
||||
ArtifactPreviewFormat.table =>
|
||||
cupertino ? CupertinoIcons.table : Icons.table_chart_outlined,
|
||||
ArtifactPreviewFormat.html => cupertino ? CupertinoIcons.globe : Icons.html,
|
||||
ArtifactPreviewFormat.none =>
|
||||
cupertino ? CupertinoIcons.doc : Icons.insert_drive_file_outlined,
|
||||
};
|
||||
}
|
||||
@@ -3,9 +3,9 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../domain/artifact_groups.dart';
|
||||
import '../domain/artifact_record.dart';
|
||||
import 'artifact_document_section.dart';
|
||||
import 'artifact_record_row.dart';
|
||||
import 'artifact_tile.dart';
|
||||
import 'artifact_viewer_fetch.dart';
|
||||
import 'artifact_row_labels.dart';
|
||||
|
||||
export 'artifact_row_labels.dart'
|
||||
@@ -33,8 +33,14 @@ class ArtifactVisitList extends StatelessWidget {
|
||||
this.header,
|
||||
this.selectedIdentity,
|
||||
this.onSelected,
|
||||
this.configuredEndpoint = '',
|
||||
this.fetch = fetchArtifact,
|
||||
});
|
||||
|
||||
/// Resolves an image's url for its thumbnail; [fetch] loads it.
|
||||
final String configuredEndpoint;
|
||||
final ArtifactFetch fetch;
|
||||
|
||||
/// An optional page header rendered above the first section, inside the same
|
||||
/// scroll view.
|
||||
///
|
||||
@@ -62,21 +68,21 @@ class ArtifactVisitList extends StatelessWidget {
|
||||
children: [
|
||||
?header,
|
||||
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(
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 4),
|
||||
// `container` keeps the heading a separate semantics node.
|
||||
child: Semantics(
|
||||
container: true,
|
||||
header: true,
|
||||
child: Text(artifactGroupLabel(group)),
|
||||
child: Text(
|
||||
artifactGroupLabel(group),
|
||||
style: TextStyle(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
hasLeading: false,
|
||||
children: [
|
||||
for (var index = 0; index < group.artifacts.length; index += 1)
|
||||
_row(group, group.artifacts[index], index),
|
||||
],
|
||||
),
|
||||
_grid(group),
|
||||
if (group.documents.isNotEmpty)
|
||||
ArtifactDocumentSection(
|
||||
group: group,
|
||||
@@ -103,13 +109,7 @@ class ArtifactVisitList extends StatelessWidget {
|
||||
child: Text(artifactGroupLabel(group), style: headingStyle),
|
||||
),
|
||||
),
|
||||
for (var index = 0; index < group.artifacts.length; index += 1) ...[
|
||||
// A hairline between rows, inset to the row's own text, is the
|
||||
// Material list idiom the web list also uses; it never follows the
|
||||
// last row, so a section ends on its content, not on a rule.
|
||||
if (index > 0) const Divider(height: 1, indent: 16, endIndent: 16),
|
||||
_row(group, group.artifacts[index], index),
|
||||
],
|
||||
_grid(group),
|
||||
if (group.documents.isNotEmpty)
|
||||
ArtifactDocumentSection(
|
||||
group: group,
|
||||
@@ -121,17 +121,43 @@ class ArtifactVisitList extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
/// A group's artifacts as a grid: two tiles across on a phone, more as the
|
||||
/// pane widens.
|
||||
Widget _grid(ArtifactGroup group) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const gap = 12.0;
|
||||
final width = constraints.maxWidth - 32;
|
||||
final columns = (width / 170).floor().clamp(2, 6);
|
||||
final tile = (width - gap * (columns - 1)) / columns;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
|
||||
child: Wrap(
|
||||
spacing: gap,
|
||||
runSpacing: gap,
|
||||
children: [
|
||||
for (var index = 0; index < group.artifacts.length; index += 1)
|
||||
SizedBox(
|
||||
width: tile,
|
||||
child: ArtifactTile(
|
||||
key: ValueKey<String>(
|
||||
'${artifactVisitIdentity(group, group.artifacts[index])}'
|
||||
'\u0000$index',
|
||||
),
|
||||
group: group,
|
||||
artifact: group.artifacts[index],
|
||||
selected:
|
||||
selectedIdentity ==
|
||||
artifactVisitIdentity(group, group.artifacts[index]),
|
||||
configuredEndpoint: configuredEndpoint,
|
||||
fetch: fetch,
|
||||
onSelected: onSelected,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _NoArtifacts extends StatelessWidget {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
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';
|
||||
import '../../artifacts/ui/artifact_gallery_page.dart';
|
||||
|
||||
/// The visit's recorded stage artifacts, in recorded order.
|
||||
///
|
||||
@@ -36,77 +30,16 @@ class RunVisitArtifacts extends StatelessWidget {
|
||||
final List<JsonMap> runSteps;
|
||||
final String configuredEndpoint;
|
||||
|
||||
/// The same gallery as the run's Artifacts tab, focused on this visit.
|
||||
@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,
|
||||
Widget build(BuildContext context) => KeyedSubtree(
|
||||
key: const Key('run-visit-body-artifacts'),
|
||||
child: ArtifactGalleryPage(
|
||||
key: ValueKey('run-visit-artifacts-$visitIndex'),
|
||||
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,
|
||||
);
|
||||
}
|
||||
embedded: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user