Files
pipelines/app/lib/features/runs/ui/run_detail_view.dart
T
alan c53dedc544 feat(app): wire retry and restart into the native run detail
Render Retry beside Rename on a stopped failed run under both native
hosts, send only {run_id, request_key} for resume and add
retry_mode=restart for a fresh start, and open the run the accepted
reply names. Keep hidden actions out of the Wrap so native 8/4 dp
spacing is not doubled, and use a literal 2^32 entropy bound because
dart2js evaluates 1 << 32 as 0.

Adds wiring, guard and layout tests, a browser-only key regression and
the retry probe; notes/R2c-wire.md records the checks and limits.
2026-10-21 22:49:26 +01:00

144 lines
4.6 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import 'run_detail_actions.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,
});
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;
@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 headerActions = RunDetailActions(
run: run,
gateway: widget.gateway,
onRunChanged: widget.controller.acceptRunDetail,
onRunOpened: widget.onRunOpened,
);
return cupertino
? buildCupertinoRunDetail(
context: context,
run: run,
headerActions: headerActions,
detailLoading: widget.controller.detailLoading,
error: widget.controller.error,
copying: _copying,
copyStatus: _copyStatus,
onBack: widget.onBack,
onCopy: () => _copyPrompt(prompt ?? '', cupertino: true),
)
: buildMaterialRunDetail(
context: context,
run: run,
headerActions: headerActions,
detailLoading: widget.controller.detailLoading,
error: widget.controller.error,
copying: _copying,
copyStatus: _copyStatus,
onBack: widget.onBack,
onCopy: () => _copyPrompt(prompt ?? '', cupertino: false),
);
},
);
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 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)));
}
}
}