5425001d82
One picker offers a new chat (the saved Open in chat harness and model) or any open chat. An existing chat gets the reference appended to its draft and focused, never sent. Artifacts gain the action in their viewer and gallery; the run and pipeline item becomes Send to chat.
106 lines
3.6 KiB
Dart
106 lines
3.6 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 '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;
|
|
|
|
/// 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));
|
|
}
|