072db8f749
- "Why it failed" banner offers Retry (the retry prompt), Run again… (New run form pre-filled; now allowed for failed runs from the banner) and Open in chat (the run's existing send-to-chat flow). - The run ⋮ menu shows while the detail loads: items listed from the run's list row, disabled until get_run answers (the loading placeholder had no actions, so the menu waited for the full detail). - Pipelines list rows: Run… in the row menu (not for archived pipelines) and a trailing Run button when the list sits beside its detail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
278 lines
9.4 KiB
Dart
278 lines
9.4 KiB
Dart
import '../../../core/servers/server_context.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../core/transport/pipelines_client.dart';
|
|
import '../../../shell/shell_bar.dart';
|
|
import '../../../ui/adaptive/segmented_bar.dart';
|
|
import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
|
import 'run_detail_actions.dart';
|
|
import 'run_more_menu.dart';
|
|
import 'run_pipeline_link.dart';
|
|
import 'run_detail_content.dart';
|
|
import 'run_detail_material.dart';
|
|
import 'run_failure_actions.dart';
|
|
import 'runs_controller.dart';
|
|
import '../../../core/error_advice.dart';
|
|
import '../../../ui/status/error_notice.dart';
|
|
|
|
class RunDetailView extends StatefulWidget {
|
|
const RunDetailView({
|
|
super.key,
|
|
required this.controller,
|
|
required this.gateway,
|
|
required this.onBack,
|
|
this.onRunOpened,
|
|
this.onOpenPipeline,
|
|
this.initialStageKey,
|
|
this.initialVisit,
|
|
this.onOpenInChat,
|
|
this.onSendToChat,
|
|
this.onRunAgain,
|
|
});
|
|
|
|
/// Opens the New run form pre-filled from this run.
|
|
final ValueChanged<JsonMap>? onRunAgain;
|
|
|
|
final RunsController controller;
|
|
|
|
/// The app's shared gateway; the rename action sends through it.
|
|
final ApiGateway gateway;
|
|
final VoidCallback onBack;
|
|
|
|
/// Opens the run named by an accepted retry reply, so the host route follows
|
|
/// the server-identified new run. Null keeps the detail on the retried run.
|
|
final ValueChanged<num>? onRunOpened;
|
|
|
|
/// Opens the run's pipeline from its name in the header.
|
|
final OpenPipeline? onOpenPipeline;
|
|
|
|
/// The route's stage and visit, forwarded to the tab body so a `/runs/:id/
|
|
/// stage/:key[?visit=N]` deep link opens that recorded visit. Null is the
|
|
/// plain detail.
|
|
final String? initialStageKey;
|
|
final int? initialVisit;
|
|
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
|
|
final Future<void> Function(BuildContext, JsonMap, String)? onSendToChat;
|
|
|
|
@override
|
|
State<RunDetailView> createState() => _RunDetailViewState();
|
|
}
|
|
|
|
class _RunDetailViewState extends State<RunDetailView> {
|
|
bool _copying = false;
|
|
String? _copyStatus;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => AnimatedBuilder(
|
|
animation: widget.controller,
|
|
builder: (context, _) {
|
|
final run = widget.controller.detail;
|
|
if (run == null) return _placeholder(context);
|
|
final prompt = detailPrompt(run);
|
|
final endpoint = configuredGatewayEndpoint(widget.gateway);
|
|
final headerActions = RunDetailActions(
|
|
run: run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
onRunOpened: widget.onRunOpened,
|
|
retry: false,
|
|
);
|
|
final inShellBar = ShellBar.available(context);
|
|
final detail = buildMaterialRunDetail(
|
|
context: context,
|
|
run: run,
|
|
headerActions: headerActions,
|
|
detailLoading: widget.controller.detailLoading,
|
|
error: widget.controller.error,
|
|
copying: _copying,
|
|
copyStatus: _copyStatus,
|
|
onCopy: () => _copyPrompt(prompt ?? ''),
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
configuredEndpoint: endpoint,
|
|
initialStageKey: widget.initialStageKey,
|
|
initialVisit: widget.initialVisit,
|
|
onSendToChat: widget.onSendToChat == null
|
|
? null
|
|
: (draft) => widget.onSendToChat!(context, run, draft),
|
|
failureActions: RunFailureActions(
|
|
run: run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
onRunOpened: widget.onRunOpened,
|
|
onRunAgain: widget.onRunAgain,
|
|
onOpenInChat: widget.onOpenInChat,
|
|
),
|
|
);
|
|
// The top bar becomes the run's: Back to the list, its title over its
|
|
// number, pipeline and version (a link to that pipeline when the host
|
|
// can open it) and its more menu, so the body repeats none of them.
|
|
// Search and the tab name return when the run closes.
|
|
final title = detailTitle(run);
|
|
final subtitle = detailSubtitle(run);
|
|
final openPipeline = _openPipeline(run);
|
|
final pipelineName = detailPipeline(run);
|
|
final pipelineAction = openPipeline == null
|
|
? null
|
|
: Semantics(
|
|
button: true,
|
|
label: 'Open pipeline $pipelineName',
|
|
excludeSemantics: true,
|
|
child: GestureDetector(
|
|
key: runPipelineLinkKey,
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: openPipeline,
|
|
child: const Padding(
|
|
padding: EdgeInsets.all(12),
|
|
child: Icon(Icons.account_tree_outlined),
|
|
),
|
|
),
|
|
);
|
|
final more = RunMoreMenu(
|
|
run: run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
onRunOpened: widget.onRunOpened,
|
|
onDeleted: widget.controller.applyDeletion,
|
|
onOpenInChat: widget.onOpenInChat,
|
|
onRunAgain: widget.onRunAgain,
|
|
);
|
|
if (inShellBar) {
|
|
return ShellBar(
|
|
title: title,
|
|
subtitle: ServerContext.metadata(context, subtitle),
|
|
onTitlePressed: openPipeline,
|
|
expandableTitle: true,
|
|
titleAction: pipelineAction,
|
|
titleSemanticLabel: 'Run title $title',
|
|
onBack: widget.onBack,
|
|
actions: [more],
|
|
hideNavigation: true,
|
|
child: detail,
|
|
);
|
|
}
|
|
// On its own the run draws the same bar over its content.
|
|
return SegmentedBarOverlay(
|
|
bar: SegmentedBar(
|
|
leading: SegmentedBackButton(
|
|
key: const Key('run-detail-back'),
|
|
onPressed: widget.onBack,
|
|
),
|
|
title: title,
|
|
subtitle: ServerContext.metadata(context, subtitle),
|
|
onTitlePressed: openPipeline,
|
|
expandableTitle: true,
|
|
titleAction: pipelineAction,
|
|
titleSemanticLabel: 'Run title $title',
|
|
actions: [more],
|
|
),
|
|
child: detail,
|
|
);
|
|
},
|
|
);
|
|
|
|
/// Opens the run's pipeline at its pinned version, or null when the run
|
|
/// names none or the host cannot navigate.
|
|
VoidCallback? _openPipeline(JsonMap run) {
|
|
final id = runPipelineId(run);
|
|
final open = widget.onOpenPipeline;
|
|
if (id == null || open == null) return null;
|
|
final version = run['version'];
|
|
return () => open(id, version is num ? version.toInt() : 0);
|
|
}
|
|
|
|
Widget _placeholder(BuildContext context) {
|
|
final loading = widget.controller.detailLoading;
|
|
final message = loading
|
|
? 'Loading run details…'
|
|
: widget.controller.error ?? 'Run details unavailable.';
|
|
// Back stays available while the detail is pending as well as after a
|
|
// failure, so a slow or refused request can never trap the destination.
|
|
// The more menu is there from the first frame: while the detail loads its
|
|
// items are listed from the run's list row, disabled until the detail
|
|
// they act on arrives.
|
|
final pending = _pendingRun();
|
|
return ShellBar(
|
|
title: 'Run',
|
|
onBack: widget.onBack,
|
|
hideNavigation: true,
|
|
actions: [
|
|
if (loading && pending != null)
|
|
RunMoreMenu(
|
|
run: pending,
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
onDeleted: widget.controller.applyDeletion,
|
|
onOpenInChat: widget.onOpenInChat,
|
|
onRunAgain: widget.onRunAgain,
|
|
pending: true,
|
|
),
|
|
],
|
|
child: _placeholderBody(loading, message),
|
|
);
|
|
}
|
|
|
|
/// The selected run as its list row knows it, else only its id; null when
|
|
/// no run is selected.
|
|
JsonMap? _pendingRun() {
|
|
final id = widget.controller.selectedRunId;
|
|
if (id == null) return null;
|
|
for (final run in widget.controller.runs) {
|
|
if (run['id'] == id) return run;
|
|
}
|
|
return {'id': id};
|
|
}
|
|
|
|
Widget _placeholderBody(bool loading, String message) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (loading) ...[
|
|
const CircularProgressIndicator(),
|
|
const SizedBox(height: 12),
|
|
],
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: loading || errorAdvice(message) == null
|
|
? Text(message, textAlign: TextAlign.center)
|
|
: ErrorNotice(error: message, textAlign: TextAlign.center),
|
|
),
|
|
const SizedBox(height: 12),
|
|
FilledButton(
|
|
onPressed: widget.onBack,
|
|
child: const Text('Back to list'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Copies the stored prompt byte-for-byte. A refusal is surfaced, never
|
|
/// replaced by copying a title or the formatted detail.
|
|
Future<void> _copyPrompt(String prompt) async {
|
|
if (_copying) return;
|
|
setState(() => _copying = true);
|
|
String message;
|
|
try {
|
|
await Clipboard.setData(ClipboardData(text: prompt));
|
|
message = 'Prompt copied to clipboard.';
|
|
} catch (_) {
|
|
message = 'Could not copy prompt to clipboard.';
|
|
}
|
|
if (!mounted) return;
|
|
final scaffold = Scaffold.maybeOf(context);
|
|
setState(() {
|
|
_copying = false;
|
|
_copyStatus = scaffold == null ? message : null;
|
|
});
|
|
if (scaffold != null) {
|
|
ScaffoldMessenger.maybeOf(
|
|
context,
|
|
)?.showSnackBar(SnackBar(content: Text(message)));
|
|
}
|
|
}
|
|
}
|