Files
pipelines/app/lib/features/artifacts/ui/artifact_gallery_action.dart
T
alan a6db4ba20e App: run tabs under the header on wide layouts, stable Artifacts tab, spelled-out pipeline status, shared list selection, code block header and edge fades
- Run detail: on a wide window (>= 840, pane >= 600) the tabs are Material
  segments under the run header; phones keep the floating bottom bar.
  Artifacts is always a tab, badged with its count and disabled with 0 (its
  tooltip says why), so Changes never moves.
- Pipelines list: 'Failed · last run 19 Oct' beside the status dot; facts on
  the next line; compact rows keep 'Failed · 19 Oct'.
- Settings: Disconnect is outlined beside a tonal Reconnect.
- Lists: one selection style (tonal fill plus one leading accent bar) for
  runs, pipelines and chats; chat's border, fill and pointer removed.
- Transcript: overflowing blocks fade at the edge with a chevron instead of
  a 'Scroll horizontally' line (semantics hint kept); code blocks get a
  header strip with language and Copy; lighter light-mode code fill.
- Runs list: rows under a day heading show only the time of day.
- Artifact search reveal re-centres once the lazy list's extent settles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 00:55:50 +00:00

113 lines
3.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/transport/pipelines_client.dart';
import '../domain/artifact_chat_context.dart';
import '../domain/artifact_groups.dart';
import 'artifact_external_open.dart';
import 'artifact_gallery_page.dart';
/// The run detail's action label key, so a host can find the one action.
const ValueKey<String> runArtifactsButtonKey = ValueKey<String>(
'run-detail-artifacts',
);
const Set<String> _executingStatuses = {'queued', 'running', 'waiting'};
/// The detail's `steps` exactly as returned by the server. The pushed page
/// snapshots the returned list once, so it never re-derives on each rebuild.
List<JsonMap> runDetailArtifactSteps(JsonMap run) {
final steps = run['steps'];
if (steps is List<JsonMap>) return steps;
if (steps is List) return steps.cast<JsonMap>();
return const <JsonMap>[];
}
/// Whether the run detail offers the gallery action at all: only once the
/// loaded detail actually carries steps. A run with no steps has nothing to
/// list, so the action is absent rather than opening a page that says so.
bool showRunArtifactsAction(JsonMap run) =>
runDetailArtifactSteps(run).isNotEmpty;
/// How many recorded entries the run's gallery lists (stage files plus
/// recorded turn documents), as the gallery header counts them.
int runArtifactCount(JsonMap run) => galleryGroups(
runDetailArtifactSteps(run),
).fold<int>(0, (sum, group) => sum + group.recordedCount);
/// Whether the run is still executing, so the page can say capture pending
/// instead of claiming nothing was recorded.
bool runDetailExecuting(JsonMap run) => _runExecuting(run);
bool _runExecuting(JsonMap run) =>
run['executing'] == true ||
_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
/// The run detail's standard native action that opens the recorded artifact
/// groups. It is composed only when [showRunArtifactsAction] is true.
class RunArtifactsButton extends StatelessWidget {
const RunArtifactsButton({
super.key,
required this.run,
required this.gateway,
this.onSendToChat,
});
final JsonMap run;
final ApiGateway gateway;
final void Function(String draft)? onSendToChat;
@override
Widget build(BuildContext context) {
final steps = runDetailArtifactSteps(run);
void open() => showArtifactGallery(
context,
steps: steps,
executing: _runExecuting(run),
configuredEndpoint: configuredGatewayEndpoint(gateway),
artifactChatContext: ArtifactChatContext(
runId: '${run['id'] ?? ''}',
runTitle: '${run['title'] ?? run['name'] ?? ''}',
pipelineName: '${run['name'] ?? ''}',
pipelineVersion: run['version'] is num
? (run['version'] as num).toInt().toString()
: null,
configuredEndpoint: configuredGatewayEndpoint(gateway),
),
onSendToChat: onSendToChat,
);
return OutlinedButton.icon(
key: runArtifactsButtonKey,
onPressed: open,
icon: const Icon(Icons.inventory_2_outlined),
label: const Text(artifactGalleryTitle),
);
}
}
/// Opens the recorded artifact groups on a native page. The steps are
/// snapshotted once; the page never re-fetches or re-derives them.
Future<void> showArtifactGallery(
BuildContext context, {
required List<JsonMap> steps,
int? focusIndex,
bool executing = false,
String configuredEndpoint = '',
ArtifactExternalOpen openExternal = openArtifactExternally,
ArtifactChatContext? artifactChatContext,
void Function(String draft)? onSendToChat,
}) {
final page = ArtifactGalleryPage(
steps: List<JsonMap>.unmodifiable(steps),
focusIndex: focusIndex,
executing: executing,
configuredEndpoint: configuredEndpoint,
openExternal: openExternal,
artifactChatContext: artifactChatContext,
onSendToChat: onSendToChat,
);
return Navigator.of(
context,
).push<void>(MaterialPageRoute<void>(builder: (_) => page));
}