f2c33d2a1e
The run detail now offers the web's "Schedule this run" action when the
run names a positive pipeline and pinned version. It opens the existing
create editor seeded from the run and sends nothing until Save.
The seed preserves every field the browser's scheduleDraft({ run })
copies: title (following the title_source rule), all input keys with
prompt kept editable, pinned version, workspace, notify mode, write
paths, tool access, model, stage models and output format. build() emits
the same conditional payload as serializeSchedule.
One request key is minted per editor opening so a refused save retries
without duplicating the schedule. Advanced options are seed-only for
now: the editor has no controls for them yet.
87 lines
3.0 KiB
Dart
87 lines
3.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../../../ui/adaptive/host.dart';
|
|
import '../../data/schedules_repository.dart';
|
|
import '../../domain/editor/schedule_draft.dart';
|
|
import '../../domain/schedule_json.dart';
|
|
import '../pipeline/schedule_pipeline_editor.dart';
|
|
|
|
/// Browser wording for the run detail's independent schedule entry point.
|
|
const scheduleRunActionLabel = 'Schedule this run';
|
|
const scheduleRunActionHint =
|
|
'Save this run\'s prompt and options with an independent timer; '
|
|
'does not rerun it now';
|
|
const scheduleRunActionKey = ValueKey<String>('schedule-run-action');
|
|
|
|
/// Whether [run] names the positive pipeline and pinned version the web client
|
|
/// requires before offering "Schedule this run" (`Number(...) > 0`).
|
|
bool canScheduleRun(JsonMap run) =>
|
|
_positive(jsonInteger(run['pipeline_id'])) &&
|
|
_positive(jsonInteger(run['version']));
|
|
|
|
bool _positive(int? value) => value != null && value > 0;
|
|
|
|
/// The run detail's "Schedule this run" action.
|
|
///
|
|
/// Pressing it only opens the landed create editor over [ScheduleDraft.fromRun]:
|
|
/// the run's prompt, title, pinned version, absolute workspace, notification
|
|
/// mode and advanced options are prefilled and nothing is sent until Save. One
|
|
/// request key is minted per opening and captured by the submit callback, so
|
|
/// retrying a refused save cannot create a duplicate. An accepted save closes
|
|
/// the editor; this action never runs, retries or changes the source run.
|
|
class ScheduleRunAction extends StatefulWidget {
|
|
const ScheduleRunAction({
|
|
super.key,
|
|
required this.run,
|
|
required this.gateway,
|
|
});
|
|
|
|
final JsonMap run;
|
|
final ApiGateway gateway;
|
|
|
|
@override
|
|
State<ScheduleRunAction> createState() => _ScheduleRunActionState();
|
|
}
|
|
|
|
class _ScheduleRunActionState extends State<ScheduleRunAction> {
|
|
bool _opening = false;
|
|
|
|
Future<void> _open() async {
|
|
if (_opening || !canScheduleRun(widget.run)) return;
|
|
_opening = true;
|
|
// Minted once for this editor; every retry inside it reuses the key.
|
|
final requestKey = newScheduleCreateRequestKey();
|
|
final repository = SchedulesRepository(widget.gateway);
|
|
try {
|
|
await openSchedulePipelineEditor(
|
|
context,
|
|
draft: ScheduleDraft.fromRun(widget.run),
|
|
onSubmit: (record) =>
|
|
repository.saveSchedule(record, requestKey: requestKey),
|
|
);
|
|
} finally {
|
|
_opening = false;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!canScheduleRun(widget.run)) return const SizedBox.shrink();
|
|
final cupertino = usesCupertinoHost(context);
|
|
final action = cupertino
|
|
? CupertinoButton(
|
|
key: scheduleRunActionKey,
|
|
onPressed: _open,
|
|
child: const Text(scheduleRunActionLabel),
|
|
)
|
|
: OutlinedButton(
|
|
key: scheduleRunActionKey,
|
|
onPressed: _open,
|
|
child: const Text(scheduleRunActionLabel),
|
|
);
|
|
return Tooltip(message: scheduleRunActionHint, child: action);
|
|
}
|
|
}
|