203 lines
6.8 KiB
Dart
203 lines
6.8 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../core/transport/pipelines_client.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../../shell/shell_bar.dart';
|
|
import 'run_detail_actions.dart';
|
|
import 'run_more_menu.dart';
|
|
import 'run_pipeline_link.dart';
|
|
import 'run_detail_content.dart';
|
|
import 'run_detail_cupertino.dart';
|
|
import 'run_detail_material.dart';
|
|
import 'runs_controller.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,
|
|
});
|
|
|
|
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;
|
|
|
|
@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 cupertino = usesCupertinoHost(context);
|
|
final run = widget.controller.detail;
|
|
if (run == null) return _placeholder(context, cupertino: cupertino);
|
|
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 = cupertino
|
|
? buildCupertinoRunDetail(
|
|
context: context,
|
|
run: run,
|
|
headerActions: headerActions,
|
|
onRunOpened: widget.onRunOpened,
|
|
onOpenPipeline: widget.onOpenPipeline,
|
|
inShellBar: inShellBar,
|
|
detailLoading: widget.controller.detailLoading,
|
|
error: widget.controller.error,
|
|
copying: _copying,
|
|
copyStatus: _copyStatus,
|
|
onBack: widget.onBack,
|
|
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
configuredEndpoint: endpoint,
|
|
initialStageKey: widget.initialStageKey,
|
|
initialVisit: widget.initialVisit,
|
|
)
|
|
: buildMaterialRunDetail(
|
|
context: context,
|
|
run: run,
|
|
headerActions: headerActions,
|
|
onRunOpened: widget.onRunOpened,
|
|
onOpenPipeline: widget.onOpenPipeline,
|
|
inShellBar: inShellBar,
|
|
detailLoading: widget.controller.detailLoading,
|
|
error: widget.controller.error,
|
|
copying: _copying,
|
|
copyStatus: _copyStatus,
|
|
onBack: widget.onBack,
|
|
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
configuredEndpoint: endpoint,
|
|
initialStageKey: widget.initialStageKey,
|
|
initialVisit: widget.initialVisit,
|
|
);
|
|
// The app bar becomes the run's: Back to the list, the run and its
|
|
// more menu. Search and the tab name return when the run closes.
|
|
return ShellBar(
|
|
title: 'Run ${run['id']}',
|
|
onBack: widget.onBack,
|
|
actions: [
|
|
RunMoreMenu(
|
|
run: run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: widget.controller.acceptRunDetail,
|
|
cupertino: cupertino,
|
|
onRunOpened: widget.onRunOpened,
|
|
),
|
|
],
|
|
child: detail,
|
|
);
|
|
},
|
|
);
|
|
|
|
Widget _placeholder(BuildContext context, {required bool cupertino}) {
|
|
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.
|
|
return ShellBar(
|
|
title: 'Run',
|
|
onBack: widget.onBack,
|
|
child: _placeholderBody(cupertino, loading, message),
|
|
);
|
|
}
|
|
|
|
Widget _placeholderBody(bool cupertino, bool loading, String message) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (loading) ...[
|
|
if (cupertino)
|
|
const CupertinoActivityIndicator()
|
|
else
|
|
const CircularProgressIndicator(),
|
|
const SizedBox(height: 12),
|
|
],
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Text(message, textAlign: TextAlign.center),
|
|
),
|
|
const SizedBox(height: 12),
|
|
if (cupertino)
|
|
CupertinoButton(
|
|
onPressed: widget.onBack,
|
|
child: const Text('Back to list'),
|
|
)
|
|
else
|
|
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, {required bool cupertino}) 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 = cupertino ? null : Scaffold.maybeOf(context);
|
|
final inline = cupertino || scaffold == null;
|
|
setState(() {
|
|
_copying = false;
|
|
_copyStatus = inline ? message : null;
|
|
});
|
|
if (!cupertino && scaffold != null) {
|
|
ScaffoldMessenger.maybeOf(
|
|
context,
|
|
)?.showSnackBar(SnackBar(content: Text(message)));
|
|
}
|
|
}
|
|
}
|