merge(app): land func-repair-pending
This commit is contained in:
@@ -63,10 +63,28 @@ class SessionExportRepairAction extends StatefulWidget {
|
|||||||
_SessionExportRepairActionState();
|
_SessionExportRepairActionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `run:sequence` repairs in flight, shared by every mounted control, as
|
||||||
|
/// the web's page-level `sessionRepairs` set: leaving the Session section and
|
||||||
|
/// returning before the reply cannot send the same repair twice.
|
||||||
|
final ValueNotifier<Set<String>> pendingSessionExportRepairs = ValueNotifier(
|
||||||
|
const <String>{},
|
||||||
|
);
|
||||||
|
|
||||||
|
String _repairKey(num runId, int sequence) => '$runId:$sequence';
|
||||||
|
|
||||||
class _SessionExportRepairActionState extends State<SessionExportRepairAction> {
|
class _SessionExportRepairActionState extends State<SessionExportRepairAction> {
|
||||||
bool _sending = false;
|
|
||||||
String? _refusal;
|
String? _refusal;
|
||||||
|
|
||||||
|
bool get _sending => pendingSessionExportRepairs.value.contains(
|
||||||
|
_repairKey(widget.runId, widget.sequence),
|
||||||
|
);
|
||||||
|
|
||||||
|
void _setPending(String key, bool pending) {
|
||||||
|
final next = {...pendingSessionExportRepairs.value};
|
||||||
|
pending ? next.add(key) : next.remove(key);
|
||||||
|
pendingSessionExportRepairs.value = next;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant SessionExportRepairAction oldWidget) {
|
void didUpdateWidget(covariant SessionExportRepairAction oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
@@ -74,7 +92,6 @@ class _SessionExportRepairActionState extends State<SessionExportRepairAction> {
|
|||||||
// visit the pane happens to show next.
|
// visit the pane happens to show next.
|
||||||
if (oldWidget.runId != widget.runId ||
|
if (oldWidget.runId != widget.runId ||
|
||||||
oldWidget.sequence != widget.sequence) {
|
oldWidget.sequence != widget.sequence) {
|
||||||
_sending = false;
|
|
||||||
_refusal = null;
|
_refusal = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,10 +103,9 @@ class _SessionExportRepairActionState extends State<SessionExportRepairAction> {
|
|||||||
if (_sending || widget.running) return;
|
if (_sending || widget.running) return;
|
||||||
final runId = widget.runId;
|
final runId = widget.runId;
|
||||||
final sequence = widget.sequence;
|
final sequence = widget.sequence;
|
||||||
setState(() {
|
final key = _repairKey(runId, sequence);
|
||||||
_sending = true;
|
_setPending(key, true);
|
||||||
_refusal = null;
|
setState(() => _refusal = null);
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
final detail = await RunsRepository(
|
final detail = await RunsRepository(
|
||||||
widget.gateway,
|
widget.gateway,
|
||||||
@@ -100,12 +116,17 @@ class _SessionExportRepairActionState extends State<SessionExportRepairAction> {
|
|||||||
if (!_owns(runId, sequence)) return;
|
if (!_owns(runId, sequence)) return;
|
||||||
setState(() => _refusal = describeSessionExportRepairError(error));
|
setState(() => _refusal = describeSessionExportRepairError(error));
|
||||||
} finally {
|
} finally {
|
||||||
if (_owns(runId, sequence)) setState(() => _sending = false);
|
_setPending(key, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => ValueListenableBuilder<Set<String>>(
|
||||||
|
valueListenable: pendingSessionExportRepairs,
|
||||||
|
builder: (context, _, _) => _build(context),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _build(BuildContext context) {
|
||||||
final enabled = !_sending && !widget.running;
|
final enabled = !_sending && !widget.running;
|
||||||
final label = _sending
|
final label = _sending
|
||||||
? sessionExportRepairBusyLabel
|
? sessionExportRepairBusyLabel
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/actions/session_export_repair_action.dart';
|
||||||
|
|
||||||
|
class _HeldGateway implements ApiGateway {
|
||||||
|
final requests = <JsonMap>[];
|
||||||
|
final reply = Completer<JsonMap>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<JsonMap> get frames => const Stream.empty();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||||
|
requests.add({'type': type, ...fields});
|
||||||
|
return reply.future;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _host(ApiGateway gateway) => MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: SessionExportRepairAction(
|
||||||
|
runId: 7,
|
||||||
|
sequence: 2,
|
||||||
|
gateway: gateway,
|
||||||
|
running: false,
|
||||||
|
onRepaired: (_) {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('leaving and returning mid-repair cannot send it twice', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final gateway = _HeldGateway();
|
||||||
|
await tester.pumpWidget(_host(gateway));
|
||||||
|
await tester.tap(find.text(sessionExportRepairLabel));
|
||||||
|
await tester.pump();
|
||||||
|
expect(gateway.requests, hasLength(1));
|
||||||
|
|
||||||
|
// The Session section unmounts and mounts again before the reply.
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pumpWidget(_host(gateway));
|
||||||
|
expect(find.text(sessionExportRepairBusyLabel), findsOneWidget);
|
||||||
|
await tester.tap(find.text(sessionExportRepairBusyLabel));
|
||||||
|
await tester.pump();
|
||||||
|
expect(gateway.requests, hasLength(1));
|
||||||
|
|
||||||
|
gateway.reply.complete({
|
||||||
|
'run_detail': {'id': 7},
|
||||||
|
});
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text(sessionExportRepairLabel), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user