127 lines
4.4 KiB
Dart
127 lines
4.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../changes/changes.dart';
|
|
|
|
/// The run detail's action and page label. The viewer itself owns the
|
|
/// recorded summary and capture wording, so this bar stays neutral.
|
|
const runChangesLabel = 'Changes';
|
|
const runChangesButtonKey = ValueKey<String>('run-detail-changes');
|
|
|
|
/// 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> runDetailChangeSteps(JsonMap run) {
|
|
final steps = run['steps'];
|
|
if (steps is List<JsonMap>) return steps;
|
|
if (steps is List) return steps.cast<JsonMap>();
|
|
return const <JsonMap>[];
|
|
}
|
|
|
|
const _executingStatuses = {'queued', 'running', 'waiting'};
|
|
|
|
/// Whether the run detail offers the action at all. The opened page is a
|
|
/// snapshot of the recorded steps, so it is offered only once nothing is
|
|
/// executing: the server's own `executing` flag (which can stay true on a
|
|
/// failed run whose step is still active) or a queued/running/waiting status
|
|
/// would otherwise show a page that silently goes stale.
|
|
bool showRunChangesAction(JsonMap run) =>
|
|
run['executing'] != true &&
|
|
!_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
|
|
|
|
/// A standard native button for the run detail body. It opens the recorded
|
|
/// changes in a platform page whose single navigation bar is the only chrome.
|
|
class RunChangesButton extends StatelessWidget {
|
|
const RunChangesButton({super.key, required this.run});
|
|
|
|
final JsonMap run;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final steps = runDetailChangeSteps(run);
|
|
// The web client shows the run-wide aggregate only for a succeeded run; a
|
|
// failed run still keeps each visit's own recorded capture.
|
|
final summary = showRunChangesSummary(run['status']);
|
|
void open() => showRunChanges(context, steps: steps, showSummary: summary);
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoButton.tinted(
|
|
key: runChangesButtonKey,
|
|
onPressed: open,
|
|
child: const Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(CupertinoIcons.doc_text),
|
|
SizedBox(width: 6),
|
|
Text(runChangesLabel),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return FilledButton.tonalIcon(
|
|
key: runChangesButtonKey,
|
|
onPressed: open,
|
|
icon: const Icon(Icons.difference_outlined),
|
|
label: const Text(runChangesLabel),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Opens the already-landed [ChangesViewer] for [steps] on a native page.
|
|
/// The bar is the one title bar; the viewer's own summary and capture facts
|
|
/// are passed through untouched, except for the caller's [showSummary] gate.
|
|
Future<void> showRunChanges(
|
|
BuildContext context, {
|
|
required List<JsonMap> steps,
|
|
required bool showSummary,
|
|
}) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
return Navigator.of(context).push<void>(
|
|
cupertino
|
|
? CupertinoPageRoute<void>(
|
|
builder: (_) =>
|
|
_CupertinoChangesPage(steps: steps, showSummary: showSummary),
|
|
)
|
|
: MaterialPageRoute<void>(
|
|
builder: (_) =>
|
|
_MaterialChangesPage(steps: steps, showSummary: showSummary),
|
|
),
|
|
);
|
|
}
|
|
|
|
class _MaterialChangesPage extends StatelessWidget {
|
|
const _MaterialChangesPage({required this.steps, required this.showSummary});
|
|
|
|
final List<JsonMap> steps;
|
|
final bool showSummary;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Scaffold(
|
|
appBar: AppBar(title: const Text(runChangesLabel)),
|
|
body: SafeArea(
|
|
top: false,
|
|
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
|
),
|
|
);
|
|
}
|
|
|
|
class _CupertinoChangesPage extends StatelessWidget {
|
|
const _CupertinoChangesPage({required this.steps, required this.showSummary});
|
|
|
|
final List<JsonMap> steps;
|
|
final bool showSummary;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => CupertinoPageScaffold(
|
|
navigationBar: const CupertinoNavigationBar(middle: Text(runChangesLabel)),
|
|
child: SafeArea(
|
|
// A CupertinoApp supplies no Material theme; follow the host brightness
|
|
// so the viewer's Material-derived section text stays readable.
|
|
child: Theme(
|
|
data: hostTextTheme(context),
|
|
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
|
),
|
|
),
|
|
);
|
|
}
|