171 lines
4.8 KiB
Dart
171 lines
4.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:js_interop';
|
|
import 'dart:js_interop_unsafe';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/schedules/domain/editor/schedule_draft.dart';
|
|
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_form.dart';
|
|
|
|
/// Isolated browser fixture for the native saved-schedule form.
|
|
///
|
|
/// flutter build web -t tool/schedule_editor_probe_app.dart
|
|
///
|
|
/// Query: `host=cupertino`, `brightness=dark`, `scale=2`. The injected callback
|
|
/// refuses the first valid submit and accepts the retry; it never opens a
|
|
/// socket or touches a real schedule. Its counters/record are published at
|
|
/// `globalThis.scheduleEditorProbe` for the Chrome probe.
|
|
void main() => runApp(const _ProbeApp());
|
|
|
|
class _ProbeApp extends StatelessWidget {
|
|
const _ProbeApp();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final parameters = Uri.base.queryParameters;
|
|
final cupertino = parameters['host'] == 'cupertino';
|
|
final dark = parameters['brightness'] == 'dark';
|
|
final scale = double.tryParse(parameters['scale'] ?? '') ?? 1.0;
|
|
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
|
data: MediaQuery.of(
|
|
context,
|
|
).copyWith(textScaler: TextScaler.linear(scale)),
|
|
child: app!,
|
|
);
|
|
final home = _ProbeHome(cupertino: cupertino);
|
|
if (cupertino) {
|
|
return CupertinoApp(
|
|
theme: CupertinoThemeData(
|
|
brightness: dark ? Brightness.dark : Brightness.light,
|
|
),
|
|
builder: media,
|
|
home: CupertinoPageScaffold(
|
|
navigationBar: const CupertinoNavigationBar(
|
|
middle: Text('Schedule editor probe'),
|
|
),
|
|
child: SafeArea(child: home),
|
|
),
|
|
);
|
|
}
|
|
return MaterialApp(
|
|
theme: ThemeData(
|
|
brightness: dark ? Brightness.dark : Brightness.light,
|
|
platform: TargetPlatform.android,
|
|
),
|
|
builder: media,
|
|
home: Scaffold(
|
|
appBar: AppBar(title: const Text('Schedule editor probe')),
|
|
body: SafeArea(child: home),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Refusal implements Exception {
|
|
const _Refusal();
|
|
|
|
@override
|
|
String toString() => 'conflict: revision 13 is stale';
|
|
}
|
|
|
|
class _ProbeHome extends StatefulWidget {
|
|
const _ProbeHome({required this.cupertino});
|
|
|
|
final bool cupertino;
|
|
|
|
@override
|
|
State<_ProbeHome> createState() => _ProbeHomeState();
|
|
}
|
|
|
|
class _ProbeHomeState extends State<_ProbeHome> {
|
|
final _draft = ScheduleDraft.create(
|
|
pipelineId: 4,
|
|
version: '2',
|
|
workspace: '/srv/research',
|
|
timezone: 'Europe/London',
|
|
);
|
|
int _submits = 0;
|
|
int _records = 0;
|
|
bool _pending = false;
|
|
bool _refuseNext = true;
|
|
String? _lastError;
|
|
JsonMap? _lastRecord;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_publish();
|
|
}
|
|
|
|
void _publish() {
|
|
globalContext.setProperty(
|
|
'scheduleEditorProbe'.toJS,
|
|
<String, Object?>{
|
|
'submits': _submits,
|
|
'records': _records,
|
|
'pending': _pending,
|
|
'lastError': _lastError,
|
|
'lastRecord': _lastRecord,
|
|
}.jsify(),
|
|
);
|
|
}
|
|
|
|
Future<void> _submit(JsonMap record) async {
|
|
_submits++;
|
|
_pending = true;
|
|
_publish();
|
|
if (mounted) setState(() {});
|
|
await Future<void>.delayed(const Duration(milliseconds: 900));
|
|
if (_refuseNext) {
|
|
_refuseNext = false;
|
|
_pending = false;
|
|
_lastError = 'conflict: revision 13 is stale';
|
|
_publish();
|
|
if (mounted) setState(() {});
|
|
throw const _Refusal();
|
|
}
|
|
_pending = false;
|
|
_records++;
|
|
_lastRecord = record;
|
|
_publish();
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final record = _lastRecord;
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Center(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 640),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
ScheduleEditorForm(
|
|
draft: _draft,
|
|
onSubmit: _submit,
|
|
onCancel: () {},
|
|
),
|
|
if (record != null) ...[
|
|
const SizedBox(height: 24),
|
|
Text(
|
|
'Submitted record',
|
|
style: widget.cupertino
|
|
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
|
: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
const SizedBox(height: 8),
|
|
SelectableText(
|
|
const JsonEncoder.withIndent(' ').convert(record),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|